Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

swh:1:snp:6a0ac420dcf26f4ce7b9c8b5d3c5816f5620bd13
  • Code
  • Branches (20)
  • Releases (0)
    • Branches
    • Releases
    • HEAD
    • refs/heads/master
    • refs/tags/1.2.2
    • refs/tags/1.3.1
    • refs/tags/1.3.2
    • refs/tags/1.3.4
    • refs/tags/1.4.0
    • refs/tags/1.4.1
    • refs/tags/1.4.2
    • refs/tags/1.4.4
    • refs/tags/1.4.5
    • refs/tags/1.5.0
    • refs/tags/1.5.1
    • refs/tags/1.5.2
    • refs/tags/1.5.5
    • refs/tags/1.5.6
    • refs/tags/1.5.7
    • refs/tags/1.5.8
    • refs/tags/1.5.9
    • refs/tags/1.6.1
    • refs/tags/1.6.2
    No releases to show
  • ce51085
  • /
  • R
  • /
  • tvc.coxph.R
Raw File Download

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
  • revision
  • snapshot
content badge Iframe embedding
swh:1:cnt:82bb677edf4f36697763f16568004085f1b2156a
directory badge Iframe embedding
swh:1:dir:47f94e4cd5f75dc44d576eace1626d60791e64fc
revision badge
swh:1:rev:11f1ef137931871a851aa94ab98296376fc10888
snapshot badge
swh:1:snp:6a0ac420dcf26f4ce7b9c8b5d3c5816f5620bd13

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • content
  • directory
  • revision
  • snapshot
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Tip revision: 11f1ef137931871a851aa94ab98296376fc10888 authored by Mark Clements on 08 March 2023, 12:20:05 UTC
version 1.6.2
Tip revision: 11f1ef1
tvc.coxph.R
setClass("tvcCoxph", contains="mle2")
## setClass("tvcCoxphList", contains="list")

cox.tvc <- function(obj,var=NULL,method="logt") {
    stopifnot(attr(obj$y,"type") == "right")
    if (is.null(var))
        return(as(lapply(attr(obj$terms,"term.labels"),
                      function(name) cox.tvc(obj, var=name,method=method)),
                  "tvcCoxList"))
    method <- match.arg(method)
    y <- as.matrix(obj$y)
    time <- y[,1]
    status <- y[,2]
    X <- as.matrix(model.matrix(obj))
    index <- order(time,-status)
    X <- X[index, , drop = FALSE]
    time <- time[index]
    status <- status[index]
    k <- match(var,attr(obj$terms,"term.labels"))
    beta <- c(coef(obj),0)
    names(beta) <- c(names(coef(obj)),sprintf("%s:log(t)",var))
    minuslogl <- function(beta) -.Call("test_cox_tvc2",
                                   list(time=time,event=status,X=X,beta=beta,k=k-1),PACKAGE="rstpm2")
    gr <- function(beta) -.Call("test_cox_tvc2_grad",
                                list(time=time,event=status,X=X,beta=beta,k=k-1),PACKAGE="rstpm2")
    parnames(minuslogl) <- parnames(gr) <- names(beta)
    fit <- mle2(start=beta,
                 minuslogl = minuslogl,
                 gr = gr,
                 method="BFGS")
    fit@data <- list(object=obj,k=k,var=var)
    ## return the mle2 object
    as(fit,"tvcCoxph")
}

setMethod("show", "tvcCoxph", function(object) print(summary(object)))

setMethod("plot", signature(x="tvcCoxph", y="missing"),
          function(x,y,
                   add=FALSE,rug=!add,
                   type="l",lty=c(1,2,2),col=1,ylab="Effect",log="y",...) {
              obj <- x@data$object
              y <- as.matrix(obj$y)
              time <- y[,1]
              status <- y[,2]
              timek <- seq(min(time[status==1]), max(time[status==1]), length=301)
              Xk <- cbind(1,log(timek))
              k <- x@data$k
              index <- c(k,length(coef(x)))
              betak <- coef(x)[index]
              fitted <- as.vector(Xk %*% betak)
              gd <- t(Xk)
              se.fit <- sqrt(colSums(gd * (vcov(x)[index,index] %*% gd)))
              if (add) {
                  matlines(timek,exp(fitted+cbind(0,-1.96*se.fit,1.96*se.fit)),lty=lty,col=col,...)
              } else {
                  matplot(timek,exp(fitted+cbind(0,-1.96*se.fit,1.96*se.fit)),type=type,lty=lty,col=col,ylab=ylab,log=log,...)
              }
              abline(h=exp(coef(obj)[k]),lty=3)
              if (rug)
                  rug(time[status==1])
          })

back to top

Software Heritage — Copyright (C) 2015–2025, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Content policy— Contact— JavaScript license information— Web API