BARTpred | R Documentation |
A helper function. Allows you to fit observed joint probabilities with BART, or with a monotonicity constraint
BARTpred( df, treat = "G", Outcome = "B", vars, mono = T, nd_post = 2000, n_skip = 2000 )
df |
dataframe including the covariates plus the treatment and outcome columns |
treat |
String of name of treatment column |
Outcome |
string, name of outcome column |
vars |
list of names of columns of covariates |
mono |
boolean, whether or not to impose monotonicity constraint, use if monbart is installed |
nd_post |
number of posterior draws to keep |
n_skip |
number of burn in samples |
#' N <- 500 # Number of random samples a=1 x1=runif(N, -a,a) x2=runif(N, -a,a) x3=runif(N,-a,a) x4=runif(N,-a,a) x5=runif(N, -a,a) beta1= -0.2 alpha1= 0.7 beta0= -0 alpha0= -0.5 mu1 <- beta0+beta1*(x1+x2+x3+x4+x5) mu2 <- alpha0+alpha1*(x1+x2+x3+x4+x5) mu<-matrix(c(mu1, mu2), nrow=N, ncol=2) rho=.5 gamma=1 B1.true=pnorm(mu2+gamma) B0.true=pnorm(mu2) sigma <- matrix(c(1, rho,rho,1), 2) # Covariance matrix sim_data=t(sapply(1:N, function(i)MASS::mvrnorm(1, mu = mu[i,], Sigma = sigma ))) #generate the binary treatments G=sapply(1:N, function(i)ifelse(sim_data[i,1]>=0, 1,0)) #generate the binary outcomes B=sapply(1:N, function(i)ifelse(sim_data[i,2]>=-1*gamma*G[i], 1,0)) print(table(G,B)) covariates=data.frame(x1,x2,x3,x4,x5,B, G) vars=c('x1','x2','x3','x4','x5') CV_pred=BARTpred_CV(covariates, treat='G', Outcome='B', vars=vars,mono=T, nd_post=200, n_skip=500, nfold=5)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.