Load the package:
library(CAPPMx)
We set the sample size and dimension.
=10 #total number of covariates
p=3; # number of categorical covariates
p_cat=p-p_cat # number of continuous covariates
p_cont=100 #number of subjects in the Trt arm
nsamp1=6
samp.ratio=samp.ratio * nsamp1 #number of subjects in the RWD arm nsamp2
We set the sample size in the RWD considerably larger than that in the treatment arm. Then we generate the covariates from mixture model. We consider a 2-component mixture in the treatment arm and a 3-component mixture in RWD such that the atoms of the mixtures in the RWD form a superset of the atoms of the mixtures in the treatment arm.
set.seed(1)
library(mvtnorm)
=2 ####number of true cluster -1
k2
##############sample mixture assignments########
= sample.int(n=k2,size=nsamp1, replace = T) #
lab1= sample(1:(k2+1),size=nsamp2, replace = T,prob = c(1,1,4))
lab2################################################
##set atoms for the mixtures of the coninuous covariates
=matrix(0,nrow=k2+1,ncol=p-3)
mu1,1:2]=mu[2,5:6]=2
mu[########################################################
######Binary categorical covariates
=.6
prob_trt=.85
prob_rwd#########################
=matrix(0, nrow=nsamp1,ncol=p_cont)
X1.cont=matrix(0, nrow=nsamp2,ncol=p_cont); X2.cat=matrix(0, nrow=nsamp2,ncol=p_cat);
X2.cont
=.05
var_each_mix##########Generate from case (iii) Lamb model ########################
# lambda=simulate_lambda(d,p,1)
for(i in 1:(k2+1)){
####set RWD
=which(lab2==i)
indsif(length(inds>0)){
= rmvnorm(length(inds),mean = mu[i,],sigma = var_each_mix*diag(p_cont ) )
X2.cont[inds,]if(i<=k2) ###set categorical covs in RWD
= matrix(rbinom(p_cat*length(inds), size=1,prob = prob_trt),
X2.cat[inds,]nrow=length(inds)) else X2.cat[inds,]= matrix(rbinom(p_cat*length(inds),
size=1,prob = prob_rwd) ,nrow=length(inds))
}rm(inds)
###########
####set Trt Arm
=which(lab1==i)
indsif(length(inds>0))
= rmvnorm(length(inds),mean = mu[i,],sigma = var_each_mix*diag(p_cont ) )
X1.cont[inds,]rm(inds)
###########
# print(i)
}
###set categorical covs in trt arm
=matrix(rbinom(p_cat*nsamp1, size=1,prob = prob_trt) ,nrow=nsamp1) X1.cat
Thus we have generated the following:
X1.cont
- continuous covariates in the treatment
arm.
X1.cat
- categorical covariates in the treatment
arm.
X2.cont
- continuous covariates in the RWD.
X2.cat
- categorical covariates in the RWD.
Next we sample responses using a linear model
=cbind(X1.cont, X1.cat)
X1=cbind(X2.cont, X2.cat)
X2# rm(X1.cont, X1.cat, X2.cont,X2.cat)
#########################################
=1 ##treatment effect
delta
#sample true regression coefficients for the linear response model
= sample(c(-1,2),size=p,replace = T )
betasample.int(p,5)]=0
beta[
=rnorm(X1%*%beta)+delta #response in the treatment arm
y1=rnorm(X2%*%beta) #response in the RWD
y2rm(X1,X2)
We deliberately make 5% entries missing in each covariate vector
=function(x, missing_percent=.05){
make_missing=x
x.missample.int(n=length(x),size=floor(length(x)*.05)) ]=NA
x.mis[
x.mis
}
=make_missing(X1.cat);X1.cont.mis=make_missing(X1.cont)
X1.cat.mis=make_missing(X2.cat);X2.cont.mis=make_missing(X2.cont) X2.cat.mis
Then we fit the CA-PPMx model
=cappmx_fit(X1.cat.mis, #categorical covariates in the trt arm
result#continuous covariates in the trt arm
X1.cont.mis, #observed responses in the trt arm
y1, rep(TRUE,length(y1)), #survival indicators in the trt arm
#categorical covariates in the RWD
X2.cat.mis, #continuous covariates in the RWD
X2.cont.mis, # observed responses in the RWD
y2, rep(TRUE,length(y2)) #survival indicators in the RWD
)
We compare the area under the curve (AUC) values using Bayesian additive regression tree (BART) classifiers for our importance-resampling adjusted synthetic control population versus randomly resampled population.
=get_auc(cat_cov_trt=X1.cat.mis,cont_cov_trt=X1.cont.mis,
aucscat_cov_rwd=X2.cat.mis,cont_cov_rwd=X2.cont.mis, result)
aucs#> IR_Adjusted Random
#> 0.5866667 0.8266667
Next we proceed towards model-based analysis on treatment effects.
Estimate the treatment effect from the MCMC outputs
average_trt_effect(result)
#> [1] 1.006211
We use the previously sampled categorical covariates. Then we generate the response
=cbind( X1.cat)
X1=cbind(X2.cat)
X2#########################################
=1 ##treatment effect
delta
#sample true regression coefficients for the linear response model
= c(-1,0,2)
beta
=rnorm(X1%*%beta)+delta #response in the treatment arm
y1=rnorm(X2%*%beta) #response in the RWD
y2rm(X1,X2)
Then we fit the CA-PPMx model
=cappmx_fit(cat_cov_trt=X1.cat.mis, #categorical covariates in the trt arm
resultcont_cov_trt= NULL, #we set the continuous covariate=NULL
#observed responses in the trt arm
y1, rep(TRUE,length(y1)), #survival indicators in the trt arm
cat_cov_rwd=X2.cat.mis, #categorical covariates in the RWD
cont_cov_rwd=NULL, #continuous covariates in the RWD
# observed responses in the RWD
y2, rep(TRUE,length(y2)) #survival indicators in the RWD
)
We compare the area under the curve (AUC) values using Bayesian additive regression tree (BART) classifiers for our importance-resampling adjusted synthetic control population versus randomly resampled population.
=get_auc(cat_cov_trt=X1.cat.mis, #categorical covariates in the trt arm
aucscat_cov_rwd=X2.cat.mis, #categorical covariates in the RWD
result=result)
aucs#> IR_Adjusted Random
#> 0.5422222 0.6222222
Next we proceed towards model-based analysis on treatment effects.
Estimate the treatment effect from the MCMC outputs
average_trt_effect(result)
#> [1] 0.9300987
We use the previously sampled categorical covariates. Then we generate the response
=cbind( X1.cont)
X1=cbind(X2.cont)
X2#########################################
=1 ##treatment effect
delta
#sample true regression coefficients for the linear response model
= sample(x=c(-1,0,2),size=ncol(X1),replace = T,prob = c(1,2,1))
beta
=rnorm(X1%*%beta)+delta #response in the treatment arm
y1=rnorm(X2%*%beta) #response in the RWD
y2rm(X1,X2)
Then we fit the CA-PPMx model
=cappmx_fit(cont_cov_trt= X1.cont.mis,
resultresponse_trt=y1, #observed responses in the trt arm
surv_ind_trt=rep(TRUE,length(y1)), #survival indicators in the trt arm
cont_cov_rwd=X2.cont.mis, #continuous covariates in the RWD
response_rwd=y2, # observed responses in the RWD
surv_ind_rwd=rep(TRUE,length(y2)) #survival indicators in the RWD
)
We compare the area under the curve (AUC) values using Bayesian additive regression tree (BART) classifiers for our importance-resampling adjusted synthetic control population versus randomly resampled population.
=get_auc(cont_cov_trt= X1.cont.mis,
aucscont_cov_rwd=X2.cont.mis, #continuous covariates in the RWD,
result=result)
aucs#> IR_Adjusted Random
#> 0.6711111 0.8177778
Next we proceed towards model-based analysis on treatment effects.
Estimate the treatment effect from the MCMC outputs
average_trt_effect(result)
#> [1] 1.042574