The survPCA
package estimates the covariance matrix for martingales and counting processes both in the semi-competing risk setting and the no competing risk setting.
devtools::install_github("blangworthy/survPCA")
library(survPCA)
library(survPCA)
library(MASS)
#####Example without competing risks
###In this example we simulate 4 non-competing events and calculate the martingale and counting process
###covariance and correlation matrices. All events have exponential 1 distribution and we estimate the
###covariance/correlation matrices at timepoint 1.
n <- 200 # sample size
sigma <- toeplitz(c(1,0.6,0.4,0.2)) # Correlation structure for gaussian copula
samps <- mvrnorm(n,rep(0,4),sigma) #Simulate from multivariate normal
psamps <- pnorm(samps) #Transform marginals to uniform
expsamps <- -log(1-psamps) #Transform marginals to exponential(1), this is failure time
cens <- runif(n,min=0,max=4) #Censoring time
eventsamps <-apply(expsamps,2,function(x)ifelse(x< cens,1,0)) #Censoring indicator
observed_time <- apply(expsamps,2,function(x) pmin(x,cens)) #Minimum of failure time and censoring time
cov_est_data <- cbind(observed_time,eventsamps) #Data in format for CovMatNoComp function
t <- 1 #Time to estimate martingale/counting process covariance and correlation matrices
cov_out <- CovMatNoComp(data = cov_est_data,p = 4,t = t) #Gives output of martingale/counting process correlation and covariance matrices
pc_mart_cor <- eigen(cov_out$CorMart)$vectors # PC directions for martingale correlation matrix
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.