prediction_function | R Documentation |
This function allows you to express your love of cats.
prediction_function( df, treat = "G", Outcome = "B", vars, model = "random forest" )
df |
The data you wanna pass. Should have your covariates, treatment column, and outcome column |
treat |
the treatment column name (pass as a string) |
Outcome |
the outcome column name (pass as a string) |
vars |
the column names of the covariates you wanna pass, should all be in the df dataframe |
model |
options include random forest, logit |
set.seed(0) 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') prediction_function(covariates, 'G', 'B', vars, model='random forest')
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.