prediction_function: A helper function. Allows you to fit observed joint...

View source: R/mono_bart.R

prediction_functionR Documentation

A helper function. Allows you to fit observed joint probabilities with linear model, or with a monotonicity constraint also have an option for random forest

Description

This function allows you to express your love of cats.

Usage

prediction_function(
  df,
  treat = "G",
  Outcome = "B",
  vars,
  model = "random forest"
)

Arguments

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

Examples

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')

demetrios1/Causallysensitive documentation built on Nov. 18, 2022, 5:27 p.m.