View source: R/ipwCoxCluster.R
| ipwCoxCluster | R Documentation |
Inference for the marginal hazard ratio (HR) in the inverse probability weighted (IPW) Cox model for clustered data, such as repeated measurements within individuals (i.e., multiple rows of observations for the same individual). Corrected sandwich variance (CSV) estimation method is used to estimate the variance of the estimated log HR and to construct confidence intervals for the HR.
ipwCoxCluster(
data,
indID,
indA,
indX,
indStatus,
indTime,
weightType = "ATE",
ties = "breslow",
confidence = 0.95
)
data |
A clustered data set to be analyzed in the form of R data frame. |
indID |
A column name indicating the cluster variable. Observations from the same cluster (e.g., multiple rows of observations for the same individual) have the same indID value. |
indA |
A column name indicating the treatment variable (1 = treated, 0 = untreated). |
indX |
A vector of column names specifying the covariates to be included in the propensity score model. Any covariate with the same value across all observations will be excluded, as it does not contribute to propensity score estimation. |
indStatus |
A column name indicating the non-censoring status (1 = event, 0 = censored). |
indTime |
A column name indicating the outcome variable, i.e., min(true event time, censoring time). |
weightType |
A character string specifying the type of weight ("ATE" when the estimand is the average treatment effect, or "ATT" when the estimand is the average treatment effect in the treated); the default is "ATE". |
ties |
A character string specifying the method ("efron","breslow", or "exact") used to handle tied event times for point estimation; the default is "breslow". For variance estimation, the Breslow method is used to handle tied event times. |
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 the inverse probability weighted Cox model for clustered data. The columns report the estimated log hazard ratio, the corrected sandwich standard error of the log hazard ratio, the estimated hazard ratio, the confidence interval for the hazard ratio computed using the corrected sandwich variance, and the p-value, respectively. Each row corresponds to a weight type.
#simulate a clustered data set with a marginal hazard ratio of 1.5
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)
#corrected sandwich variance-based inference results for the marginal hazard ratio
ipwCoxCluster(data=da,indID="id",indA="A",indX=c("X1","X2","X3"),indStatus="status",indTime="time")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.