README.md

survPCA: A package for estimating martingale and counting process covariance matrix at a specified time

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.

Installation

devtools::install_github("blangworthy/survPCA")
library(survPCA)

Examples

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


blangworthy/survPCA documentation built on Oct. 3, 2020, 3:04 p.m.