Title: | Variable Selection Methods Including an Exposure Variable |
---|---|
Description: | Utilizes multiple variable selection methods to estimate Average Treatment Effect. |
Authors: | Alex Martinez [aut, cre], Andrew Chapple [aut] |
Maintainer: | Alex Martinez <[email protected]> |
License: | GPL-2 |
Version: | 1.0.3 |
Built: | 2024-11-20 06:25:33 UTC |
Source: | CRAN |
Returns the estimated Average Treatment Effect and estimated Relative Treatment Effect calculated by the optimal model chosen via backward selection including an exposure variable.
BACKWARD_EXPOSURE(Data)
BACKWARD_EXPOSURE(Data)
Data |
Data frame containing outcome variable (Y), exposure variable (E), and candidate covariates. |
List containing (1) the estimated Average Treatment Effect, (2) estimated Relative Treatment Effect, (3) summary of the selected model, and (4) the first 6 rows of the data frame containing backward-selected covariates.
[1] **will contain our paper later**
###Generate data with n rows and p covariates, can be any number but we'll choose 750 rows ###and 7 covariates for this example set.seed(3) p = 7 n = 750 beta0 = rnorm(1, mean = 0, sd = 1) betaE = rnorm(1, mean = 0, sd = 1) beta0_E = rnorm(1, mean = 0, sd = 1) betaX_E = c() betaX_Y = c() Y = rep(NA, n) E = rep(NA, n) pi0 = rep(NA, n) pi1 = rep(NA, n) data = data.frame(cbind(Y, E, pi0, pi1)) j = round(runif(1, 0, p)) for(i in 1:p){ betaX_Y[i] = rnorm(1, mean = 0, sd = 0.5) betaX_E[i] = rnorm(1, mean = 0, sd = 0.5) } zeros = sample(1:p, j, replace = FALSE) betaX_Y[zeros] = 0 betaX_E[zeros] = 0 mu = 0 sigma = 1 for(i in 1:p){ covar = rnorm(n, 0, 1) data[,i+4] = covar names(data)[i+4] = paste("X", i, sep = "") } for(i in 1:n){ p.event_E = beta0_E + sum(betaX_E*data[i,5:(p+4)]) pi1_E = exp(p.event_E)/(1+exp(p.event_E)) data[i,2] = rbinom(1, 1, prob = pi1_E) } for(i in 1:n){ p.event = beta0 + betaE + sum(betaX_Y*data[i,5:(p+4)]) p.noevent = beta0 + sum(betaX_Y*data[i,5:(p+4)]) pi0 = exp(p.noevent)/(1+exp(p.noevent)) pi1 = exp(p.event)/(1+exp(p.event)) data[i,3] = pi0 data[i,4] = pi1 if(data[i,2] == 1){ data[i,1] = rbinom(1, 1, prob = pi1) }else{ data[i,1] = rbinom(1, 1, prob = pi0) } } for(i in 1:n){ p.event_E = beta0_E + sum(betaX_E*data[i,5:(p+4)]) pi1_E = exp(p.event_E)/(1+exp(p.event_E)) data[i,2] = rbinom(1, 1, prob = pi1_E) } ###Raw data includes pi0 and pi1 columns used to fill Y and E, so to test ###the function we'll remove these testdata = data[,-c(3,4)] BACKWARD_EXPOSURE(testdata)
###Generate data with n rows and p covariates, can be any number but we'll choose 750 rows ###and 7 covariates for this example set.seed(3) p = 7 n = 750 beta0 = rnorm(1, mean = 0, sd = 1) betaE = rnorm(1, mean = 0, sd = 1) beta0_E = rnorm(1, mean = 0, sd = 1) betaX_E = c() betaX_Y = c() Y = rep(NA, n) E = rep(NA, n) pi0 = rep(NA, n) pi1 = rep(NA, n) data = data.frame(cbind(Y, E, pi0, pi1)) j = round(runif(1, 0, p)) for(i in 1:p){ betaX_Y[i] = rnorm(1, mean = 0, sd = 0.5) betaX_E[i] = rnorm(1, mean = 0, sd = 0.5) } zeros = sample(1:p, j, replace = FALSE) betaX_Y[zeros] = 0 betaX_E[zeros] = 0 mu = 0 sigma = 1 for(i in 1:p){ covar = rnorm(n, 0, 1) data[,i+4] = covar names(data)[i+4] = paste("X", i, sep = "") } for(i in 1:n){ p.event_E = beta0_E + sum(betaX_E*data[i,5:(p+4)]) pi1_E = exp(p.event_E)/(1+exp(p.event_E)) data[i,2] = rbinom(1, 1, prob = pi1_E) } for(i in 1:n){ p.event = beta0 + betaE + sum(betaX_Y*data[i,5:(p+4)]) p.noevent = beta0 + sum(betaX_Y*data[i,5:(p+4)]) pi0 = exp(p.noevent)/(1+exp(p.noevent)) pi1 = exp(p.event)/(1+exp(p.event)) data[i,3] = pi0 data[i,4] = pi1 if(data[i,2] == 1){ data[i,1] = rbinom(1, 1, prob = pi1) }else{ data[i,1] = rbinom(1, 1, prob = pi0) } } for(i in 1:n){ p.event_E = beta0_E + sum(betaX_E*data[i,5:(p+4)]) pi1_E = exp(p.event_E)/(1+exp(p.event_E)) data[i,2] = rbinom(1, 1, prob = pi1_E) } ###Raw data includes pi0 and pi1 columns used to fill Y and E, so to test ###the function we'll remove these testdata = data[,-c(3,4)] BACKWARD_EXPOSURE(testdata)
Returns the estimated Average Treatment Effect and estimated Relative Treatment Effect calculated by the optimal model chosen via forward selection including an exposure variable.
FORWARD_EXPOSURE(Data)
FORWARD_EXPOSURE(Data)
Data |
Data frame containing outcome variable (Y), exposure variable (E), and candidate covariates. |
List containing (1) the estimated Average Treatment Effect, (2) summary of the selected model, and (3) the first 6 rows of the data frame containing forward-selected covariates.
[1] **will contain our paper later**
###Generate data with n rows and p covariates, can be any number but we'll choose 750 rows ###and 7 covariates for this example set.seed(3) p = 7 n = 750 beta0 = rnorm(1, mean = 0, sd = 1) betaE = rnorm(1, mean = 0, sd = 1) beta0_E = rnorm(1, mean = 0, sd = 1) betaX_E = c() betaX_Y = c() Y = rep(NA, n) E = rep(NA, n) pi0 = rep(NA, n) pi1 = rep(NA, n) data = data.frame(cbind(Y, E, pi0, pi1)) j = round(runif(1, 0, p)) for(i in 1:p){ betaX_Y[i] = rnorm(1, mean = 0, sd = 0.5) betaX_E[i] = rnorm(1, mean = 0, sd = 0.5) } zeros = sample(1:p, j, replace = FALSE) betaX_Y[zeros] = 0 betaX_E[zeros] = 0 mu = 0 sigma = 1 for(i in 1:p){ covar = rnorm(n, 0, 1) data[,i+4] = covar names(data)[i+4] = paste("X", i, sep = "") } for(i in 1:n){ p.event_E = beta0_E + sum(betaX_E*data[i,5:(p+4)]) pi1_E = exp(p.event_E)/(1+exp(p.event_E)) data[i,2] = rbinom(1, 1, prob = pi1_E) } for(i in 1:n){ p.event = beta0 + betaE + sum(betaX_Y*data[i,5:(p+4)]) p.noevent = beta0 + sum(betaX_Y*data[i,5:(p+4)]) pi0 = exp(p.noevent)/(1+exp(p.noevent)) pi1 = exp(p.event)/(1+exp(p.event)) data[i,3] = pi0 data[i,4] = pi1 if(data[i,2] == 1){ data[i,1] = rbinom(1, 1, prob = pi1) }else{ data[i,1] = rbinom(1, 1, prob = pi0) } } for(i in 1:n){ p.event_E = beta0_E + sum(betaX_E*data[i,5:(p+4)]) pi1_E = exp(p.event_E)/(1+exp(p.event_E)) data[i,2] = rbinom(1, 1, prob = pi1_E) } ###Raw data includes pi0 and pi1 columns used to fill Y and E, so to test ###the function we'll remove these testdata = data[,-c(3,4)] FORWARD_EXPOSURE(testdata)
###Generate data with n rows and p covariates, can be any number but we'll choose 750 rows ###and 7 covariates for this example set.seed(3) p = 7 n = 750 beta0 = rnorm(1, mean = 0, sd = 1) betaE = rnorm(1, mean = 0, sd = 1) beta0_E = rnorm(1, mean = 0, sd = 1) betaX_E = c() betaX_Y = c() Y = rep(NA, n) E = rep(NA, n) pi0 = rep(NA, n) pi1 = rep(NA, n) data = data.frame(cbind(Y, E, pi0, pi1)) j = round(runif(1, 0, p)) for(i in 1:p){ betaX_Y[i] = rnorm(1, mean = 0, sd = 0.5) betaX_E[i] = rnorm(1, mean = 0, sd = 0.5) } zeros = sample(1:p, j, replace = FALSE) betaX_Y[zeros] = 0 betaX_E[zeros] = 0 mu = 0 sigma = 1 for(i in 1:p){ covar = rnorm(n, 0, 1) data[,i+4] = covar names(data)[i+4] = paste("X", i, sep = "") } for(i in 1:n){ p.event_E = beta0_E + sum(betaX_E*data[i,5:(p+4)]) pi1_E = exp(p.event_E)/(1+exp(p.event_E)) data[i,2] = rbinom(1, 1, prob = pi1_E) } for(i in 1:n){ p.event = beta0 + betaE + sum(betaX_Y*data[i,5:(p+4)]) p.noevent = beta0 + sum(betaX_Y*data[i,5:(p+4)]) pi0 = exp(p.noevent)/(1+exp(p.noevent)) pi1 = exp(p.event)/(1+exp(p.event)) data[i,3] = pi0 data[i,4] = pi1 if(data[i,2] == 1){ data[i,1] = rbinom(1, 1, prob = pi1) }else{ data[i,1] = rbinom(1, 1, prob = pi0) } } for(i in 1:n){ p.event_E = beta0_E + sum(betaX_E*data[i,5:(p+4)]) pi1_E = exp(p.event_E)/(1+exp(p.event_E)) data[i,2] = rbinom(1, 1, prob = pi1_E) } ###Raw data includes pi0 and pi1 columns used to fill Y and E, so to test ###the function we'll remove these testdata = data[,-c(3,4)] FORWARD_EXPOSURE(testdata)
Calculates likelihood from observed outcome data and given covariate data/parameters.
LIKE(Y, X, beta0, beta)
LIKE(Y, X, beta0, beta)
Y |
Binary outcome vector. |
X |
Matrix of covariates. |
beta0 |
Intercept parameter. |
beta |
Vector of covariate parameters of length p. |
Likelihood
Performs posterior sampling from an MCMC algorithm to estimate average treatment effect and posterior probability of inclusion of candidate variables.
MCMC_LOGIT_KEEP(Y, Z, PIN, MAX_COV, SdBeta, NUM_REPS)
MCMC_LOGIT_KEEP(Y, Z, PIN, MAX_COV, SdBeta, NUM_REPS)
Y |
Binary outcome vector. |
Z |
Matrix of covariates including binary exposure variable. |
PIN |
Prior probability of inclusion of candidate variables. |
MAX_COV |
Maximum number of covariates in desired model. |
SdBeta |
Prior standard deviation for generating distrubtion of proposal coefficients. |
NUM_REPS |
Number of MCMC iterations to perform. |
List containing (1) the posterior distribution of the estimated Average Treatment Effect, (2) the posterior distributions of the intercept parameter, (3) the posterior distributions of the rest of the coefficients including the exposure coefficient, and (4) the posterior distribution for the indication of whether or not the variable was included in a given iteration's model.
Returns the estimated Average Treatment Effect and estimated Relative Treatment Effect calculated by the optimal model chosen via stepwise selection including an exposure variable.
STEPWISE_EXPOSURE(Data)
STEPWISE_EXPOSURE(Data)
Data |
Data frame containing outcome variable (Y), exposure variable (E), and candidate covariates. |
List containing (1) the estimated Average Treatment Effect, (2) summary of the selected model, and (3) the first 6 rows of the data frame containing stepwise-selected covariates.
[1] **will contain our paper later**
###Generate data with n rows and p covariates, can be any number but we'll choose 750 rows ###and 7 covariates for this example set.seed(3) p = 7 n = 750 beta0 = rnorm(1, mean = 0, sd = 1) betaE = rnorm(1, mean = 0, sd = 1) beta0_E = rnorm(1, mean = 0, sd = 1) betaX_E = c() betaX_Y = c() Y = rep(NA, n) E = rep(NA, n) pi0 = rep(NA, n) pi1 = rep(NA, n) data = data.frame(cbind(Y, E, pi0, pi1)) j = round(runif(1, 0, p)) for(i in 1:p){ betaX_Y[i] = rnorm(1, mean = 0, sd = 0.5) betaX_E[i] = rnorm(1, mean = 0, sd = 0.5) } zeros = sample(1:p, j, replace = FALSE) betaX_Y[zeros] = 0 betaX_E[zeros] = 0 mu = 0 sigma = 1 for(i in 1:p){ covar = rnorm(n, 0, 1) data[,i+4] = covar names(data)[i+4] = paste("X", i, sep = "") } for(i in 1:n){ p.event_E = beta0_E + sum(betaX_E*data[i,5:(p+4)]) pi1_E = exp(p.event_E)/(1+exp(p.event_E)) data[i,2] = rbinom(1, 1, prob = pi1_E) } for(i in 1:n){ p.event = beta0 + betaE + sum(betaX_Y*data[i,5:(p+4)]) p.noevent = beta0 + sum(betaX_Y*data[i,5:(p+4)]) pi0 = exp(p.noevent)/(1+exp(p.noevent)) pi1 = exp(p.event)/(1+exp(p.event)) data[i,3] = pi0 data[i,4] = pi1 if(data[i,2] == 1){ data[i,1] = rbinom(1, 1, prob = pi1) }else{ data[i,1] = rbinom(1, 1, prob = pi0) } } for(i in 1:n){ p.event_E = beta0_E + sum(betaX_E*data[i,5:(p+4)]) pi1_E = exp(p.event_E)/(1+exp(p.event_E)) data[i,2] = rbinom(1, 1, prob = pi1_E) } ###Raw data includes pi0 and pi1 columns used to fill Y and E, so to test ###the function we'll remove these testdata = data[,-c(3,4)] STEPWISE_EXPOSURE(testdata)
###Generate data with n rows and p covariates, can be any number but we'll choose 750 rows ###and 7 covariates for this example set.seed(3) p = 7 n = 750 beta0 = rnorm(1, mean = 0, sd = 1) betaE = rnorm(1, mean = 0, sd = 1) beta0_E = rnorm(1, mean = 0, sd = 1) betaX_E = c() betaX_Y = c() Y = rep(NA, n) E = rep(NA, n) pi0 = rep(NA, n) pi1 = rep(NA, n) data = data.frame(cbind(Y, E, pi0, pi1)) j = round(runif(1, 0, p)) for(i in 1:p){ betaX_Y[i] = rnorm(1, mean = 0, sd = 0.5) betaX_E[i] = rnorm(1, mean = 0, sd = 0.5) } zeros = sample(1:p, j, replace = FALSE) betaX_Y[zeros] = 0 betaX_E[zeros] = 0 mu = 0 sigma = 1 for(i in 1:p){ covar = rnorm(n, 0, 1) data[,i+4] = covar names(data)[i+4] = paste("X", i, sep = "") } for(i in 1:n){ p.event_E = beta0_E + sum(betaX_E*data[i,5:(p+4)]) pi1_E = exp(p.event_E)/(1+exp(p.event_E)) data[i,2] = rbinom(1, 1, prob = pi1_E) } for(i in 1:n){ p.event = beta0 + betaE + sum(betaX_Y*data[i,5:(p+4)]) p.noevent = beta0 + sum(betaX_Y*data[i,5:(p+4)]) pi0 = exp(p.noevent)/(1+exp(p.noevent)) pi1 = exp(p.event)/(1+exp(p.event)) data[i,3] = pi0 data[i,4] = pi1 if(data[i,2] == 1){ data[i,1] = rbinom(1, 1, prob = pi1) }else{ data[i,1] = rbinom(1, 1, prob = pi0) } } for(i in 1:n){ p.event_E = beta0_E + sum(betaX_E*data[i,5:(p+4)]) pi1_E = exp(p.event_E)/(1+exp(p.event_E)) data[i,2] = rbinom(1, 1, prob = pi1_E) } ###Raw data includes pi0 and pi1 columns used to fill Y and E, so to test ###the function we'll remove these testdata = data[,-c(3,4)] STEPWISE_EXPOSURE(testdata)