Skip to content

Commit eab4fe1

Browse files
committed
Updated variable selection vignette
1 parent 1978ffd commit eab4fe1

File tree

1 file changed

+9
-21
lines changed

1 file changed

+9
-21
lines changed

vignettes/CausalInference.Rmd

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -803,9 +803,9 @@ We draw from a modified "demo 1" DGP
803803

804804
```{r}
805805
mu <- function(x) {1+g(x)+x[,1]*x[,3]-x[,2]+3*x[,3]}
806-
tau <- function(x) {1+0.5*x[,1]}
806+
tau <- function(x) {1 - 2*x[,1] + 2*x[,2] + 1*x[,1]*x[,2]}
807807
n <- 500
808-
snr <- 2
808+
snr <- 4
809809
x1 <- rnorm(n)
810810
x2 <- rnorm(n)
811811
x3 <- rnorm(n)
@@ -829,7 +829,7 @@ X$x4 <- factor(X$x4, ordered = TRUE)
829829
X$x5 <- factor(X$x5, ordered = TRUE)
830830
831831
# Split data into test and train sets
832-
test_set_pct <- 0.2
832+
test_set_pct <- 0.5
833833
n_test <- round(test_set_pct*n)
834834
n_train <- n - n_test
835835
test_inds <- sort(sample(1:n, n_test, replace = FALSE))
@@ -857,7 +857,7 @@ Here we simulate from the model with the original MCMC sampler, using all of the
857857
```{r}
858858
num_gfr <- 0
859859
num_burnin <- 1000
860-
num_mcmc <- 100
860+
num_mcmc <- 1000
861861
num_samples <- num_gfr + num_burnin + num_mcmc
862862
bcf_model_mcmc <- bcf(
863863
X_train = X_train, Z_train = Z_train, y_train = y_train, pi_train = pi_train,
@@ -879,9 +879,6 @@ abline(0,1,col="red",lty=3,lwd=3)
879879
plot(rowMeans(bcf_model_mcmc$y_hat_test), y_test,
880880
xlab = "predicted", ylab = "actual", main = "Outcome")
881881
abline(0,1,col="red",lty=3,lwd=3)
882-
plot(rowMeans(bcf_model_mcmc$y_hat_test-bcf_model_mcmc$mu_hat_test), tau_test*Z_test,
883-
xlab = "predicted", ylab = "actual", main = "Treatment effect term")
884-
abline(0,1,col="red",lty=3,lwd=3)
885882
sigma_observed <- var(y-E_XZ)
886883
plot_bounds <- c(min(c(bcf_model_mcmc$sigma2_samples, sigma_observed)),
887884
max(c(bcf_model_mcmc$sigma2_samples, sigma_observed)))
@@ -918,14 +915,14 @@ Here we simulate from the model with the original MCMC sampler, using only covar
918915
```{r}
919916
num_gfr <- 0
920917
num_burnin <- 1000
921-
num_mcmc <- 100
918+
num_mcmc <- 1000
922919
num_samples <- num_gfr + num_burnin + num_mcmc
923920
bcf_model_mcmc <- bcf(
924921
X_train = X_train, Z_train = Z_train, y_train = y_train, pi_train = pi_train,
925922
X_test = X_test, Z_test = Z_test, pi_test = pi_test,
926923
num_gfr = num_gfr, num_burnin = num_burnin, num_mcmc = num_mcmc,
927924
sample_sigma_leaf_mu = F, sample_sigma_leaf_tau = F,
928-
keep_vars_tau = c("x1")
925+
keep_vars_tau = c("x1","x2")
929926
)
930927
```
931928

@@ -941,9 +938,6 @@ abline(0,1,col="red",lty=3,lwd=3)
941938
plot(rowMeans(bcf_model_mcmc$y_hat_test), y_test,
942939
xlab = "predicted", ylab = "actual", main = "Outcome")
943940
abline(0,1,col="red",lty=3,lwd=3)
944-
plot(rowMeans(bcf_model_mcmc$y_hat_test-bcf_model_mcmc$mu_hat_test), tau_test*Z_test,
945-
xlab = "predicted", ylab = "actual", main = "Treatment effect term")
946-
abline(0,1,col="red",lty=3,lwd=3)
947941
sigma_observed <- var(y-E_XZ)
948942
plot_bounds <- c(min(c(bcf_model_mcmc$sigma2_samples, sigma_observed)),
949943
max(c(bcf_model_mcmc$sigma2_samples, sigma_observed)))
@@ -980,7 +974,7 @@ Here we simulate from the model with the warm-start sampler, using all of the co
980974
```{r}
981975
num_gfr <- 10
982976
num_burnin <- 0
983-
num_mcmc <- 100
977+
num_mcmc <- 1000
984978
num_samples <- num_gfr + num_burnin + num_mcmc
985979
bcf_model_warmstart <- bcf(
986980
X_train = X_train, Z_train = Z_train, y_train = y_train, pi_train = pi_train,
@@ -1002,9 +996,6 @@ abline(0,1,col="red",lty=3,lwd=3)
1002996
plot(rowMeans(bcf_model_warmstart$y_hat_test), y_test,
1003997
xlab = "predicted", ylab = "actual", main = "Outcome")
1004998
abline(0,1,col="red",lty=3,lwd=3)
1005-
plot(rowMeans(bcf_model_warmstart$y_hat_test - bcf_model_warmstart$mu_hat_test), tau_test*Z_test,
1006-
xlab = "predicted", ylab = "actual", main = "Treatment effect term")
1007-
abline(0,1,col="red",lty=3,lwd=3)
1008999
sigma_observed <- var(y-E_XZ)
10091000
plot_bounds <- c(min(c(bcf_model_warmstart$sigma2_samples, sigma_observed)),
10101001
max(c(bcf_model_warmstart$sigma2_samples, sigma_observed)))
@@ -1041,14 +1032,14 @@ Here we simulate from the model with the warm-start sampler, using only covariat
10411032
```{r}
10421033
num_gfr <- 10
10431034
num_burnin <- 0
1044-
num_mcmc <- 100
1035+
num_mcmc <- 1000
10451036
num_samples <- num_gfr + num_burnin + num_mcmc
10461037
bcf_model_warmstart <- bcf(
10471038
X_train = X_train, Z_train = Z_train, y_train = y_train, pi_train = pi_train,
10481039
X_test = X_test, Z_test = Z_test, pi_test = pi_test,
10491040
num_gfr = num_gfr, num_burnin = num_burnin, num_mcmc = num_mcmc,
10501041
sample_sigma_leaf_mu = F, sample_sigma_leaf_tau = F,
1051-
keep_vars_tau = c("x1"), random_seed = 2
1042+
keep_vars_tau = c("x1", "x2")
10521043
)
10531044
```
10541045

@@ -1064,9 +1055,6 @@ abline(0,1,col="red",lty=3,lwd=3)
10641055
plot(rowMeans(bcf_model_warmstart$y_hat_test), y_test,
10651056
xlab = "predicted", ylab = "actual", main = "Outcome")
10661057
abline(0,1,col="red",lty=3,lwd=3)
1067-
plot(rowMeans(bcf_model_warmstart$y_hat_test-bcf_model_warmstart$mu_hat_test), tau_test*Z_test,
1068-
xlab = "predicted", ylab = "actual", main = "Treatment effect term")
1069-
abline(0,1,col="red",lty=3,lwd=3)
10701058
sigma_observed <- var(y-E_XZ)
10711059
plot_bounds <- c(min(c(bcf_model_warmstart$sigma2_samples, sigma_observed)),
10721060
max(c(bcf_model_warmstart$sigma2_samples, sigma_observed)))

0 commit comments

Comments
 (0)