Title: | Inverse Probability Weighted Cox Model with Corrected Sandwich Variance |
---|---|
Description: | An implementation of corrected sandwich variance (CSV) estimation method for making inference of marginal hazard ratios (HR) in inverse probability weighted (IPW) Cox model without and with clustered data, proposed by Shu, Young, Toh, and Wang (2019) in their paper under revision for Biometrics. Both conventional inverse probability weights and stabilized weights are implemented. Logistic regression model is assumed for propensity score model. |
Authors: | Di Shu <[email protected]>, Rui Wang <[email protected]> |
Maintainer: | Di Shu <[email protected]> |
License: | GPL (>= 2) |
Version: | 1.0 |
Built: | 2025-02-15 04:54:13 UTC |
Source: | https://github.com/cran/ipwCoxCSV |
This package is an implementation of the corrected sandwich variance (CSV) estimation method for making inference of marginal hazard ratios (HR) in inverse probability weighted (IPW) Cox model without and with clustered data, under both the conventional inverse probability weights and the stabilized weights, proposed by Shu, Young, Toh, and Wang (2019). Logistic regression model is assumed for propensity score model.
The ipwCoxCSV
package implements the corrected sandwich variance estimation method for making inference of marginal hazard ratios in inverse probability weighted Cox model without and with clustered data, under both the conventional inverse probability weights and the stabilized weights, proposed by Shu, Young, Toh, and Wang (2019). This sandwich type variance estimation is referred to as corrected sandwich variance estimation, because it takes into account the uncertainty in weight estimation. The function ipwCoxInd
implements the corrected sandwich variance estimation method without clustered data (i.e., assuming independence among observations). The function ipwCoxCluster
implements the corrected sandwich variance estimation method with clustered data (i.e., allowing for within-cluster correlation).
Di Shu and Rui Wang
Maintainer: Di Shu <[email protected]>
Shu D, Young JG, Toh S, Wang R (2019). Variance estimation in inverse probability weighted Cox model. Biometrics, under revision.
Inference of marginal hazard ratios (HR) in inverse probability weighted (IPW) Cox model with clustered data, under both the conventional inverse probability weights and the stabilized weights. Corrected sandwich variance (CSV) estimation method is used for variance estimation of estimated log marginal hazard ratios.
ipwCoxCluster(data, indID, indA, indX, indStatus, indTime, ties = "breslow", confidence = 0.95)
ipwCoxCluster(data, indID, indA, indX, indStatus, indTime, ties = "breslow", confidence = 0.95)
data |
A clustered dataset to be analyzed in the form of R data frame. |
indID |
A column name indicating the cluster variable. Observations from the same cluster have the same indID value. |
indA |
A column name indicating the treatment variable. |
indX |
A vector of column names indicating the covariates included in the propensity score model. |
indStatus |
A column name indicating the non-censoring status (1 if observed and 0 if censored). |
indTime |
A column name indicating the outcome variable, i.e., min(true event time, censoring time). |
ties |
A character string indicating the method ("efron","breslow",or "exact") to deal with tied events for point estimation; the default is "breslow". For variance estimation, Breslow method is used to deal with tied events. |
confidence |
A confidence level between 0 and 1; the default is 0.95 corresponding to a 95 per cent confidence interval. |
A matrix of inference results from inverse probability weighted Cox model with clustered data. The first and the second rows report log marginal hazard ratio estimate and associated corrected sandwich based standard error, marginal hazard ratio estimate and associated normality-based confidence interval, under conventional inverse probability weights and stabilized weights, respectively.
#simulate a dataset under marginal hazard ratio 1.5 with clustering set.seed(100) n=300 oneGene<-function(id){ tau=0.7 alpha=(1/tau-1)/2 u1=runif(1) u2=runif(1) af=(1-u2)^(-1/alpha) T0v1=-log(1-u2) T0v2=alpha*log((1-af)+af*((1-u1)^(-1/(1+alpha)))) T0=c(T0v1,T0v2) ZZZ=rep(rnorm(1),2) X1before= 0.5*(T0+0.2)/(T0+1)+0.3*ZZZ X1=mean(X1before) X2= 1/log(1.3*T0+3)-0.3*ZZZ X3= rbinom(2,1,0.3+0.5/(T0+1)) A=rbinom(2,1,1/(1+exp(1-2*X1-X2-X3))) Ttime <- T0*exp(-log(1.5)*A) rateC=0.5 C <- rexp(2, rate=rateC) time <- pmin(Ttime, C) status <- as.numeric(Ttime <= C) cbind(id=id,time=time,status=status,A=A,X1=X1,X2=X2,X3=X3) } da=as.data.frame(do.call("rbind",lapply(1:n,oneGene))) head(da) #inference results for marginal hazard ratio ipwCoxCluster(data=da,indID="id",indA="A",indX=c("X1","X2","X3"),indStatus="status",indTime="time")
#simulate a dataset under marginal hazard ratio 1.5 with clustering set.seed(100) n=300 oneGene<-function(id){ tau=0.7 alpha=(1/tau-1)/2 u1=runif(1) u2=runif(1) af=(1-u2)^(-1/alpha) T0v1=-log(1-u2) T0v2=alpha*log((1-af)+af*((1-u1)^(-1/(1+alpha)))) T0=c(T0v1,T0v2) ZZZ=rep(rnorm(1),2) X1before= 0.5*(T0+0.2)/(T0+1)+0.3*ZZZ X1=mean(X1before) X2= 1/log(1.3*T0+3)-0.3*ZZZ X3= rbinom(2,1,0.3+0.5/(T0+1)) A=rbinom(2,1,1/(1+exp(1-2*X1-X2-X3))) Ttime <- T0*exp(-log(1.5)*A) rateC=0.5 C <- rexp(2, rate=rateC) time <- pmin(Ttime, C) status <- as.numeric(Ttime <= C) cbind(id=id,time=time,status=status,A=A,X1=X1,X2=X2,X3=X3) } da=as.data.frame(do.call("rbind",lapply(1:n,oneGene))) head(da) #inference results for marginal hazard ratio ipwCoxCluster(data=da,indID="id",indA="A",indX=c("X1","X2","X3"),indStatus="status",indTime="time")
Inference of marginal hazard ratios (HR) in inverse probability weighted (IPW) Cox model with independent sample (i.e, without clustered data), under both the conventional inverse probability weights and the stabilized weights. Corrected sandwich variance (CSV) estimation method is used for variance estimation of estimated log marginal hazard ratios.
ipwCoxInd(data, indA, indX, indStatus, indTime, ties = "breslow", confidence = 0.95)
ipwCoxInd(data, indA, indX, indStatus, indTime, ties = "breslow", confidence = 0.95)
data |
A dataset to be analyzed in the form of R data frame. |
indA |
A column name indicating the treatment variable. |
indX |
A vector of column names indicating the covariates included in the propensity score model. |
indStatus |
A column name indicating the non-censoring status (1 if observed and 0 if censored). |
indTime |
A column name indicating the outcome variable, i.e., min(true event time, censoring time). |
ties |
A character string indicating the method ("efron","breslow",or "exact") to deal with tied events for point estimation; the default is "breslow". For variance estimation, Breslow method is used to deal with tied events. |
confidence |
A confidence level between 0 and 1; the default is 0.95 corresponding to a 95 per cent confidence interval. |
A matrix of inference results from inverse probability weighted Cox model with independent sample. The first and the second rows report log marginal hazard ratio estimate and associated corrected sandwich based standard error, marginal hazard ratio estimate and associated normality-based confidence interval, under conventional inverse probability weights and stabilized weights, respectively.
#simulate a dataset under marginal hazard ratio 1.5 without clustering set.seed(100) n=700 T0=rexp(n, rate=0.01) ZZZ=rnorm(n) X1= 0.5*(T0+0.2)/(T0+1)+0.3*ZZZ X2= 1/log(1.3*T0+3)-0.3*ZZZ X3= rbinom(n,1,0.3+0.5/(T0+1)) A=rbinom(n,1,1/(1+exp(0.53+X1-X2-X3))) Ttime <- T0*exp(-log(1.5)*A) rateC=0.0005 C <- rexp(n, rate=rateC) time <- pmin(Ttime, C) status <- as.numeric(Ttime <= C) da=data.frame(id=1:n,time=time,status=status,A=A,X1=X1,X2=X2,X3=X3) head(da) #inference results for marginal hazard ratio ipwCoxInd(data=da,indA="A",indX=c("X1","X2","X3"),indStatus="status",indTime="time")
#simulate a dataset under marginal hazard ratio 1.5 without clustering set.seed(100) n=700 T0=rexp(n, rate=0.01) ZZZ=rnorm(n) X1= 0.5*(T0+0.2)/(T0+1)+0.3*ZZZ X2= 1/log(1.3*T0+3)-0.3*ZZZ X3= rbinom(n,1,0.3+0.5/(T0+1)) A=rbinom(n,1,1/(1+exp(0.53+X1-X2-X3))) Ttime <- T0*exp(-log(1.5)*A) rateC=0.0005 C <- rexp(n, rate=rateC) time <- pmin(Ttime, C) status <- as.numeric(Ttime <= C) da=data.frame(id=1:n,time=time,status=status,A=A,X1=X1,X2=X2,X3=X3) head(da) #inference results for marginal hazard ratio ipwCoxInd(data=da,indA="A",indX=c("X1","X2","X3"),indStatus="status",indTime="time")