diff --git a/articles/BayesianSupervisedLearning_files/figure-html/bart_root_plot-1.png b/articles/BayesianSupervisedLearning_files/figure-html/bart_root_plot-1.png index c8aa618..9c4fbb6 100644 Binary files a/articles/BayesianSupervisedLearning_files/figure-html/bart_root_plot-1.png and b/articles/BayesianSupervisedLearning_files/figure-html/bart_root_plot-1.png differ diff --git a/articles/BayesianSupervisedLearning_files/figure-html/bart_root_plot-2.png b/articles/BayesianSupervisedLearning_files/figure-html/bart_root_plot-2.png index 87c35f1..181b65d 100644 Binary files a/articles/BayesianSupervisedLearning_files/figure-html/bart_root_plot-2.png and b/articles/BayesianSupervisedLearning_files/figure-html/bart_root_plot-2.png differ diff --git a/articles/BayesianSupervisedLearning_files/figure-html/bart_root_plot_plm-1.png b/articles/BayesianSupervisedLearning_files/figure-html/bart_root_plot_plm-1.png index 637e1f8..35d125c 100644 Binary files a/articles/BayesianSupervisedLearning_files/figure-html/bart_root_plot_plm-1.png and b/articles/BayesianSupervisedLearning_files/figure-html/bart_root_plot_plm-1.png differ diff --git a/articles/BayesianSupervisedLearning_files/figure-html/bart_root_plot_plm-2.png b/articles/BayesianSupervisedLearning_files/figure-html/bart_root_plot_plm-2.png index 69365ec..d8a0ab6 100644 Binary files a/articles/BayesianSupervisedLearning_files/figure-html/bart_root_plot_plm-2.png and b/articles/BayesianSupervisedLearning_files/figure-html/bart_root_plot_plm-2.png differ diff --git a/articles/BayesianSupervisedLearning_files/figure-html/bart_root_plot_plm_rfx-1.png b/articles/BayesianSupervisedLearning_files/figure-html/bart_root_plot_plm_rfx-1.png index fdc4d15..98bea58 100644 Binary files a/articles/BayesianSupervisedLearning_files/figure-html/bart_root_plot_plm_rfx-1.png and b/articles/BayesianSupervisedLearning_files/figure-html/bart_root_plot_plm_rfx-1.png differ diff --git a/articles/BayesianSupervisedLearning_files/figure-html/bart_root_plot_plm_rfx-2.png b/articles/BayesianSupervisedLearning_files/figure-html/bart_root_plot_plm_rfx-2.png index 8d8b22a..6a981a4 100644 Binary files a/articles/BayesianSupervisedLearning_files/figure-html/bart_root_plot_plm_rfx-2.png and b/articles/BayesianSupervisedLearning_files/figure-html/bart_root_plot_plm_rfx-2.png differ diff --git a/articles/BayesianSupervisedLearning_files/figure-html/bart_warmstart_plot-1.png b/articles/BayesianSupervisedLearning_files/figure-html/bart_warmstart_plot-1.png index 3002f56..1777807 100644 Binary files a/articles/BayesianSupervisedLearning_files/figure-html/bart_warmstart_plot-1.png and b/articles/BayesianSupervisedLearning_files/figure-html/bart_warmstart_plot-1.png differ diff --git a/articles/BayesianSupervisedLearning_files/figure-html/bart_warmstart_plot-2.png b/articles/BayesianSupervisedLearning_files/figure-html/bart_warmstart_plot-2.png index 61cf601..79de8bf 100644 Binary files a/articles/BayesianSupervisedLearning_files/figure-html/bart_warmstart_plot-2.png and b/articles/BayesianSupervisedLearning_files/figure-html/bart_warmstart_plot-2.png differ diff --git a/articles/BayesianSupervisedLearning_files/figure-html/bart_warmstart_plot_plm-1.png b/articles/BayesianSupervisedLearning_files/figure-html/bart_warmstart_plot_plm-1.png index d383a57..033a9e3 100644 Binary files a/articles/BayesianSupervisedLearning_files/figure-html/bart_warmstart_plot_plm-1.png and b/articles/BayesianSupervisedLearning_files/figure-html/bart_warmstart_plot_plm-1.png differ diff --git a/articles/BayesianSupervisedLearning_files/figure-html/bart_warmstart_plot_plm-2.png b/articles/BayesianSupervisedLearning_files/figure-html/bart_warmstart_plot_plm-2.png index c4cb28c..d84420e 100644 Binary files a/articles/BayesianSupervisedLearning_files/figure-html/bart_warmstart_plot_plm-2.png and b/articles/BayesianSupervisedLearning_files/figure-html/bart_warmstart_plot_plm-2.png differ diff --git a/articles/BayesianSupervisedLearning_files/figure-html/bart_warmstart_plot_plm_rfx-1.png b/articles/BayesianSupervisedLearning_files/figure-html/bart_warmstart_plot_plm_rfx-1.png index e2ff692..b2980e5 100644 Binary files a/articles/BayesianSupervisedLearning_files/figure-html/bart_warmstart_plot_plm_rfx-1.png and b/articles/BayesianSupervisedLearning_files/figure-html/bart_warmstart_plot_plm_rfx-1.png differ diff --git a/articles/BayesianSupervisedLearning_files/figure-html/bart_warmstart_plot_plm_rfx-2.png b/articles/BayesianSupervisedLearning_files/figure-html/bart_warmstart_plot_plm_rfx-2.png index d322671..8eb1594 100644 Binary files a/articles/BayesianSupervisedLearning_files/figure-html/bart_warmstart_plot_plm_rfx-2.png and b/articles/BayesianSupervisedLearning_files/figure-html/bart_warmstart_plot_plm_rfx-2.png differ diff --git a/articles/CausalInference.html b/articles/CausalInference.html index 3adb45f..0b16afb 100644 --- a/articles/CausalInference.html +++ b/articles/CausalInference.html @@ -195,7 +195,7 @@

Warmstart(test_ub >= tau_x[test_inds]) ) mean(cover) -#> [1] 0.92 +#> [1] 0.98

BART MCMC without Warmstart @@ -241,7 +241,7 @@

BART MCMC without Warmstart(test_ub >= tau_x[test_inds]) ) mean(cover) -#> [1] 0.97

+#> [1] 0.96 @@ -351,7 +351,7 @@

Warmstart(test_ub >= tau_x[test_inds]) ) mean(cover) -#> [1] 0.83 +#> [1] 0.56

BART MCMC without Warmstart @@ -397,7 +397,7 @@

BART MCMC without Warmstart(test_ub >= tau_x[test_inds]) ) mean(cover) -#> [1] 0.86

+#> [1] 0.91 @@ -666,7 +666,7 @@

Warmstart(test_ub >= tau_x[test_inds]) ) mean(cover) -#> [1] 0.97 +#> [1] 0.98

BART MCMC without Warmstart @@ -712,7 +712,7 @@

BART MCMC without Warmstart(test_ub >= tau_x[test_inds]) ) mean(cover) -#> [1] 0.94

+#> [1] 0.98 @@ -836,7 +836,7 @@

Warmstart(test_ub >= tau_x[test_inds]) ) mean(cover) -#> [1] 0.9 +#> [1] 0.96

It is clear that causal inference is much more difficult in the presence of both strong covariate-dependent prognostic effects and strong group-level random effects. In this sense, proper diff --git a/articles/CausalInference_files/figure-html/bart_root_plot-1.png b/articles/CausalInference_files/figure-html/bart_root_plot-1.png index 22def19..b6700bb 100644 Binary files a/articles/CausalInference_files/figure-html/bart_root_plot-1.png and b/articles/CausalInference_files/figure-html/bart_root_plot-1.png differ diff --git a/articles/CausalInference_files/figure-html/bart_root_plot-2.png b/articles/CausalInference_files/figure-html/bart_root_plot-2.png index 9454135..2b763cb 100644 Binary files a/articles/CausalInference_files/figure-html/bart_root_plot-2.png and b/articles/CausalInference_files/figure-html/bart_root_plot-2.png differ diff --git a/articles/CausalInference_files/figure-html/bart_root_plot-3.png b/articles/CausalInference_files/figure-html/bart_root_plot-3.png index e4bc7b7..8adbfe6 100644 Binary files a/articles/CausalInference_files/figure-html/bart_root_plot-3.png and b/articles/CausalInference_files/figure-html/bart_root_plot-3.png differ diff --git a/articles/CausalInference_files/figure-html/bart_root_plot_2-1.png b/articles/CausalInference_files/figure-html/bart_root_plot_2-1.png index f6393ff..cfe80e0 100644 Binary files a/articles/CausalInference_files/figure-html/bart_root_plot_2-1.png and b/articles/CausalInference_files/figure-html/bart_root_plot_2-1.png differ diff --git a/articles/CausalInference_files/figure-html/bart_root_plot_2-2.png b/articles/CausalInference_files/figure-html/bart_root_plot_2-2.png index 0860b45..2e87fac 100644 Binary files a/articles/CausalInference_files/figure-html/bart_root_plot_2-2.png and b/articles/CausalInference_files/figure-html/bart_root_plot_2-2.png differ diff --git a/articles/CausalInference_files/figure-html/bart_root_plot_2-3.png b/articles/CausalInference_files/figure-html/bart_root_plot_2-3.png index fb86afd..fec4235 100644 Binary files a/articles/CausalInference_files/figure-html/bart_root_plot_2-3.png and b/articles/CausalInference_files/figure-html/bart_root_plot_2-3.png differ diff --git a/articles/CausalInference_files/figure-html/bart_root_plot_3-1.png b/articles/CausalInference_files/figure-html/bart_root_plot_3-1.png index 9d945e7..6444501 100644 Binary files a/articles/CausalInference_files/figure-html/bart_root_plot_3-1.png and b/articles/CausalInference_files/figure-html/bart_root_plot_3-1.png differ diff --git a/articles/CausalInference_files/figure-html/bart_root_plot_3-2.png b/articles/CausalInference_files/figure-html/bart_root_plot_3-2.png index dc22c99..7a93506 100644 Binary files a/articles/CausalInference_files/figure-html/bart_root_plot_3-2.png and b/articles/CausalInference_files/figure-html/bart_root_plot_3-2.png differ diff --git a/articles/CausalInference_files/figure-html/bart_root_plot_3-3.png b/articles/CausalInference_files/figure-html/bart_root_plot_3-3.png index b40ffd8..7812ce3 100644 Binary files a/articles/CausalInference_files/figure-html/bart_root_plot_3-3.png and b/articles/CausalInference_files/figure-html/bart_root_plot_3-3.png differ diff --git a/articles/CausalInference_files/figure-html/bart_root_plot_4-1.png b/articles/CausalInference_files/figure-html/bart_root_plot_4-1.png index 52ff96b..d3cde6c 100644 Binary files a/articles/CausalInference_files/figure-html/bart_root_plot_4-1.png and b/articles/CausalInference_files/figure-html/bart_root_plot_4-1.png differ diff --git a/articles/CausalInference_files/figure-html/bart_root_plot_4-2.png b/articles/CausalInference_files/figure-html/bart_root_plot_4-2.png index 7f490eb..df10ddb 100644 Binary files a/articles/CausalInference_files/figure-html/bart_root_plot_4-2.png and b/articles/CausalInference_files/figure-html/bart_root_plot_4-2.png differ diff --git a/articles/CausalInference_files/figure-html/bart_root_plot_4-3.png b/articles/CausalInference_files/figure-html/bart_root_plot_4-3.png index 0c91d51..62c564d 100644 Binary files a/articles/CausalInference_files/figure-html/bart_root_plot_4-3.png and b/articles/CausalInference_files/figure-html/bart_root_plot_4-3.png differ diff --git a/articles/CausalInference_files/figure-html/bart_warmstart_plot-1.png b/articles/CausalInference_files/figure-html/bart_warmstart_plot-1.png index 58091f0..73c1011 100644 Binary files a/articles/CausalInference_files/figure-html/bart_warmstart_plot-1.png and b/articles/CausalInference_files/figure-html/bart_warmstart_plot-1.png differ diff --git a/articles/CausalInference_files/figure-html/bart_warmstart_plot-2.png b/articles/CausalInference_files/figure-html/bart_warmstart_plot-2.png index 282decf..457b848 100644 Binary files a/articles/CausalInference_files/figure-html/bart_warmstart_plot-2.png and b/articles/CausalInference_files/figure-html/bart_warmstart_plot-2.png differ diff --git a/articles/CausalInference_files/figure-html/bart_warmstart_plot-3.png b/articles/CausalInference_files/figure-html/bart_warmstart_plot-3.png index 3c7d5d0..873eb90 100644 Binary files a/articles/CausalInference_files/figure-html/bart_warmstart_plot-3.png and b/articles/CausalInference_files/figure-html/bart_warmstart_plot-3.png differ diff --git a/articles/CausalInference_files/figure-html/bart_warmstart_plot_2-1.png b/articles/CausalInference_files/figure-html/bart_warmstart_plot_2-1.png index 2c03a67..39ddf2e 100644 Binary files a/articles/CausalInference_files/figure-html/bart_warmstart_plot_2-1.png and b/articles/CausalInference_files/figure-html/bart_warmstart_plot_2-1.png differ diff --git a/articles/CausalInference_files/figure-html/bart_warmstart_plot_2-2.png b/articles/CausalInference_files/figure-html/bart_warmstart_plot_2-2.png index 91b407f..fa6c06a 100644 Binary files a/articles/CausalInference_files/figure-html/bart_warmstart_plot_2-2.png and b/articles/CausalInference_files/figure-html/bart_warmstart_plot_2-2.png differ diff --git a/articles/CausalInference_files/figure-html/bart_warmstart_plot_2-3.png b/articles/CausalInference_files/figure-html/bart_warmstart_plot_2-3.png index 8527d82..3652958 100644 Binary files a/articles/CausalInference_files/figure-html/bart_warmstart_plot_2-3.png and b/articles/CausalInference_files/figure-html/bart_warmstart_plot_2-3.png differ diff --git a/articles/CausalInference_files/figure-html/bart_warmstart_plot_3-1.png b/articles/CausalInference_files/figure-html/bart_warmstart_plot_3-1.png index 808db44..4ac69d1 100644 Binary files a/articles/CausalInference_files/figure-html/bart_warmstart_plot_3-1.png and b/articles/CausalInference_files/figure-html/bart_warmstart_plot_3-1.png differ diff --git a/articles/CausalInference_files/figure-html/bart_warmstart_plot_3-2.png b/articles/CausalInference_files/figure-html/bart_warmstart_plot_3-2.png index 878f5e2..1ce2350 100644 Binary files a/articles/CausalInference_files/figure-html/bart_warmstart_plot_3-2.png and b/articles/CausalInference_files/figure-html/bart_warmstart_plot_3-2.png differ diff --git a/articles/CausalInference_files/figure-html/bart_warmstart_plot_3-3.png b/articles/CausalInference_files/figure-html/bart_warmstart_plot_3-3.png index 2a78a56..f3cc7f3 100644 Binary files a/articles/CausalInference_files/figure-html/bart_warmstart_plot_3-3.png and b/articles/CausalInference_files/figure-html/bart_warmstart_plot_3-3.png differ diff --git a/articles/CausalInference_files/figure-html/bart_warmstart_plot_4-1.png b/articles/CausalInference_files/figure-html/bart_warmstart_plot_4-1.png index 620f0cc..9fb720e 100644 Binary files a/articles/CausalInference_files/figure-html/bart_warmstart_plot_4-1.png and b/articles/CausalInference_files/figure-html/bart_warmstart_plot_4-1.png differ diff --git a/articles/CausalInference_files/figure-html/bart_warmstart_plot_4-2.png b/articles/CausalInference_files/figure-html/bart_warmstart_plot_4-2.png index bb0a286..5c353da 100644 Binary files a/articles/CausalInference_files/figure-html/bart_warmstart_plot_4-2.png and b/articles/CausalInference_files/figure-html/bart_warmstart_plot_4-2.png differ diff --git a/articles/CausalInference_files/figure-html/bart_warmstart_plot_4-3.png b/articles/CausalInference_files/figure-html/bart_warmstart_plot_4-3.png index 560fc2b..6eaa775 100644 Binary files a/articles/CausalInference_files/figure-html/bart_warmstart_plot_4-3.png and b/articles/CausalInference_files/figure-html/bart_warmstart_plot_4-3.png differ diff --git a/articles/CausalInference_files/figure-html/bart_warmstart_plot_rfx-1.png b/articles/CausalInference_files/figure-html/bart_warmstart_plot_rfx-1.png index d9da2a6..ad57d08 100644 Binary files a/articles/CausalInference_files/figure-html/bart_warmstart_plot_rfx-1.png and b/articles/CausalInference_files/figure-html/bart_warmstart_plot_rfx-1.png differ diff --git a/articles/CausalInference_files/figure-html/bart_warmstart_plot_rfx-2.png b/articles/CausalInference_files/figure-html/bart_warmstart_plot_rfx-2.png index b83bc80..e0a1de8 100644 Binary files a/articles/CausalInference_files/figure-html/bart_warmstart_plot_rfx-2.png and b/articles/CausalInference_files/figure-html/bart_warmstart_plot_rfx-2.png differ diff --git a/articles/CausalInference_files/figure-html/bart_warmstart_plot_rfx-3.png b/articles/CausalInference_files/figure-html/bart_warmstart_plot_rfx-3.png index 03b9361..19f8d14 100644 Binary files a/articles/CausalInference_files/figure-html/bart_warmstart_plot_rfx-3.png and b/articles/CausalInference_files/figure-html/bart_warmstart_plot_rfx-3.png differ diff --git a/articles/CausalInference_files/figure-html/bart_warmstart_plot_rfx-4.png b/articles/CausalInference_files/figure-html/bart_warmstart_plot_rfx-4.png index a6c757e..99c0eae 100644 Binary files a/articles/CausalInference_files/figure-html/bart_warmstart_plot_rfx-4.png and b/articles/CausalInference_files/figure-html/bart_warmstart_plot_rfx-4.png differ diff --git a/articles/CausalInference_files/figure-html/bart_warmstart_plot_rfx-5.png b/articles/CausalInference_files/figure-html/bart_warmstart_plot_rfx-5.png index e939994..8afa259 100644 Binary files a/articles/CausalInference_files/figure-html/bart_warmstart_plot_rfx-5.png and b/articles/CausalInference_files/figure-html/bart_warmstart_plot_rfx-5.png differ diff --git a/articles/CustomSamplingRoutine.html b/articles/CustomSamplingRoutine.html index 436b98e..8e1ae7a 100644 --- a/articles/CustomSamplingRoutine.html +++ b/articles/CustomSamplingRoutine.html @@ -1067,7 +1067,7 @@

Results

 mean((rowMeans(tau_hat[,1:num_gfr]) - tau_x)^2)
-#> [1] 0.3375474
+#> [1] 0.3495556

Inspect the warm start BART results

 plot(sigma_samples[(num_gfr+1):num_samples], ylab="sigma^2")
@@ -1084,7 +1084,7 @@

Results

 mean((rowMeans(tau_hat[,(num_gfr+1):num_samples]) - tau_x)^2)
-#> [1] 0.3512077
+#> [1] 0.4305235

Inspect the “adaptive coding” parameters \(b_0\) and \(b_1\).

 plot(b_0_samples, col = "blue", ylab = "Coding parameter draws", 
diff --git a/articles/CustomSamplingRoutine_files/figure-html/adaptive_coding-1.png b/articles/CustomSamplingRoutine_files/figure-html/adaptive_coding-1.png
index c20b52e..e972879 100644
Binary files a/articles/CustomSamplingRoutine_files/figure-html/adaptive_coding-1.png and b/articles/CustomSamplingRoutine_files/figure-html/adaptive_coding-1.png differ
diff --git a/articles/CustomSamplingRoutine_files/figure-html/bcf_warm_start_plot-1.png b/articles/CustomSamplingRoutine_files/figure-html/bcf_warm_start_plot-1.png
index 5be191d..15786e0 100644
Binary files a/articles/CustomSamplingRoutine_files/figure-html/bcf_warm_start_plot-1.png and b/articles/CustomSamplingRoutine_files/figure-html/bcf_warm_start_plot-1.png differ
diff --git a/articles/CustomSamplingRoutine_files/figure-html/bcf_warm_start_plot-2.png b/articles/CustomSamplingRoutine_files/figure-html/bcf_warm_start_plot-2.png
index a8e2e97..9bdbfef 100644
Binary files a/articles/CustomSamplingRoutine_files/figure-html/bcf_warm_start_plot-2.png and b/articles/CustomSamplingRoutine_files/figure-html/bcf_warm_start_plot-2.png differ
diff --git a/articles/CustomSamplingRoutine_files/figure-html/bcf_warm_start_plot-3.png b/articles/CustomSamplingRoutine_files/figure-html/bcf_warm_start_plot-3.png
index bb30769..8513441 100644
Binary files a/articles/CustomSamplingRoutine_files/figure-html/bcf_warm_start_plot-3.png and b/articles/CustomSamplingRoutine_files/figure-html/bcf_warm_start_plot-3.png differ
diff --git a/articles/CustomSamplingRoutine_files/figure-html/bcf_xbcf_plot-1.png b/articles/CustomSamplingRoutine_files/figure-html/bcf_xbcf_plot-1.png
index 8060303..f5f9ef9 100644
Binary files a/articles/CustomSamplingRoutine_files/figure-html/bcf_xbcf_plot-1.png and b/articles/CustomSamplingRoutine_files/figure-html/bcf_xbcf_plot-1.png differ
diff --git a/articles/CustomSamplingRoutine_files/figure-html/bcf_xbcf_plot-2.png b/articles/CustomSamplingRoutine_files/figure-html/bcf_xbcf_plot-2.png
index 4e46268..493a8fd 100644
Binary files a/articles/CustomSamplingRoutine_files/figure-html/bcf_xbcf_plot-2.png and b/articles/CustomSamplingRoutine_files/figure-html/bcf_xbcf_plot-2.png differ
diff --git a/articles/CustomSamplingRoutine_files/figure-html/bcf_xbcf_plot-3.png b/articles/CustomSamplingRoutine_files/figure-html/bcf_xbcf_plot-3.png
index 1351d2f..9670072 100644
Binary files a/articles/CustomSamplingRoutine_files/figure-html/bcf_xbcf_plot-3.png and b/articles/CustomSamplingRoutine_files/figure-html/bcf_xbcf_plot-3.png differ
diff --git a/articles/CustomSamplingRoutine_files/figure-html/unnamed-chunk-11-1.png b/articles/CustomSamplingRoutine_files/figure-html/unnamed-chunk-11-1.png
index 5e8fd3a..66f65ca 100644
Binary files a/articles/CustomSamplingRoutine_files/figure-html/unnamed-chunk-11-1.png and b/articles/CustomSamplingRoutine_files/figure-html/unnamed-chunk-11-1.png differ
diff --git a/articles/CustomSamplingRoutine_files/figure-html/unnamed-chunk-11-2.png b/articles/CustomSamplingRoutine_files/figure-html/unnamed-chunk-11-2.png
index 77b6c13..7e809da 100644
Binary files a/articles/CustomSamplingRoutine_files/figure-html/unnamed-chunk-11-2.png and b/articles/CustomSamplingRoutine_files/figure-html/unnamed-chunk-11-2.png differ
diff --git a/articles/CustomSamplingRoutine_files/figure-html/unnamed-chunk-12-1.png b/articles/CustomSamplingRoutine_files/figure-html/unnamed-chunk-12-1.png
index a3a4180..82e02bf 100644
Binary files a/articles/CustomSamplingRoutine_files/figure-html/unnamed-chunk-12-1.png and b/articles/CustomSamplingRoutine_files/figure-html/unnamed-chunk-12-1.png differ
diff --git a/articles/CustomSamplingRoutine_files/figure-html/unnamed-chunk-12-2.png b/articles/CustomSamplingRoutine_files/figure-html/unnamed-chunk-12-2.png
index 4e950b3..4bd2c0b 100644
Binary files a/articles/CustomSamplingRoutine_files/figure-html/unnamed-chunk-12-2.png and b/articles/CustomSamplingRoutine_files/figure-html/unnamed-chunk-12-2.png differ
diff --git a/articles/CustomSamplingRoutine_files/figure-html/unnamed-chunk-13-1.png b/articles/CustomSamplingRoutine_files/figure-html/unnamed-chunk-13-1.png
index 39f70b0..b3cc6e7 100644
Binary files a/articles/CustomSamplingRoutine_files/figure-html/unnamed-chunk-13-1.png and b/articles/CustomSamplingRoutine_files/figure-html/unnamed-chunk-13-1.png differ
diff --git a/articles/CustomSamplingRoutine_files/figure-html/unnamed-chunk-22-1.png b/articles/CustomSamplingRoutine_files/figure-html/unnamed-chunk-22-1.png
index c6fce6b..8a0a970 100644
Binary files a/articles/CustomSamplingRoutine_files/figure-html/unnamed-chunk-22-1.png and b/articles/CustomSamplingRoutine_files/figure-html/unnamed-chunk-22-1.png differ
diff --git a/articles/CustomSamplingRoutine_files/figure-html/unnamed-chunk-22-2.png b/articles/CustomSamplingRoutine_files/figure-html/unnamed-chunk-22-2.png
index dc8260b..e82a41d 100644
Binary files a/articles/CustomSamplingRoutine_files/figure-html/unnamed-chunk-22-2.png and b/articles/CustomSamplingRoutine_files/figure-html/unnamed-chunk-22-2.png differ
diff --git a/articles/CustomSamplingRoutine_files/figure-html/unnamed-chunk-23-1.png b/articles/CustomSamplingRoutine_files/figure-html/unnamed-chunk-23-1.png
index 99e1f54..aa20302 100644
Binary files a/articles/CustomSamplingRoutine_files/figure-html/unnamed-chunk-23-1.png and b/articles/CustomSamplingRoutine_files/figure-html/unnamed-chunk-23-1.png differ
diff --git a/articles/CustomSamplingRoutine_files/figure-html/unnamed-chunk-23-2.png b/articles/CustomSamplingRoutine_files/figure-html/unnamed-chunk-23-2.png
index f03dff8..2c702e6 100644
Binary files a/articles/CustomSamplingRoutine_files/figure-html/unnamed-chunk-23-2.png and b/articles/CustomSamplingRoutine_files/figure-html/unnamed-chunk-23-2.png differ
diff --git a/articles/CustomSamplingRoutine_files/figure-html/unnamed-chunk-24-1.png b/articles/CustomSamplingRoutine_files/figure-html/unnamed-chunk-24-1.png
index df41641..3d662d4 100644
Binary files a/articles/CustomSamplingRoutine_files/figure-html/unnamed-chunk-24-1.png and b/articles/CustomSamplingRoutine_files/figure-html/unnamed-chunk-24-1.png differ
diff --git a/articles/CustomSamplingRoutine_files/figure-html/warm_start_plot-1.png b/articles/CustomSamplingRoutine_files/figure-html/warm_start_plot-1.png
index 06f8718..44c5b8f 100644
Binary files a/articles/CustomSamplingRoutine_files/figure-html/warm_start_plot-1.png and b/articles/CustomSamplingRoutine_files/figure-html/warm_start_plot-1.png differ
diff --git a/articles/CustomSamplingRoutine_files/figure-html/warm_start_plot-2.png b/articles/CustomSamplingRoutine_files/figure-html/warm_start_plot-2.png
index eae9595..4bac355 100644
Binary files a/articles/CustomSamplingRoutine_files/figure-html/warm_start_plot-2.png and b/articles/CustomSamplingRoutine_files/figure-html/warm_start_plot-2.png differ
diff --git a/articles/CustomSamplingRoutine_files/figure-html/xbart_plot-1.png b/articles/CustomSamplingRoutine_files/figure-html/xbart_plot-1.png
index f147345..7cb8f06 100644
Binary files a/articles/CustomSamplingRoutine_files/figure-html/xbart_plot-1.png and b/articles/CustomSamplingRoutine_files/figure-html/xbart_plot-1.png differ
diff --git a/articles/CustomSamplingRoutine_files/figure-html/xbart_plot-2.png b/articles/CustomSamplingRoutine_files/figure-html/xbart_plot-2.png
index 7caa8cc..d65e699 100644
Binary files a/articles/CustomSamplingRoutine_files/figure-html/xbart_plot-2.png and b/articles/CustomSamplingRoutine_files/figure-html/xbart_plot-2.png differ
diff --git a/articles/EnsembleKernel.html b/articles/EnsembleKernel.html
index adf67c3..74a149d 100644
--- a/articles/EnsembleKernel.html
+++ b/articles/EnsembleKernel.html
@@ -186,7 +186,7 @@ 

BART-based Gaussian process
 sqrt(mean((yhat_mean_test - y_test)^2))
-#> [1] 0.09020581

+#> [1] 0.09174463
@@ -255,7 +255,7 @@

BART-based Gaussian process
 sqrt(mean((yhat_mean_test - y_test)^2))
-#> [1] 5.615765

+#> [1] 5.235603

While the use case of a BART kernel for classical kriging is perhaps unclear without more empirical investigation, we will see in a later vignette that the kernel approach can be very beneficial for causal diff --git a/articles/EnsembleKernel_files/figure-html/unnamed-chunk-4-1.png b/articles/EnsembleKernel_files/figure-html/unnamed-chunk-4-1.png index a49c3da..6870f30 100644 Binary files a/articles/EnsembleKernel_files/figure-html/unnamed-chunk-4-1.png and b/articles/EnsembleKernel_files/figure-html/unnamed-chunk-4-1.png differ diff --git a/articles/EnsembleKernel_files/figure-html/unnamed-chunk-8-1.png b/articles/EnsembleKernel_files/figure-html/unnamed-chunk-8-1.png index 98b51e0..51aec61 100644 Binary files a/articles/EnsembleKernel_files/figure-html/unnamed-chunk-8-1.png and b/articles/EnsembleKernel_files/figure-html/unnamed-chunk-8-1.png differ diff --git a/articles/ModelSerialization.html b/articles/ModelSerialization.html index 15d6e95..a081a3b 100644 --- a/articles/ModelSerialization.html +++ b/articles/ModelSerialization.html @@ -167,7 +167,7 @@

Serialization
-saveToJsonFile(bcf_model, "bcf.json")
+saveBCFModelToJsonFile(bcf_model, "bcf.json")

Deserialization diff --git a/articles/ModelSerialization_files/figure-html/bcf_roundtrip-1.png b/articles/ModelSerialization_files/figure-html/bcf_roundtrip-1.png index 91069dd..9b78780 100644 Binary files a/articles/ModelSerialization_files/figure-html/bcf_roundtrip-1.png and b/articles/ModelSerialization_files/figure-html/bcf_roundtrip-1.png differ diff --git a/articles/ModelSerialization_files/figure-html/bcf_roundtrip-2.png b/articles/ModelSerialization_files/figure-html/bcf_roundtrip-2.png index a777577..7b4dda1 100644 Binary files a/articles/ModelSerialization_files/figure-html/bcf_roundtrip-2.png and b/articles/ModelSerialization_files/figure-html/bcf_roundtrip-2.png differ diff --git a/articles/ModelSerialization_files/figure-html/bcf_roundtrip-3.png b/articles/ModelSerialization_files/figure-html/bcf_roundtrip-3.png index 8090461..07b0132 100644 Binary files a/articles/ModelSerialization_files/figure-html/bcf_roundtrip-3.png and b/articles/ModelSerialization_files/figure-html/bcf_roundtrip-3.png differ diff --git a/pkgdown.yml b/pkgdown.yml index d044dda..12d7cd9 100644 --- a/pkgdown.yml +++ b/pkgdown.yml @@ -7,7 +7,7 @@ articles: CustomSamplingRoutine: CustomSamplingRoutine.html EnsembleKernel: EnsembleKernel.html ModelSerialization: ModelSerialization.html -last_built: 2024-05-12T06:06Z +last_built: 2024-05-12T07:27Z urls: reference: https://stochastictree.github.io/stochtree-r/reference article: https://stochastictree.github.io/stochtree-r/articles diff --git a/reference/convertBCFModelToJson.html b/reference/convertBCFModelToJson.html new file mode 100644 index 0000000..a98131b --- /dev/null +++ b/reference/convertBCFModelToJson.html @@ -0,0 +1,154 @@ + +Convert the persistent aspects of a BCF model to (in-memory) JSON — convertBCFModelToJson • stochtree + Skip to contents + + +
+
+
+ +
+

Convert the persistent aspects of a BCF model to (in-memory) JSON

+
+ +
+

Usage

+
convertBCFModelToJson(object)
+
+ +
+

Arguments

+
object
+

Object of type bcf containing draws of a Bayesian causal forest model and associated sampling outputs.

+ +
+
+

Value

+ + +

Object of type CppJson

+ + +
+ +
+

Examples

+
n <- 500
+x1 <- rnorm(n)
+x2 <- rnorm(n)
+x3 <- rnorm(n)
+x4 <- as.numeric(rbinom(n,1,0.5))
+x5 <- as.numeric(sample(1:3,n,replace=T))
+X <- cbind(x1,x2,x3,x4,x5)
+p <- ncol(X)
+g <- function(x) {ifelse(x[,5]==1,2,ifelse(x[,5]==2,-1,4))}
+mu1 <- function(x) {1+g(x)+x[,1]*x[,3]}
+mu2 <- function(x) {1+g(x)+6*abs(x[,3]-1)}
+tau1 <- function(x) {rep(3,nrow(x))}
+tau2 <- function(x) {1+2*x[,2]*x[,4]}
+mu_x <- mu1(X)
+tau_x <- tau2(X)
+pi_x <- 0.8*pnorm((3*mu_x/sd(mu_x)) - 0.5*X[,1]) + 0.05 + runif(n)/10
+Z <- rbinom(n,1,pi_x)
+E_XZ <- mu_x + Z*tau_x
+snr <- 3
+group_ids <- rep(c(1,2), n %/% 2)
+rfx_coefs <- matrix(c(-1, -1, 1, 1),nrow=2,byrow=T)
+rfx_basis <- cbind(1, runif(n, -1, 1))
+rfx_term <- rowSums(rfx_coefs[group_ids,] * rfx_basis)
+y <- E_XZ + rfx_term + rnorm(n, 0, 1)*(sd(E_XZ)/snr)
+test_set_pct <- 0.2
+n_test <- round(test_set_pct*n)
+n_train <- n - n_test
+test_inds <- sort(sample(1:n, n_test, replace = F))
+train_inds <- (1:n)[!((1:n) %in% test_inds)]
+X_test <- X[test_inds,]
+X_train <- X[train_inds,]
+pi_test <- pi_x[test_inds]
+pi_train <- pi_x[train_inds]
+Z_test <- Z[test_inds]
+Z_train <- Z[train_inds]
+y_test <- y[test_inds]
+y_train <- y[train_inds]
+mu_test <- mu_x[test_inds]
+mu_train <- mu_x[train_inds]
+tau_test <- tau_x[test_inds]
+tau_train <- tau_x[train_inds]
+group_ids_test <- group_ids[test_inds]
+group_ids_train <- group_ids[train_inds]
+rfx_basis_test <- rfx_basis[test_inds,]
+rfx_basis_train <- rfx_basis[train_inds,]
+rfx_term_test <- rfx_term[test_inds]
+rfx_term_train <- rfx_term[train_inds]
+bcf_model <- bcf(X_train = X_train, Z_train = Z_train, y_train = y_train, 
+                 pi_train = pi_train, group_ids_train = group_ids_train, 
+                 rfx_basis_train = rfx_basis_train, X_test = X_test, 
+                 Z_test = Z_test, pi_test = pi_test, group_ids_test = group_ids_test,
+                 rfx_basis_test = rfx_basis_test, ordered_cat_vars = c(4,5), 
+                 num_gfr = 100, num_burnin = 0, num_mcmc = 100, 
+                 sample_sigma_leaf_mu = T, sample_sigma_leaf_tau = F)
+# bcf_json <- convertBCFModelToJson(bcf_model)
+
+
+
+ + +
+ + + +
+ + + + + + + diff --git a/reference/createBCFModelFromJson.html b/reference/createBCFModelFromJson.html index 5b3c044..a49b208 100644 --- a/reference/createBCFModelFromJson.html +++ b/reference/createBCFModelFromJson.html @@ -132,7 +132,7 @@

Examples rfx_basis_test = rfx_basis_test, ordered_cat_vars = c(4,5), num_gfr = 100, num_burnin = 0, num_mcmc = 100, sample_sigma_leaf_mu = T, sample_sigma_leaf_tau = F) -# bcf_json <- convertToJson(bcf_model) +# bcf_json <- convertBCFModelToJson(bcf_model) # bcf_model_roundtrip <- createBCFModelFromJson(bcf_json)

diff --git a/reference/createBCFModelFromJsonFile.html b/reference/createBCFModelFromJsonFile.html index 95c4ed4..7932334 100644 --- a/reference/createBCFModelFromJsonFile.html +++ b/reference/createBCFModelFromJsonFile.html @@ -132,7 +132,7 @@

Examples rfx_basis_test = rfx_basis_test, ordered_cat_vars = c(4,5), num_gfr = 100, num_burnin = 0, num_mcmc = 100, sample_sigma_leaf_mu = T, sample_sigma_leaf_tau = F) -# saveToJsonFile(bcf_model, "test.json") +# saveBCFModelToJsonFile(bcf_model, "test.json") # bcf_model_roundtrip <- createBCFModelFromJsonFile("test.json") diff --git a/reference/index.html b/reference/index.html index ea95084..868db3a 100644 --- a/reference/index.html +++ b/reference/index.html @@ -91,7 +91,7 @@

Causal inferencePredict from a sampled BCF model on new data
- saveToJsonFile(<bcf>) + saveBCFModelToJsonFile()
Convert the persistent aspects of a BCF model to (in-memory) JSON and save to a file
@@ -101,7 +101,7 @@

Causal inferenceConvert a JSON file containing sample information on a trained BCF model to a BCF model object which can be used for prediction, etc...

- convertToJson(<bcf>) + convertBCFModelToJson()
Convert the persistent aspects of a BCF model to (in-memory) JSON
@@ -158,19 +158,9 @@

SerializationconvertToJson() -

-
Convert a model object (BCF, BART, etc...) to JSON
-
- createCppJsonFile()
Create a C++ Json object from a Json file
-
- - saveToJsonFile() -
-
Convert a model object (BCF, BART, etc...) to JSON and save it to a file with a json suffix named filename

Data

diff --git a/reference/saveBCFModelToJsonFile.html b/reference/saveBCFModelToJsonFile.html new file mode 100644 index 0000000..a200877 --- /dev/null +++ b/reference/saveBCFModelToJsonFile.html @@ -0,0 +1,150 @@ + +Convert the persistent aspects of a BCF model to (in-memory) JSON and save to a file — saveBCFModelToJsonFile • stochtree + Skip to contents + + +
+
+
+ +
+

Convert the persistent aspects of a BCF model to (in-memory) JSON and save to a file

+
+ +
+

Usage

+
saveBCFModelToJsonFile(object, filename)
+
+ +
+

Arguments

+
object
+

Object of type bcf containing draws of a Bayesian causal forest model and associated sampling outputs.

+ + +
filename
+

String of filepath, must end in ".json"

+ +
+ +
+

Examples

+
n <- 500
+x1 <- rnorm(n)
+x2 <- rnorm(n)
+x3 <- rnorm(n)
+x4 <- as.numeric(rbinom(n,1,0.5))
+x5 <- as.numeric(sample(1:3,n,replace=T))
+X <- cbind(x1,x2,x3,x4,x5)
+p <- ncol(X)
+g <- function(x) {ifelse(x[,5]==1,2,ifelse(x[,5]==2,-1,4))}
+mu1 <- function(x) {1+g(x)+x[,1]*x[,3]}
+mu2 <- function(x) {1+g(x)+6*abs(x[,3]-1)}
+tau1 <- function(x) {rep(3,nrow(x))}
+tau2 <- function(x) {1+2*x[,2]*x[,4]}
+mu_x <- mu1(X)
+tau_x <- tau2(X)
+pi_x <- 0.8*pnorm((3*mu_x/sd(mu_x)) - 0.5*X[,1]) + 0.05 + runif(n)/10
+Z <- rbinom(n,1,pi_x)
+E_XZ <- mu_x + Z*tau_x
+snr <- 3
+group_ids <- rep(c(1,2), n %/% 2)
+rfx_coefs <- matrix(c(-1, -1, 1, 1),nrow=2,byrow=T)
+rfx_basis <- cbind(1, runif(n, -1, 1))
+rfx_term <- rowSums(rfx_coefs[group_ids,] * rfx_basis)
+y <- E_XZ + rfx_term + rnorm(n, 0, 1)*(sd(E_XZ)/snr)
+test_set_pct <- 0.2
+n_test <- round(test_set_pct*n)
+n_train <- n - n_test
+test_inds <- sort(sample(1:n, n_test, replace = F))
+train_inds <- (1:n)[!((1:n) %in% test_inds)]
+X_test <- X[test_inds,]
+X_train <- X[train_inds,]
+pi_test <- pi_x[test_inds]
+pi_train <- pi_x[train_inds]
+Z_test <- Z[test_inds]
+Z_train <- Z[train_inds]
+y_test <- y[test_inds]
+y_train <- y[train_inds]
+mu_test <- mu_x[test_inds]
+mu_train <- mu_x[train_inds]
+tau_test <- tau_x[test_inds]
+tau_train <- tau_x[train_inds]
+group_ids_test <- group_ids[test_inds]
+group_ids_train <- group_ids[train_inds]
+rfx_basis_test <- rfx_basis[test_inds,]
+rfx_basis_train <- rfx_basis[train_inds,]
+rfx_term_test <- rfx_term[test_inds]
+rfx_term_train <- rfx_term[train_inds]
+bcf_model <- bcf(X_train = X_train, Z_train = Z_train, y_train = y_train, 
+                 pi_train = pi_train, group_ids_train = group_ids_train, 
+                 rfx_basis_train = rfx_basis_train, X_test = X_test, 
+                 Z_test = Z_test, pi_test = pi_test, group_ids_test = group_ids_test,
+                 rfx_basis_test = rfx_basis_test, ordered_cat_vars = c(4,5), 
+                 num_gfr = 100, num_burnin = 0, num_mcmc = 100, 
+                 sample_sigma_leaf_mu = T, sample_sigma_leaf_tau = F)
+# saveBCFModelToJsonFile(bcf_model, "test.json")
+
+
+
+ + +
+ + + +
+ + + + + + + diff --git a/search.json b/search.json index bbee0bc..d461009 100644 --- a/search.json +++ b/search.json @@ -1 +1 @@ -[{"path":"https://stochastictree.github.io/stochtree-r/LICENSE.html","id":null,"dir":"","previous_headings":"","what":"MIT License","title":"MIT License","text":"Copyright (c) 2024 stochtree authors Permission hereby granted, free charge, person obtaining copy software associated documentation files (“Software”), deal Software without restriction, including without limitation rights use, copy, modify, merge, publish, distribute, sublicense, /sell copies Software, permit persons Software furnished , subject following conditions: copyright notice permission notice shall included copies substantial portions Software. SOFTWARE PROVIDED “”, WITHOUT WARRANTY KIND, EXPRESS IMPLIED, INCLUDING LIMITED WARRANTIES MERCHANTABILITY, FITNESS PARTICULAR PURPOSE NONINFRINGEMENT. EVENT SHALL AUTHORS COPYRIGHT HOLDERS LIABLE CLAIM, DAMAGES LIABILITY, WHETHER ACTION CONTRACT, TORT OTHERWISE, ARISING , CONNECTION SOFTWARE USE DEALINGS SOFTWARE.","code":""},{"path":[]},{"path":"https://stochastictree.github.io/stochtree-r/articles/BayesianSupervisedLearning.html","id":"simulation","dir":"Articles","previous_headings":"Demo 1: Step Function","what":"Simulation","title":"Bayesian Supervised Learning in StochTree","text":", generate data simple step function.","code":"# Generate the data n <- 500 p_x <- 10 snr <- 3 X <- matrix(runif(n*p_x), ncol = p_x) f_XW <- ( ((0 <= X[,1]) & (0.25 > X[,1])) * (-7.5) + ((0.25 <= X[,1]) & (0.5 > X[,1])) * (-2.5) + ((0.5 <= X[,1]) & (0.75 > X[,1])) * (2.5) + ((0.75 <= X[,1]) & (1 > X[,1])) * (7.5) ) noise_sd <- sd(f_XW) / snr y <- f_XW + rnorm(n, 0, 1)*noise_sd # Split data into test and train sets test_set_pct <- 0.2 n_test <- round(test_set_pct*n) n_train <- n - n_test test_inds <- sort(sample(1:n, n_test, replace = F)) train_inds <- (1:n)[!((1:n) %in% test_inds)] X_test <- X[test_inds,] X_train <- X[train_inds,] W_test <- NULL W_train <- NULL y_test <- y[test_inds] y_train <- y[train_inds]"},{"path":[]},{"path":"https://stochastictree.github.io/stochtree-r/articles/BayesianSupervisedLearning.html","id":"warmstart","dir":"Articles","previous_headings":"Demo 1: Step Function > Sampling and Analysis","what":"Warmstart","title":"Bayesian Supervised Learning in StochTree","text":"first sample ensemble model \\(y \\mid X\\) using “warm-start” initialization samples (Hahn (2023)). default stochtree. Inspect MCMC samples","code":"num_gfr <- 10 num_burnin <- 0 num_mcmc <- 100 num_samples <- num_gfr + num_burnin + num_mcmc bart_model_warmstart <- stochtree::bart( X_train = X_train, y_train = y_train, X_test = X_test, num_trees = 100, num_gfr = num_gfr, num_burnin = num_burnin, num_mcmc = num_mcmc, sample_sigma = T, sample_tau = T ) plot(bart_model_warmstart$sigma2_samples, ylab=\"sigma^2\") plot(rowMeans(bart_model_warmstart$y_hat_test), y_test, pch=16, cex=0.75, xlab = \"pred\", ylab = \"actual\") abline(0,1,col=\"red\",lty=2,lwd=2.5)"},{"path":"https://stochastictree.github.io/stochtree-r/articles/BayesianSupervisedLearning.html","id":"bart-mcmc-without-warmstart","dir":"Articles","previous_headings":"Demo 1: Step Function > Sampling and Analysis","what":"BART MCMC without Warmstart","title":"Bayesian Supervised Learning in StochTree","text":"Next, sample ensemble model without warm-start initialization. Inspect MCMC samples","code":"num_gfr <- 0 num_burnin <- 100 num_mcmc <- 100 num_samples <- num_gfr + num_burnin + num_mcmc bart_model_root <- stochtree::bart( X_train = X_train, y_train = y_train, X_test = X_test, num_trees = 100, num_gfr = num_gfr, num_burnin = num_burnin, num_mcmc = num_mcmc, sample_sigma = T, sample_tau = T ) plot(bart_model_root$sigma2_samples, ylab=\"sigma^2\") plot(rowMeans(bart_model_root$y_hat_test), y_test, pch=16, cex=0.75, xlab = \"pred\", ylab = \"actual\") abline(0,1,col=\"red\",lty=2,lwd=2.5)"},{"path":[]},{"path":"https://stochastictree.github.io/stochtree-r/articles/BayesianSupervisedLearning.html","id":"simulation-1","dir":"Articles","previous_headings":"Demo 2: Partitioned Linear Model","what":"Simulation","title":"Bayesian Supervised Learning in StochTree","text":", generate data simple partitioned linear model.","code":"# Generate the data n <- 500 p_x <- 10 p_w <- 1 snr <- 3 X <- matrix(runif(n*p_x), ncol = p_x) W <- matrix(runif(n*p_w), ncol = p_w) f_XW <- ( ((0 <= X[,1]) & (0.25 > X[,1])) * (-7.5*W[,1]) + ((0.25 <= X[,1]) & (0.5 > X[,1])) * (-2.5*W[,1]) + ((0.5 <= X[,1]) & (0.75 > X[,1])) * (2.5*W[,1]) + ((0.75 <= X[,1]) & (1 > X[,1])) * (7.5*W[,1]) ) noise_sd <- sd(f_XW) / snr y <- f_XW + rnorm(n, 0, 1)*noise_sd # Split data into test and train sets test_set_pct <- 0.2 n_test <- round(test_set_pct*n) n_train <- n - n_test test_inds <- sort(sample(1:n, n_test, replace = F)) train_inds <- (1:n)[!((1:n) %in% test_inds)] X_test <- X[test_inds,] X_train <- X[train_inds,] W_test <- W[test_inds,] W_train <- W[train_inds,] y_test <- y[test_inds] y_train <- y[train_inds]"},{"path":[]},{"path":"https://stochastictree.github.io/stochtree-r/articles/BayesianSupervisedLearning.html","id":"warmstart-1","dir":"Articles","previous_headings":"Demo 2: Partitioned Linear Model > Sampling and Analysis","what":"Warmstart","title":"Bayesian Supervised Learning in StochTree","text":"first sample ensemble model \\(y \\mid X\\) using “warm-start” initialization samples (Hahn (2023)). default stochtree. Inspect MCMC samples","code":"num_gfr <- 10 num_burnin <- 0 num_mcmc <- 100 num_samples <- num_gfr + num_burnin + num_mcmc bart_model_warmstart <- stochtree::bart( X_train = X_train, W_train = W_train, y_train = y_train, X_test = X_test, W_test = W_test, num_trees = 100, num_gfr = num_gfr, num_burnin = num_burnin, num_mcmc = num_mcmc, sample_sigma = T, sample_tau = T ) plot(bart_model_warmstart$sigma2_samples, ylab=\"sigma^2\") plot(rowMeans(bart_model_warmstart$y_hat_test), y_test, pch=16, cex=0.75, xlab = \"pred\", ylab = \"actual\") abline(0,1,col=\"red\",lty=2,lwd=2.5)"},{"path":"https://stochastictree.github.io/stochtree-r/articles/BayesianSupervisedLearning.html","id":"bart-mcmc-without-warmstart-1","dir":"Articles","previous_headings":"Demo 2: Partitioned Linear Model > Sampling and Analysis","what":"BART MCMC without Warmstart","title":"Bayesian Supervised Learning in StochTree","text":"Next, sample ensemble model without warm-start initialization. Inspect BART samples burnin.","code":"num_gfr <- 0 num_burnin <- 100 num_mcmc <- 100 num_samples <- num_gfr + num_burnin + num_mcmc bart_model_root <- stochtree::bart( X_train = X_train, W_train = W_train, y_train = y_train, X_test = X_test, W_test = W_test, num_trees = 100, num_gfr = num_gfr, num_burnin = num_burnin, num_mcmc = num_mcmc, sample_sigma = T, sample_tau = T ) plot(bart_model_root$sigma2_samples, ylab=\"sigma^2\") plot(rowMeans(bart_model_root$y_hat_test), y_test, pch=16, cex=0.75, xlab = \"pred\", ylab = \"actual\") abline(0,1,col=\"red\",lty=2,lwd=2.5)"},{"path":[]},{"path":"https://stochastictree.github.io/stochtree-r/articles/BayesianSupervisedLearning.html","id":"simulation-2","dir":"Articles","previous_headings":"Demo 3: Partitioned Linear Model with Random Effects","what":"Simulation","title":"Bayesian Supervised Learning in StochTree","text":", generate data simple partitioned linear model additive random effect structure.","code":"# Generate the data n <- 500 p_x <- 10 p_w <- 1 snr <- 3 X <- matrix(runif(n*p_x), ncol = p_x) W <- matrix(runif(n*p_w), ncol = p_w) group_ids <- rep(c(1,2), n %/% 2) rfx_coefs <- matrix(c(-5, -3, 5, 3),nrow=2,byrow=T) rfx_basis <- cbind(1, runif(n, -1, 1)) f_XW <- ( ((0 <= X[,1]) & (0.25 > X[,1])) * (-7.5*W[,1]) + ((0.25 <= X[,1]) & (0.5 > X[,1])) * (-2.5*W[,1]) + ((0.5 <= X[,1]) & (0.75 > X[,1])) * (2.5*W[,1]) + ((0.75 <= X[,1]) & (1 > X[,1])) * (7.5*W[,1]) ) rfx_term <- rowSums(rfx_coefs[group_ids,] * rfx_basis) noise_sd <- sd(f_XW) / snr y <- f_XW + rfx_term + rnorm(n, 0, 1)*noise_sd # Split data into test and train sets test_set_pct <- 0.2 n_test <- round(test_set_pct*n) n_train <- n - n_test test_inds <- sort(sample(1:n, n_test, replace = F)) train_inds <- (1:n)[!((1:n) %in% test_inds)] X_test <- X[test_inds,] X_train <- X[train_inds,] W_test <- W[test_inds,] W_train <- W[train_inds,] y_test <- y[test_inds] y_train <- y[train_inds] group_ids_test <- group_ids[test_inds] group_ids_train <- group_ids[train_inds] rfx_basis_test <- rfx_basis[test_inds,] rfx_basis_train <- rfx_basis[train_inds,]"},{"path":[]},{"path":"https://stochastictree.github.io/stochtree-r/articles/BayesianSupervisedLearning.html","id":"warmstart-2","dir":"Articles","previous_headings":"Demo 3: Partitioned Linear Model with Random Effects > Sampling and Analysis","what":"Warmstart","title":"Bayesian Supervised Learning in StochTree","text":"first sample ensemble model \\(y \\mid X\\) using “warm-start” initialization samples (Hahn (2023)). default stochtree. Inspect MCMC samples","code":"num_gfr <- 10 num_burnin <- 0 num_mcmc <- 100 num_samples <- num_gfr + num_burnin + num_mcmc bart_model_warmstart <- stochtree::bart( X_train = X_train, W_train = W_train, y_train = y_train, group_ids_train = group_ids_train, rfx_basis_train = rfx_basis_train, X_test = X_test, W_test = W_test, group_ids_test = group_ids_test, rfx_basis_test = rfx_basis_test, num_trees = 100, num_gfr = num_gfr, num_burnin = num_burnin, num_mcmc = num_mcmc, sample_sigma = T, sample_tau = T ) plot(bart_model_warmstart$sigma2_samples, ylab=\"sigma^2\") abline(h=noise_sd^2,col=\"red\",lty=2,lwd=2.5) plot(rowMeans(bart_model_warmstart$y_hat_test), y_test, pch=16, cex=0.75, xlab = \"pred\", ylab = \"actual\") abline(0,1,col=\"red\",lty=2,lwd=2.5)"},{"path":"https://stochastictree.github.io/stochtree-r/articles/BayesianSupervisedLearning.html","id":"bart-mcmc-without-warmstart-2","dir":"Articles","previous_headings":"Demo 3: Partitioned Linear Model with Random Effects > Sampling and Analysis","what":"BART MCMC without Warmstart","title":"Bayesian Supervised Learning in StochTree","text":"Next, sample ensemble model without warm-start initialization. Inspect MCMC samples","code":"num_gfr <- 0 num_burnin <- 100 num_mcmc <- 100 num_samples <- num_gfr + num_burnin + num_mcmc bart_model_root <- stochtree::bart( X_train = X_train, W_train = W_train, y_train = y_train, group_ids_train = group_ids_train, rfx_basis_train = rfx_basis_train, X_test = X_test, W_test = W_test, group_ids_test = group_ids_test, rfx_basis_test = rfx_basis_test, num_trees = 100, num_gfr = num_gfr, num_burnin = num_burnin, num_mcmc = num_mcmc, sample_sigma = T, sample_tau = T ) plot(bart_model_root$sigma2_samples, ylab=\"sigma^2\") abline(h=noise_sd^2,col=\"red\",lty=2,lwd=2.5) plot(rowMeans(bart_model_root$y_hat_test), y_test, pch=16, cex=0.75, xlab = \"pred\", ylab = \"actual\") abline(0,1,col=\"red\",lty=2,lwd=2.5)"},{"path":[]},{"path":"https://stochastictree.github.io/stochtree-r/articles/CausalInference.html","id":"demo-1-nonlinear-outcome-model-heterogeneous-treatment-effect","dir":"Articles","previous_headings":"","what":"Demo 1: Nonlinear Outcome Model, Heterogeneous Treatment Effect","title":"Causal Machine Learning in StochTree","text":"consider following data generating process Hahn, Murray, Carvalho (2020): \\[\\begin{equation*} \\begin{aligned} y &= \\mu(X) + \\tau(X) Z + \\epsilon\\\\ \\epsilon &\\sim N\\left(0,\\sigma^2\\right)\\\\ \\mu(X) &= 1 + g(X) + 6 \\lvert X_3 - 1 \\rvert\\\\ \\tau(X) &= 1 + 2 X_2 X_4\\\\ g(X) &= \\mathbb{}(X_5=1) \\times 2 - \\mathbb{}(X_5=2) \\times 1 - \\mathbb{}(X_5=3) \\times 4\\\\ X_1,X_2,X_3 &\\sim N\\left(0,1\\right)\\\\ X_4 &\\sim \\text{Bernoulli}(1/2)\\\\ X_5 &\\sim \\text{Categorical}(1/3,1/3,1/3)\\\\ \\end{aligned} \\end{equation*}\\]","code":""},{"path":"https://stochastictree.github.io/stochtree-r/articles/CausalInference.html","id":"simulation","dir":"Articles","previous_headings":"Demo 1: Nonlinear Outcome Model, Heterogeneous Treatment Effect","what":"Simulation","title":"Causal Machine Learning in StochTree","text":"draw DGP defined ","code":"n <- 500 snr <- 3 x1 <- rnorm(n) x2 <- rnorm(n) x3 <- rnorm(n) x4 <- as.numeric(rbinom(n,1,0.5)) x5 <- as.numeric(sample(1:3,n,replace=T)) X <- cbind(x1,x2,x3,x4,x5) p <- ncol(X) mu_x <- mu1(X) tau_x <- tau2(X) pi_x <- 0.8*pnorm((3*mu_x/sd(mu_x)) - 0.5*X[,1]) + 0.05 + runif(n)/10 Z <- rbinom(n,1,pi_x) E_XZ <- mu_x + Z*tau_x y <- E_XZ + rnorm(n, 0, 1)*(sd(E_XZ)/snr) # Split data into test and train sets test_set_pct <- 0.2 n_test <- round(test_set_pct*n) n_train <- n - n_test test_inds <- sort(sample(1:n, n_test, replace = F)) train_inds <- (1:n)[!((1:n) %in% test_inds)] X_test <- X[test_inds,] X_train <- X[train_inds,] pi_test <- pi_x[test_inds] pi_train <- pi_x[train_inds] Z_test <- Z[test_inds] Z_train <- Z[train_inds] y_test <- y[test_inds] y_train <- y[train_inds] mu_test <- mu_x[test_inds] mu_train <- mu_x[train_inds] tau_test <- tau_x[test_inds] tau_train <- tau_x[train_inds]"},{"path":[]},{"path":"https://stochastictree.github.io/stochtree-r/articles/CausalInference.html","id":"warmstart","dir":"Articles","previous_headings":"Demo 1: Nonlinear Outcome Model, Heterogeneous Treatment Effect > Sampling and Analysis","what":"Warmstart","title":"Causal Machine Learning in StochTree","text":"first simulate ensemble model \\(y \\mid X\\) using “warm-start” initialization samples (Krantsevich, , Hahn (2023)). default stochtree. Inspect BART samples initialized XBART warm-start Examine test set interval coverage","code":"num_gfr <- 10 num_burnin <- 0 num_mcmc <- 1000 num_samples <- num_gfr + num_burnin + num_mcmc bcf_model_warmstart <- bcf( X_train = X_train, Z_train = Z_train, y_train = y_train, pi_train = pi_train, X_test = X_test, Z_test = Z_test, pi_test = pi_test, ordered_cat_vars = c(4,5), num_gfr = num_gfr, num_burnin = num_burnin, num_mcmc = num_mcmc, sample_sigma_leaf_mu = F, sample_sigma_leaf_tau = F ) plot(rowMeans(bcf_model_warmstart$mu_hat_test), mu_test, xlab = \"predicted\", ylab = \"actual\", main = \"Prognostic function\") abline(0,1,col=\"red\",lty=3,lwd=3) plot(rowMeans(bcf_model_warmstart$tau_hat_test), tau_test, xlab = \"predicted\", ylab = \"actual\", main = \"Treatment effect\") abline(0,1,col=\"red\",lty=3,lwd=3) sigma_observed <- var(y-E_XZ) plot_bounds <- c(min(c(bcf_model_warmstart$sigma2_samples, sigma_observed)), max(c(bcf_model_warmstart$sigma2_samples, sigma_observed))) plot(bcf_model_warmstart$sigma2_samples, ylim = plot_bounds, ylab = \"sigma^2\", xlab = \"Sample\", main = \"Global variance parameter\") abline(h = sigma_observed, lty=3, lwd = 3, col = \"blue\") test_lb <- apply(bcf_model_warmstart$tau_hat_test, 1, quantile, 0.025) test_ub <- apply(bcf_model_warmstart$tau_hat_test, 1, quantile, 0.975) cover <- ( (test_lb <= tau_x[test_inds]) & (test_ub >= tau_x[test_inds]) ) mean(cover) #> [1] 0.92"},{"path":"https://stochastictree.github.io/stochtree-r/articles/CausalInference.html","id":"bart-mcmc-without-warmstart","dir":"Articles","previous_headings":"Demo 1: Nonlinear Outcome Model, Heterogeneous Treatment Effect > Sampling and Analysis","what":"BART MCMC without Warmstart","title":"Causal Machine Learning in StochTree","text":"Next, simulate ensemble model without warm-start initialization. Inspect BART samples burnin Examine test set interval coverage","code":"num_gfr <- 0 num_burnin <- 1000 num_mcmc <- 1000 num_samples <- num_gfr + num_burnin + num_mcmc bcf_model_root <- bcf( X_train = X_train, Z_train = Z_train, y_train = y_train, pi_train = pi_train, X_test = X_test, Z_test = Z_test, pi_test = pi_test, ordered_cat_vars = c(4,5), num_gfr = num_gfr, num_burnin = num_burnin, num_mcmc = num_mcmc, sample_sigma_leaf_mu = F, sample_sigma_leaf_tau = F ) plot(rowMeans(bcf_model_root$mu_hat_test), mu_test, xlab = \"predicted\", ylab = \"actual\", main = \"Prognostic function\") abline(0,1,col=\"red\",lty=3,lwd=3) plot(rowMeans(bcf_model_root$tau_hat_test), tau_test, xlab = \"predicted\", ylab = \"actual\", main = \"Treatment effect\") abline(0,1,col=\"red\",lty=3,lwd=3) sigma_observed <- var(y-E_XZ) plot_bounds <- c(min(c(bcf_model_root$sigma2_samples, sigma_observed)), max(c(bcf_model_root$sigma2_samples, sigma_observed))) plot(bcf_model_root$sigma2_samples, ylim = plot_bounds, ylab = \"sigma^2\", xlab = \"Sample\", main = \"Global variance parameter\") abline(h = sigma_observed, lty=3, lwd = 3, col = \"blue\") test_lb <- apply(bcf_model_root$tau_hat_test, 1, quantile, 0.025) test_ub <- apply(bcf_model_root$tau_hat_test, 1, quantile, 0.975) cover <- ( (test_lb <= tau_x[test_inds]) & (test_ub >= tau_x[test_inds]) ) mean(cover) #> [1] 0.97"},{"path":"https://stochastictree.github.io/stochtree-r/articles/CausalInference.html","id":"demo-2-linear-outcome-model-heterogeneous-treatment-effect","dir":"Articles","previous_headings":"","what":"Demo 2: Linear Outcome Model, Heterogeneous Treatment Effect","title":"Causal Machine Learning in StochTree","text":"consider following data generating process Hahn, Murray, Carvalho (2020): \\[\\begin{equation*} \\begin{aligned} y &= \\mu(X) + \\tau(X) Z + \\epsilon\\\\ \\epsilon &\\sim N\\left(0,\\sigma^2\\right)\\\\ \\mu(X) &= 1 + g(X) + 6 X_1 X_3\\\\ \\tau(X) &= 1 + 2 X_2 X_4\\\\ g(X) &= \\mathbb{}(X_5=1) \\times 2 - \\mathbb{}(X_5=2) \\times 1 - \\mathbb{}(X_5=3) \\times 4\\\\ X_1,X_2,X_3 &\\sim N\\left(0,1\\right)\\\\ X_4 &\\sim \\text{Bernoulli}(1/2)\\\\ X_5 &\\sim \\text{Categorical}(1/3,1/3,1/3)\\\\ \\end{aligned} \\end{equation*}\\]","code":""},{"path":"https://stochastictree.github.io/stochtree-r/articles/CausalInference.html","id":"simulation-1","dir":"Articles","previous_headings":"Demo 2: Linear Outcome Model, Heterogeneous Treatment Effect","what":"Simulation","title":"Causal Machine Learning in StochTree","text":"draw DGP defined ","code":"n <- 500 snr <- 3 x1 <- rnorm(n) x2 <- rnorm(n) x3 <- rnorm(n) x4 <- as.numeric(rbinom(n,1,0.5)) x5 <- as.numeric(sample(1:3,n,replace=T)) X <- cbind(x1,x2,x3,x4,x5) p <- ncol(X) mu_x <- mu2(X) tau_x <- tau2(X) pi_x <- 0.8*pnorm((3*mu_x/sd(mu_x)) - 0.5*X[,1]) + 0.05 + runif(n)/10 Z <- rbinom(n,1,pi_x) E_XZ <- mu_x + Z*tau_x y <- E_XZ + rnorm(n, 0, 1)*(sd(E_XZ)/snr) # Split data into test and train sets test_set_pct <- 0.2 n_test <- round(test_set_pct*n) n_train <- n - n_test test_inds <- sort(sample(1:n, n_test, replace = F)) train_inds <- (1:n)[!((1:n) %in% test_inds)] X_test <- X[test_inds,] X_train <- X[train_inds,] pi_test <- pi_x[test_inds] pi_train <- pi_x[train_inds] Z_test <- Z[test_inds] Z_train <- Z[train_inds] y_test <- y[test_inds] y_train <- y[train_inds] mu_test <- mu_x[test_inds] mu_train <- mu_x[train_inds] tau_test <- tau_x[test_inds] tau_train <- tau_x[train_inds]"},{"path":[]},{"path":"https://stochastictree.github.io/stochtree-r/articles/CausalInference.html","id":"warmstart-1","dir":"Articles","previous_headings":"Demo 2: Linear Outcome Model, Heterogeneous Treatment Effect > Sampling and Analysis","what":"Warmstart","title":"Causal Machine Learning in StochTree","text":"first simulate ensemble model \\(y \\mid X\\) using “warm-start” initialization samples (Krantsevich, , Hahn (2023)). default stochtree. Inspect BART samples initialized XBART warm-start Examine test set interval coverage","code":"num_gfr <- 10 num_burnin <- 0 num_mcmc <- 100 num_samples <- num_gfr + num_burnin + num_mcmc bcf_model_warmstart <- bcf( X_train = X_train, Z_train = Z_train, y_train = y_train, pi_train = pi_train, X_test = X_test, Z_test = Z_test, pi_test = pi_test, ordered_cat_vars = c(4,5), num_gfr = num_gfr, num_burnin = num_burnin, num_mcmc = num_mcmc, sample_sigma_leaf_mu = F, sample_sigma_leaf_tau = F ) plot(rowMeans(bcf_model_warmstart$mu_hat_test), mu_test, xlab = \"predicted\", ylab = \"actual\", main = \"Prognostic function\") abline(0,1,col=\"red\",lty=3,lwd=3) plot(rowMeans(bcf_model_warmstart$tau_hat_test), tau_test, xlab = \"predicted\", ylab = \"actual\", main = \"Treatment effect\") abline(0,1,col=\"red\",lty=3,lwd=3) sigma_observed <- var(y-E_XZ) plot_bounds <- c(min(c(bcf_model_warmstart$sigma2_samples, sigma_observed)), max(c(bcf_model_warmstart$sigma2_samples, sigma_observed))) plot(bcf_model_warmstart$sigma2_samples, ylim = plot_bounds, ylab = \"sigma^2\", xlab = \"Sample\", main = \"Global variance parameter\") abline(h = sigma_observed, lty=3, lwd = 3, col = \"blue\") test_lb <- apply(bcf_model_warmstart$tau_hat_test, 1, quantile, 0.025) test_ub <- apply(bcf_model_warmstart$tau_hat_test, 1, quantile, 0.975) cover <- ( (test_lb <= tau_x[test_inds]) & (test_ub >= tau_x[test_inds]) ) mean(cover) #> [1] 0.83"},{"path":"https://stochastictree.github.io/stochtree-r/articles/CausalInference.html","id":"bart-mcmc-without-warmstart-1","dir":"Articles","previous_headings":"Demo 2: Linear Outcome Model, Heterogeneous Treatment Effect > Sampling and Analysis","what":"BART MCMC without Warmstart","title":"Causal Machine Learning in StochTree","text":"Next, simulate ensemble model without warm-start initialization. Inspect BART samples burnin Examine test set interval coverage","code":"num_gfr <- 0 num_burnin <- 100 num_mcmc <- 100 num_samples <- num_gfr + num_burnin + num_mcmc bcf_model_root <- bcf( X_train = X_train, Z_train = Z_train, y_train = y_train, pi_train = pi_train, X_test = X_test, Z_test = Z_test, pi_test = pi_test, ordered_cat_vars = c(4,5), num_gfr = num_gfr, num_burnin = num_burnin, num_mcmc = num_mcmc, sample_sigma_leaf_mu = F, sample_sigma_leaf_tau = F ) plot(rowMeans(bcf_model_root$mu_hat_test), mu_test, xlab = \"predicted\", ylab = \"actual\", main = \"Prognostic function\") abline(0,1,col=\"red\",lty=3,lwd=3) plot(rowMeans(bcf_model_root$tau_hat_test), tau_test, xlab = \"predicted\", ylab = \"actual\", main = \"Treatment effect\") abline(0,1,col=\"red\",lty=3,lwd=3) sigma_observed <- var(y-E_XZ) plot_bounds <- c(min(c(bcf_model_root$sigma2_samples, sigma_observed)), max(c(bcf_model_root$sigma2_samples, sigma_observed))) plot(bcf_model_root$sigma2_samples, ylim = plot_bounds, ylab = \"sigma^2\", xlab = \"Sample\", main = \"Global variance parameter\") abline(h = sigma_observed, lty=3, lwd = 3, col = \"blue\") test_lb <- apply(bcf_model_root$tau_hat_test, 1, quantile, 0.025) test_ub <- apply(bcf_model_root$tau_hat_test, 1, quantile, 0.975) cover <- ( (test_lb <= tau_x[test_inds]) & (test_ub >= tau_x[test_inds]) ) mean(cover) #> [1] 0.86"},{"path":"https://stochastictree.github.io/stochtree-r/articles/CausalInference.html","id":"demo-3-linear-outcome-model-homogeneous-treatment-effect","dir":"Articles","previous_headings":"","what":"Demo 3: Linear Outcome Model, Homogeneous Treatment Effect","title":"Causal Machine Learning in StochTree","text":"consider following data generating process Hahn, Murray, Carvalho (2020): \\[\\begin{equation*} \\begin{aligned} y &= \\mu(X) + \\tau(X) Z + \\epsilon\\\\ \\epsilon &\\sim N\\left(0,\\sigma^2\\right)\\\\ \\mu(X) &= 1 + g(X) + 6 X_1 X_3\\\\ \\tau(X) &= 3\\\\ g(X) &= \\mathbb{}(X_5=1) \\times 2 - \\mathbb{}(X_5=2) \\times 1 - \\mathbb{}(X_5=3) \\times 4\\\\ X_1,X_2,X_3 &\\sim N\\left(0,1\\right)\\\\ X_4 &\\sim \\text{Bernoulli}(1/2)\\\\ X_5 &\\sim \\text{Categorical}(1/3,1/3,1/3)\\\\ \\end{aligned} \\end{equation*}\\]","code":""},{"path":"https://stochastictree.github.io/stochtree-r/articles/CausalInference.html","id":"simulation-2","dir":"Articles","previous_headings":"Demo 3: Linear Outcome Model, Homogeneous Treatment Effect","what":"Simulation","title":"Causal Machine Learning in StochTree","text":"draw DGP defined ","code":"n <- 500 snr <- 3 x1 <- rnorm(n) x2 <- rnorm(n) x3 <- rnorm(n) x4 <- as.numeric(rbinom(n,1,0.5)) x5 <- as.numeric(sample(1:3,n,replace=T)) X <- cbind(x1,x2,x3,x4,x5) p <- ncol(X) mu_x <- mu2(X) tau_x <- tau1(X) pi_x <- 0.8*pnorm((3*mu_x/sd(mu_x)) - 0.5*X[,1]) + 0.05 + runif(n)/10 Z <- rbinom(n,1,pi_x) E_XZ <- mu_x + Z*tau_x y <- E_XZ + rnorm(n, 0, 1)*(sd(E_XZ)/snr) # Split data into test and train sets test_set_pct <- 0.2 n_test <- round(test_set_pct*n) n_train <- n - n_test test_inds <- sort(sample(1:n, n_test, replace = F)) train_inds <- (1:n)[!((1:n) %in% test_inds)] X_test <- X[test_inds,] X_train <- X[train_inds,] pi_test <- pi_x[test_inds] pi_train <- pi_x[train_inds] Z_test <- Z[test_inds] Z_train <- Z[train_inds] y_test <- y[test_inds] y_train <- y[train_inds] mu_test <- mu_x[test_inds] mu_train <- mu_x[train_inds] tau_test <- tau_x[test_inds] tau_train <- tau_x[train_inds]"},{"path":[]},{"path":"https://stochastictree.github.io/stochtree-r/articles/CausalInference.html","id":"warmstart-2","dir":"Articles","previous_headings":"Demo 3: Linear Outcome Model, Homogeneous Treatment Effect > Sampling and Analysis","what":"Warmstart","title":"Causal Machine Learning in StochTree","text":"first simulate ensemble model \\(y \\mid X\\) using “warm-start” initialization samples (Krantsevich, , Hahn (2023)). default stochtree. Inspect BART samples initialized XBART warm-start Examine test set interval coverage","code":"num_gfr <- 10 num_burnin <- 0 num_mcmc <- 100 num_samples <- num_gfr + num_burnin + num_mcmc bcf_model_warmstart <- bcf( X_train = X_train, Z_train = Z_train, y_train = y_train, pi_train = pi_train, X_test = X_test, Z_test = Z_test, pi_test = pi_test, ordered_cat_vars = c(4,5), num_gfr = num_gfr, num_burnin = num_burnin, num_mcmc = num_mcmc, sample_sigma_leaf_mu = F, sample_sigma_leaf_tau = F ) plot(rowMeans(bcf_model_warmstart$mu_hat_test), mu_test, xlab = \"predicted\", ylab = \"actual\", main = \"Prognostic function\") abline(0,1,col=\"red\",lty=3,lwd=3) plot(rowMeans(bcf_model_warmstart$tau_hat_test), tau_test, xlab = \"predicted\", ylab = \"actual\", main = \"Treatment effect\") abline(0,1,col=\"red\",lty=3,lwd=3) sigma_observed <- var(y-E_XZ) plot_bounds <- c(min(c(bcf_model_warmstart$sigma2_samples, sigma_observed)), max(c(bcf_model_warmstart$sigma2_samples, sigma_observed))) plot(bcf_model_warmstart$sigma2_samples, ylim = plot_bounds, ylab = \"sigma^2\", xlab = \"Sample\", main = \"Global variance parameter\") abline(h = sigma_observed, lty=3, lwd = 3, col = \"blue\") test_lb <- apply(bcf_model_warmstart$tau_hat_test, 1, quantile, 0.025) test_ub <- apply(bcf_model_warmstart$tau_hat_test, 1, quantile, 0.975) cover <- ( (test_lb <= tau_x[test_inds]) & (test_ub >= tau_x[test_inds]) ) mean(cover) #> [1] 1"},{"path":"https://stochastictree.github.io/stochtree-r/articles/CausalInference.html","id":"bart-mcmc-without-warmstart-2","dir":"Articles","previous_headings":"Demo 3: Linear Outcome Model, Homogeneous Treatment Effect > Sampling and Analysis","what":"BART MCMC without Warmstart","title":"Causal Machine Learning in StochTree","text":"Next, simulate ensemble model without warm-start initialization. Inspect BART samples burnin Examine test set interval coverage","code":"num_gfr <- 0 num_burnin <- 100 num_mcmc <- 100 num_samples <- num_gfr + num_burnin + num_mcmc bcf_model_root <- bcf( X_train = X_train, Z_train = Z_train, y_train = y_train, pi_train = pi_train, X_test = X_test, Z_test = Z_test, pi_test = pi_test, ordered_cat_vars = c(4,5), num_gfr = num_gfr, num_burnin = num_burnin, num_mcmc = num_mcmc, sample_sigma_leaf_mu = F, sample_sigma_leaf_tau = F ) plot(rowMeans(bcf_model_root$mu_hat_test), mu_test, xlab = \"predicted\", ylab = \"actual\", main = \"Prognostic function\") abline(0,1,col=\"red\",lty=3,lwd=3) plot(rowMeans(bcf_model_root$tau_hat_test), tau_test, xlab = \"predicted\", ylab = \"actual\", main = \"Treatment effect\") abline(0,1,col=\"red\",lty=3,lwd=3) sigma_observed <- var(y-E_XZ) plot_bounds <- c(min(c(bcf_model_root$sigma2_samples, sigma_observed)), max(c(bcf_model_root$sigma2_samples, sigma_observed))) plot(bcf_model_root$sigma2_samples, ylim = plot_bounds, ylab = \"sigma^2\", xlab = \"Sample\", main = \"Global variance parameter\") abline(h = sigma_observed, lty=3, lwd = 3, col = \"blue\") test_lb <- apply(bcf_model_root$tau_hat_test, 1, quantile, 0.025) test_ub <- apply(bcf_model_root$tau_hat_test, 1, quantile, 0.975) cover <- ( (test_lb <= tau_x[test_inds]) & (test_ub >= tau_x[test_inds]) ) mean(cover) #> [1] 1"},{"path":"https://stochastictree.github.io/stochtree-r/articles/CausalInference.html","id":"demo-4-nonlinear-outcome-model-heterogeneous-treatment-effect","dir":"Articles","previous_headings":"","what":"Demo 4: Nonlinear Outcome Model, Heterogeneous Treatment Effect","title":"Causal Machine Learning in StochTree","text":"consider following data generating process: \\[\\begin{equation*} \\begin{aligned} y &= \\mu(X) + \\tau(X) Z + \\epsilon\\\\ \\epsilon &\\sim N\\left(0,\\sigma^2\\right)\\\\ \\mu(X) &= \\begin{cases} -1.1 & \\text{ } X_1 > X_2\\\\ 0.9 & \\text{ } X_1 \\leq X_2 \\end{cases}\\\\ \\tau(X) &= \\frac{1}{1+\\exp(-X_3)} + \\frac{X_2}{10}\\\\ \\pi(X) &= \\Phi\\left(\\mu(X)\\right)\\\\ Z &\\sim \\text{Bernoulli}\\left(\\pi(X)\\right)\\\\ X_1,X_2,X_3 &\\sim N\\left(0,1\\right)\\\\ X_4 &\\sim N\\left(X_2,1\\right)\\\\ \\end{aligned} \\end{equation*}\\]","code":""},{"path":"https://stochastictree.github.io/stochtree-r/articles/CausalInference.html","id":"simulation-3","dir":"Articles","previous_headings":"Demo 4: Nonlinear Outcome Model, Heterogeneous Treatment Effect","what":"Simulation","title":"Causal Machine Learning in StochTree","text":"draw DGP defined ","code":"n <- 1000 x1 <- rnorm(n) x2 <- rnorm(n) x3 <- rnorm(n) x4 <- rnorm(n,x2,1) X <- cbind(x1,x2,x3,x4) p <- ncol(X) mu <- function(x) {-1*(x[,1]>(x[,2])) + 1*(x[,1]<(x[,2])) - 0.1} tau <- function(x) {1/(1 + exp(-x[,3])) + x[,2]/10} mu_x <- mu(X) tau_x <- tau(X) pi_x <- pnorm(mu_x) Z <- rbinom(n,1,pi_x) E_XZ <- mu_x + Z*tau_x sigma <- diff(range(mu_x + tau_x*pi))/8 y <- E_XZ + sigma*rnorm(n) # Split data into test and train sets test_set_pct <- 0.2 n_test <- round(test_set_pct*n) n_train <- n - n_test test_inds <- sort(sample(1:n, n_test, replace = F)) train_inds <- (1:n)[!((1:n) %in% test_inds)] X_test <- X[test_inds,] X_train <- X[train_inds,] pi_test <- pi_x[test_inds] pi_train <- pi_x[train_inds] Z_test <- Z[test_inds] Z_train <- Z[train_inds] y_test <- y[test_inds] y_train <- y[train_inds] mu_test <- mu_x[test_inds] mu_train <- mu_x[train_inds] tau_test <- tau_x[test_inds] tau_train <- tau_x[train_inds]"},{"path":[]},{"path":"https://stochastictree.github.io/stochtree-r/articles/CausalInference.html","id":"warmstart-3","dir":"Articles","previous_headings":"Demo 4: Nonlinear Outcome Model, Heterogeneous Treatment Effect > Sampling and Analysis","what":"Warmstart","title":"Causal Machine Learning in StochTree","text":"first simulate ensemble model \\(y \\mid X\\) using “warm-start” initialization samples (Krantsevich, , Hahn (2023)). default stochtree. Inspect BART samples initialized XBART warm-start Examine test set interval coverage","code":"num_gfr <- 10 num_burnin <- 0 num_mcmc <- 100 num_samples <- num_gfr + num_burnin + num_mcmc bcf_model_warmstart <- bcf( X_train = X_train, Z_train = Z_train, y_train = y_train, pi_train = pi_train, X_test = X_test, Z_test = Z_test, pi_test = pi_test, num_gfr = num_gfr, num_burnin = num_burnin, num_mcmc = num_mcmc, sample_sigma_leaf_mu = F, sample_sigma_leaf_tau = F ) plot(rowMeans(bcf_model_warmstart$mu_hat_test), mu_test, xlab = \"predicted\", ylab = \"actual\", main = \"Prognostic function\") abline(0,1,col=\"red\",lty=3,lwd=3) plot(rowMeans(bcf_model_warmstart$tau_hat_test), tau_test, xlab = \"predicted\", ylab = \"actual\", main = \"Treatment effect\") abline(0,1,col=\"red\",lty=3,lwd=3) sigma_observed <- var(y-E_XZ) plot_bounds <- c(min(c(bcf_model_warmstart$sigma2_samples, sigma_observed)), max(c(bcf_model_warmstart$sigma2_samples, sigma_observed))) plot(bcf_model_warmstart$sigma2_samples, ylim = plot_bounds, ylab = \"sigma^2\", xlab = \"Sample\", main = \"Global variance parameter\") abline(h = sigma_observed, lty=3, lwd = 3, col = \"blue\") test_lb <- apply(bcf_model_warmstart$tau_hat_test, 1, quantile, 0.025) test_ub <- apply(bcf_model_warmstart$tau_hat_test, 1, quantile, 0.975) cover <- ( (test_lb <= tau_x[test_inds]) & (test_ub >= tau_x[test_inds]) ) mean(cover) #> [1] 0.97"},{"path":"https://stochastictree.github.io/stochtree-r/articles/CausalInference.html","id":"bart-mcmc-without-warmstart-3","dir":"Articles","previous_headings":"Demo 4: Nonlinear Outcome Model, Heterogeneous Treatment Effect > Sampling and Analysis","what":"BART MCMC without Warmstart","title":"Causal Machine Learning in StochTree","text":"Next, simulate ensemble model without warm-start initialization. Inspect BART samples burnin Examine test set interval coverage","code":"num_gfr <- 0 num_burnin <- 100 num_mcmc <- 100 num_samples <- num_gfr + num_burnin + num_mcmc bcf_model_root <- bcf( X_train = X_train, Z_train = Z_train, y_train = y_train, pi_train = pi_train, X_test = X_test, Z_test = Z_test, pi_test = pi_test, num_gfr = num_gfr, num_burnin = num_burnin, num_mcmc = num_mcmc, sample_sigma_leaf_mu = F, sample_sigma_leaf_tau = F ) plot(rowMeans(bcf_model_root$mu_hat_test), mu_test, xlab = \"predicted\", ylab = \"actual\", main = \"Prognostic function\") abline(0,1,col=\"red\",lty=3,lwd=3) plot(rowMeans(bcf_model_root$tau_hat_test), tau_test, xlab = \"predicted\", ylab = \"actual\", main = \"Treatment effect\") abline(0,1,col=\"red\",lty=3,lwd=3) sigma_observed <- var(y-E_XZ) plot_bounds <- c(min(c(bcf_model_root$sigma2_samples, sigma_observed)), max(c(bcf_model_root$sigma2_samples, sigma_observed))) plot(bcf_model_root$sigma2_samples, ylim = plot_bounds, ylab = \"sigma^2\", xlab = \"Sample\", main = \"Global variance parameter\") abline(h = sigma_observed, lty=3, lwd = 3, col = \"blue\") test_lb <- apply(bcf_model_root$tau_hat_test, 1, quantile, 0.025) test_ub <- apply(bcf_model_root$tau_hat_test, 1, quantile, 0.975) cover <- ( (test_lb <= tau_x[test_inds]) & (test_ub >= tau_x[test_inds]) ) mean(cover) #> [1] 0.94"},{"path":"https://stochastictree.github.io/stochtree-r/articles/CausalInference.html","id":"demo-5-nonlinear-outcome-model-heterogeneous-treatment-effect-with-additive-random-effects","dir":"Articles","previous_headings":"","what":"Demo 5: Nonlinear Outcome Model, Heterogeneous Treatment Effect with Additive Random Effects","title":"Causal Machine Learning in StochTree","text":"augment simulated example Demo 1 additive random effect structure show bcf() function can estimate incorporate effects forest sampling procedure.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/articles/CausalInference.html","id":"simulation-4","dir":"Articles","previous_headings":"Demo 5: Nonlinear Outcome Model, Heterogeneous Treatment Effect with Additive Random Effects","what":"Simulation","title":"Causal Machine Learning in StochTree","text":"draw augmented “demo 1” DGP","code":"n <- 500 snr <- 3 x1 <- rnorm(n) x2 <- rnorm(n) x3 <- rnorm(n) x4 <- as.numeric(rbinom(n,1,0.5)) x5 <- as.numeric(sample(1:3,n,replace=T)) X <- cbind(x1,x2,x3,x4,x5) p <- ncol(X) mu_x <- mu1(X) tau_x <- tau2(X) pi_x <- 0.8*pnorm((3*mu_x/sd(mu_x)) - 0.5*X[,1]) + 0.05 + runif(n)/10 Z <- rbinom(n,1,pi_x) E_XZ <- mu_x + Z*tau_x group_ids <- rep(c(1,2), n %/% 2) rfx_coefs <- matrix(c(-1, -1, 1, 1),nrow=2,byrow=T) rfx_basis <- cbind(1, runif(n, -1, 1)) rfx_term <- rowSums(rfx_coefs[group_ids,] * rfx_basis) y <- E_XZ + rfx_term + rnorm(n, 0, 1)*(sd(E_XZ)/snr) # Split data into test and train sets test_set_pct <- 0.2 n_test <- round(test_set_pct*n) n_train <- n - n_test test_inds <- sort(sample(1:n, n_test, replace = F)) train_inds <- (1:n)[!((1:n) %in% test_inds)] X_test <- X[test_inds,] X_train <- X[train_inds,] pi_test <- pi_x[test_inds] pi_train <- pi_x[train_inds] Z_test <- Z[test_inds] Z_train <- Z[train_inds] y_test <- y[test_inds] y_train <- y[train_inds] mu_test <- mu_x[test_inds] mu_train <- mu_x[train_inds] tau_test <- tau_x[test_inds] tau_train <- tau_x[train_inds] group_ids_test <- group_ids[test_inds] group_ids_train <- group_ids[train_inds] rfx_basis_test <- rfx_basis[test_inds,] rfx_basis_train <- rfx_basis[train_inds,] rfx_term_test <- rfx_term[test_inds] rfx_term_train <- rfx_term[train_inds]"},{"path":[]},{"path":"https://stochastictree.github.io/stochtree-r/articles/CausalInference.html","id":"warmstart-4","dir":"Articles","previous_headings":"Demo 5: Nonlinear Outcome Model, Heterogeneous Treatment Effect with Additive Random Effects > Sampling and Analysis","what":"Warmstart","title":"Causal Machine Learning in StochTree","text":"simulate “warm-start” model (running root-MCMC BART random effects simply matter modifying code snippet setting num_gfr <- 0 num_mcmc > 0). Inspect BART samples initialized XBART warm-start Examine test set interval coverage clear causal inference much difficult presence strong covariate-dependent prognostic effects strong group-level random effects. sense, proper prior calibration three \\(\\mu\\), \\(\\tau\\) random effects models crucial.","code":"num_gfr <- 100 num_burnin <- 0 num_mcmc <- 500 num_samples <- num_gfr + num_burnin + num_mcmc bcf_model_warmstart <- bcf( X_train = X_train, Z_train = Z_train, y_train = y_train, pi_train = pi_train, group_ids_train = group_ids_train, rfx_basis_train = rfx_basis_train, X_test = X_test, Z_test = Z_test, pi_test = pi_test, group_ids_test = group_ids_test, rfx_basis_test = rfx_basis_test, ordered_cat_vars = c(4,5), num_gfr = num_gfr, num_burnin = num_burnin, num_mcmc = num_mcmc, sample_sigma_leaf_mu = T, sample_sigma_leaf_tau = F ) plot(rowMeans(bcf_model_warmstart$mu_hat_test), mu_test, xlab = \"predicted\", ylab = \"actual\", main = \"Prognostic function\") abline(0,1,col=\"red\",lty=3,lwd=3) plot(rowMeans(bcf_model_warmstart$tau_hat_test), tau_test, xlab = \"predicted\", ylab = \"actual\", main = \"Treatment effect\") abline(0,1,col=\"red\",lty=3,lwd=3) plot(rowMeans(bcf_model_warmstart$y_hat_test), y_test, xlab = \"predicted\", ylab = \"actual\", main = \"Outcome\") abline(0,1,col=\"red\",lty=3,lwd=3) plot(rowMeans(bcf_model_warmstart$rfx_preds_test), rfx_term_test, xlab = \"predicted\", ylab = \"actual\", main = \"Random effects terms\") abline(0,1,col=\"red\",lty=3,lwd=3) sigma_observed <- var(y-E_XZ-rfx_term) plot_bounds <- c(min(c(bcf_model_warmstart$sigma2_samples, sigma_observed)), max(c(bcf_model_warmstart$sigma2_samples, sigma_observed))) plot(bcf_model_warmstart$sigma2_samples, ylim = plot_bounds, ylab = \"sigma^2\", xlab = \"Sample\", main = \"Global variance parameter\") abline(h = sigma_observed, lty=3, lwd = 3, col = \"blue\") test_lb <- apply(bcf_model_warmstart$tau_hat_test, 1, quantile, 0.025) test_ub <- apply(bcf_model_warmstart$tau_hat_test, 1, quantile, 0.975) cover <- ( (test_lb <= tau_x[test_inds]) & (test_ub >= tau_x[test_inds]) ) mean(cover) #> [1] 0.9"},{"path":[]},{"path":"https://stochastictree.github.io/stochtree-r/articles/CustomSamplingRoutine.html","id":"motivation","dir":"Articles","previous_headings":"","what":"Motivation","title":"Custom Sampling Routines in StochTree","text":"functions bart() bcf() provide simple performant interfaces supervised learning / causal inference, stochtree also offers access many “low-level” data structures typically implemented C++. low-level interface designed performance even simplicity — rather intent provide “prototype” interface C++ code doesn’t require modifying C++. illustrate prototype interface might useful, consider classic BART algorithm:    INPUT: \\(y\\), \\(X\\), \\(\\tau\\), \\(\\nu\\), \\(\\lambda\\), \\(\\alpha\\), \\(\\beta\\)    OUTPUT: \\(m\\) samples decision forest \\(k\\) trees global variance parameter \\(\\sigma^2\\)    Initialize \\(\\sigma^2\\) via default data-dependent calibration exercise    Initialize “forest 0” \\(k\\) trees single root node, referring tree \\(j\\)’s prediction vector \\(f_{0,j}\\)    Compute residual \\(r = y - \\sum_{j=1}^k f_{0,j}\\)    \\(\\) \\(\\left\\{1,\\dots,m\\right\\}\\):       Initialize forest \\(\\) forest \\(-1\\)       \\(j\\) \\(\\left\\{1,\\dots,k\\right\\}\\):          Add predictions tree \\(j\\) residual: \\(r = r + f_{,j}\\)          Update tree \\(j\\) via Metropolis-Hastings \\(r\\) \\(X\\) data tree priors depending (\\(\\tau\\), \\(\\sigma^2\\), \\(\\alpha\\), \\(\\beta\\))          Sample leaf node parameters tree \\(j\\) via Gibbs (leaf node prior \\(N\\left(0,\\tau\\right)\\))          Subtract (updated) predictions tree \\(j\\) residual: \\(r = r - f_{,j}\\)       Sample \\(\\sigma^2\\) via Gibbs (prior \\(IG(\\nu/2,\\nu\\lambda/2)\\)) algorithm conceptually simple, much core computation carried low-level languages C C++ tree data structure. result, changes algorithm, supporting heteroskedasticity (Pratola et al. (2020)), categorical outcomes (Murray (2021)) causal effect estimation (Hahn, Murray, Carvalho (2020)) require modifying low-level code. prototype interface exposes core components loop R level, thus making possible interchange C++ computation steps like “update tree \\(j\\) via Metropolis-Hastings” R computation custom variance model, user-specified additive mean model components, . begin, load stochtree package","code":"library(stochtree)"},{"path":[]},{"path":"https://stochastictree.github.io/stochtree-r/articles/CustomSamplingRoutine.html","id":"simulation","dir":"Articles","previous_headings":"Demo 1: Supervised Learning","what":"Simulation","title":"Custom Sampling Routines in StochTree","text":"Simulate simple partitioned linear model","code":"# Generate the data n <- 500 p_X <- 10 p_W <- 1 X <- matrix(runif(n*p_X), ncol = p_X) W <- matrix(runif(n*p_W), ncol = p_W) f_XW <- ( ((0 <= X[,1]) & (0.25 > X[,1])) * (-3*W[,1]) + ((0.25 <= X[,1]) & (0.5 > X[,1])) * (-1*W[,1]) + ((0.5 <= X[,1]) & (0.75 > X[,1])) * (1*W[,1]) + ((0.75 <= X[,1]) & (1 > X[,1])) * (3*W[,1]) ) y <- f_XW + rnorm(n, 0, 1) # Standardize outcome y_bar <- mean(y) y_std <- sd(y) resid <- (y-y_bar)/y_std"},{"path":"https://stochastictree.github.io/stochtree-r/articles/CustomSamplingRoutine.html","id":"sampling","dir":"Articles","previous_headings":"Demo 1: Supervised Learning","what":"Sampling","title":"Custom Sampling Routines in StochTree","text":"Set parameters inform forest variance parameter samplers Initialize R-level access C++ classes needed sample model Prepare run sampler Run grow--root sampler “warm-start” BART Pick last GFR forest (associated global variance / leaf scale parameters) MCMC sampler Predict rescale samples","code":"alpha <- 0.9 beta <- 1.25 min_samples_leaf <- 1 num_trees <- 100 cutpoint_grid_size = 100 global_variance_init = 1. tau_init = 0.5 leaf_prior_scale = matrix(c(tau_init), ncol = 1) nu <- 4 lambda <- 0.5 a_leaf <- 2. b_leaf <- 0.5 leaf_regression <- T feature_types <- as.integer(rep(0, p_X)) # 0 = numeric var_weights <- rep(1/p_X, p_X) # Data if (leaf_regression) { forest_dataset <- createForestDataset(X, W) outcome_model_type <- 1 } else { forest_dataset <- createForestDataset(X) outcome_model_type <- 0 } outcome <- createOutcome(resid) # Random number generator (std::mt19937) rng <- createRNG() # Sampling data structures forest_model <- createForestModel(forest_dataset, feature_types, num_trees, n, alpha, beta, min_samples_leaf) # Container of forest samples if (leaf_regression) { forest_samples <- createForestContainer(num_trees, 1, F) } else { forest_samples <- createForestContainer(num_trees, 1, T) } num_warmstart <- 10 num_mcmc <- 100 num_samples <- num_warmstart + num_mcmc global_var_samples <- c(global_variance_init, rep(0, num_samples)) leaf_scale_samples <- c(tau_init, rep(0, num_samples)) for (i in 1:num_warmstart) { # Sample forest forest_model$sample_one_iteration( forest_dataset, outcome, forest_samples, rng, feature_types, outcome_model_type, leaf_prior_scale, var_weights, global_var_samples[i], cutpoint_grid_size, gfr = T ) # Sample global variance parameter global_var_samples[i+1] <- sample_sigma2_one_iteration( outcome, rng, nu, lambda ) # Sample leaf node variance parameter and update `leaf_prior_scale` leaf_scale_samples[i+1] <- sample_tau_one_iteration( forest_samples, rng, a_leaf, b_leaf, i-1 ) leaf_prior_scale[1,1] <- leaf_scale_samples[i+1] } for (i in (num_warmstart+1):num_samples) { # Sample forest forest_model$sample_one_iteration( forest_dataset, outcome, forest_samples, rng, feature_types, outcome_model_type, leaf_prior_scale, var_weights, global_var_samples[i], cutpoint_grid_size, gfr = F ) # Sample global variance parameter global_var_samples[i+1] <- sample_sigma2_one_iteration( outcome, rng, nu, lambda ) # Sample leaf node variance parameter and update `leaf_prior_scale` leaf_scale_samples[i+1] <- sample_tau_one_iteration( forest_samples, rng, a_leaf, b_leaf, i-1 ) leaf_prior_scale[1,1] <- leaf_scale_samples[i+1] } # Forest predictions preds <- forest_samples$predict(forest_dataset)*y_std + y_bar # Global error variance sigma_samples <- sqrt(global_var_samples)*y_std"},{"path":"https://stochastictree.github.io/stochtree-r/articles/CustomSamplingRoutine.html","id":"results","dir":"Articles","previous_headings":"Demo 1: Supervised Learning","what":"Results","title":"Custom Sampling Routines in StochTree","text":"Inspect initial samples obtained via “grow--root” (Hahn (2023)) Inspect BART samples obtained “warm-starting”","code":"plot(sigma_samples[1:num_warmstart], ylab=\"sigma\") plot(rowMeans(preds[,1:num_warmstart]), y, pch=16, cex=0.75, xlab = \"pred\", ylab = \"actual\") abline(0,1,col=\"red\",lty=2,lwd=2.5) plot(sigma_samples[(num_warmstart+1):num_samples], ylab=\"sigma\") plot(rowMeans(preds[,(num_warmstart+1):num_samples]), y, pch=16, cex=0.75, xlab = \"pred\", ylab = \"actual\") abline(0,1,col=\"red\",lty=2,lwd=2.5)"},{"path":"https://stochastictree.github.io/stochtree-r/articles/CustomSamplingRoutine.html","id":"demo-2-supervised-learning-with-additive-random-effects","dir":"Articles","previous_headings":"","what":"Demo 2: Supervised Learning with Additive Random Effects","title":"Custom Sampling Routines in StochTree","text":"build example add simple “random effects” structure: every observation either group 1 group 2 random group intercept (simulated quite strong, underscoring need random effects modeling).","code":""},{"path":"https://stochastictree.github.io/stochtree-r/articles/CustomSamplingRoutine.html","id":"simulation-1","dir":"Articles","previous_headings":"Demo 2: Supervised Learning with Additive Random Effects","what":"Simulation","title":"Custom Sampling Routines in StochTree","text":"Simulate partitioned linear model simple additive group random effect structure","code":"# Generate the data n <- 500 p_X <- 10 p_W <- 1 X <- matrix(runif(n*p_X), ncol = p_X) W <- matrix(runif(n*p_W), ncol = p_W) group_ids <- rep(c(1,2), n %/% 2) rfx_coefs <- c(-5, 5) rfx_basis <- rep(1, n) f_XW <- ( ((0 <= X[,1]) & (0.25 > X[,1])) * (-3*W[,1]) + ((0.25 <= X[,1]) & (0.5 > X[,1])) * (-1*W[,1]) + ((0.5 <= X[,1]) & (0.75 > X[,1])) * (1*W[,1]) + ((0.75 <= X[,1]) & (1 > X[,1])) * (3*W[,1]) ) rfx_term <- rfx_coefs[group_ids] * rfx_basis y <- f_XW + rfx_term + rnorm(n, 0, 1) # Standardize outcome y_bar <- mean(y) y_std <- sd(y) resid <- (y-y_bar)/y_std"},{"path":"https://stochastictree.github.io/stochtree-r/articles/CustomSamplingRoutine.html","id":"sampling-1","dir":"Articles","previous_headings":"Demo 2: Supervised Learning with Additive Random Effects","what":"Sampling","title":"Custom Sampling Routines in StochTree","text":"Set parameters inform forest variance parameter samplers Set parameters inform random effects samplers Initialize R-level access C++ classes needed sample model Prepare run sampler Run grow--root sampler “warm-start” BART Pick last GFR forest (associated global variance / leaf scale parameters) MCMC sampler Predict rescale samples","code":"alpha <- 0.9 beta <- 1.25 min_samples_leaf <- 1 num_trees <- 100 cutpoint_grid_size = 100 global_variance_init = 1. tau_init = 0.5 leaf_prior_scale = matrix(c(tau_init), ncol = 1) nu <- 4 lambda <- 0.5 a_leaf <- 2. b_leaf <- 0.5 leaf_regression <- T feature_types <- as.integer(rep(0, p_X)) # 0 = numeric var_weights <- rep(1/p_X, p_X) alpha_init <- c(1) xi_init <- matrix(c(1,1),1,2) sigma_alpha_init <- matrix(c(1),1,1) sigma_xi_init <- matrix(c(1),1,1) sigma_xi_shape <- 1 sigma_xi_scale <- 1 # Data if (leaf_regression) { forest_dataset <- createForestDataset(X, W) outcome_model_type <- 1 } else { forest_dataset <- createForestDataset(X) outcome_model_type <- 0 } outcome <- createOutcome(resid) # Random number generator (std::mt19937) rng <- createRNG() # Sampling data structures forest_model <- createForestModel(forest_dataset, feature_types, num_trees, n, alpha, beta, min_samples_leaf) # Container of forest samples if (leaf_regression) { forest_samples <- createForestContainer(num_trees, 1, F) } else { forest_samples <- createForestContainer(num_trees, 1, T) } # Random effects dataset rfx_basis <- as.matrix(rfx_basis) group_ids <- as.integer(group_ids) rfx_dataset <- createRandomEffectsDataset(group_ids, rfx_basis) # Random effects details num_groups <- length(unique(group_ids)) num_components <- ncol(rfx_basis) # Random effects tracker rfx_tracker <- createRandomEffectsTracker(group_ids) # Random effects model rfx_model <- createRandomEffectsModel(num_components, num_groups) rfx_model$set_working_parameter(alpha_init) rfx_model$set_group_parameters(xi_init) rfx_model$set_working_parameter_cov(sigma_alpha_init) rfx_model$set_group_parameter_cov(sigma_xi_init) rfx_model$set_variance_prior_shape(sigma_xi_shape) rfx_model$set_variance_prior_scale(sigma_xi_scale) # Random effect samples rfx_samples <- createRandomEffectSamples(num_components, num_groups, rfx_tracker) num_warmstart <- 10 num_mcmc <- 100 num_samples <- num_warmstart + num_mcmc global_var_samples <- c(global_variance_init, rep(0, num_samples)) leaf_scale_samples <- c(tau_init, rep(0, num_samples)) for (i in 1:num_warmstart) { # Sample forest forest_model$sample_one_iteration( forest_dataset, outcome, forest_samples, rng, feature_types, outcome_model_type, leaf_prior_scale, var_weights, global_var_samples[i], cutpoint_grid_size, gfr = T ) # Sample global variance parameter global_var_samples[i+1] <- sample_sigma2_one_iteration( outcome, rng, nu, lambda ) # Sample leaf node variance parameter and update `leaf_prior_scale` leaf_scale_samples[i+1] <- sample_tau_one_iteration( forest_samples, rng, a_leaf, b_leaf, i-1 ) leaf_prior_scale[1,1] <- leaf_scale_samples[i+1] # Sample random effects model rfx_model$sample_random_effect(rfx_dataset, outcome, rfx_tracker, rfx_samples, global_var_samples[i+1], rng) } for (i in (num_warmstart+1):num_samples) { # Sample forest forest_model$sample_one_iteration( forest_dataset, outcome, forest_samples, rng, feature_types, outcome_model_type, leaf_prior_scale, var_weights, global_var_samples[i], cutpoint_grid_size, gfr = F ) # Sample global variance parameter global_var_samples[i+1] <- sample_sigma2_one_iteration( outcome, rng, nu, lambda ) # Sample leaf node variance parameter and update `leaf_prior_scale` leaf_scale_samples[i+1] <- sample_tau_one_iteration( forest_samples, rng, a_leaf, b_leaf, i-1 ) leaf_prior_scale[1,1] <- leaf_scale_samples[i+1] # Sample random effects model rfx_model$sample_random_effect(rfx_dataset, outcome, rfx_tracker, rfx_samples, global_var_samples[i+1], rng) } # Forest predictions forest_preds <- forest_samples$predict(forest_dataset)*y_std + y_bar # Random effects predictions rfx_preds <- rfx_samples$predict(group_ids, rfx_basis)*y_std # Overall predictions preds <- forest_preds + rfx_preds # Global error variance sigma_samples <- sqrt(global_var_samples)*y_std"},{"path":"https://stochastictree.github.io/stochtree-r/articles/CustomSamplingRoutine.html","id":"results-1","dir":"Articles","previous_headings":"Demo 2: Supervised Learning with Additive Random Effects","what":"Results","title":"Custom Sampling Routines in StochTree","text":"Inspect initial samples obtained via grow--root additive random effects model Inspect BART samples obtained “warm-starting” plus additive random effects model Now inspect samples BART forest alone (without considering random effect predictions)","code":"plot(sigma_samples[1:num_warmstart], ylab=\"sigma\") plot(rowMeans(preds[,1:num_warmstart]), y, pch=16, cex=0.75, xlab = \"pred\", ylab = \"actual\") abline(0,1,col=\"red\",lty=2,lwd=2.5) plot(sigma_samples[(num_warmstart+1):num_samples], ylab=\"sigma\") plot(rowMeans(preds[,(num_warmstart+1):num_samples]), y, pch=16, cex=0.75, xlab = \"pred\", ylab = \"actual\") abline(0,1,col=\"red\",lty=2,lwd=2.5) plot(rowMeans(forest_preds[,(num_warmstart+1):num_samples]), y, pch=16, cex=0.75, xlab = \"pred\", ylab = \"actual\") abline(0,1,col=\"red\",lty=2,lwd=2.5)"},{"path":"https://stochastictree.github.io/stochtree-r/articles/CustomSamplingRoutine.html","id":"demo-3-supervised-learning-with-additive-multi-component-random-effects","dir":"Articles","previous_headings":"","what":"Demo 3: Supervised Learning with Additive Multi-Component Random Effects","title":"Custom Sampling Routines in StochTree","text":"build example, case allowing random intercept regression coefficient (pre-specified basis) group (1 2).","code":""},{"path":"https://stochastictree.github.io/stochtree-r/articles/CustomSamplingRoutine.html","id":"simulation-2","dir":"Articles","previous_headings":"Demo 3: Supervised Learning with Additive Multi-Component Random Effects","what":"Simulation","title":"Custom Sampling Routines in StochTree","text":"Simulate partitioned linear model simple additive group random effect structure","code":"# Generate the data n <- 500 p_X <- 10 p_W <- 1 X <- matrix(runif(n*p_X), ncol = p_X) W <- matrix(runif(n*p_W), ncol = p_W) group_ids <- rep(c(1,2), n %/% 2) rfx_coefs <- matrix(c(-5, -3, 5, 3),nrow=2,byrow=T) rfx_basis <- cbind(1, runif(n, -1, 1)) f_XW <- ( ((0 <= X[,1]) & (0.25 > X[,1])) * (-3*W[,1]) + ((0.25 <= X[,1]) & (0.5 > X[,1])) * (-1*W[,1]) + ((0.5 <= X[,1]) & (0.75 > X[,1])) * (1*W[,1]) + ((0.75 <= X[,1]) & (1 > X[,1])) * (3*W[,1]) ) rfx_term <- rowSums(rfx_coefs[group_ids,] * rfx_basis) y <- f_XW + rfx_term + rnorm(n, 0, 1) # Standardize outcome y_bar <- mean(y) y_std <- sd(y) resid <- (y-y_bar)/y_std"},{"path":"https://stochastictree.github.io/stochtree-r/articles/CustomSamplingRoutine.html","id":"sampling-2","dir":"Articles","previous_headings":"Demo 3: Supervised Learning with Additive Multi-Component Random Effects","what":"Sampling","title":"Custom Sampling Routines in StochTree","text":"Set parameters inform forest variance parameter samplers Set parameters inform random effects samplers Initialize R-level access C++ classes needed sample model Prepare run sampler Run grow--root sampler “warm-start” BART Pick last GFR forest (associated global variance / leaf scale parameters) MCMC sampler Predict rescale samples","code":"alpha <- 0.9 beta <- 1.25 min_samples_leaf <- 1 num_trees <- 100 cutpoint_grid_size = 100 global_variance_init = 1. tau_init = 0.5 leaf_prior_scale = matrix(c(tau_init), ncol = 1) nu <- 4 lambda <- 0.5 a_leaf <- 2. b_leaf <- 0.5 leaf_regression <- T feature_types <- as.integer(rep(0, p_X)) # 0 = numeric var_weights <- rep(1/p_X, p_X) alpha_init <- c(1,0) xi_init <- matrix(c(1,0,1,0),2,2) sigma_alpha_init <- diag(1,2,2) sigma_xi_init <- diag(1,2,2) sigma_xi_shape <- 1 sigma_xi_scale <- 1 # Data if (leaf_regression) { forest_dataset <- createForestDataset(X, W) outcome_model_type <- 1 } else { forest_dataset <- createForestDataset(X) outcome_model_type <- 0 } outcome <- createOutcome(resid) # Random number generator (std::mt19937) rng <- createRNG() # Sampling data structures forest_model <- createForestModel(forest_dataset, feature_types, num_trees, n, alpha, beta, min_samples_leaf) # Container of forest samples if (leaf_regression) { forest_samples <- createForestContainer(num_trees, 1, F) } else { forest_samples <- createForestContainer(num_trees, 1, T) } # Random effects dataset rfx_basis <- as.matrix(rfx_basis) group_ids <- as.integer(group_ids) rfx_dataset <- createRandomEffectsDataset(group_ids, rfx_basis) # Random effects details num_groups <- length(unique(group_ids)) num_components <- ncol(rfx_basis) # Random effects tracker rfx_tracker <- createRandomEffectsTracker(group_ids) # Random effects model rfx_model <- createRandomEffectsModel(num_components, num_groups) rfx_model$set_working_parameter(alpha_init) rfx_model$set_group_parameters(xi_init) rfx_model$set_working_parameter_cov(sigma_alpha_init) rfx_model$set_group_parameter_cov(sigma_xi_init) rfx_model$set_variance_prior_shape(sigma_xi_shape) rfx_model$set_variance_prior_scale(sigma_xi_scale) # Random effect samples rfx_samples <- createRandomEffectSamples(num_components, num_groups, rfx_tracker) num_warmstart <- 10 num_mcmc <- 100 num_samples <- num_warmstart + num_mcmc global_var_samples <- c(global_variance_init, rep(0, num_samples)) leaf_scale_samples <- c(tau_init, rep(0, num_samples)) for (i in 1:num_warmstart) { # Sample forest forest_model$sample_one_iteration( forest_dataset, outcome, forest_samples, rng, feature_types, outcome_model_type, leaf_prior_scale, var_weights, global_var_samples[i], cutpoint_grid_size, gfr = T ) # Sample global variance parameter global_var_samples[i+1] <- sample_sigma2_one_iteration( outcome, rng, nu, lambda ) # Sample leaf node variance parameter and update `leaf_prior_scale` leaf_scale_samples[i+1] <- sample_tau_one_iteration( forest_samples, rng, a_leaf, b_leaf, i-1 ) leaf_prior_scale[1,1] <- leaf_scale_samples[i+1] # Sample random effects model rfx_model$sample_random_effect(rfx_dataset, outcome, rfx_tracker, rfx_samples, global_var_samples[i+1], rng) } for (i in (num_warmstart+1):num_samples) { # Sample forest forest_model$sample_one_iteration( forest_dataset, outcome, forest_samples, rng, feature_types, outcome_model_type, leaf_prior_scale, var_weights, global_var_samples[i], cutpoint_grid_size, gfr = F ) # Sample global variance parameter global_var_samples[i+1] <- sample_sigma2_one_iteration( outcome, rng, nu, lambda ) # Sample leaf node variance parameter and update `leaf_prior_scale` leaf_scale_samples[i+1] <- sample_tau_one_iteration( forest_samples, rng, a_leaf, b_leaf, i-1 ) leaf_prior_scale[1,1] <- leaf_scale_samples[i+1] # Sample random effects model rfx_model$sample_random_effect(rfx_dataset, outcome, rfx_tracker, rfx_samples, global_var_samples[i+1], rng) } # Forest predictions forest_preds <- forest_samples$predict(forest_dataset)*y_std + y_bar # Random effects predictions rfx_preds <- rfx_samples$predict(group_ids, rfx_basis)*y_std # Overall predictions preds <- forest_preds + rfx_preds # Global error variance sigma_samples <- sqrt(global_var_samples)*y_std"},{"path":"https://stochastictree.github.io/stochtree-r/articles/CustomSamplingRoutine.html","id":"results-2","dir":"Articles","previous_headings":"Demo 3: Supervised Learning with Additive Multi-Component Random Effects","what":"Results","title":"Custom Sampling Routines in StochTree","text":"Inspect initial samples obtained via grow--root additive random effects model Inspect BART samples obtained “warm-starting” plus additive random effects model Now inspect samples BART forest alone (without considering random effect predictions)","code":"plot(sigma_samples[1:num_warmstart], ylab=\"sigma\") plot(rowMeans(preds[,1:num_warmstart]), y, pch=16, cex=0.75, xlab = \"pred\", ylab = \"actual\") abline(0,1,col=\"red\",lty=2,lwd=2.5) plot(sigma_samples[(num_warmstart+1):num_samples], ylab=\"sigma\") plot(rowMeans(preds[,(num_warmstart+1):num_samples]), y, pch=16, cex=0.75, xlab = \"pred\", ylab = \"actual\") abline(0,1,col=\"red\",lty=2,lwd=2.5) plot(rowMeans(forest_preds[,(num_warmstart+1):num_samples]), y, pch=16, cex=0.75, xlab = \"pred\", ylab = \"actual\") abline(0,1,col=\"red\",lty=2,lwd=2.5)"},{"path":"https://stochastictree.github.io/stochtree-r/articles/CustomSamplingRoutine.html","id":"demo-4-causal-inference","dir":"Articles","previous_headings":"","what":"Demo 4: Causal Inference","title":"Custom Sampling Routines in StochTree","text":"show implement Bayesian Causal Forest (BCF) model Hahn, Murray, Carvalho (2020) using stochtree’s prototype API, including demoing non-trivial sampling step done R level.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/articles/CustomSamplingRoutine.html","id":"background","dir":"Articles","previous_headings":"Demo 4: Causal Inference","what":"Background","title":"Custom Sampling Routines in StochTree","text":"supervised learning case previous demo conceptually simple, motivate causal effect estimation task additional notation. Let \\(y\\) refer continuous outcome interest, \\(Z\\) refer binary treatment, \\(X\\) set covariates may influence \\(Y\\), \\(Z\\), . \\(X\\) exhaustive set covariates influence \\(Z\\) \\(Y\\), can specific \\(Y\\) terms causal model (see example Pearl (2009)) \\[\\begin{equation*} \\begin{aligned} Y &= F(Z, X, \\epsilon_Y) \\end{aligned} \\end{equation*}\\] \\(\\epsilon_Y\\) outcome specific random noise \\(F\\) function generates \\(Y\\) (many cases, \\(F\\) can thought inverse CDF conditional \\(X\\) \\(Z\\)). “potential outcomes” (see Imbens Rubin (2015)) can recovered \\(Y^1 = F(1, X, \\epsilon_Y)\\) \\(Y^0 = F(0, X, \\epsilon_Y)\\). causal outcome model can decomposed “mean” “error” terms \\[\\begin{equation*} \\begin{aligned} Y &= \\mu(X) + Z\\tau(X) + \\left[\\eta(X) + Z\\delta(X)\\right]\\\\ \\mu(X) &= \\mathbb{E}_{\\epsilon_Y}\\left[F(0, X, \\epsilon_Y)\\right]\\\\ \\tau(X) &= \\mathbb{E}_{\\epsilon_Y}\\left[F(1, X, \\epsilon_Y) - F(0, X, \\epsilon_Y)\\right]\\\\ \\eta(X) &= F(0, X, \\epsilon_Y) - \\mathbb{E}_{\\epsilon_Y}\\left[F(0, X, \\epsilon_Y)\\right]\\\\ \\delta(X) &= F(1, X, \\epsilon_Y) - F(0, X, \\epsilon_Y) - \\mathbb{E}_{\\epsilon_Y}\\left[F(1, X, \\epsilon_Y) - F(0, X, \\epsilon_Y)\\right] \\end{aligned} \\end{equation*}\\] \\(\\tau(X)\\) precisely conditional average treatment effect (CATE) estimand. Unfortunately, functional form \\(F\\) unavailable analysis, \\(\\tau(X)\\) derived. flexible, regularized nonparametrics enter picture, aim estimate \\(\\mu(X)\\) \\(\\tau(X)\\) data.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/articles/CustomSamplingRoutine.html","id":"bayesian-causal-forest-bcf","dir":"Articles","previous_headings":"Demo 4: Causal Inference > Background","what":"Bayesian Causal Forest (BCF)","title":"Custom Sampling Routines in StochTree","text":"BCF estimates \\(\\mu(X)\\) \\(\\tau(X)\\) using separate BART forests term. Furthermore, rather rely common implicit coding \\(Z\\) 0 control observations 1 treated observations, consider coding control observations parameter \\(b_0\\) treated observations parameter \\(b_1\\). Placing \\(N(0,1/2)\\) prior \\(b_z\\), essentially redefines outcome model \\[\\begin{equation*} \\begin{aligned} y &= \\mu(X) + \\tau(X) f(Z) + \\epsilon\\\\ f(Z) &= b_0(1-Z) + b_1 Z\\\\ \\epsilon &\\sim N\\left(0, \\sigma^2\\right)\\\\ b_0, b_1 &\\sim N\\left(0, 1/2\\right) \\end{aligned} \\end{equation*}\\] Updating \\(b_z\\) requires additional Gibbs step, derive . Conditioning sampled forests \\(\\mu\\) \\(\\tau\\), essentially regressing \\(y - \\mu(Z)\\) \\(\\left[(1-Z)\\tau(X), Z\\tau(X)\\right]\\) closed form posterior \\[\\begin{equation*} \\begin{aligned} b_0 \\mid y, X, \\mu,\\tau &\\sim N\\left(\\frac{s_{y\\tau,0}}{s_{\\tau\\tau,0} + 2\\sigma^2}, \\frac{\\sigma^2}{s_{\\tau\\tau,0} + 2\\sigma^2}\\right)\\\\ b_1 \\mid y, X, \\mu,\\tau &\\sim N\\left(\\frac{s_{y\\tau,1}}{s_{\\tau\\tau,1} + 2\\sigma^2}, \\frac{\\sigma^2}{s_{\\tau\\tau,1} + 2\\sigma^2}\\right) \\end{aligned} \\end{equation*}\\] \\(s_{y\\tau,z} = \\sum_{: Z_i = z} (y_i - \\mu(X_i))\\tau(X_i)\\) \\(s_{\\tau\\tau,z} = \\sum_{: Z_i = z} \\tau(X_i)\\tau(X_i)\\).","code":""},{"path":"https://stochastictree.github.io/stochtree-r/articles/CustomSamplingRoutine.html","id":"simulation-3","dir":"Articles","previous_headings":"Demo 4: Causal Inference","what":"Simulation","title":"Custom Sampling Routines in StochTree","text":"simulated causal DGP mirrors nonlinear, heterogeneous treatment effect DGP presented Hahn, Murray, Carvalho (2020).","code":"n <- 500 x1 <- rnorm(n) x2 <- rnorm(n) x3 <- rnorm(n) x4 <- as.numeric(rbinom(n,1,0.5)) x5 <- as.numeric(sample(1:3,n,replace=T)) X <- cbind(x1,x2,x3,x4,x5) p <- ncol(X) g <- function(x) {ifelse(x[,5]==1,2,ifelse(x[,5]==2,-1,4))} mu1 <- function(x) {1+g(x)+x[,1]*x[,3]} mu2 <- function(x) {1+g(x)+6*abs(x[,3]-1)} tau1 <- function(x) {rep(3,nrow(x))} tau2 <- function(x) {1+2*x[,2]*x[,4]} mu_x <- mu1(X) tau_x <- tau2(X) pi_x <- 0.8*pnorm((3*mu_x/sd(mu_x)) - 0.5*X[,1]) + 0.05 + runif(n)/10 Z <- rbinom(n,1,pi_x) E_XZ <- mu_x + Z*tau_x snr <- 4 y <- E_XZ + rnorm(n, 0, 1)*(sd(E_XZ)/snr) # Standardize outcome y_bar <- mean(y) y_std <- sd(y) resid <- (y-y_bar)/y_std"},{"path":"https://stochastictree.github.io/stochtree-r/articles/CustomSamplingRoutine.html","id":"sampling-3","dir":"Articles","previous_headings":"Demo 4: Causal Inference","what":"Sampling","title":"Custom Sampling Routines in StochTree","text":"Set parameters inform forest variance parameter samplers Prepare run sampler (now must specify initial values \\(b_0\\) \\(b_1\\), choose -1/2 1/2 instead 0 1). Initialize R-level access C++ classes needed sample model Run grow--root sampler “warm-start” BART, also updating adaptive coding parameter \\(b_0\\) \\(b_1\\) Pick last GFR forest (associated global variance / leaf scale parameters) MCMC sampler Predict rescale samples","code":"# Mu forest alpha_mu <- 0.95 beta_mu <- 2.0 min_samples_leaf_mu <- 5 num_trees_mu <- 250 cutpoint_grid_size_mu = 100 tau_init_mu = 1/num_trees_mu leaf_prior_scale_mu = matrix(c(tau_init_mu), ncol = 1) a_leaf_mu <- 3. b_leaf_mu <- var(resid)/(num_trees_mu) leaf_regression_mu <- F sigma_leaf_mu <- var(resid)/(num_trees_mu) current_leaf_scale_mu <- as.matrix(sigma_leaf_mu) # Tau forest alpha_tau <- 0.25 beta_tau <- 3.0 min_samples_leaf_tau <- 5 num_trees_tau <- 50 cutpoint_grid_size_tau = 100 a_leaf_tau <- 3. b_leaf_tau <- var(resid)/(2*num_trees_tau) leaf_regression_tau <- T sigma_leaf_tau <- var(resid)/(2*num_trees_tau) current_leaf_scale_tau <- as.matrix(sigma_leaf_tau) # Common parameters nu <- 3 sigma2hat <- (sigma(lm(resid~X)))^2 quantile_cutoff <- 0.9 if (is.null(lambda)) { lambda <- (sigma2hat*qgamma(1-quantile_cutoff,nu))/nu } sigma2 <- sigma2hat current_sigma2 <- sigma2 # Sampling composition num_gfr <- 20 num_burnin <- 0 num_mcmc <- 100 num_samples <- num_gfr + num_burnin + num_mcmc # Sigma^2 samples global_var_samples <- rep(0, num_samples) # Adaptive coding parameter samples b_0_samples <- rep(0, num_samples) b_1_samples <- rep(0, num_samples) b_0 <- -0.5 b_1 <- 0.5 current_b_0 <- b_0 current_b_1 <- b_1 tau_basis <- (1-Z)*current_b_0 + Z*current_b_1 # Data X_mu <- cbind(X, pi_x) X_tau <- X feature_types <- c(0,0,0,1,1) feature_types_mu <- as.integer(c(feature_types,0)) feature_types_tau <- as.integer(feature_types) variable_weights_mu = rep(1/ncol(X_mu), ncol(X_mu)) variable_weights_tau = rep(1/ncol(X_tau), ncol(X_tau)) forest_dataset_mu <- createForestDataset(X_mu) forest_dataset_tau <- createForestDataset(X_tau, tau_basis) outcome <- createOutcome(resid) # Random number generator (std::mt19937) rng <- createRNG() # Sampling data structures forest_model_mu <- createForestModel( forest_dataset_mu, feature_types_mu, num_trees_mu, nrow(X_mu), alpha_mu, beta_mu, min_samples_leaf_mu ) forest_model_tau <- createForestModel( forest_dataset_tau, feature_types_tau, num_trees_tau, nrow(X_tau), alpha_tau, beta_tau, min_samples_leaf_tau ) # Container of forest samples forest_samples_mu <- createForestContainer(num_trees_mu, 1, T) forest_samples_tau <- createForestContainer(num_trees_tau, 1, F) # Initialize the leaves of each tree in the prognostic forest forest_samples_mu$set_root_leaves(0, mean(resid) / num_trees_mu) forest_samples_mu$update_residual( forest_dataset_mu, outcome, forest_model_mu, F, 0, F ) # Initialize the leaves of each tree in the treatment effect forest forest_samples_tau$set_root_leaves(0, 0.) forest_samples_tau$update_residual( forest_dataset_tau, outcome, forest_model_tau, T, 0, F ) if (num_gfr > 0){ for (i in 1:num_gfr) { # Sample the prognostic forest forest_model_mu$sample_one_iteration( forest_dataset_mu, outcome, forest_samples_mu, rng, feature_types_mu, 0, current_leaf_scale_mu, variable_weights_mu, current_sigma2, cutpoint_grid_size, gfr = T, pre_initialized = T ) # Sample variance parameters (if requested) global_var_samples[i] <- sample_sigma2_one_iteration( outcome, rng, nu, lambda ) current_sigma2 <- global_var_samples[i] # Sample the treatment forest forest_model_tau$sample_one_iteration( forest_dataset_tau, outcome, forest_samples_tau, rng, feature_types_tau, 1, current_leaf_scale_tau, variable_weights_tau, current_sigma2, cutpoint_grid_size, gfr = T, pre_initialized = T ) # Sample adaptive coding parameters mu_x_raw <- forest_samples_mu$predict_raw_single_forest(forest_dataset_mu, i-1) tau_x_raw <- forest_samples_tau$predict_raw_single_forest(forest_dataset_tau, i-1) s_tt0 <- sum(tau_x_raw*tau_x_raw*(Z==0)) s_tt1 <- sum(tau_x_raw*tau_x_raw*(Z==1)) partial_resid_mu <- resid - mu_x_raw s_ty0 <- sum(tau_x_raw*partial_resid_mu*(Z==0)) s_ty1 <- sum(tau_x_raw*partial_resid_mu*(Z==1)) current_b_0 <- rnorm(1, (s_ty0/(s_tt0 + 2*current_sigma2)), sqrt(current_sigma2/(s_tt0 + 2*current_sigma2))) current_b_1 <- rnorm(1, (s_ty1/(s_tt1 + 2*current_sigma2)), sqrt(current_sigma2/(s_tt1 + 2*current_sigma2))) tau_basis <- (1-Z)*current_b_0 + Z*current_b_1 forest_dataset_tau$update_basis(tau_basis) b_0_samples[i] <- current_b_0 b_1_samples[i] <- current_b_1 # Sample variance parameters (if requested) global_var_samples[i] <- sample_sigma2_one_iteration(outcome, rng, nu, lambda) current_sigma2 <- global_var_samples[i] } } if (num_burnin + num_mcmc > 0) { for (i in (num_gfr+1):num_samples) { # Sample the prognostic forest forest_model_mu$sample_one_iteration( forest_dataset_mu, outcome, forest_samples_mu, rng, feature_types_mu, 0, current_leaf_scale_mu, variable_weights_mu, current_sigma2, cutpoint_grid_size, gfr = F, pre_initialized = T ) # Sample global variance parameter global_var_samples[i] <- sample_sigma2_one_iteration(outcome, rng, nu, lambda) current_sigma2 <- global_var_samples[i] # Sample the treatment forest forest_model_tau$sample_one_iteration( forest_dataset_tau, outcome, forest_samples_tau, rng, feature_types_tau, 1, current_leaf_scale_tau, variable_weights_tau, current_sigma2, cutpoint_grid_size, gfr = F, pre_initialized = T ) # Sample coding parameters mu_x_raw <- forest_samples_mu$predict_raw_single_forest(forest_dataset_mu, i-1) tau_x_raw <- forest_samples_tau$predict_raw_single_forest(forest_dataset_tau, i-1) s_tt0 <- sum(tau_x_raw*tau_x_raw*(Z==0)) s_tt1 <- sum(tau_x_raw*tau_x_raw*(Z==1)) partial_resid_mu <- resid - mu_x_raw s_ty0 <- sum(tau_x_raw*partial_resid_mu*(Z==0)) s_ty1 <- sum(tau_x_raw*partial_resid_mu*(Z==1)) current_b_0 <- rnorm(1, (s_ty0/(s_tt0 + 2*current_sigma2)), sqrt(current_sigma2/(s_tt0 + 2*current_sigma2))) current_b_1 <- rnorm(1, (s_ty1/(s_tt1 + 2*current_sigma2)), sqrt(current_sigma2/(s_tt1 + 2*current_sigma2))) tau_basis <- (1-Z)*current_b_0 + Z*current_b_1 forest_dataset_tau$update_basis(tau_basis) b_0_samples[i] <- current_b_0 b_1_samples[i] <- current_b_1 # Sample global variance parameter global_var_samples[i] <- sample_sigma2_one_iteration(outcome, rng, nu, lambda) current_sigma2 <- global_var_samples[i] } } # Forest predictions mu_hat <- forest_samples_mu$predict(forest_dataset_mu)*y_std + y_bar tau_hat_raw <- forest_samples_tau$predict_raw(forest_dataset_tau) tau_hat <- t(t(tau_hat_raw) * (b_1_samples - b_0_samples))*y_std y_hat <- mu_hat + tau_hat * as.numeric(Z) # Global error variance sigma2_samples <- global_var_samples*(y_std^2)"},{"path":"https://stochastictree.github.io/stochtree-r/articles/CustomSamplingRoutine.html","id":"results-3","dir":"Articles","previous_headings":"Demo 4: Causal Inference","what":"Results","title":"Custom Sampling Routines in StochTree","text":"Inspect XBART results Inspect warm start BART results Inspect “adaptive coding” parameters \\(b_0\\) \\(b_1\\).","code":"plot(sigma2_samples[1:num_gfr], ylab=\"sigma^2\") plot(rowMeans(mu_hat[,1:num_gfr]), mu_x, pch=16, cex=0.75, xlab = \"pred\", ylab = \"actual\", main = \"prognostic term\") abline(0,1,col=\"red\",lty=2,lwd=2.5) plot(rowMeans(tau_hat[,1:num_gfr]), tau_x, pch=16, cex=0.75, xlab = \"pred\", ylab = \"actual\", main = \"treatment effect term\") abline(0,1,col=\"red\",lty=2,lwd=2.5) mean((rowMeans(tau_hat[,1:num_gfr]) - tau_x)^2) #> [1] 0.3375474 plot(sigma_samples[(num_gfr+1):num_samples], ylab=\"sigma^2\") plot(rowMeans(mu_hat[,(num_gfr+1):num_samples]), mu_x, pch=16, cex=0.75, xlab = \"pred\", ylab = \"actual\", main = \"prognostic term\") abline(0,1,col=\"red\",lty=2,lwd=2.5) plot(rowMeans(tau_hat[,(num_gfr+1):num_samples]), tau_x, pch=16, cex=0.75, xlab = \"pred\", ylab = \"actual\", main = \"treatment effect term\") abline(0,1,col=\"red\",lty=2,lwd=2.5) mean((rowMeans(tau_hat[,(num_gfr+1):num_samples]) - tau_x)^2) #> [1] 0.3512077 plot(b_0_samples, col = \"blue\", ylab = \"Coding parameter draws\", ylim = c(min(min(b_0_samples), min(b_1_samples)), max(max(b_0_samples), max(b_1_samples)))) points(b_1_samples, col = \"orange\") legend(\"topleft\", legend = c(\"b_0\", \"b_1\"), col = c(\"blue\", \"orange\"), pch = c(1,1))"},{"path":[]},{"path":"https://stochastictree.github.io/stochtree-r/articles/EnsembleKernel.html","id":"motivation","dir":"Articles","previous_headings":"","what":"Motivation","title":"Kernel Methods from Tree Ensembles in StochTree","text":"trained tree ensemble strong --sample performance admits natural motivation “distance” two samples: shared leaf membership. number leaves ensemble 1 \\(s\\) (, tree 1 3 leaves, reserves numbers 1 - 3, turn tree 2 5 leaves, reserves numbers 4 - 8 label leaves, ). dataset \\(n\\) observations, construct matrix \\(W\\) follows:    Initialize \\(W\\) matrix zeroes \\(n\\) rows many columns leaves ensemble    Let s = 0    \\(j\\) \\(\\left\\{1,\\dots,m\\right\\}\\):       Let num_leaves number leaves tree \\(j\\)       \\(\\) \\(\\left\\{1,\\dots,n\\right\\}\\):          Let k leaf tree \\(j\\) maps observation \\(\\)          Set element \\(W_{,k+s} = 1\\)       Let s = s + num_leaves sparse matrix \\(W\\) matrix representation basis predictions ensemble (.e. integrating leaf parameters just analyzing leaf indices). ensemble \\(m\\) trees, can determine proportion trees map observation leaf computing \\(W W^T / m\\). can form basis kernel function used Gaussian process regression, demonstrate . begin, load stochtree package tgp package serve point reference.","code":"library(stochtree) library(tgp) library(MASS) library(mvtnorm)"},{"path":"https://stochastictree.github.io/stochtree-r/articles/EnsembleKernel.html","id":"demo-1-univariate-supervised-learning","dir":"Articles","previous_headings":"","what":"Demo 1: Univariate Supervised Learning","title":"Kernel Methods from Tree Ensembles in StochTree","text":"begin simulated example tgp package (Gramacy Taddy (2010)). data generating process (DGP) non-stationary single numeric covariate. define training set test set evaluate various approaches modeling sample outcome data.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/articles/EnsembleKernel.html","id":"traditional-gaussian-process","dir":"Articles","previous_headings":"Demo 1: Univariate Supervised Learning","what":"Traditional Gaussian Process","title":"Kernel Methods from Tree Ensembles in StochTree","text":"can use tgp package model data classical Gaussian Process. Assess RMSE","code":"# Generate the data X_train <- seq(0,20,length=100) X_test <- seq(0,20,length=99) y_train <- (sin(pi*X_train/5) + 0.2*cos(4*pi*X_train/5)) * (X_train <= 9.6) lin_train <- X_train>9.6; y_train[lin_train] <- -1 + X_train[lin_train]/10 y_train <- y_train + rnorm(length(y_train), sd=0.1) y_test <- (sin(pi*X_test/5) + 0.2*cos(4*pi*X_test/5)) * (X_test <= 9.6) lin_test <- X_test>9.6; y_test[lin_test] <- -1 + X_test[lin_test]/10 # Fit the GP model_gp <- bgp(X=X_train, Z=y_train, XX=X_test) plot(model_gp$ZZ.mean, y_test, xlab = \"predicted\", ylab = \"actual\", main = \"Gaussian process\") abline(0,1,lwd=2.5,lty=3,col=\"red\") sqrt(mean((model_gp$ZZ.mean - y_test)^2)) sqrt(mean((model_gp$ZZ.mean - y_test)^2)) #> [1] 0.0466081"},{"path":"https://stochastictree.github.io/stochtree-r/articles/EnsembleKernel.html","id":"bart-based-gaussian-process","dir":"Articles","previous_headings":"Demo 1: Univariate Supervised Learning","what":"BART-based Gaussian process","title":"Kernel Methods from Tree Ensembles in StochTree","text":"Assess RMSE","code":"# Run BART on the data num_trees <- 200 sigma_leaf <- 1/num_trees bart_model <- bart(X_train=X_train, y_train=y_train, X_test=X_test, num_trees=num_trees) # Extract kernels needed for kriging result_kernels <- computeForestKernels(bart_model=bart_model, X_train=X_train, X_test=X_test) Sigma_11 <- result_kernels$kernel_test Sigma_12 <- result_kernels$kernel_test_train Sigma_22 <- result_kernels$kernel_train Sigma_22_inv <- ginv(Sigma_22) Sigma_21 <- t(Sigma_12) # Compute mean and covariance for the test set posterior mu_tilde <- Sigma_12 %*% Sigma_22_inv %*% y_train Sigma_tilde <- (sigma_leaf)*(Sigma_11 - Sigma_12 %*% Sigma_22_inv %*% Sigma_21) # Sample from f(X_test) | X_test, X_train, f(X_train) gp_samples <- mvtnorm::rmvnorm(1000, mean = mu_tilde, sigma = Sigma_tilde) # Compute posterior mean predictions for f(X_test) yhat_mean_test <- colMeans(gp_samples) plot(yhat_mean_test, y_test, xlab = \"predicted\", ylab = \"actual\", main = \"BART Gaussian process\") abline(0,1,lwd=2.5,lty=3,col=\"red\") sqrt(mean((yhat_mean_test - y_test)^2)) #> [1] 0.09020581"},{"path":"https://stochastictree.github.io/stochtree-r/articles/EnsembleKernel.html","id":"demo-2-multivariate-supervised-learning","dir":"Articles","previous_headings":"","what":"Demo 2: Multivariate Supervised Learning","title":"Kernel Methods from Tree Ensembles in StochTree","text":"proceed simulated “Friedman” dataset, implemented tgp.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/articles/EnsembleKernel.html","id":"traditional-gaussian-process-1","dir":"Articles","previous_headings":"Demo 2: Multivariate Supervised Learning","what":"Traditional Gaussian Process","title":"Kernel Methods from Tree Ensembles in StochTree","text":"can use tgp package model data classical Gaussian Process. Assess RMSE","code":"# Generate the data, add many \"noise variables\" n <- 100 friedman.df <- friedman.1.data(n=n) train_inds <- sort(sample(1:n, floor(0.8*n), replace = F)) test_inds <- (1:n)[!((1:n) %in% train_inds)] X <- as.matrix(friedman.df)[,1:10] X <- cbind(X, matrix(runif(n*10), ncol = 10)) y <- as.matrix(friedman.df)[,12] + rnorm(n,0,1)*(sd(as.matrix(friedman.df)[,11])/2) X_train <- X[train_inds,] X_test <- X[test_inds,] y_train <- y[train_inds] y_test <- y[test_inds] # Fit the GP model_gp <- bgp(X=X_train, Z=y_train, XX=X_test) plot(model_gp$ZZ.mean, y_test, xlab = \"predicted\", ylab = \"actual\", main = \"Gaussian process\") abline(0,1,lwd=2.5,lty=3,col=\"red\") sqrt(mean((model_gp$ZZ.mean - y_test)^2)) #> [1] 5.023593"},{"path":"https://stochastictree.github.io/stochtree-r/articles/EnsembleKernel.html","id":"bart-based-gaussian-process-1","dir":"Articles","previous_headings":"Demo 2: Multivariate Supervised Learning","what":"BART-based Gaussian process","title":"Kernel Methods from Tree Ensembles in StochTree","text":"Assess RMSE use case BART kernel classical kriging perhaps unclear without empirical investigation, see later vignette kernel approach can beneficial causal inference applications.","code":"# Run BART on the data num_trees <- 200 sigma_leaf <- 1/num_trees bart_model <- bart(X_train=X_train, y_train=y_train, X_test=X_test, num_trees=num_trees) # Extract kernels needed for kriging result_kernels <- computeForestKernels(bart_model=bart_model, X_train=X_train, X_test=X_test) Sigma_11 <- result_kernels$kernel_test Sigma_12 <- result_kernels$kernel_test_train Sigma_22 <- result_kernels$kernel_train Sigma_22_inv <- ginv(Sigma_22) Sigma_21 <- t(Sigma_12) # Compute mean and covariance for the test set posterior mu_tilde <- Sigma_12 %*% Sigma_22_inv %*% y_train Sigma_tilde <- (sigma_leaf)*(Sigma_11 - Sigma_12 %*% Sigma_22_inv %*% Sigma_21) # Sample from f(X_test) | X_test, X_train, f(X_train) gp_samples <- mvtnorm::rmvnorm(1000, mean = mu_tilde, sigma = Sigma_tilde) # Compute posterior mean predictions for f(X_test) yhat_mean_test <- colMeans(gp_samples) plot(yhat_mean_test, y_test, xlab = \"predicted\", ylab = \"actual\", main = \"BART Gaussian process\") abline(0,1,lwd=2.5,lty=3,col=\"red\") sqrt(mean((yhat_mean_test - y_test)^2)) #> [1] 5.615765"},{"path":[]},{"path":"https://stochastictree.github.io/stochtree-r/articles/ModelSerialization.html","id":"demo-1-bayesian-causal-forest-bcf","dir":"Articles","previous_headings":"","what":"Demo 1: Bayesian Causal Forest (BCF)","title":"Model Serialization in StochTree","text":"BCF models initially sampled constructed using bcf() function. show save reload models JSON files disk.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/articles/ModelSerialization.html","id":"model-building","dir":"Articles","previous_headings":"Demo 1: Bayesian Causal Forest (BCF)","what":"Model Building","title":"Model Serialization in StochTree","text":"Draw modified version data generating process defined Hahn, Murray, Carvalho (2020). Sample BCF model.","code":"# Generate synthetic data n <- 1000 snr <- 2 x1 <- rnorm(n) x2 <- rnorm(n) x3 <- rnorm(n) x4 <- as.numeric(rbinom(n,1,0.5)) x5 <- as.numeric(sample(1:3,n,replace=T)) X <- cbind(x1,x2,x3,x4,x5) p <- ncol(X) mu_x <- mu1(X) tau_x <- tau2(X) pi_x <- 0.8*pnorm((3*mu_x/sd(mu_x)) - 0.5*X[,1]) + 0.05 + runif(n)/10 Z <- rbinom(n,1,pi_x) E_XZ <- mu_x + Z*tau_x group_ids <- rep(c(1,2), n %/% 2) rfx_coefs <- matrix(c(-1, -1, 1, 1),nrow=2,byrow=T) rfx_basis <- cbind(1, runif(n, -1, 1)) rfx_term <- rowSums(rfx_coefs[group_ids,] * rfx_basis) y <- E_XZ + rfx_term + rnorm(n, 0, 1)*(sd(E_XZ)/snr) # Split data into test and train sets test_set_pct <- 0.2 n_test <- round(test_set_pct*n) n_train <- n - n_test test_inds <- sort(sample(1:n, n_test, replace = F)) train_inds <- (1:n)[!((1:n) %in% test_inds)] X_test <- X[test_inds,] X_train <- X[train_inds,] pi_test <- pi_x[test_inds] pi_train <- pi_x[train_inds] Z_test <- Z[test_inds] Z_train <- Z[train_inds] y_test <- y[test_inds] y_train <- y[train_inds] mu_test <- mu_x[test_inds] mu_train <- mu_x[train_inds] tau_test <- tau_x[test_inds] tau_train <- tau_x[train_inds] group_ids_test <- group_ids[test_inds] group_ids_train <- group_ids[train_inds] rfx_basis_test <- rfx_basis[test_inds,] rfx_basis_train <- rfx_basis[train_inds,] rfx_term_test <- rfx_term[test_inds] rfx_term_train <- rfx_term[train_inds] num_gfr <- 10 num_burnin <- 0 num_mcmc <- 100 num_samples <- num_gfr + num_burnin + num_mcmc bcf_model <- bcf( X_train = X_train, Z_train = Z_train, y_train = y_train, pi_train = pi_train, group_ids_train = group_ids_train, rfx_basis_train = rfx_basis_train, X_test = X_test, Z_test = Z_test, pi_test = pi_test, group_ids_test = group_ids_test, rfx_basis_test = rfx_basis_test, ordered_cat_vars = c(4,5), num_gfr = num_gfr, num_burnin = num_burnin, num_mcmc = num_mcmc, sample_sigma_leaf_mu = F, sample_sigma_leaf_tau = F )"},{"path":"https://stochastictree.github.io/stochtree-r/articles/ModelSerialization.html","id":"serialization","dir":"Articles","previous_headings":"Demo 1: Bayesian Causal Forest (BCF)","what":"Serialization","title":"Model Serialization in StochTree","text":"Save BCF model disk.","code":"saveToJsonFile(bcf_model, \"bcf.json\")"},{"path":"https://stochastictree.github.io/stochtree-r/articles/ModelSerialization.html","id":"deserialization","dir":"Articles","previous_headings":"Demo 1: Bayesian Causal Forest (BCF)","what":"Deserialization","title":"Model Serialization in StochTree","text":"Reload BCF model disk. Check predictions align original model.","code":"bcf_model_reload <- createBCFModelFromJsonFile(\"bcf.json\") bcf_preds_reload <- predict(bcf_model_reload, X_train, Z_train, pi_train, group_ids_train, rfx_basis_train) plot(rowMeans(bcf_model$mu_hat_train), rowMeans(bcf_preds_reload$mu_hat), xlab = \"Original\", ylab = \"Deserialized\", main = \"Prognostic forest\") abline(0,1,col=\"red\",lwd=3,lty=3) plot(rowMeans(bcf_model$tau_hat_train), rowMeans(bcf_preds_reload$tau_hat), xlab = \"Original\", ylab = \"Deserialized\", main = \"Treatment forest\") abline(0,1,col=\"red\",lwd=3,lty=3) plot(rowMeans(bcf_model$y_hat_train), rowMeans(bcf_preds_reload$y_hat), xlab = \"Original\", ylab = \"Deserialized\", main = \"Overall outcome\") abline(0,1,col=\"red\",lwd=3,lty=3)"},{"path":[]},{"path":"https://stochastictree.github.io/stochtree-r/authors.html","id":null,"dir":"","previous_headings":"","what":"Authors","title":"Authors and Citation","text":"Drew Herren. Author, maintainer. Richard Hahn. Author. Jared Murray. Author. Carlos Carvalho. Author. Jingyu . Author.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/authors.html","id":"citation","dir":"","previous_headings":"","what":"Citation","title":"Authors and Citation","text":"Herren D, Hahn R, Murray J, Carvalho C, J (2024). stochtree: Stochastic tree ensembles (XBART BART) supervised learning causal inference. R package version 0.0.0.9000, https://stochastictree.github.io/stochtree-r/.","code":"@Manual{, title = {stochtree: Stochastic tree ensembles (XBART and BART) for supervised learning and causal inference}, author = {Drew Herren and Richard Hahn and Jared Murray and Carlos Carvalho and Jingyu He}, year = {2024}, note = {R package version 0.0.0.9000}, url = {https://stochastictree.github.io/stochtree-r/}, }"},{"path":[]},{"path":"https://stochastictree.github.io/stochtree-r/index.html","id":"getting-started","dir":"","previous_headings":"","what":"Getting started","title":"Stochastic tree ensembles (XBART and BART) for supervised learning and causal inference","text":"package can installed R via","code":"remotes::install_github(\"StochasticTree/stochtree-r\")"},{"path":"https://stochastictree.github.io/stochtree-r/reference/BART.html","id":null,"dir":"Reference","previous_headings":"","what":"Run the BART algorithm for supervised learning. — bart","title":"Run the BART algorithm for supervised learning. — bart","text":"Run BART algorithm supervised learning.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/BART.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Run the BART algorithm for supervised learning. — bart","text":"","code":"bart( X_train, y_train, W_train = NULL, group_ids_train = NULL, rfx_basis_train = NULL, X_test = NULL, W_test = NULL, group_ids_test = NULL, rfx_basis_test = NULL, ordered_cat_vars = NULL, unordered_cat_vars = NULL, cutpoint_grid_size = 100, tau_init = NULL, alpha = 0.95, beta = 2, min_samples_leaf = 5, leaf_model = 0, nu = 3, lambda = NULL, a_leaf = 3, b_leaf = NULL, q = 0.9, sigma2_init = NULL, num_trees = 200, num_gfr = 5, num_burnin = 0, num_mcmc = 100, sample_sigma = T, sample_tau = T, random_seed = -1, keep_burnin = F, keep_gfr = F )"},{"path":"https://stochastictree.github.io/stochtree-r/reference/BART.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Run the BART algorithm for supervised learning. — bart","text":"X_train Covariates used split trees ensemble. y_train Outcome modeled ensemble. W_train (Optional) Bases used define regression model y ~ W leaf regression tree. default, BART assumes constant leaf node parameters, implicitly regressing constant basis ones (.e. y ~ 1). group_ids_train (Optional) Group labels used additive random effects model. rfx_basis_train (Optional) Basis \"random-slope\" regression additive random effects model. group_ids_train provided regression basis, intercept-random effects model estimated. X_test (Optional) Test set covariates used define \"sample\" evaluation data. W_test (Optional) Test set bases used define \"sample\" evaluation data. test set optional, structure provided test set must match training set (.e. X_train W_train provided, test set must consist X_test W_test number columns). group_ids_test (Optional) Test set group labels used additive random effects model. currently support (plan near future), test set evaluation group labels training set. rfx_basis_test (Optional) Test set basis \"random-slope\" regression additive random effects model. ordered_cat_vars Vector names ordered categorical variables. unordered_cat_vars Vector names unordered categorical variables. cutpoint_grid_size Maximum size \"grid\" potential cutpoints consider. Default: 100. tau_init Starting value leaf node scale parameter. Calibrated internally 1/num_trees set . alpha Prior probability splitting tree depth 0. Tree split prior combines alpha beta via alpha*(1+node_depth)^-beta. beta Exponent decreases split probabilities nodes depth > 0. Tree split prior combines alpha beta via alpha*(1+node_depth)^-beta. min_samples_leaf Minimum allowable size leaf, terms training samples. Default: 5. nu Shape parameter IG(nu, nu*lambda) global error variance model. Default: 3. lambda Component scale parameter IG(nu, nu*lambda) global error variance prior. specified, calibrated Sparapani et al (2021). a_leaf Shape parameter IG(a_leaf, b_leaf) leaf node parameter variance model. Default: 3. b_leaf Scale parameter IG(a_leaf, b_leaf) leaf node parameter variance model. Calibrated internally 0.5/num_trees set . q Quantile used calibrated lambda Sparapani et al (2021). Default: 0.9. sigma2_init Starting value global variance parameter. Calibrated internally Sparapani et al (2021) set . num_trees Number trees ensemble. Default: 200. num_gfr Number \"warm-start\" iterations run using grow--root algorithm (Hahn, 2021). Default: 5. num_burnin Number \"burn-\" iterations MCMC sampler. Default: 0. num_mcmc Number \"retained\" iterations MCMC sampler. Default: 100. sample_sigma Whether update sigma^2 global error variance parameter based IG(nu, nu*lambda). Default: T. sample_tau Whether update tau leaf scale variance parameter based IG(a_leaf, b_leaf). (currently) set true ncol(W_train)>1. Default: T. random_seed Integer parameterizing C++ random number generator. specified, C++ random number generator seeded according std::random_device. keep_burnin Whether \"burnin\" samples included cached predictions. Default FALSE. Ignored num_mcmc = 0. keep_gfr Whether \"grow--root\" samples included cached predictions. Default TRUE. Ignored num_mcmc = 0. variable_weights Vector length ncol(X_train) indicating \"weight\" placed variable sampling purposes. Default: rep(1/ncol(X_train),ncol(X_train)).","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/BART.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Run the BART algorithm for supervised learning. — bart","text":"List sampling outputs wrapper around sampled forests (can used -memory prediction new data, serialized JSON disk).","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/BART.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Run the BART algorithm for supervised learning. — bart","text":"","code":"n <- 100 p <- 5 X <- matrix(runif(n*p), ncol = p) f_XW <- ( ((0 <= X[,1]) & (0.25 > X[,1])) * (-7.5) + ((0.25 <= X[,1]) & (0.5 > X[,1])) * (-2.5) + ((0.5 <= X[,1]) & (0.75 > X[,1])) * (2.5) + ((0.75 <= X[,1]) & (1 > X[,1])) * (7.5) ) noise_sd <- 1 y <- f_XW + rnorm(n, 0, noise_sd) test_set_pct <- 0.2 n_test <- round(test_set_pct*n) n_train <- n - n_test test_inds <- sort(sample(1:n, n_test, replace = F)) train_inds <- (1:n)[!((1:n) %in% test_inds)] X_test <- X[test_inds,] X_train <- X[train_inds,] y_test <- y[test_inds] y_train <- y[train_inds] bart_model <- bart(X_train = X_train, y_train = y_train, X_test = X_test) # plot(rowMeans(bart_model$y_hat_test), y_test, xlab = \"predicted\", ylab = \"actual\") # abline(0,1,col=\"red\",lty=3,lwd=3)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":null,"dir":"Reference","previous_headings":"","what":"Class that stores draws from an random ensemble of decision trees — CppJson","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"Wrapper around C++ container tree ensembles","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"public-fields","dir":"Reference","previous_headings":"","what":"Public fields","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"json_ptr External pointer C++ nlohmann::json object num_forests Number forests nlohmann::json object forest_labels Names forest objects overall nlohmann::json object num_rfx Number random effects terms nlohman::json object rfx_container_labels Names rfx container objects overall nlohmann::json object rfx_mapper_labels Names rfx label mapper objects overall nlohmann::json object rfx_groupid_labels Names rfx group id objects overall nlohmann::json object","code":""},{"path":[]},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"public-methods","dir":"Reference","previous_headings":"","what":"Public methods","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"CppJson$new() CppJson$add_forest() CppJson$add_random_effects() CppJson$add_scalar() CppJson$add_boolean() CppJson$add_string() CppJson$add_vector() CppJson$add_string_vector() CppJson$add_list() CppJson$add_string_list() CppJson$get_scalar() CppJson$get_boolean() CppJson$get_string() CppJson$get_vector() CppJson$get_string_vector() CppJson$get_numeric_list() CppJson$get_string_list() CppJson$save_file() CppJson$load_from_file()","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"method-new-","dir":"Reference","previous_headings":"","what":"Method new()","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"Create new CppJson object.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"","code":"CppJson$new()"},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"returns","dir":"Reference","previous_headings":"","what":"Returns","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"new CppJson object.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"method-add-forest-","dir":"Reference","previous_headings":"","what":"Method add_forest()","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"Convert forest container json add current CppJson object","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"usage-1","dir":"Reference","previous_headings":"","what":"Usage","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"","code":"CppJson$add_forest(forest_samples)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"forest_samples ForestSamples R class","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"returns-1","dir":"Reference","previous_headings":"","what":"Returns","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"NULL","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"method-add-random-effects-","dir":"Reference","previous_headings":"","what":"Method add_random_effects()","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"Convert random effects container json add current CppJson object","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"usage-2","dir":"Reference","previous_headings":"","what":"Usage","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"","code":"CppJson$add_random_effects(rfx_samples)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"arguments-1","dir":"Reference","previous_headings":"","what":"Arguments","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"rfx_samples RandomEffectSamples R class","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"returns-2","dir":"Reference","previous_headings":"","what":"Returns","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"NULL","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"method-add-scalar-","dir":"Reference","previous_headings":"","what":"Method add_scalar()","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"Add scalar json object name \"field_name\" (optional subfolder \"subfolder_name\")","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"usage-3","dir":"Reference","previous_headings":"","what":"Usage","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"","code":"CppJson$add_scalar(field_name, field_value, subfolder_name = NULL)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"arguments-2","dir":"Reference","previous_headings":"","what":"Arguments","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"field_name name field added json field_value Numeric value field added json subfolder_name (Optional) Name subfolder / hierarchy place value","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"returns-3","dir":"Reference","previous_headings":"","what":"Returns","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"NULL","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"method-add-boolean-","dir":"Reference","previous_headings":"","what":"Method add_boolean()","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"Add boolean value json object name \"field_name\" (optional subfolder \"subfolder_name\")","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"usage-4","dir":"Reference","previous_headings":"","what":"Usage","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"","code":"CppJson$add_boolean(field_name, field_value, subfolder_name = NULL)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"arguments-3","dir":"Reference","previous_headings":"","what":"Arguments","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"field_name name field added json field_value Numeric value field added json subfolder_name (Optional) Name subfolder / hierarchy place value","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"returns-4","dir":"Reference","previous_headings":"","what":"Returns","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"NULL","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"method-add-string-","dir":"Reference","previous_headings":"","what":"Method add_string()","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"Add string value json object name \"field_name\" (optional subfolder \"subfolder_name\")","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"usage-5","dir":"Reference","previous_headings":"","what":"Usage","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"","code":"CppJson$add_string(field_name, field_value, subfolder_name = NULL)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"arguments-4","dir":"Reference","previous_headings":"","what":"Arguments","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"field_name name field added json field_value Numeric value field added json subfolder_name (Optional) Name subfolder / hierarchy place value","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"returns-5","dir":"Reference","previous_headings":"","what":"Returns","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"NULL","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"method-add-vector-","dir":"Reference","previous_headings":"","what":"Method add_vector()","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"Add array json object name \"field_name\" (optional subfolder \"subfolder_name\")","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"usage-6","dir":"Reference","previous_headings":"","what":"Usage","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"","code":"CppJson$add_vector(field_name, field_vector, subfolder_name = NULL)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"arguments-5","dir":"Reference","previous_headings":"","what":"Arguments","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"field_name name field added json field_vector Vector stored json subfolder_name (Optional) Name subfolder / hierarchy place value","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"returns-6","dir":"Reference","previous_headings":"","what":"Returns","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"NULL","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"method-add-string-vector-","dir":"Reference","previous_headings":"","what":"Method add_string_vector()","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"Add array json object name \"field_name\" (optional subfolder \"subfolder_name\")","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"usage-7","dir":"Reference","previous_headings":"","what":"Usage","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"","code":"CppJson$add_string_vector(field_name, field_vector, subfolder_name = NULL)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"arguments-6","dir":"Reference","previous_headings":"","what":"Arguments","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"field_name name field added json field_vector Character vector stored json subfolder_name (Optional) Name subfolder / hierarchy place value","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"returns-7","dir":"Reference","previous_headings":"","what":"Returns","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"NULL","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"method-add-list-","dir":"Reference","previous_headings":"","what":"Method add_list()","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"Add list vectors (object map arrays) json object name \"field_name\"","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"usage-8","dir":"Reference","previous_headings":"","what":"Usage","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"","code":"CppJson$add_list(field_name, field_list)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"arguments-7","dir":"Reference","previous_headings":"","what":"Arguments","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"field_name name field added json field_list List stored json","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"returns-8","dir":"Reference","previous_headings":"","what":"Returns","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"NULL","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"method-add-string-list-","dir":"Reference","previous_headings":"","what":"Method add_string_list()","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"Add list vectors (object map arrays) json object name \"field_name\"","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"usage-9","dir":"Reference","previous_headings":"","what":"Usage","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"","code":"CppJson$add_string_list(field_name, field_list)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"arguments-8","dir":"Reference","previous_headings":"","what":"Arguments","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"field_name name field added json field_list List stored json","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"returns-9","dir":"Reference","previous_headings":"","what":"Returns","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"NULL","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"method-get-scalar-","dir":"Reference","previous_headings":"","what":"Method get_scalar()","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"Retrieve scalar value json object name \"field_name\" (optional subfolder \"subfolder_name\")","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"usage-10","dir":"Reference","previous_headings":"","what":"Usage","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"","code":"CppJson$get_scalar(field_name, subfolder_name = NULL)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"arguments-9","dir":"Reference","previous_headings":"","what":"Arguments","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"field_name name field accessed json subfolder_name (Optional) Name subfolder / hierarchy field stored","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"returns-10","dir":"Reference","previous_headings":"","what":"Returns","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"NULL","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"method-get-boolean-","dir":"Reference","previous_headings":"","what":"Method get_boolean()","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"Retrieve boolean value json object name \"field_name\" (optional subfolder \"subfolder_name\")","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"usage-11","dir":"Reference","previous_headings":"","what":"Usage","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"","code":"CppJson$get_boolean(field_name, subfolder_name = NULL)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"arguments-10","dir":"Reference","previous_headings":"","what":"Arguments","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"field_name name field accessed json subfolder_name (Optional) Name subfolder / hierarchy field stored","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"returns-11","dir":"Reference","previous_headings":"","what":"Returns","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"NULL","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"method-get-string-","dir":"Reference","previous_headings":"","what":"Method get_string()","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"Retrieve string value json object name \"field_name\" (optional subfolder \"subfolder_name\")","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"usage-12","dir":"Reference","previous_headings":"","what":"Usage","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"","code":"CppJson$get_string(field_name, subfolder_name = NULL)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"arguments-11","dir":"Reference","previous_headings":"","what":"Arguments","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"field_name name field accessed json subfolder_name (Optional) Name subfolder / hierarchy field stored","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"returns-12","dir":"Reference","previous_headings":"","what":"Returns","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"NULL","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"method-get-vector-","dir":"Reference","previous_headings":"","what":"Method get_vector()","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"Retrieve vector json object name \"field_name\" (optional subfolder \"subfolder_name\")","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"usage-13","dir":"Reference","previous_headings":"","what":"Usage","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"","code":"CppJson$get_vector(field_name, subfolder_name = NULL)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"arguments-12","dir":"Reference","previous_headings":"","what":"Arguments","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"field_name name field accessed json subfolder_name (Optional) Name subfolder / hierarchy field stored","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"returns-13","dir":"Reference","previous_headings":"","what":"Returns","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"NULL","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"method-get-string-vector-","dir":"Reference","previous_headings":"","what":"Method get_string_vector()","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"Retrieve character vector json object name \"field_name\" (optional subfolder \"subfolder_name\")","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"usage-14","dir":"Reference","previous_headings":"","what":"Usage","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"","code":"CppJson$get_string_vector(field_name, subfolder_name = NULL)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"arguments-13","dir":"Reference","previous_headings":"","what":"Arguments","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"field_name name field accessed json subfolder_name (Optional) Name subfolder / hierarchy field stored","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"returns-14","dir":"Reference","previous_headings":"","what":"Returns","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"NULL","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"method-get-numeric-list-","dir":"Reference","previous_headings":"","what":"Method get_numeric_list()","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"Reconstruct list numeric vectors json object stored \"field_name\"","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"usage-15","dir":"Reference","previous_headings":"","what":"Usage","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"","code":"CppJson$get_numeric_list(field_name, key_names)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"arguments-14","dir":"Reference","previous_headings":"","what":"Arguments","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"field_name name field added json key_names Vector names list elements (vector)","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"returns-15","dir":"Reference","previous_headings":"","what":"Returns","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"NULL","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"method-get-string-list-","dir":"Reference","previous_headings":"","what":"Method get_string_list()","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"Reconstruct list string vectors json object stored \"field_name\"","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"usage-16","dir":"Reference","previous_headings":"","what":"Usage","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"","code":"CppJson$get_string_list(field_name, key_names)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"arguments-15","dir":"Reference","previous_headings":"","what":"Arguments","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"field_name name field added json key_names Vector names list elements (vector)","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"returns-16","dir":"Reference","previous_headings":"","what":"Returns","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"NULL","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"method-save-file-","dir":"Reference","previous_headings":"","what":"Method save_file()","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"Save json object file","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"usage-17","dir":"Reference","previous_headings":"","what":"Usage","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"","code":"CppJson$save_file(filename)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"arguments-16","dir":"Reference","previous_headings":"","what":"Arguments","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"filename String filepath, must end \".json\"","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"returns-17","dir":"Reference","previous_headings":"","what":"Returns","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"NULL","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"method-load-from-file-","dir":"Reference","previous_headings":"","what":"Method load_from_file()","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"Load json object file","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"usage-18","dir":"Reference","previous_headings":"","what":"Usage","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"","code":"CppJson$load_from_file(filename)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"arguments-17","dir":"Reference","previous_headings":"","what":"Arguments","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"filename String filepath, must end \".json\"","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"returns-18","dir":"Reference","previous_headings":"","what":"Returns","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"NULL","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppRNG.html","id":null,"dir":"Reference","previous_headings":"","what":"Class that wraps a C++ random number generator (for reproducibility) — CppRNG","title":"Class that wraps a C++ random number generator (for reproducibility) — CppRNG","text":"Persists C++ random number generator throughout R session ensure reproducibility given random seed. seed provided, C++ random number generator initialized using std::random_device.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppRNG.html","id":"public-fields","dir":"Reference","previous_headings":"","what":"Public fields","title":"Class that wraps a C++ random number generator (for reproducibility) — CppRNG","text":"rng_ptr External pointer C++ std::mt19937 class","code":""},{"path":[]},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppRNG.html","id":"public-methods","dir":"Reference","previous_headings":"","what":"Public methods","title":"Class that wraps a C++ random number generator (for reproducibility) — CppRNG","text":"CppRNG$new()","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppRNG.html","id":"method-new-","dir":"Reference","previous_headings":"","what":"Method new()","title":"Class that wraps a C++ random number generator (for reproducibility) — CppRNG","text":"Create new CppRNG object.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppRNG.html","id":"usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Class that wraps a C++ random number generator (for reproducibility) — CppRNG","text":"","code":"CppRNG$new(random_seed = -1)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppRNG.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Class that wraps a C++ random number generator (for reproducibility) — CppRNG","text":"random_seed (Optional) random seed sampling","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppRNG.html","id":"returns","dir":"Reference","previous_headings":"","what":"Returns","title":"Class that wraps a C++ random number generator (for reproducibility) — CppRNG","text":"new CppRNG object.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestDataset.html","id":null,"dir":"Reference","previous_headings":"","what":"Dataset used to sample a forest — ForestDataset","title":"Dataset used to sample a forest — ForestDataset","text":"dataset consists three matrices / vectors: covariates, bases, variance weights. basis vector variance weights optional.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestDataset.html","id":"public-fields","dir":"Reference","previous_headings":"","what":"Public fields","title":"Dataset used to sample a forest — ForestDataset","text":"data_ptr External pointer C++ ForestDataset class","code":""},{"path":[]},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestDataset.html","id":"public-methods","dir":"Reference","previous_headings":"","what":"Public methods","title":"Dataset used to sample a forest — ForestDataset","text":"ForestDataset$new() ForestDataset$update_basis() ForestDataset$num_observations() ForestDataset$num_covariates() ForestDataset$num_basis() ForestDataset$has_basis() ForestDataset$has_variance_weights()","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestDataset.html","id":"method-new-","dir":"Reference","previous_headings":"","what":"Method new()","title":"Dataset used to sample a forest — ForestDataset","text":"Create new ForestDataset object.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestDataset.html","id":"usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Dataset used to sample a forest — ForestDataset","text":"","code":"ForestDataset$new(covariates, basis = NULL, variance_weights = NULL)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestDataset.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Dataset used to sample a forest — ForestDataset","text":"covariates Matrix covariates basis (Optional) Matrix bases used define leaf regression variance_weights (Optional) Vector observation-specific variance weights","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestDataset.html","id":"returns","dir":"Reference","previous_headings":"","what":"Returns","title":"Dataset used to sample a forest — ForestDataset","text":"new ForestDataset object.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestDataset.html","id":"method-update-basis-","dir":"Reference","previous_headings":"","what":"Method update_basis()","title":"Dataset used to sample a forest — ForestDataset","text":"Update basis matrix dataset","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestDataset.html","id":"usage-1","dir":"Reference","previous_headings":"","what":"Usage","title":"Dataset used to sample a forest — ForestDataset","text":"","code":"ForestDataset$update_basis(basis)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestDataset.html","id":"arguments-1","dir":"Reference","previous_headings":"","what":"Arguments","title":"Dataset used to sample a forest — ForestDataset","text":"basis Updated matrix bases used define leaf regression","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestDataset.html","id":"method-num-observations-","dir":"Reference","previous_headings":"","what":"Method num_observations()","title":"Dataset used to sample a forest — ForestDataset","text":"Return number observations ForestDataset object","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestDataset.html","id":"usage-2","dir":"Reference","previous_headings":"","what":"Usage","title":"Dataset used to sample a forest — ForestDataset","text":"","code":"ForestDataset$num_observations()"},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestDataset.html","id":"returns-1","dir":"Reference","previous_headings":"","what":"Returns","title":"Dataset used to sample a forest — ForestDataset","text":"Observation count","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestDataset.html","id":"method-num-covariates-","dir":"Reference","previous_headings":"","what":"Method num_covariates()","title":"Dataset used to sample a forest — ForestDataset","text":"Return number covariates ForestDataset object","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestDataset.html","id":"usage-3","dir":"Reference","previous_headings":"","what":"Usage","title":"Dataset used to sample a forest — ForestDataset","text":"","code":"ForestDataset$num_covariates()"},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestDataset.html","id":"returns-2","dir":"Reference","previous_headings":"","what":"Returns","title":"Dataset used to sample a forest — ForestDataset","text":"Covariate count","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestDataset.html","id":"method-num-basis-","dir":"Reference","previous_headings":"","what":"Method num_basis()","title":"Dataset used to sample a forest — ForestDataset","text":"Return number bases ForestDataset object","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestDataset.html","id":"usage-4","dir":"Reference","previous_headings":"","what":"Usage","title":"Dataset used to sample a forest — ForestDataset","text":"","code":"ForestDataset$num_basis()"},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestDataset.html","id":"returns-3","dir":"Reference","previous_headings":"","what":"Returns","title":"Dataset used to sample a forest — ForestDataset","text":"Basis count","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestDataset.html","id":"method-has-basis-","dir":"Reference","previous_headings":"","what":"Method has_basis()","title":"Dataset used to sample a forest — ForestDataset","text":"Whether dataset basis matrix","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestDataset.html","id":"usage-5","dir":"Reference","previous_headings":"","what":"Usage","title":"Dataset used to sample a forest — ForestDataset","text":"","code":"ForestDataset$has_basis()"},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestDataset.html","id":"returns-4","dir":"Reference","previous_headings":"","what":"Returns","title":"Dataset used to sample a forest — ForestDataset","text":"True basis matrix loaded, false otherwise","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestDataset.html","id":"method-has-variance-weights-","dir":"Reference","previous_headings":"","what":"Method has_variance_weights()","title":"Dataset used to sample a forest — ForestDataset","text":"Whether dataset variance weights","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestDataset.html","id":"usage-6","dir":"Reference","previous_headings":"","what":"Usage","title":"Dataset used to sample a forest — ForestDataset","text":"","code":"ForestDataset$has_variance_weights()"},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestDataset.html","id":"returns-5","dir":"Reference","previous_headings":"","what":"Returns","title":"Dataset used to sample a forest — ForestDataset","text":"True variance weights loaded, false otherwise","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestKernel.html","id":null,"dir":"Reference","previous_headings":"","what":"Class that provides functionality for statistical kernel definition and computation based on shared leaf membership of observations in a tree ensemble. — ForestKernel","title":"Class that provides functionality for statistical kernel definition and computation based on shared leaf membership of observations in a tree ensemble. — ForestKernel","text":"Computes leaf membership internally sparse matrix also calculates (dense) kernel based sparse matrix C++.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestKernel.html","id":"public-fields","dir":"Reference","previous_headings":"","what":"Public fields","title":"Class that provides functionality for statistical kernel definition and computation based on shared leaf membership of observations in a tree ensemble. — ForestKernel","text":"forest_kernel_ptr External pointer C++ StochTree::ForestKernel class","code":""},{"path":[]},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestKernel.html","id":"public-methods","dir":"Reference","previous_headings":"","what":"Public methods","title":"Class that provides functionality for statistical kernel definition and computation based on shared leaf membership of observations in a tree ensemble. — ForestKernel","text":"ForestKernel$new() ForestKernel$compute_leaf_indices() ForestKernel$compute_kernel()","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestKernel.html","id":"method-new-","dir":"Reference","previous_headings":"","what":"Method new()","title":"Class that provides functionality for statistical kernel definition and computation based on shared leaf membership of observations in a tree ensemble. — ForestKernel","text":"Create new ForestKernel object.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestKernel.html","id":"usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Class that provides functionality for statistical kernel definition and computation based on shared leaf membership of observations in a tree ensemble. — ForestKernel","text":"","code":"ForestKernel$new()"},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestKernel.html","id":"returns","dir":"Reference","previous_headings":"","what":"Returns","title":"Class that provides functionality for statistical kernel definition and computation based on shared leaf membership of observations in a tree ensemble. — ForestKernel","text":"new ForestKernel object.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestKernel.html","id":"method-compute-leaf-indices-","dir":"Reference","previous_headings":"","what":"Method compute_leaf_indices()","title":"Class that provides functionality for statistical kernel definition and computation based on shared leaf membership of observations in a tree ensemble. — ForestKernel","text":"Compute leaf indices tree ensemble every observation dataset. Stores result internally, can extracted class via call get_leaf_indices.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestKernel.html","id":"usage-1","dir":"Reference","previous_headings":"","what":"Usage","title":"Class that provides functionality for statistical kernel definition and computation based on shared leaf membership of observations in a tree ensemble. — ForestKernel","text":"","code":"ForestKernel$compute_leaf_indices( covariates_train, covariates_test = NULL, forest_container, forest_num )"},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestKernel.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Class that provides functionality for statistical kernel definition and computation based on shared leaf membership of observations in a tree ensemble. — ForestKernel","text":"covariates_train Matrix training set covariates compute leaf indices covariates_test (Optional) Matrix test set covariates compute leaf indices forest_container Object type ForestSamples forest_num Index forest forest_container assessed","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestKernel.html","id":"returns-1","dir":"Reference","previous_headings":"","what":"Returns","title":"Class that provides functionality for statistical kernel definition and computation based on shared leaf membership of observations in a tree ensemble. — ForestKernel","text":"List vectors. covariates_test = NULL list one element (train set leaf indices), otherwise list two elements (train test set leaf indices).","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestKernel.html","id":"method-compute-kernel-","dir":"Reference","previous_headings":"","what":"Method compute_kernel()","title":"Class that provides functionality for statistical kernel definition and computation based on shared leaf membership of observations in a tree ensemble. — ForestKernel","text":"Compute kernel implied tree ensemble. function calls compute_leaf_indices, necessary call . compute_leaf_indices exposed class level allow extracting vector leaf indices ensemble directly R.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestKernel.html","id":"usage-2","dir":"Reference","previous_headings":"","what":"Usage","title":"Class that provides functionality for statistical kernel definition and computation based on shared leaf membership of observations in a tree ensemble. — ForestKernel","text":"","code":"ForestKernel$compute_kernel( covariates_train, covariates_test = NULL, forest_container, forest_num )"},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestKernel.html","id":"arguments-1","dir":"Reference","previous_headings":"","what":"Arguments","title":"Class that provides functionality for statistical kernel definition and computation based on shared leaf membership of observations in a tree ensemble. — ForestKernel","text":"covariates_train Matrix training set covariates assess ensemble kernel covariates_test (Optional) Matrix test set covariates assess ensemble kernel forest_container Object type ForestSamples forest_num Index forest forest_container assessed","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestKernel.html","id":"returns-2","dir":"Reference","previous_headings":"","what":"Returns","title":"Class that provides functionality for statistical kernel definition and computation based on shared leaf membership of observations in a tree ensemble. — ForestKernel","text":"List matrices. covariates_test = NULL, list contains one n_train x n_train matrix, n_train = nrow(covariates_train). matrix kernel defined W_train %*% t(W_train) W_train matrix n_train rows many columns total leaves ensemble. covariates_test NULL, list contains two matrices defined W_test %*% t(W_train) W_test %*% t(W_test).","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestModel.html","id":null,"dir":"Reference","previous_headings":"","what":"Class that defines and samples a forest model — ForestModel","title":"Class that defines and samples a forest model — ForestModel","text":"Hosts C++ data structures needed sample ensemble decision trees, exposes functionality run forest sampler (using either MCMC grow--root algorithm).","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestModel.html","id":"public-fields","dir":"Reference","previous_headings":"","what":"Public fields","title":"Class that defines and samples a forest model — ForestModel","text":"tracker_ptr External pointer C++ ForestTracker class tree_prior_ptr External pointer C++ TreePrior class","code":""},{"path":[]},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestModel.html","id":"public-methods","dir":"Reference","previous_headings":"","what":"Public methods","title":"Class that defines and samples a forest model — ForestModel","text":"ForestModel$new() ForestModel$sample_one_iteration()","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestModel.html","id":"method-new-","dir":"Reference","previous_headings":"","what":"Method new()","title":"Class that defines and samples a forest model — ForestModel","text":"Create new ForestModel object.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestModel.html","id":"usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Class that defines and samples a forest model — ForestModel","text":"","code":"ForestModel$new( forest_dataset, feature_types, num_trees, n, alpha, beta, min_samples_leaf )"},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestModel.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Class that defines and samples a forest model — ForestModel","text":"forest_dataset ForestDataset object, used initialize forest sampling data structures feature_types Feature types (integers 0 = numeric, 1 = ordered categorical, 2 = unordered categorical) num_trees Number trees forest sampled n Number observations forest_dataset alpha Root node split probability tree prior beta Depth prior penalty tree prior min_samples_leaf Minimum number samples tree leaf","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestModel.html","id":"returns","dir":"Reference","previous_headings":"","what":"Returns","title":"Class that defines and samples a forest model — ForestModel","text":"new ForestModel object.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestModel.html","id":"method-sample-one-iteration-","dir":"Reference","previous_headings":"","what":"Method sample_one_iteration()","title":"Class that defines and samples a forest model — ForestModel","text":"Run single iteration forest sampling algorithm (MCMC GFR)","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestModel.html","id":"usage-1","dir":"Reference","previous_headings":"","what":"Usage","title":"Class that defines and samples a forest model — ForestModel","text":"","code":"ForestModel$sample_one_iteration( forest_dataset, residual, forest_samples, rng, feature_types, leaf_model_int, leaf_model_scale, variable_weights, global_scale, cutpoint_grid_size = 500, gfr = T, pre_initialized = F )"},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestModel.html","id":"arguments-1","dir":"Reference","previous_headings":"","what":"Arguments","title":"Class that defines and samples a forest model — ForestModel","text":"forest_dataset Dataset used sample forest residual Outcome used sample forest forest_samples Container forest samples rng Wrapper around C++ random number generator feature_types Vector specifying type p covariates forest_dataset (0 = numeric, 1 = ordered categorical, 2 = unordered categorical) leaf_model_int Integer specifying leaf model type (0 = constant leaf, 1 = univariate leaf regression, 2 = multivariate leaf regression) leaf_model_scale Scale parameter used leaf node model (q x q matrix q dimensionality basis >1 leaf_model_int = 2) variable_weights Vector specifying sampling probability p covariates forest_dataset global_scale Global variance parameter cutpoint_grid_size (Optional) Number unique cutpoints consider (default: 500, currently used GFR = TRUE) gfr (Optional) Whether forest sampled using \"grow--root\" (GFR) algorithm pre_initialized (Optional) Whether leaves pre-initialized outside sampling loop (samples drawn). multi-forest implementations like BCF, true, though single-forest supervised learning implementation, can let C++ initialization. Default: F.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestSamples.html","id":null,"dir":"Reference","previous_headings":"","what":"Class that stores draws from an random ensemble of decision trees — ForestSamples","title":"Class that stores draws from an random ensemble of decision trees — ForestSamples","text":"Wrapper around C++ container tree ensembles","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestSamples.html","id":"public-fields","dir":"Reference","previous_headings":"","what":"Public fields","title":"Class that stores draws from an random ensemble of decision trees — ForestSamples","text":"forest_container_ptr External pointer C++ ForestContainer class","code":""},{"path":[]},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestSamples.html","id":"public-methods","dir":"Reference","previous_headings":"","what":"Public methods","title":"Class that stores draws from an random ensemble of decision trees — ForestSamples","text":"ForestSamples$new() ForestSamples$load_from_json() ForestSamples$predict() ForestSamples$predict_raw() ForestSamples$predict_raw_single_forest() ForestSamples$set_root_leaves() ForestSamples$update_residual() ForestSamples$save_json() ForestSamples$load_json() ForestSamples$num_samples() ForestSamples$num_trees() ForestSamples$output_dimension()","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestSamples.html","id":"method-new-","dir":"Reference","previous_headings":"","what":"Method new()","title":"Class that stores draws from an random ensemble of decision trees — ForestSamples","text":"Create new ForestContainer object.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestSamples.html","id":"usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Class that stores draws from an random ensemble of decision trees — ForestSamples","text":"","code":"ForestSamples$new(num_trees, output_dimension = 1, is_leaf_constant = F)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestSamples.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Class that stores draws from an random ensemble of decision trees — ForestSamples","text":"num_trees Number trees output_dimension Dimensionality outcome model is_leaf_constant Whether leaf constant","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestSamples.html","id":"returns","dir":"Reference","previous_headings":"","what":"Returns","title":"Class that stores draws from an random ensemble of decision trees — ForestSamples","text":"new ForestContainer object.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestSamples.html","id":"method-load-from-json-","dir":"Reference","previous_headings":"","what":"Method load_from_json()","title":"Class that stores draws from an random ensemble of decision trees — ForestSamples","text":"Create new ForestContainer object json object","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestSamples.html","id":"usage-1","dir":"Reference","previous_headings":"","what":"Usage","title":"Class that stores draws from an random ensemble of decision trees — ForestSamples","text":"","code":"ForestSamples$load_from_json(json_object, json_forest_label)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestSamples.html","id":"arguments-1","dir":"Reference","previous_headings":"","what":"Arguments","title":"Class that stores draws from an random ensemble of decision trees — ForestSamples","text":"json_object Object class CppJson json_forest_label Label referring particular forest (.e. \"forest_0\") overall json hierarchy","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestSamples.html","id":"returns-1","dir":"Reference","previous_headings":"","what":"Returns","title":"Class that stores draws from an random ensemble of decision trees — ForestSamples","text":"new ForestContainer object.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestSamples.html","id":"method-predict-","dir":"Reference","previous_headings":"","what":"Method predict()","title":"Class that stores draws from an random ensemble of decision trees — ForestSamples","text":"Predict every tree ensemble every sample forest_dataset","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestSamples.html","id":"usage-2","dir":"Reference","previous_headings":"","what":"Usage","title":"Class that stores draws from an random ensemble of decision trees — ForestSamples","text":"","code":"ForestSamples$predict(forest_dataset)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestSamples.html","id":"arguments-2","dir":"Reference","previous_headings":"","what":"Arguments","title":"Class that stores draws from an random ensemble of decision trees — ForestSamples","text":"forest_dataset ForestDataset R class","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestSamples.html","id":"returns-2","dir":"Reference","previous_headings":"","what":"Returns","title":"Class that stores draws from an random ensemble of decision trees — ForestSamples","text":"matrix predictions many rows forest_dataset many columns samples ForestContainer","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestSamples.html","id":"method-predict-raw-","dir":"Reference","previous_headings":"","what":"Method predict_raw()","title":"Class that stores draws from an random ensemble of decision trees — ForestSamples","text":"Predict \"raw\" leaf values (without multiplied basis) every tree ensemble every sample forest_dataset","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestSamples.html","id":"usage-3","dir":"Reference","previous_headings":"","what":"Usage","title":"Class that stores draws from an random ensemble of decision trees — ForestSamples","text":"","code":"ForestSamples$predict_raw(forest_dataset)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestSamples.html","id":"arguments-3","dir":"Reference","previous_headings":"","what":"Arguments","title":"Class that stores draws from an random ensemble of decision trees — ForestSamples","text":"forest_dataset ForestDataset R class","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestSamples.html","id":"returns-3","dir":"Reference","previous_headings":"","what":"Returns","title":"Class that stores draws from an random ensemble of decision trees — ForestSamples","text":"Array predictions observation forest_dataset sample ForestSamples class prediction dimensionality forests' leaf model. case constant leaf model univariate leaf regression, array two-dimensional (number observations, number forest samples). case multivariate leaf regression, array three-dimension (number observations, leaf model dimension, number samples).","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestSamples.html","id":"method-predict-raw-single-forest-","dir":"Reference","previous_headings":"","what":"Method predict_raw_single_forest()","title":"Class that stores draws from an random ensemble of decision trees — ForestSamples","text":"Predict \"raw\" leaf values (without multiplied basis) specific forest every sample forest_dataset","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestSamples.html","id":"usage-4","dir":"Reference","previous_headings":"","what":"Usage","title":"Class that stores draws from an random ensemble of decision trees — ForestSamples","text":"","code":"ForestSamples$predict_raw_single_forest(forest_dataset, forest_num)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestSamples.html","id":"arguments-4","dir":"Reference","previous_headings":"","what":"Arguments","title":"Class that stores draws from an random ensemble of decision trees — ForestSamples","text":"forest_dataset ForestDataset R class forest_num Index forest sample within container","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestSamples.html","id":"returns-4","dir":"Reference","previous_headings":"","what":"Returns","title":"Class that stores draws from an random ensemble of decision trees — ForestSamples","text":"matrix predictions many rows forest_dataset many columns samples ForestContainer","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestSamples.html","id":"method-set-root-leaves-","dir":"Reference","previous_headings":"","what":"Method set_root_leaves()","title":"Class that stores draws from an random ensemble of decision trees — ForestSamples","text":"Set constant predicted value every tree ensemble. Stops program tree root node.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestSamples.html","id":"usage-5","dir":"Reference","previous_headings":"","what":"Usage","title":"Class that stores draws from an random ensemble of decision trees — ForestSamples","text":"","code":"ForestSamples$set_root_leaves(forest_num, leaf_value)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestSamples.html","id":"arguments-5","dir":"Reference","previous_headings":"","what":"Arguments","title":"Class that stores draws from an random ensemble of decision trees — ForestSamples","text":"forest_num Index forest sample within container. leaf_value Constant leaf value(s) fixed tree ensemble indexed forest_num. Can either single number vector, depending forest's leaf dimension.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestSamples.html","id":"method-update-residual-","dir":"Reference","previous_headings":"","what":"Method update_residual()","title":"Class that stores draws from an random ensemble of decision trees — ForestSamples","text":"Updates residual based predictions forest","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestSamples.html","id":"usage-6","dir":"Reference","previous_headings":"","what":"Usage","title":"Class that stores draws from an random ensemble of decision trees — ForestSamples","text":"","code":"ForestSamples$update_residual( dataset, outcome, forest_model, requires_basis, forest_num, add )"},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestSamples.html","id":"arguments-6","dir":"Reference","previous_headings":"","what":"Arguments","title":"Class that stores draws from an random ensemble of decision trees — ForestSamples","text":"dataset ForestDataset object storing covariates bases given forest outcome Outcome object storing residuals updated based forest predictions forest_model ForestModel object storing tracking structures used training / sampling requires_basis Whether forest requires basis prediction forest_num Index forest used update residuals add Whether forest predictions added subtracted residuals","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestSamples.html","id":"method-save-json-","dir":"Reference","previous_headings":"","what":"Method save_json()","title":"Class that stores draws from an random ensemble of decision trees — ForestSamples","text":"Store trees metadata ForestDataset class json file","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestSamples.html","id":"usage-7","dir":"Reference","previous_headings":"","what":"Usage","title":"Class that stores draws from an random ensemble of decision trees — ForestSamples","text":"","code":"ForestSamples$save_json(json_filename)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestSamples.html","id":"arguments-7","dir":"Reference","previous_headings":"","what":"Arguments","title":"Class that stores draws from an random ensemble of decision trees — ForestSamples","text":"json_filename Name output json file (must end \".json\")","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestSamples.html","id":"method-load-json-","dir":"Reference","previous_headings":"","what":"Method load_json()","title":"Class that stores draws from an random ensemble of decision trees — ForestSamples","text":"Load trees metadata ensemble json file. Note trees metadata already present ForestDataset class overwritten.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestSamples.html","id":"usage-8","dir":"Reference","previous_headings":"","what":"Usage","title":"Class that stores draws from an random ensemble of decision trees — ForestSamples","text":"","code":"ForestSamples$load_json(json_filename)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestSamples.html","id":"arguments-8","dir":"Reference","previous_headings":"","what":"Arguments","title":"Class that stores draws from an random ensemble of decision trees — ForestSamples","text":"json_filename Name model input json file (must end \".json\")","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestSamples.html","id":"method-num-samples-","dir":"Reference","previous_headings":"","what":"Method num_samples()","title":"Class that stores draws from an random ensemble of decision trees — ForestSamples","text":"Return number samples ForestContainer object","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestSamples.html","id":"usage-9","dir":"Reference","previous_headings":"","what":"Usage","title":"Class that stores draws from an random ensemble of decision trees — ForestSamples","text":"","code":"ForestSamples$num_samples()"},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestSamples.html","id":"returns-5","dir":"Reference","previous_headings":"","what":"Returns","title":"Class that stores draws from an random ensemble of decision trees — ForestSamples","text":"Sample count","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestSamples.html","id":"method-num-trees-","dir":"Reference","previous_headings":"","what":"Method num_trees()","title":"Class that stores draws from an random ensemble of decision trees — ForestSamples","text":"Return number trees ensemble ForestContainer object","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestSamples.html","id":"usage-10","dir":"Reference","previous_headings":"","what":"Usage","title":"Class that stores draws from an random ensemble of decision trees — ForestSamples","text":"","code":"ForestSamples$num_trees()"},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestSamples.html","id":"returns-6","dir":"Reference","previous_headings":"","what":"Returns","title":"Class that stores draws from an random ensemble of decision trees — ForestSamples","text":"Tree count","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestSamples.html","id":"method-output-dimension-","dir":"Reference","previous_headings":"","what":"Method output_dimension()","title":"Class that stores draws from an random ensemble of decision trees — ForestSamples","text":"Return output dimension trees ForestContainer object","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestSamples.html","id":"usage-11","dir":"Reference","previous_headings":"","what":"Usage","title":"Class that stores draws from an random ensemble of decision trees — ForestSamples","text":"","code":"ForestSamples$output_dimension()"},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestSamples.html","id":"returns-7","dir":"Reference","previous_headings":"","what":"Returns","title":"Class that stores draws from an random ensemble of decision trees — ForestSamples","text":"Leaf node parameter size","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/Outcome.html","id":null,"dir":"Reference","previous_headings":"","what":"Outcome / partial residual used to sample an additive model. — Outcome","title":"Outcome / partial residual used to sample an additive model. — Outcome","text":"outcome class wrapper around vector (mutable) outcomes ML tasks (supervised learning, causal inference). additive tree ensemble sampled, outcome used sample specific model term \"partial residual\" consisting outcome minus predictions every model term (trees, group random effects, etc...).","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/Outcome.html","id":"public-fields","dir":"Reference","previous_headings":"","what":"Public fields","title":"Outcome / partial residual used to sample an additive model. — Outcome","text":"data_ptr External pointer C++ Outcome class","code":""},{"path":[]},{"path":"https://stochastictree.github.io/stochtree-r/reference/Outcome.html","id":"public-methods","dir":"Reference","previous_headings":"","what":"Public methods","title":"Outcome / partial residual used to sample an additive model. — Outcome","text":"Outcome$new()","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/Outcome.html","id":"method-new-","dir":"Reference","previous_headings":"","what":"Method new()","title":"Outcome / partial residual used to sample an additive model. — Outcome","text":"Create new Outcome object.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/Outcome.html","id":"usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Outcome / partial residual used to sample an additive model. — Outcome","text":"","code":"Outcome$new(outcome)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/Outcome.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Outcome / partial residual used to sample an additive model. — Outcome","text":"outcome Vector outcome values","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/Outcome.html","id":"returns","dir":"Reference","previous_headings":"","what":"Returns","title":"Outcome / partial residual used to sample an additive model. — Outcome","text":"new Outcome object.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectSamples.html","id":null,"dir":"Reference","previous_headings":"","what":"Class that wraps the ","title":"Class that wraps the ","text":"Coordinates various C++ random effects classes persists needed prediction / serialization","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectSamples.html","id":"public-fields","dir":"Reference","previous_headings":"","what":"Public fields","title":"Class that wraps the ","text":"rfx_container_ptr External pointer C++ StochTree::RandomEffectsContainer class label_mapper_ptr External pointer C++ StochTree::LabelMapper class training_group_ids Unique vector group IDs training dataset","code":""},{"path":[]},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectSamples.html","id":"public-methods","dir":"Reference","previous_headings":"","what":"Public methods","title":"Class that wraps the ","text":"RandomEffectSamples$new() RandomEffectSamples$load_in_session() RandomEffectSamples$load_from_json() RandomEffectSamples$predict() RandomEffectSamples$extract_parameter_samples() RandomEffectSamples$extract_label_mapping()","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectSamples.html","id":"method-new-","dir":"Reference","previous_headings":"","what":"Method new()","title":"Class that wraps the ","text":"Create new RandomEffectSamples object.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectSamples.html","id":"usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Class that wraps the ","text":"","code":"RandomEffectSamples$new()"},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectSamples.html","id":"returns","dir":"Reference","previous_headings":"","what":"Returns","title":"Class that wraps the ","text":"new RandomEffectSamples object.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectSamples.html","id":"method-load-in-session-","dir":"Reference","previous_headings":"","what":"Method load_in_session()","title":"Class that wraps the ","text":"Construct RandomEffectSamples object \"-session\" R objects","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectSamples.html","id":"usage-1","dir":"Reference","previous_headings":"","what":"Usage","title":"Class that wraps the ","text":"","code":"RandomEffectSamples$load_in_session( num_components, num_groups, random_effects_tracker )"},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectSamples.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Class that wraps the ","text":"num_components Number \"components\" bases defining random effects regression num_groups Number random effects groups random_effects_tracker Object type RandomEffectsTracker","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectSamples.html","id":"returns-1","dir":"Reference","previous_headings":"","what":"Returns","title":"Class that wraps the ","text":"NULL","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectSamples.html","id":"method-load-from-json-","dir":"Reference","previous_headings":"","what":"Method load_from_json()","title":"Class that wraps the ","text":"Construct RandomEffectSamples object json object","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectSamples.html","id":"usage-2","dir":"Reference","previous_headings":"","what":"Usage","title":"Class that wraps the ","text":"","code":"RandomEffectSamples$load_from_json( json_object, json_rfx_container_label, json_rfx_mapper_label, json_rfx_groupids_label )"},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectSamples.html","id":"arguments-1","dir":"Reference","previous_headings":"","what":"Arguments","title":"Class that wraps the ","text":"json_object Object class CppJson json_rfx_container_label Label referring particular rfx sample container (.e. \"random_effect_container_0\") overall json hierarchy json_rfx_mapper_label Label referring particular rfx label mapper (.e. \"random_effect_label_mapper_0\") overall json hierarchy json_rfx_groupids_label Label referring particular set rfx group IDs (.e. \"random_effect_groupids_0\") overall json hierarchy","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectSamples.html","id":"returns-2","dir":"Reference","previous_headings":"","what":"Returns","title":"Class that wraps the ","text":"new RandomEffectSamples object.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectSamples.html","id":"method-predict-","dir":"Reference","previous_headings":"","what":"Method predict()","title":"Class that wraps the ","text":"Predict random effects observation implied rfx_group_ids rfx_basis. random effects model \"intercept-\" rfx_basis vector ones size length(rfx_group_ids).","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectSamples.html","id":"usage-3","dir":"Reference","previous_headings":"","what":"Usage","title":"Class that wraps the ","text":"","code":"RandomEffectSamples$predict(rfx_group_ids, rfx_basis = NULL)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectSamples.html","id":"arguments-2","dir":"Reference","previous_headings":"","what":"Arguments","title":"Class that wraps the ","text":"rfx_group_ids Indices random effects groups prediction set rfx_basis (Optional ) Basis used random effects prediction","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectSamples.html","id":"returns-3","dir":"Reference","previous_headings":"","what":"Returns","title":"Class that wraps the ","text":"Matrix many rows observations provided many columns samples drawn model.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectSamples.html","id":"method-extract-parameter-samples-","dir":"Reference","previous_headings":"","what":"Method extract_parameter_samples()","title":"Class that wraps the ","text":"Extract random effects parameters sampled. \"redundant parameterization\" Gelman et al (2008), includes four parameters: alpha (\"working parameter\" shared across every group), xi (\"group parameter\" sampled separately group), beta (product alpha xi, corresponds overall group-level random effects), sigma (group-independent prior variance component xi).","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectSamples.html","id":"usage-4","dir":"Reference","previous_headings":"","what":"Usage","title":"Class that wraps the ","text":"","code":"RandomEffectSamples$extract_parameter_samples()"},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectSamples.html","id":"returns-4","dir":"Reference","previous_headings":"","what":"Returns","title":"Class that wraps the ","text":"List arrays. alpha array dimension (num_components, num_samples) simply vector num_components = 1. xi beta arrays dimension (num_components, num_groups, num_samples) simply matrix num_components = 1. sigma array dimension (num_components, num_samples) simply vector num_components = 1.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectSamples.html","id":"method-extract-label-mapping-","dir":"Reference","previous_headings":"","what":"Method extract_label_mapping()","title":"Class that wraps the ","text":"Convert mapping group IDs random effect components indices C++ R native format","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectSamples.html","id":"usage-5","dir":"Reference","previous_headings":"","what":"Usage","title":"Class that wraps the ","text":"","code":"RandomEffectSamples$extract_label_mapping()"},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectSamples.html","id":"returns-5","dir":"Reference","previous_headings":"","what":"Returns","title":"Class that wraps the ","text":"List mapping group ID random effect components.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsDataset.html","id":null,"dir":"Reference","previous_headings":"","what":"Dataset used to sample a random effects model — RandomEffectsDataset","title":"Dataset used to sample a random effects model — RandomEffectsDataset","text":"dataset consists three matrices / vectors: group labels, bases, variance weights. Variance weights optional.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsDataset.html","id":"public-fields","dir":"Reference","previous_headings":"","what":"Public fields","title":"Dataset used to sample a random effects model — RandomEffectsDataset","text":"data_ptr External pointer C++ RandomEffectsDataset class","code":""},{"path":[]},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsDataset.html","id":"public-methods","dir":"Reference","previous_headings":"","what":"Public methods","title":"Dataset used to sample a random effects model — RandomEffectsDataset","text":"RandomEffectsDataset$new() RandomEffectsDataset$num_observations() RandomEffectsDataset$has_group_labels() RandomEffectsDataset$has_basis() RandomEffectsDataset$has_variance_weights()","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsDataset.html","id":"method-new-","dir":"Reference","previous_headings":"","what":"Method new()","title":"Dataset used to sample a random effects model — RandomEffectsDataset","text":"Create new RandomEffectsDataset object.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsDataset.html","id":"usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Dataset used to sample a random effects model — RandomEffectsDataset","text":"","code":"RandomEffectsDataset$new(group_labels, basis, variance_weights = NULL)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsDataset.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Dataset used to sample a random effects model — RandomEffectsDataset","text":"group_labels Vector group labels basis Matrix bases used define random effects regression (intercept-model, pass array ones) variance_weights (Optional) Vector observation-specific variance weights","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsDataset.html","id":"returns","dir":"Reference","previous_headings":"","what":"Returns","title":"Dataset used to sample a random effects model — RandomEffectsDataset","text":"new RandomEffectsDataset object.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsDataset.html","id":"method-num-observations-","dir":"Reference","previous_headings":"","what":"Method num_observations()","title":"Dataset used to sample a random effects model — RandomEffectsDataset","text":"Return number observations RandomEffectsDataset object","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsDataset.html","id":"usage-1","dir":"Reference","previous_headings":"","what":"Usage","title":"Dataset used to sample a random effects model — RandomEffectsDataset","text":"","code":"RandomEffectsDataset$num_observations()"},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsDataset.html","id":"returns-1","dir":"Reference","previous_headings":"","what":"Returns","title":"Dataset used to sample a random effects model — RandomEffectsDataset","text":"Observation count","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsDataset.html","id":"method-has-group-labels-","dir":"Reference","previous_headings":"","what":"Method has_group_labels()","title":"Dataset used to sample a random effects model — RandomEffectsDataset","text":"Whether dataset group label indices","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsDataset.html","id":"usage-2","dir":"Reference","previous_headings":"","what":"Usage","title":"Dataset used to sample a random effects model — RandomEffectsDataset","text":"","code":"RandomEffectsDataset$has_group_labels()"},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsDataset.html","id":"returns-2","dir":"Reference","previous_headings":"","what":"Returns","title":"Dataset used to sample a random effects model — RandomEffectsDataset","text":"True group label vector loaded, false otherwise","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsDataset.html","id":"method-has-basis-","dir":"Reference","previous_headings":"","what":"Method has_basis()","title":"Dataset used to sample a random effects model — RandomEffectsDataset","text":"Whether dataset basis matrix","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsDataset.html","id":"usage-3","dir":"Reference","previous_headings":"","what":"Usage","title":"Dataset used to sample a random effects model — RandomEffectsDataset","text":"","code":"RandomEffectsDataset$has_basis()"},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsDataset.html","id":"returns-3","dir":"Reference","previous_headings":"","what":"Returns","title":"Dataset used to sample a random effects model — RandomEffectsDataset","text":"True basis matrix loaded, false otherwise","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsDataset.html","id":"method-has-variance-weights-","dir":"Reference","previous_headings":"","what":"Method has_variance_weights()","title":"Dataset used to sample a random effects model — RandomEffectsDataset","text":"Whether dataset variance weights","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsDataset.html","id":"usage-4","dir":"Reference","previous_headings":"","what":"Usage","title":"Dataset used to sample a random effects model — RandomEffectsDataset","text":"","code":"RandomEffectsDataset$has_variance_weights()"},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsDataset.html","id":"returns-4","dir":"Reference","previous_headings":"","what":"Returns","title":"Dataset used to sample a random effects model — RandomEffectsDataset","text":"True variance weights loaded, false otherwise","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsModel.html","id":null,"dir":"Reference","previous_headings":"","what":"The core ","title":"The core ","text":"Stores current model state, prior parameters, procedures sampling conditional posterior parameter.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsModel.html","id":"public-fields","dir":"Reference","previous_headings":"","what":"Public fields","title":"The core ","text":"rfx_model_ptr External pointer C++ StochTree::RandomEffectsModel class num_groups Number groups random effects model num_components Number components (.e. dimension basis) random effects model","code":""},{"path":[]},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsModel.html","id":"public-methods","dir":"Reference","previous_headings":"","what":"Public methods","title":"The core ","text":"RandomEffectsModel$new() RandomEffectsModel$sample_random_effect() RandomEffectsModel$predict() RandomEffectsModel$set_working_parameter() RandomEffectsModel$set_group_parameters() RandomEffectsModel$set_working_parameter_cov() RandomEffectsModel$set_group_parameter_cov() RandomEffectsModel$set_variance_prior_shape() RandomEffectsModel$set_variance_prior_scale()","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsModel.html","id":"method-new-","dir":"Reference","previous_headings":"","what":"Method new()","title":"The core ","text":"Create new RandomEffectsModel object.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsModel.html","id":"usage","dir":"Reference","previous_headings":"","what":"Usage","title":"The core ","text":"","code":"RandomEffectsModel$new(num_components, num_groups)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsModel.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"The core ","text":"num_components Number \"components\" bases defining random effects regression num_groups Number random effects groups","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsModel.html","id":"returns","dir":"Reference","previous_headings":"","what":"Returns","title":"The core ","text":"new RandomEffectsModel object.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsModel.html","id":"method-sample-random-effect-","dir":"Reference","previous_headings":"","what":"Method sample_random_effect()","title":"The core ","text":"Sample random effects model.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsModel.html","id":"usage-1","dir":"Reference","previous_headings":"","what":"Usage","title":"The core ","text":"","code":"RandomEffectsModel$sample_random_effect( rfx_dataset, residual, rfx_tracker, rfx_samples, global_variance, rng )"},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsModel.html","id":"arguments-1","dir":"Reference","previous_headings":"","what":"Arguments","title":"The core ","text":"rfx_dataset Object type RandomEffectsDataset residual Object type Outcome rfx_tracker Object type RandomEffectsTracker rfx_samples Object type RandomEffectSamples global_variance Scalar global variance parameter rng Object type CppRNG","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsModel.html","id":"returns-1","dir":"Reference","previous_headings":"","what":"Returns","title":"The core ","text":"None","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsModel.html","id":"method-predict-","dir":"Reference","previous_headings":"","what":"Method predict()","title":"The core ","text":"Predict (single sample ) random effects model.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsModel.html","id":"usage-2","dir":"Reference","previous_headings":"","what":"Usage","title":"The core ","text":"","code":"RandomEffectsModel$predict(rfx_dataset, rfx_tracker)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsModel.html","id":"arguments-2","dir":"Reference","previous_headings":"","what":"Arguments","title":"The core ","text":"rfx_dataset Object type RandomEffectsDataset rfx_tracker Object type RandomEffectsTracker","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsModel.html","id":"returns-2","dir":"Reference","previous_headings":"","what":"Returns","title":"The core ","text":"Vector predictions size matching number observations rfx_dataset","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsModel.html","id":"method-set-working-parameter-","dir":"Reference","previous_headings":"","what":"Method set_working_parameter()","title":"The core ","text":"Set value \"working parameter.\" typically used initialization, also used interrupt override sampler.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsModel.html","id":"usage-3","dir":"Reference","previous_headings":"","what":"Usage","title":"The core ","text":"","code":"RandomEffectsModel$set_working_parameter(value)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsModel.html","id":"arguments-3","dir":"Reference","previous_headings":"","what":"Arguments","title":"The core ","text":"value Parameter input","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsModel.html","id":"returns-3","dir":"Reference","previous_headings":"","what":"Returns","title":"The core ","text":"None","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsModel.html","id":"method-set-group-parameters-","dir":"Reference","previous_headings":"","what":"Method set_group_parameters()","title":"The core ","text":"Set value \"group parameters.\" typically used initialization, also used interrupt override sampler.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsModel.html","id":"usage-4","dir":"Reference","previous_headings":"","what":"Usage","title":"The core ","text":"","code":"RandomEffectsModel$set_group_parameters(value)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsModel.html","id":"arguments-4","dir":"Reference","previous_headings":"","what":"Arguments","title":"The core ","text":"value Parameter input","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsModel.html","id":"returns-4","dir":"Reference","previous_headings":"","what":"Returns","title":"The core ","text":"None","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsModel.html","id":"method-set-working-parameter-cov-","dir":"Reference","previous_headings":"","what":"Method set_working_parameter_cov()","title":"The core ","text":"Set value working parameter covariance. typically used initialization, also used interrupt override sampler.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsModel.html","id":"usage-5","dir":"Reference","previous_headings":"","what":"Usage","title":"The core ","text":"","code":"RandomEffectsModel$set_working_parameter_cov(value)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsModel.html","id":"arguments-5","dir":"Reference","previous_headings":"","what":"Arguments","title":"The core ","text":"value Parameter input","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsModel.html","id":"returns-5","dir":"Reference","previous_headings":"","what":"Returns","title":"The core ","text":"None","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsModel.html","id":"method-set-group-parameter-cov-","dir":"Reference","previous_headings":"","what":"Method set_group_parameter_cov()","title":"The core ","text":"Set value group parameter covariance. typically used initialization, also used interrupt override sampler.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsModel.html","id":"usage-6","dir":"Reference","previous_headings":"","what":"Usage","title":"The core ","text":"","code":"RandomEffectsModel$set_group_parameter_cov(value)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsModel.html","id":"arguments-6","dir":"Reference","previous_headings":"","what":"Arguments","title":"The core ","text":"value Parameter input","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsModel.html","id":"returns-6","dir":"Reference","previous_headings":"","what":"Returns","title":"The core ","text":"None","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsModel.html","id":"method-set-variance-prior-shape-","dir":"Reference","previous_headings":"","what":"Method set_variance_prior_shape()","title":"The core ","text":"Set shape parameter group parameter variance prior.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsModel.html","id":"usage-7","dir":"Reference","previous_headings":"","what":"Usage","title":"The core ","text":"","code":"RandomEffectsModel$set_variance_prior_shape(value)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsModel.html","id":"arguments-7","dir":"Reference","previous_headings":"","what":"Arguments","title":"The core ","text":"value Parameter input","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsModel.html","id":"returns-7","dir":"Reference","previous_headings":"","what":"Returns","title":"The core ","text":"None","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsModel.html","id":"method-set-variance-prior-scale-","dir":"Reference","previous_headings":"","what":"Method set_variance_prior_scale()","title":"The core ","text":"Set shape parameter group parameter variance prior.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsModel.html","id":"usage-8","dir":"Reference","previous_headings":"","what":"Usage","title":"The core ","text":"","code":"RandomEffectsModel$set_variance_prior_scale(value)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsModel.html","id":"arguments-8","dir":"Reference","previous_headings":"","what":"Arguments","title":"The core ","text":"value Parameter input","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsModel.html","id":"returns-8","dir":"Reference","previous_headings":"","what":"Returns","title":"The core ","text":"None","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsTracker.html","id":null,"dir":"Reference","previous_headings":"","what":"Class that defines a ","title":"Class that defines a ","text":"Stores mapping every observation group index, mapping group indices training sample observations available group, predictions observation.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsTracker.html","id":"public-fields","dir":"Reference","previous_headings":"","what":"Public fields","title":"Class that defines a ","text":"rfx_tracker_ptr External pointer C++ StochTree::RandomEffectsTracker class","code":""},{"path":[]},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsTracker.html","id":"public-methods","dir":"Reference","previous_headings":"","what":"Public methods","title":"Class that defines a ","text":"RandomEffectsTracker$new()","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsTracker.html","id":"method-new-","dir":"Reference","previous_headings":"","what":"Method new()","title":"Class that defines a ","text":"Create new RandomEffectsTracker object.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsTracker.html","id":"usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Class that defines a ","text":"","code":"RandomEffectsTracker$new(rfx_group_indices)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsTracker.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Class that defines a ","text":"rfx_group_indices Integer indices indicating groups used define random effects","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsTracker.html","id":"returns","dir":"Reference","previous_headings":"","what":"Returns","title":"Class that defines a ","text":"new RandomEffectsTracker object.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/bcf.html","id":null,"dir":"Reference","previous_headings":"","what":"Run the Bayesian Causal Forest (BCF) algorithm for regularized causal effect estimation. — bcf","title":"Run the Bayesian Causal Forest (BCF) algorithm for regularized causal effect estimation. — bcf","text":"Run Bayesian Causal Forest (BCF) algorithm regularized causal effect estimation.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/bcf.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Run the Bayesian Causal Forest (BCF) algorithm for regularized causal effect estimation. — bcf","text":"","code":"bcf( X_train, Z_train, y_train, pi_train = NULL, group_ids_train = NULL, rfx_basis_train = NULL, X_test = NULL, Z_test = NULL, pi_test = NULL, group_ids_test = NULL, rfx_basis_test = NULL, ordered_cat_vars = NULL, unordered_cat_vars = NULL, cutpoint_grid_size = 100, sigma_leaf_mu = NULL, sigma_leaf_tau = NULL, alpha_mu = 0.95, alpha_tau = 0.25, beta_mu = 2, beta_tau = 3, min_samples_leaf_mu = 5, min_samples_leaf_tau = 5, nu = 3, lambda = NULL, a_leaf_mu = 3, a_leaf_tau = 3, b_leaf_mu = NULL, b_leaf_tau = NULL, q = 0.9, sigma2 = NULL, num_trees_mu = 250, num_trees_tau = 50, num_gfr = 5, num_burnin = 0, num_mcmc = 100, sample_sigma_global = T, sample_sigma_leaf_mu = T, sample_sigma_leaf_tau = F, propensity_covariate = \"mu\", adaptive_coding = T, b_0 = -0.5, b_1 = 0.5, random_seed = -1, keep_burnin = F, keep_gfr = F )"},{"path":"https://stochastictree.github.io/stochtree-r/reference/bcf.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Run the Bayesian Causal Forest (BCF) algorithm for regularized causal effect estimation. — bcf","text":"X_train Covariates used split trees ensemble. Can passed either matrix dataframe. Z_train Vector (continuous binary) treatment assignments. y_train Outcome modeled ensemble. pi_train (Optional) Vector propensity scores. provided, estimated data. group_ids_train (Optional) Group labels used additive random effects model. rfx_basis_train (Optional) Basis \"random-slope\" regression additive random effects model. group_ids_train provided regression basis, intercept-random effects model estimated. X_test (Optional) Test set covariates used define \"sample\" evaluation data. Can passed either matrix dataframe. Z_test (Optional) Test set (continuous binary) treatment assignments. pi_test (Optional) Vector propensity scores. provided, estimated data. group_ids_test (Optional) Test set group labels used additive random effects model. currently support (plan near future), test set evaluation group labels training set. rfx_basis_test (Optional) Test set basis \"random-slope\" regression additive random effects model. ordered_cat_vars Vector names ordered categorical variables. unordered_cat_vars Vector names unordered categorical variables. cutpoint_grid_size Maximum size \"grid\" potential cutpoints consider. Default: 100. sigma_leaf_mu Starting value leaf node scale parameter prognostic forest. Calibrated internally 2/num_trees_mu set . sigma_leaf_tau Starting value leaf node scale parameter treatment effect forest. Calibrated internally 1/num_trees_tau set . alpha_mu Prior probability splitting tree depth 0 prognostic forest. Tree split prior combines alpha beta via alpha*(1+node_depth)^-beta. Default: 0.95. alpha_tau Prior probability splitting tree depth 0 treatment effect forest. Tree split prior combines alpha beta via alpha*(1+node_depth)^-beta. Default: 0.25. beta_mu Exponent decreases split probabilities nodes depth > 0 prognostic forest. Tree split prior combines alpha beta via alpha*(1+node_depth)^-beta. Default: 2.0. beta_tau Exponent decreases split probabilities nodes depth > 0 treatment effect forest. Tree split prior combines alpha beta via alpha*(1+node_depth)^-beta. Default: 3.0. min_samples_leaf_mu Minimum allowable size leaf, terms training samples, prognostic forest. Default: 5. min_samples_leaf_tau Minimum allowable size leaf, terms training samples, treatment effect forest. Default: 5. nu Shape parameter IG(nu, nu*lambda) global error variance model. Default: 3. lambda Component scale parameter IG(nu, nu*lambda) global error variance prior. specified, calibrated Sparapani et al (2021). a_leaf_mu Shape parameter IG(a_leaf, b_leaf) leaf node parameter variance model prognostic forest. Default: 3. a_leaf_tau Shape parameter IG(a_leaf, b_leaf) leaf node parameter variance model treatment effect forest. Default: 3. b_leaf_mu Scale parameter IG(a_leaf, b_leaf) leaf node parameter variance model prognostic forest. Calibrated internally 0.5/num_trees set . b_leaf_tau Scale parameter IG(a_leaf, b_leaf) leaf node parameter variance model treatment effect forest. Calibrated internally 0.5/num_trees set . q Quantile used calibrated lambda Sparapani et al (2021). Default: 0.9. sigma2 Starting value global variance parameter. Calibrated internally Sparapani et al (2021) set . num_trees_mu Number trees prognostic forest. Default: 200. num_trees_tau Number trees treatment effect forest. Default: 50. num_gfr Number \"warm-start\" iterations run using grow--root algorithm (Hahn, 2021). Default: 5. num_burnin Number \"burn-\" iterations MCMC sampler. Default: 0. num_mcmc Number \"retained\" iterations MCMC sampler. Default: 100. sample_sigma_global Whether update sigma^2 global error variance parameter based IG(nu, nu*lambda). Default: T. sample_sigma_leaf_mu Whether update sigma_leaf_mu leaf scale variance parameter prognostic forest based IG(a_leaf_mu, b_leaf_mu). Default: T. sample_sigma_leaf_tau Whether update sigma_leaf_tau leaf scale variance parameter treatment effect forest based IG(a_leaf_tau, b_leaf_tau). Default: T. propensity_covariate Whether include propensity score covariate either forests. Enter \"none\" neither, \"mu\" prognostic forest, \"tau\" treatment forest, \"\" forests. \"none\" propensity score provided, estimated (X_train, Z_train) using xgboost. Default: \"mu\". adaptive_coding Whether use \"adaptive coding\" scheme binary treatment variable coded manually (0,1) (-1,1) learned via parameters b_0 b_1 attach outcome model [b_0 (1-Z) + b_1 Z] tau(X). ignored Z binary. Default: T. b_0 Initial value \"control\" group coding parameter. ignored Z binary. Default: -0.5. b_1 Initial value \"treatment\" group coding parameter. ignored Z binary. Default: 0.5. random_seed Integer parameterizing C++ random number generator. specified, C++ random number generator seeded according std::random_device. keep_burnin Whether \"burnin\" samples included cached predictions. Default FALSE. Ignored num_mcmc = 0. keep_gfr Whether \"grow--root\" samples included cached predictions. Default FALSE. Ignored num_mcmc = 0.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/bcf.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Run the Bayesian Causal Forest (BCF) algorithm for regularized causal effect estimation. — bcf","text":"List sampling outputs wrapper around sampled forests (can used -memory prediction new data, serialized JSON disk).","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/bcf.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Run the Bayesian Causal Forest (BCF) algorithm for regularized causal effect estimation. — bcf","text":"","code":"n <- 500 x1 <- rnorm(n) x2 <- rnorm(n) x3 <- rnorm(n) x4 <- as.numeric(rbinom(n,1,0.5)) x5 <- as.numeric(sample(1:3,n,replace=T)) X <- cbind(x1,x2,x3,x4,x5) p <- ncol(X) g <- function(x) {ifelse(x[,5]==1,2,ifelse(x[,5]==2,-1,4))} mu1 <- function(x) {1+g(x)+x[,1]*x[,3]} mu2 <- function(x) {1+g(x)+6*abs(x[,3]-1)} tau1 <- function(x) {rep(3,nrow(x))} tau2 <- function(x) {1+2*x[,2]*x[,4]} mu_x <- mu1(X) tau_x <- tau2(X) pi_x <- 0.8*pnorm((3*mu_x/sd(mu_x)) - 0.5*X[,1]) + 0.05 + runif(n)/10 Z <- rbinom(n,1,pi_x) E_XZ <- mu_x + Z*tau_x snr <- 4 y <- E_XZ + rnorm(n, 0, 1)*(sd(E_XZ)/snr) test_set_pct <- 0.2 n_test <- round(test_set_pct*n) n_train <- n - n_test test_inds <- sort(sample(1:n, n_test, replace = F)) train_inds <- (1:n)[!((1:n) %in% test_inds)] X_test <- X[test_inds,] X_train <- X[train_inds,] pi_test <- pi_x[test_inds] pi_train <- pi_x[train_inds] Z_test <- Z[test_inds] Z_train <- Z[train_inds] y_test <- y[test_inds] y_train <- y[train_inds] mu_test <- mu_x[test_inds] mu_train <- mu_x[train_inds] tau_test <- tau_x[test_inds] tau_train <- tau_x[train_inds] bcf_model <- bcf(X_train = X_train, Z_train = Z_train, y_train = y_train, pi_train = pi_train, X_test = X_test, Z_test = Z_test, pi_test = pi_test, ordered_cat_vars = c(4,5)) # plot(rowMeans(bcf_model$mu_hat_test), mu_test, xlab = \"predicted\", ylab = \"actual\", main = \"Prognostic function\") # abline(0,1,col=\"red\",lty=3,lwd=3) # plot(rowMeans(bcf_model$tau_hat_test), tau_test, xlab = \"predicted\", ylab = \"actual\", main = \"Treatment effect\") # abline(0,1,col=\"red\",lty=3,lwd=3)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/computeForestKernels.html","id":null,"dir":"Reference","previous_headings":"","what":"Compute a kernel from a tree ensemble, defined by the fraction of trees of an ensemble in which two observations fall into the same leaf. — computeForestKernels","title":"Compute a kernel from a tree ensemble, defined by the fraction of trees of an ensemble in which two observations fall into the same leaf. — computeForestKernels","text":"Compute kernel tree ensemble, defined fraction trees ensemble two observations fall leaf.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/computeForestKernels.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Compute a kernel from a tree ensemble, defined by the fraction of trees of an ensemble in which two observations fall into the same leaf. — computeForestKernels","text":"","code":"computeForestKernels(bart_model, X_train, X_test = NULL, forest_num = NULL)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/computeForestKernels.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Compute a kernel from a tree ensemble, defined by the fraction of trees of an ensemble in which two observations fall into the same leaf. — computeForestKernels","text":"bart_model Object type bartmodel corresponding BART model least one sample X_train Matrix \"training\" data. traditional Gaussian process kriging context, corresponds observations outcomes observed. X_test (Optional) Matrix \"test\" data. traditional Gaussian process kriging context, corresponds observations outcomes unobserved must estimated based kernels k(X_test,X_test), k(X_test,X_train), k(X_train,X_train). provided, function compute k(X_train, X_train). forest_num (Option) Index forest sample use kernel computation. provided, function use last forest.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/computeForestKernels.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Compute a kernel from a tree ensemble, defined by the fraction of trees of an ensemble in which two observations fall into the same leaf. — computeForestKernels","text":"List kernel matrices. X_test = NULL, list contains one n_train x n_train matrix, n_train = nrow(X_train). matrix kernel defined W_train %*% t(W_train) W_train matrix n_train rows many columns total leaves ensemble. X_test NULL, list contains two matrices defined W_test %*% t(W_train) W_test %*% t(W_test).","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/computeForestLeafIndices.html","id":null,"dir":"Reference","previous_headings":"","what":"Compute and return a vector representation of a forest's leaf predictions for every observation in a dataset. The vector has a ","title":"Compute and return a vector representation of a forest's leaf predictions for every observation in a dataset. The vector has a ","text":"Compute return vector representation forest's leaf predictions every observation dataset. vector \"column-major\" format can easily re-represented CSC sparse matrix: elements organized first n elements correspond leaf predictions n observations dataset first tree ensemble, next n elements correspond predictions second tree . \"data\" element corresponds uniquely mapped column index corresponds single leaf single tree (.e. tree 1 3 leaves, column indices range 0 2, tree 2's leaf indices begin 3, etc...). Users may pass single dataset (refer \"training set\") two datasets (refer \"training test sets\"). verbiage hints one potential use-case matrix leaf indices define ensemble-based kernel kriging.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/computeForestLeafIndices.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Compute and return a vector representation of a forest's leaf predictions for every observation in a dataset. The vector has a ","text":"","code":"computeForestLeafIndices(bart_model, X_train, X_test = NULL, forest_num = NULL)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/computeForestLeafIndices.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Compute and return a vector representation of a forest's leaf predictions for every observation in a dataset. The vector has a ","text":"bart_model Object type bartmodel corresponding BART model least one sample X_train Matrix \"training\" data. traditional Gaussian process kriging context, corresponds observations outcomes observed. X_test (Optional) Matrix \"test\" data. traditional Gaussian process kriging context, corresponds observations outcomes unobserved must estimated based kernels k(X_test,X_test), k(X_test,X_train), k(X_train,X_train). provided, function compute k(X_train, X_train). forest_num (Option) Index forest sample use kernel computation. provided, function use last forest.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/computeForestLeafIndices.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Compute and return a vector representation of a forest's leaf predictions for every observation in a dataset. The vector has a ","text":"List vectors. X_test = NULL, list contains one vector length n_train * num_trees, n_train = nrow(X_train) num_trees number trees bart_model. X_test NULL, list contains another vector length n_test * num_trees.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/convertToJson.bcf.html","id":null,"dir":"Reference","previous_headings":"","what":"Convert the persistent aspects of a BCF model to (in-memory) JSON — convertToJson.bcf","title":"Convert the persistent aspects of a BCF model to (in-memory) JSON — convertToJson.bcf","text":"Convert persistent aspects BCF model (-memory) JSON","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/convertToJson.bcf.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Convert the persistent aspects of a BCF model to (in-memory) JSON — convertToJson.bcf","text":"","code":"# S3 method for bcf convertToJson(object, ...)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/convertToJson.bcf.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Convert the persistent aspects of a BCF model to (in-memory) JSON — convertToJson.bcf","text":"object Object type bcf containing draws Bayesian causal forest model associated sampling outputs.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/convertToJson.bcf.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Convert the persistent aspects of a BCF model to (in-memory) JSON — convertToJson.bcf","text":"Object type CppJson","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/convertToJson.bcf.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Convert the persistent aspects of a BCF model to (in-memory) JSON — convertToJson.bcf","text":"","code":"n <- 500 x1 <- rnorm(n) x2 <- rnorm(n) x3 <- rnorm(n) x4 <- as.numeric(rbinom(n,1,0.5)) x5 <- as.numeric(sample(1:3,n,replace=T)) X <- cbind(x1,x2,x3,x4,x5) p <- ncol(X) g <- function(x) {ifelse(x[,5]==1,2,ifelse(x[,5]==2,-1,4))} mu1 <- function(x) {1+g(x)+x[,1]*x[,3]} mu2 <- function(x) {1+g(x)+6*abs(x[,3]-1)} tau1 <- function(x) {rep(3,nrow(x))} tau2 <- function(x) {1+2*x[,2]*x[,4]} mu_x <- mu1(X) tau_x <- tau2(X) pi_x <- 0.8*pnorm((3*mu_x/sd(mu_x)) - 0.5*X[,1]) + 0.05 + runif(n)/10 Z <- rbinom(n,1,pi_x) E_XZ <- mu_x + Z*tau_x snr <- 3 group_ids <- rep(c(1,2), n %/% 2) rfx_coefs <- matrix(c(-1, -1, 1, 1),nrow=2,byrow=T) rfx_basis <- cbind(1, runif(n, -1, 1)) rfx_term <- rowSums(rfx_coefs[group_ids,] * rfx_basis) y <- E_XZ + rfx_term + rnorm(n, 0, 1)*(sd(E_XZ)/snr) test_set_pct <- 0.2 n_test <- round(test_set_pct*n) n_train <- n - n_test test_inds <- sort(sample(1:n, n_test, replace = F)) train_inds <- (1:n)[!((1:n) %in% test_inds)] X_test <- X[test_inds,] X_train <- X[train_inds,] pi_test <- pi_x[test_inds] pi_train <- pi_x[train_inds] Z_test <- Z[test_inds] Z_train <- Z[train_inds] y_test <- y[test_inds] y_train <- y[train_inds] mu_test <- mu_x[test_inds] mu_train <- mu_x[train_inds] tau_test <- tau_x[test_inds] tau_train <- tau_x[train_inds] group_ids_test <- group_ids[test_inds] group_ids_train <- group_ids[train_inds] rfx_basis_test <- rfx_basis[test_inds,] rfx_basis_train <- rfx_basis[train_inds,] rfx_term_test <- rfx_term[test_inds] rfx_term_train <- rfx_term[train_inds] bcf_model <- bcf(X_train = X_train, Z_train = Z_train, y_train = y_train, pi_train = pi_train, group_ids_train = group_ids_train, rfx_basis_train = rfx_basis_train, X_test = X_test, Z_test = Z_test, pi_test = pi_test, group_ids_test = group_ids_test, rfx_basis_test = rfx_basis_test, ordered_cat_vars = c(4,5), num_gfr = 100, num_burnin = 0, num_mcmc = 100, sample_sigma_leaf_mu = T, sample_sigma_leaf_tau = F) # bcf_json <- convertToJson(bcf_model)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/convertToJson.html","id":null,"dir":"Reference","previous_headings":"","what":"Convert a model object (BCF, BART, etc...) to JSON — convertToJson","title":"Convert a model object (BCF, BART, etc...) to JSON — convertToJson","text":"Convert model object (BCF, BART, etc...) JSON","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/convertToJson.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Convert a model object (BCF, BART, etc...) to JSON — convertToJson","text":"","code":"convertToJson(object, ...)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/convertToJson.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Convert a model object (BCF, BART, etc...) to JSON — convertToJson","text":"Object type CppJson can saved disk save_file(filename) method","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/createBCFModelFromJson.html","id":null,"dir":"Reference","previous_headings":"","what":"Convert an (in-memory) JSON representation of a BCF model to a BCF model object which can be used for prediction, etc... — createBCFModelFromJson","title":"Convert an (in-memory) JSON representation of a BCF model to a BCF model object which can be used for prediction, etc... — createBCFModelFromJson","text":"Convert (-memory) JSON representation BCF model BCF model object can used prediction, etc...","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/createBCFModelFromJson.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Convert an (in-memory) JSON representation of a BCF model to a BCF model object which can be used for prediction, etc... — createBCFModelFromJson","text":"","code":"createBCFModelFromJson(json_object)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/createBCFModelFromJson.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Convert an (in-memory) JSON representation of a BCF model to a BCF model object which can be used for prediction, etc... — createBCFModelFromJson","text":"json_object Object type CppJson containing Json representation BCF model","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/createBCFModelFromJson.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Convert an (in-memory) JSON representation of a BCF model to a BCF model object which can be used for prediction, etc... — createBCFModelFromJson","text":"Object type bcf","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/createBCFModelFromJson.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Convert an (in-memory) JSON representation of a BCF model to a BCF model object which can be used for prediction, etc... — createBCFModelFromJson","text":"","code":"n <- 500 x1 <- rnorm(n) x2 <- rnorm(n) x3 <- rnorm(n) x4 <- as.numeric(rbinom(n,1,0.5)) x5 <- as.numeric(sample(1:3,n,replace=T)) X <- cbind(x1,x2,x3,x4,x5) p <- ncol(X) g <- function(x) {ifelse(x[,5]==1,2,ifelse(x[,5]==2,-1,4))} mu1 <- function(x) {1+g(x)+x[,1]*x[,3]} mu2 <- function(x) {1+g(x)+6*abs(x[,3]-1)} tau1 <- function(x) {rep(3,nrow(x))} tau2 <- function(x) {1+2*x[,2]*x[,4]} mu_x <- mu1(X) tau_x <- tau2(X) pi_x <- 0.8*pnorm((3*mu_x/sd(mu_x)) - 0.5*X[,1]) + 0.05 + runif(n)/10 Z <- rbinom(n,1,pi_x) E_XZ <- mu_x + Z*tau_x snr <- 3 group_ids <- rep(c(1,2), n %/% 2) rfx_coefs <- matrix(c(-1, -1, 1, 1),nrow=2,byrow=T) rfx_basis <- cbind(1, runif(n, -1, 1)) rfx_term <- rowSums(rfx_coefs[group_ids,] * rfx_basis) y <- E_XZ + rfx_term + rnorm(n, 0, 1)*(sd(E_XZ)/snr) test_set_pct <- 0.2 n_test <- round(test_set_pct*n) n_train <- n - n_test test_inds <- sort(sample(1:n, n_test, replace = F)) train_inds <- (1:n)[!((1:n) %in% test_inds)] X_test <- X[test_inds,] X_train <- X[train_inds,] pi_test <- pi_x[test_inds] pi_train <- pi_x[train_inds] Z_test <- Z[test_inds] Z_train <- Z[train_inds] y_test <- y[test_inds] y_train <- y[train_inds] mu_test <- mu_x[test_inds] mu_train <- mu_x[train_inds] tau_test <- tau_x[test_inds] tau_train <- tau_x[train_inds] group_ids_test <- group_ids[test_inds] group_ids_train <- group_ids[train_inds] rfx_basis_test <- rfx_basis[test_inds,] rfx_basis_train <- rfx_basis[train_inds,] rfx_term_test <- rfx_term[test_inds] rfx_term_train <- rfx_term[train_inds] bcf_model <- bcf(X_train = X_train, Z_train = Z_train, y_train = y_train, pi_train = pi_train, group_ids_train = group_ids_train, rfx_basis_train = rfx_basis_train, X_test = X_test, Z_test = Z_test, pi_test = pi_test, group_ids_test = group_ids_test, rfx_basis_test = rfx_basis_test, ordered_cat_vars = c(4,5), num_gfr = 100, num_burnin = 0, num_mcmc = 100, sample_sigma_leaf_mu = T, sample_sigma_leaf_tau = F) # bcf_json <- convertToJson(bcf_model) # bcf_model_roundtrip <- createBCFModelFromJson(bcf_json)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/createBCFModelFromJsonFile.html","id":null,"dir":"Reference","previous_headings":"","what":"Convert a JSON file containing sample information on a trained BCF model to a BCF model object which can be used for prediction, etc... — createBCFModelFromJsonFile","title":"Convert a JSON file containing sample information on a trained BCF model to a BCF model object which can be used for prediction, etc... — createBCFModelFromJsonFile","text":"Convert JSON file containing sample information trained BCF model BCF model object can used prediction, etc...","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/createBCFModelFromJsonFile.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Convert a JSON file containing sample information on a trained BCF model to a BCF model object which can be used for prediction, etc... — createBCFModelFromJsonFile","text":"","code":"createBCFModelFromJsonFile(json_filename)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/createBCFModelFromJsonFile.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Convert a JSON file containing sample information on a trained BCF model to a BCF model object which can be used for prediction, etc... — createBCFModelFromJsonFile","text":"json_filename String filepath, must end \".json\"","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/createBCFModelFromJsonFile.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Convert a JSON file containing sample information on a trained BCF model to a BCF model object which can be used for prediction, etc... — createBCFModelFromJsonFile","text":"Object type bcf","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/createBCFModelFromJsonFile.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Convert a JSON file containing sample information on a trained BCF model to a BCF model object which can be used for prediction, etc... — createBCFModelFromJsonFile","text":"","code":"n <- 500 x1 <- rnorm(n) x2 <- rnorm(n) x3 <- rnorm(n) x4 <- as.numeric(rbinom(n,1,0.5)) x5 <- as.numeric(sample(1:3,n,replace=T)) X <- cbind(x1,x2,x3,x4,x5) p <- ncol(X) g <- function(x) {ifelse(x[,5]==1,2,ifelse(x[,5]==2,-1,4))} mu1 <- function(x) {1+g(x)+x[,1]*x[,3]} mu2 <- function(x) {1+g(x)+6*abs(x[,3]-1)} tau1 <- function(x) {rep(3,nrow(x))} tau2 <- function(x) {1+2*x[,2]*x[,4]} mu_x <- mu1(X) tau_x <- tau2(X) pi_x <- 0.8*pnorm((3*mu_x/sd(mu_x)) - 0.5*X[,1]) + 0.05 + runif(n)/10 Z <- rbinom(n,1,pi_x) E_XZ <- mu_x + Z*tau_x snr <- 3 group_ids <- rep(c(1,2), n %/% 2) rfx_coefs <- matrix(c(-1, -1, 1, 1),nrow=2,byrow=T) rfx_basis <- cbind(1, runif(n, -1, 1)) rfx_term <- rowSums(rfx_coefs[group_ids,] * rfx_basis) y <- E_XZ + rfx_term + rnorm(n, 0, 1)*(sd(E_XZ)/snr) test_set_pct <- 0.2 n_test <- round(test_set_pct*n) n_train <- n - n_test test_inds <- sort(sample(1:n, n_test, replace = F)) train_inds <- (1:n)[!((1:n) %in% test_inds)] X_test <- X[test_inds,] X_train <- X[train_inds,] pi_test <- pi_x[test_inds] pi_train <- pi_x[train_inds] Z_test <- Z[test_inds] Z_train <- Z[train_inds] y_test <- y[test_inds] y_train <- y[train_inds] mu_test <- mu_x[test_inds] mu_train <- mu_x[train_inds] tau_test <- tau_x[test_inds] tau_train <- tau_x[train_inds] group_ids_test <- group_ids[test_inds] group_ids_train <- group_ids[train_inds] rfx_basis_test <- rfx_basis[test_inds,] rfx_basis_train <- rfx_basis[train_inds,] rfx_term_test <- rfx_term[test_inds] rfx_term_train <- rfx_term[train_inds] bcf_model <- bcf(X_train = X_train, Z_train = Z_train, y_train = y_train, pi_train = pi_train, group_ids_train = group_ids_train, rfx_basis_train = rfx_basis_train, X_test = X_test, Z_test = Z_test, pi_test = pi_test, group_ids_test = group_ids_test, rfx_basis_test = rfx_basis_test, ordered_cat_vars = c(4,5), num_gfr = 100, num_burnin = 0, num_mcmc = 100, sample_sigma_leaf_mu = T, sample_sigma_leaf_tau = F) # saveToJsonFile(bcf_model, \"test.json\") # bcf_model_roundtrip <- createBCFModelFromJsonFile(\"test.json\")"},{"path":"https://stochastictree.github.io/stochtree-r/reference/createCppJson.html","id":null,"dir":"Reference","previous_headings":"","what":"Create a new (empty) C++ Json object — createCppJson","title":"Create a new (empty) C++ Json object — createCppJson","text":"Create new (empty) C++ Json object","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/createCppJson.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create a new (empty) C++ Json object — createCppJson","text":"","code":"createCppJson()"},{"path":"https://stochastictree.github.io/stochtree-r/reference/createCppJson.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Create a new (empty) C++ Json object — createCppJson","text":"CppJson object","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/createCppJsonFile.html","id":null,"dir":"Reference","previous_headings":"","what":"Create a C++ Json object from a Json file — createCppJsonFile","title":"Create a C++ Json object from a Json file — createCppJsonFile","text":"Create C++ Json object Json file","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/createCppJsonFile.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create a C++ Json object from a Json file — createCppJsonFile","text":"","code":"createCppJsonFile(json_filename)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/createCppJsonFile.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Create a C++ Json object from a Json file — createCppJsonFile","text":"CppJson object","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/createForestContainer.html","id":null,"dir":"Reference","previous_headings":"","what":"Create a container of forest samples — createForestContainer","title":"Create a container of forest samples — createForestContainer","text":"Create container forest samples","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/createForestContainer.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create a container of forest samples — createForestContainer","text":"","code":"createForestContainer(num_trees, output_dimension = 1, is_leaf_constant = F)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/createForestContainer.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Create a container of forest samples — createForestContainer","text":"num_trees Number trees output_dimension Dimensionality outcome model is_leaf_constant Whether leaf constant","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/createForestContainer.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Create a container of forest samples — createForestContainer","text":"ForestSamples object","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/createForestCovariates.html","id":null,"dir":"Reference","previous_headings":"","what":"Preprocess a dataframe of covariate values, converting categorical variables to integers and one-hot encoding if need be. Returns a list including a matrix of preprocessed covariate values and associated tracking. — createForestCovariates","title":"Preprocess a dataframe of covariate values, converting categorical variables to integers and one-hot encoding if need be. Returns a list including a matrix of preprocessed covariate values and associated tracking. — createForestCovariates","text":"Preprocess dataframe covariate values, converting categorical variables integers one-hot encoding need . Returns list including matrix preprocessed covariate values associated tracking.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/createForestCovariates.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Preprocess a dataframe of covariate values, converting categorical variables to integers and one-hot encoding if need be. Returns a list including a matrix of preprocessed covariate values and associated tracking. — createForestCovariates","text":"","code":"createForestCovariates( input_data, ordered_cat_vars = NULL, unordered_cat_vars = NULL )"},{"path":"https://stochastictree.github.io/stochtree-r/reference/createForestCovariates.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Preprocess a dataframe of covariate values, converting categorical variables to integers and one-hot encoding if need be. Returns a list including a matrix of preprocessed covariate values and associated tracking. — createForestCovariates","text":"input_data Dataframe matrix covariates. Users may pre-process categorical variables factors necessary. ordered_cat_vars (Optional) Vector names ordered categorical variables, vector column indices input_data matrix. unordered_cat_vars (Optional) Vector names unordered categorical variables, vector column indices input_data matrix.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/createForestCovariates.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Preprocess a dataframe of covariate values, converting categorical variables to integers and one-hot encoding if need be. Returns a list including a matrix of preprocessed covariate values and associated tracking. — createForestCovariates","text":"List preprocessed data details number type variable, unique categories associated categorical variables, vector feature types needed calls BART BCF.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/createForestCovariates.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Preprocess a dataframe of covariate values, converting categorical variables to integers and one-hot encoding if need be. Returns a list including a matrix of preprocessed covariate values and associated tracking. — createForestCovariates","text":"","code":"cov_df <- data.frame(x1 = 1:5, x2 = 5:1, x3 = 6:10) preprocess_list <- createForestCovariates(cov_df) X <- preprocess_list$X"},{"path":"https://stochastictree.github.io/stochtree-r/reference/createForestCovariatesFromMetadata.html","id":null,"dir":"Reference","previous_headings":"","what":"Preprocess a dataframe of covariate values, converting categorical variables to integers and one-hot encoding if need be. Returns a list including a matrix of preprocessed covariate values and associated tracking. — createForestCovariatesFromMetadata","title":"Preprocess a dataframe of covariate values, converting categorical variables to integers and one-hot encoding if need be. Returns a list including a matrix of preprocessed covariate values and associated tracking. — createForestCovariatesFromMetadata","text":"Preprocess dataframe covariate values, converting categorical variables integers one-hot encoding need . Returns list including matrix preprocessed covariate values associated tracking.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/createForestCovariatesFromMetadata.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Preprocess a dataframe of covariate values, converting categorical variables to integers and one-hot encoding if need be. Returns a list including a matrix of preprocessed covariate values and associated tracking. — createForestCovariatesFromMetadata","text":"","code":"createForestCovariatesFromMetadata(input_data, metadata)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/createForestCovariatesFromMetadata.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Preprocess a dataframe of covariate values, converting categorical variables to integers and one-hot encoding if need be. Returns a list including a matrix of preprocessed covariate values and associated tracking. — createForestCovariatesFromMetadata","text":"input_data Dataframe matrix covariates. Users may pre-process categorical variables factors necessary. metadata List containing information variables, including train set categories categorical variables","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/createForestCovariatesFromMetadata.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Preprocess a dataframe of covariate values, converting categorical variables to integers and one-hot encoding if need be. Returns a list including a matrix of preprocessed covariate values and associated tracking. — createForestCovariatesFromMetadata","text":"Preprocessed data categorical variables appropriately preprocessed","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/createForestCovariatesFromMetadata.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Preprocess a dataframe of covariate values, converting categorical variables to integers and one-hot encoding if need be. Returns a list including a matrix of preprocessed covariate values and associated tracking. — createForestCovariatesFromMetadata","text":"","code":"cov_df <- data.frame(x1 = 1:5, x2 = 5:1, x3 = 6:10) metadata <- list(num_ordered_cat_vars = 0, num_unordered_cat_vars = 0, num_numeric_vars = 3) X_preprocessed <- createForestCovariatesFromMetadata(cov_df, metadata) #> Error in `[.data.frame`(numeric_df, , i): undefined columns selected"},{"path":"https://stochastictree.github.io/stochtree-r/reference/createForestDataset.html","id":null,"dir":"Reference","previous_headings":"","what":"Create a forest dataset object — createForestDataset","title":"Create a forest dataset object — createForestDataset","text":"Create forest dataset object","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/createForestDataset.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create a forest dataset object — createForestDataset","text":"","code":"createForestDataset(covariates, basis = NULL, variance_weights = NULL)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/createForestDataset.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Create a forest dataset object — createForestDataset","text":"covariates Matrix covariates basis (Optional) Matrix bases used define leaf regression variance_weights (Optional) Vector observation-specific variance weights","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/createForestDataset.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Create a forest dataset object — createForestDataset","text":"ForestDataset object","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/createForestKernel.html","id":null,"dir":"Reference","previous_headings":"","what":"Create a ForestKernel object — createForestKernel","title":"Create a ForestKernel object — createForestKernel","text":"Create ForestKernel object","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/createForestKernel.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create a ForestKernel object — createForestKernel","text":"","code":"createForestKernel()"},{"path":"https://stochastictree.github.io/stochtree-r/reference/createForestKernel.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Create a ForestKernel object — createForestKernel","text":"ForestKernel object","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/createForestModel.html","id":null,"dir":"Reference","previous_headings":"","what":"Create a forest model object — createForestModel","title":"Create a forest model object — createForestModel","text":"Create forest model object","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/createForestModel.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create a forest model object — createForestModel","text":"","code":"createForestModel( forest_dataset, feature_types, num_trees, n, alpha, beta, min_samples_leaf )"},{"path":"https://stochastictree.github.io/stochtree-r/reference/createForestModel.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Create a forest model object — createForestModel","text":"forest_dataset ForestDataset object, used initialize forest sampling data structures feature_types Feature types (integers 0 = numeric, 1 = ordered categorical, 2 = unordered categorical) num_trees Number trees forest sampled n Number observations forest_dataset alpha Root node split probability tree prior beta Depth prior penalty tree prior min_samples_leaf Minimum number samples tree leaf","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/createForestModel.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Create a forest model object — createForestModel","text":"ForestModel object","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/createOutcome.html","id":null,"dir":"Reference","previous_headings":"","what":"Create an outcome object — createOutcome","title":"Create an outcome object — createOutcome","text":"Create outcome object","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/createOutcome.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create an outcome object — createOutcome","text":"","code":"createOutcome(outcome)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/createOutcome.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Create an outcome object — createOutcome","text":"outcome Vector outcome values","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/createOutcome.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Create an outcome object — createOutcome","text":"Outcome object","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/createRNG.html","id":null,"dir":"Reference","previous_headings":"","what":"Create an R class that wraps a C++ random number generator — createRNG","title":"Create an R class that wraps a C++ random number generator — createRNG","text":"Create R class wraps C++ random number generator","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/createRNG.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create an R class that wraps a C++ random number generator — createRNG","text":"","code":"createRNG(random_seed = -1)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/createRNG.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Create an R class that wraps a C++ random number generator — createRNG","text":"random_seed (Optional) random seed sampling","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/createRNG.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Create an R class that wraps a C++ random number generator — createRNG","text":"CppRng object","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/createRandomEffectSamples.html","id":null,"dir":"Reference","previous_headings":"","what":"Create a RandomEffectSamples object — createRandomEffectSamples","title":"Create a RandomEffectSamples object — createRandomEffectSamples","text":"Create RandomEffectSamples object","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/createRandomEffectSamples.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create a RandomEffectSamples object — createRandomEffectSamples","text":"","code":"createRandomEffectSamples(num_components, num_groups, random_effects_tracker)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/createRandomEffectSamples.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Create a RandomEffectSamples object — createRandomEffectSamples","text":"num_components Number \"components\" bases defining random effects regression num_groups Number random effects groups random_effects_tracker Object type RandomEffectsTracker","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/createRandomEffectSamples.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Create a RandomEffectSamples object — createRandomEffectSamples","text":"RandomEffectSamples object","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/createRandomEffectsDataset.html","id":null,"dir":"Reference","previous_headings":"","what":"Create a random effects dataset object — createRandomEffectsDataset","title":"Create a random effects dataset object — createRandomEffectsDataset","text":"Create random effects dataset object","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/createRandomEffectsDataset.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create a random effects dataset object — createRandomEffectsDataset","text":"","code":"createRandomEffectsDataset(group_labels, basis, variance_weights = NULL)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/createRandomEffectsDataset.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Create a random effects dataset object — createRandomEffectsDataset","text":"group_labels Vector group labels basis Matrix bases used define random effects regression (intercept-model, pass array ones) variance_weights (Optional) Vector observation-specific variance weights","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/createRandomEffectsDataset.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Create a random effects dataset object — createRandomEffectsDataset","text":"RandomEffectsDataset object","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/createRandomEffectsModel.html","id":null,"dir":"Reference","previous_headings":"","what":"Create a RandomEffectsModel object — createRandomEffectsModel","title":"Create a RandomEffectsModel object — createRandomEffectsModel","text":"Create RandomEffectsModel object","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/createRandomEffectsModel.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create a RandomEffectsModel object — createRandomEffectsModel","text":"","code":"createRandomEffectsModel(num_components, num_groups)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/createRandomEffectsModel.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Create a RandomEffectsModel object — createRandomEffectsModel","text":"num_components Number \"components\" bases defining random effects regression num_groups Number random effects groups","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/createRandomEffectsModel.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Create a RandomEffectsModel object — createRandomEffectsModel","text":"RandomEffectsModel object","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/createRandomEffectsTracker.html","id":null,"dir":"Reference","previous_headings":"","what":"Create a RandomEffectsTracker object — createRandomEffectsTracker","title":"Create a RandomEffectsTracker object — createRandomEffectsTracker","text":"Create RandomEffectsTracker object","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/createRandomEffectsTracker.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create a RandomEffectsTracker object — createRandomEffectsTracker","text":"","code":"createRandomEffectsTracker(rfx_group_indices)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/createRandomEffectsTracker.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Create a RandomEffectsTracker object — createRandomEffectsTracker","text":"rfx_group_indices Integer indices indicating groups used define random effects","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/createRandomEffectsTracker.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Create a RandomEffectsTracker object — createRandomEffectsTracker","text":"RandomEffectsTracker object","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/getRandomEffectSamples.bartmodel.html","id":null,"dir":"Reference","previous_headings":"","what":"Extract raw sample values for each of the random effect parameter terms. — getRandomEffectSamples.bartmodel","title":"Extract raw sample values for each of the random effect parameter terms. — getRandomEffectSamples.bartmodel","text":"Extract raw sample values random effect parameter terms.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/getRandomEffectSamples.bartmodel.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Extract raw sample values for each of the random effect parameter terms. — getRandomEffectSamples.bartmodel","text":"","code":"# S3 method for bartmodel getRandomEffectSamples(object, ...)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/getRandomEffectSamples.bartmodel.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Extract raw sample values for each of the random effect parameter terms. — getRandomEffectSamples.bartmodel","text":"object Object type bcf containing draws Bayesian causal forest model associated sampling outputs.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/getRandomEffectSamples.bartmodel.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Extract raw sample values for each of the random effect parameter terms. — getRandomEffectSamples.bartmodel","text":"List arrays. alpha array dimension (num_components, num_samples) simply vector num_components = 1. xi beta arrays dimension (num_components, num_groups, num_samples) simply matrix num_components = 1. sigma array dimension (num_components, num_samples) simply vector num_components = 1.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/getRandomEffectSamples.bartmodel.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Extract raw sample values for each of the random effect parameter terms. — getRandomEffectSamples.bartmodel","text":"","code":"n <- 100 p <- 5 X <- matrix(runif(n*p), ncol = p) f_XW <- ( ((0 <= X[,1]) & (0.25 > X[,1])) * (-7.5) + ((0.25 <= X[,1]) & (0.5 > X[,1])) * (-2.5) + ((0.5 <= X[,1]) & (0.75 > X[,1])) * (2.5) + ((0.75 <= X[,1]) & (1 > X[,1])) * (7.5) ) snr <- 3 group_ids <- rep(c(1,2), n %/% 2) rfx_coefs <- matrix(c(-1, -1, 1, 1),nrow=2,byrow=T) rfx_basis <- cbind(1, runif(n, -1, 1)) rfx_term <- rowSums(rfx_coefs[group_ids,] * rfx_basis) E_y <- f_XW + rfx_term y <- E_y + rnorm(n, 0, 1)*(sd(E_y)/snr) test_set_pct <- 0.2 n_test <- round(test_set_pct*n) n_train <- n - n_test test_inds <- sort(sample(1:n, n_test, replace = F)) train_inds <- (1:n)[!((1:n) %in% test_inds)] X_test <- X[test_inds,] X_train <- X[train_inds,] y_test <- y[test_inds] y_train <- y[train_inds] group_ids_test <- group_ids[test_inds] group_ids_train <- group_ids[train_inds] rfx_basis_test <- rfx_basis[test_inds,] rfx_basis_train <- rfx_basis[train_inds,] rfx_term_test <- rfx_term[test_inds] rfx_term_train <- rfx_term[train_inds] bart_model <- bart(X_train = X_train, y_train = y_train, group_ids_train = group_ids_train, rfx_basis_train = rfx_basis_train, X_test = X_test, group_ids_test = group_ids_test, rfx_basis_test = rfx_basis_test, num_gfr = 100, num_burnin = 0, num_mcmc = 100, sample_tau = T) rfx_samples <- getRandomEffectSamples(bart_model)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/getRandomEffectSamples.bcf.html","id":null,"dir":"Reference","previous_headings":"","what":"Extract raw sample values for each of the random effect parameter terms. — getRandomEffectSamples.bcf","title":"Extract raw sample values for each of the random effect parameter terms. — getRandomEffectSamples.bcf","text":"Extract raw sample values random effect parameter terms.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/getRandomEffectSamples.bcf.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Extract raw sample values for each of the random effect parameter terms. — getRandomEffectSamples.bcf","text":"","code":"# S3 method for bcf getRandomEffectSamples(object, ...)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/getRandomEffectSamples.bcf.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Extract raw sample values for each of the random effect parameter terms. — getRandomEffectSamples.bcf","text":"object Object type bcf containing draws Bayesian causal forest model associated sampling outputs.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/getRandomEffectSamples.bcf.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Extract raw sample values for each of the random effect parameter terms. — getRandomEffectSamples.bcf","text":"List arrays. alpha array dimension (num_components, num_samples) simply vector num_components = 1. xi beta arrays dimension (num_components, num_groups, num_samples) simply matrix num_components = 1. sigma array dimension (num_components, num_samples) simply vector num_components = 1.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/getRandomEffectSamples.bcf.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Extract raw sample values for each of the random effect parameter terms. — getRandomEffectSamples.bcf","text":"","code":"n <- 500 x1 <- rnorm(n) x2 <- rnorm(n) x3 <- rnorm(n) x4 <- as.numeric(rbinom(n,1,0.5)) x5 <- as.numeric(sample(1:3,n,replace=T)) X <- cbind(x1,x2,x3,x4,x5) p <- ncol(X) g <- function(x) {ifelse(x[,5]==1,2,ifelse(x[,5]==2,-1,4))} mu1 <- function(x) {1+g(x)+x[,1]*x[,3]} mu2 <- function(x) {1+g(x)+6*abs(x[,3]-1)} tau1 <- function(x) {rep(3,nrow(x))} tau2 <- function(x) {1+2*x[,2]*x[,4]} mu_x <- mu1(X) tau_x <- tau2(X) pi_x <- 0.8*pnorm((3*mu_x/sd(mu_x)) - 0.5*X[,1]) + 0.05 + runif(n)/10 Z <- rbinom(n,1,pi_x) E_XZ <- mu_x + Z*tau_x snr <- 3 group_ids <- rep(c(1,2), n %/% 2) rfx_coefs <- matrix(c(-1, -1, 1, 1),nrow=2,byrow=T) rfx_basis <- cbind(1, runif(n, -1, 1)) rfx_term <- rowSums(rfx_coefs[group_ids,] * rfx_basis) y <- E_XZ + rfx_term + rnorm(n, 0, 1)*(sd(E_XZ)/snr) test_set_pct <- 0.2 n_test <- round(test_set_pct*n) n_train <- n - n_test test_inds <- sort(sample(1:n, n_test, replace = F)) train_inds <- (1:n)[!((1:n) %in% test_inds)] X_test <- X[test_inds,] X_train <- X[train_inds,] pi_test <- pi_x[test_inds] pi_train <- pi_x[train_inds] Z_test <- Z[test_inds] Z_train <- Z[train_inds] y_test <- y[test_inds] y_train <- y[train_inds] mu_test <- mu_x[test_inds] mu_train <- mu_x[train_inds] tau_test <- tau_x[test_inds] tau_train <- tau_x[train_inds] group_ids_test <- group_ids[test_inds] group_ids_train <- group_ids[train_inds] rfx_basis_test <- rfx_basis[test_inds,] rfx_basis_train <- rfx_basis[train_inds,] rfx_term_test <- rfx_term[test_inds] rfx_term_train <- rfx_term[train_inds] bcf_model <- bcf(X_train = X_train, Z_train = Z_train, y_train = y_train, pi_train = pi_train, group_ids_train = group_ids_train, rfx_basis_train = rfx_basis_train, X_test = X_test, Z_test = Z_test, pi_test = pi_test, group_ids_test = group_ids_test, rfx_basis_test = rfx_basis_test, ordered_cat_vars = c(4,5), num_gfr = 100, num_burnin = 0, num_mcmc = 100, sample_sigma_leaf_mu = T, sample_sigma_leaf_tau = F) rfx_samples <- getRandomEffectSamples(bcf_model)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/getRandomEffectSamples.html","id":null,"dir":"Reference","previous_headings":"","what":"Generic function for extracting random effect samples from a model object (BCF, BART, etc...) — getRandomEffectSamples","title":"Generic function for extracting random effect samples from a model object (BCF, BART, etc...) — getRandomEffectSamples","text":"Generic function extracting random effect samples model object (BCF, BART, etc...)","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/getRandomEffectSamples.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Generic function for extracting random effect samples from a model object (BCF, BART, etc...) — getRandomEffectSamples","text":"","code":"getRandomEffectSamples(object, ...)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/getRandomEffectSamples.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Generic function for extracting random effect samples from a model object (BCF, BART, etc...) — getRandomEffectSamples","text":"List random effect samples","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/loadForestContainerJson.html","id":null,"dir":"Reference","previous_headings":"","what":"Load a container of forest samples from json — loadForestContainerJson","title":"Load a container of forest samples from json — loadForestContainerJson","text":"Load container forest samples json","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/loadForestContainerJson.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Load a container of forest samples from json — loadForestContainerJson","text":"","code":"loadForestContainerJson(json_object, json_forest_label)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/loadForestContainerJson.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Load a container of forest samples from json — loadForestContainerJson","text":"json_object Object class CppJson json_forest_label Label referring particular forest (.e. \"forest_0\") overall json hierarchy","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/loadForestContainerJson.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Load a container of forest samples from json — loadForestContainerJson","text":"ForestSamples object","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/loadRandomEffectSamplesJson.html","id":null,"dir":"Reference","previous_headings":"","what":"Load a container of forest samples from json — loadRandomEffectSamplesJson","title":"Load a container of forest samples from json — loadRandomEffectSamplesJson","text":"Load container forest samples json","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/loadRandomEffectSamplesJson.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Load a container of forest samples from json — loadRandomEffectSamplesJson","text":"","code":"loadRandomEffectSamplesJson(json_object, json_rfx_num)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/loadRandomEffectSamplesJson.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Load a container of forest samples from json — loadRandomEffectSamplesJson","text":"json_object Object class CppJson json_rfx_num Integer index indicating position random effects term unpacked","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/loadRandomEffectSamplesJson.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Load a container of forest samples from json — loadRandomEffectSamplesJson","text":"RandomEffectSamples object","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/loadScalarJson.html","id":null,"dir":"Reference","previous_headings":"","what":"Load a scalar from json — loadScalarJson","title":"Load a scalar from json — loadScalarJson","text":"Load scalar json","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/loadScalarJson.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Load a scalar from json — loadScalarJson","text":"","code":"loadScalarJson(json_object, json_scalar_label, subfolder_name = NULL)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/loadScalarJson.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Load a scalar from json — loadScalarJson","text":"json_object Object class CppJson json_scalar_label Label referring particular scalar / string value (.e. \"num_samples\") overall json hierarchy subfolder_name (Optional) Name subfolder / hierarchy vector sits","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/loadScalarJson.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Load a scalar from json — loadScalarJson","text":"R vector","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/loadVectorJson.html","id":null,"dir":"Reference","previous_headings":"","what":"Load a vector from json — loadVectorJson","title":"Load a vector from json — loadVectorJson","text":"Load vector json","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/loadVectorJson.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Load a vector from json — loadVectorJson","text":"","code":"loadVectorJson(json_object, json_vector_label, subfolder_name = NULL)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/loadVectorJson.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Load a vector from json — loadVectorJson","text":"json_object Object class CppJson json_vector_label Label referring particular vector (.e. \"sigma2_samples\") overall json hierarchy subfolder_name (Optional) Name subfolder / hierarchy vector sits","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/loadVectorJson.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Load a vector from json — loadVectorJson","text":"R vector","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/oneHotEncode.html","id":null,"dir":"Reference","previous_headings":"","what":"Convert a vector of unordered categorical data (either numeric or character labels) to a ","title":"Convert a vector of unordered categorical data (either numeric or character labels) to a ","text":"procedure assumes reference set observations variable (typically training set used sample forest) already one-hot encoded unique levels training set variable available (passed unique_levels). Test set observations contain categories unique_levels mapped last column matrix","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/oneHotEncode.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Convert a vector of unordered categorical data (either numeric or character labels) to a ","text":"","code":"oneHotEncode(x_input, unique_levels)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/oneHotEncode.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Convert a vector of unordered categorical data (either numeric or character labels) to a ","text":"x_input Vector unordered categorical data (typically either strings integers, function also accepts floating point data). unique_levels Unique values categorical variable used create initial one-hot matrix (typically training set)","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/oneHotEncode.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Convert a vector of unordered categorical data (either numeric or character labels) to a ","text":"Binary one-hot matrix","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/oneHotEncode.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Convert a vector of unordered categorical data (either numeric or character labels) to a ","text":"","code":"x <- sample(1:8, 100, T) x_test <- sample(1:9, 10, T) x_onehot <- oneHotEncode(x_test, levels(factor(x)))"},{"path":"https://stochastictree.github.io/stochtree-r/reference/oneHotInitializeAndEncode.html","id":null,"dir":"Reference","previous_headings":"","what":"Convert a vector of unordered categorical data (either numeric or character labels) to a ","title":"Convert a vector of unordered categorical data (either numeric or character labels) to a ","text":"allow prediction \"unseen\" categories test dataset, procedure pads one-hot matrix blank \"\" column. Test set observations contain categories levels(factor(x_input)) mapped column.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/oneHotInitializeAndEncode.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Convert a vector of unordered categorical data (either numeric or character labels) to a ","text":"","code":"oneHotInitializeAndEncode(x_input)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/oneHotInitializeAndEncode.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Convert a vector of unordered categorical data (either numeric or character labels) to a ","text":"x_input Vector unordered categorical data (typically either strings integers, function also accepts floating point data).","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/oneHotInitializeAndEncode.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Convert a vector of unordered categorical data (either numeric or character labels) to a ","text":"List containing binary one-hot matrix unique levels input variable. unique levels used BCF BART functions.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/oneHotInitializeAndEncode.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Convert a vector of unordered categorical data (either numeric or character labels) to a ","text":"","code":"x <- c(\"a\",\"c\",\"b\",\"c\",\"d\",\"a\",\"c\",\"a\",\"b\",\"d\") x_onehot <- oneHotInitializeAndEncode(x)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/orderedCatInitializeAndPreprocess.html","id":null,"dir":"Reference","previous_headings":"","what":"Run some simple preprocessing of ordered categorical variables, converting ordered levels to integers if necessary, and storing the unique levels of a variable. — orderedCatInitializeAndPreprocess","title":"Run some simple preprocessing of ordered categorical variables, converting ordered levels to integers if necessary, and storing the unique levels of a variable. — orderedCatInitializeAndPreprocess","text":"Run simple preprocessing ordered categorical variables, converting ordered levels integers necessary, storing unique levels variable.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/orderedCatInitializeAndPreprocess.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Run some simple preprocessing of ordered categorical variables, converting ordered levels to integers if necessary, and storing the unique levels of a variable. — orderedCatInitializeAndPreprocess","text":"","code":"orderedCatInitializeAndPreprocess(x_input)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/orderedCatInitializeAndPreprocess.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Run some simple preprocessing of ordered categorical variables, converting ordered levels to integers if necessary, and storing the unique levels of a variable. — orderedCatInitializeAndPreprocess","text":"x_input Vector ordered categorical data. data already stored ordered factor, converted one using default sort order.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/orderedCatInitializeAndPreprocess.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Run some simple preprocessing of ordered categorical variables, converting ordered levels to integers if necessary, and storing the unique levels of a variable. — orderedCatInitializeAndPreprocess","text":"List containing preprocessed vector integer-converted ordered categorical observations unique level original ordered categorical feature.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/orderedCatInitializeAndPreprocess.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Run some simple preprocessing of ordered categorical variables, converting ordered levels to integers if necessary, and storing the unique levels of a variable. — orderedCatInitializeAndPreprocess","text":"","code":"x <- c(\"1. Strongly disagree\", \"3. Neither agree nor disagree\", \"2. Disagree\", \"4. Agree\", \"3. Neither agree nor disagree\", \"5. Strongly agree\", \"4. Agree\") preprocess_list <- orderedCatInitializeAndPreprocess(x) x_preprocessed <- preprocess_list$x_preprocessed"},{"path":"https://stochastictree.github.io/stochtree-r/reference/orderedCatPreprocess.html","id":null,"dir":"Reference","previous_headings":"","what":"Run some simple preprocessing of ordered categorical variables, converting ordered levels to integers if necessary, and storing the unique levels of a variable. — orderedCatPreprocess","title":"Run some simple preprocessing of ordered categorical variables, converting ordered levels to integers if necessary, and storing the unique levels of a variable. — orderedCatPreprocess","text":"Run simple preprocessing ordered categorical variables, converting ordered levels integers necessary, storing unique levels variable.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/orderedCatPreprocess.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Run some simple preprocessing of ordered categorical variables, converting ordered levels to integers if necessary, and storing the unique levels of a variable. — orderedCatPreprocess","text":"","code":"orderedCatPreprocess(x_input, unique_levels, var_name = NULL)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/orderedCatPreprocess.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Run some simple preprocessing of ordered categorical variables, converting ordered levels to integers if necessary, and storing the unique levels of a variable. — orderedCatPreprocess","text":"x_input Vector ordered categorical data. data already stored ordered factor, converted one using default sort order.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/orderedCatPreprocess.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Run some simple preprocessing of ordered categorical variables, converting ordered levels to integers if necessary, and storing the unique levels of a variable. — orderedCatPreprocess","text":"List containing preprocessed vector integer-converted ordered categorical observations unique level original ordered categorical feature.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/orderedCatPreprocess.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Run some simple preprocessing of ordered categorical variables, converting ordered levels to integers if necessary, and storing the unique levels of a variable. — orderedCatPreprocess","text":"","code":"x_levels <- c(\"1. Strongly disagree\", \"2. Disagree\", \"3. Neither agree nor disagree\", \"4. Agree\", \"5. Strongly agree\") x <- c(\"1. Strongly disagree\", \"3. Neither agree nor disagree\", \"2. Disagree\", \"4. Agree\", \"3. Neither agree nor disagree\", \"5. Strongly agree\", \"4. Agree\") x_processed <- orderedCatPreprocess(x, x_levels)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/predict.bartmodel.html","id":null,"dir":"Reference","previous_headings":"","what":"Predict from a sampled BART model on new data — predict.bartmodel","title":"Predict from a sampled BART model on new data — predict.bartmodel","text":"Predict sampled BART model new data","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/predict.bartmodel.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Predict from a sampled BART model on new data — predict.bartmodel","text":"","code":"# S3 method for bartmodel predict( bart, X_test, W_test = NULL, group_ids_test = NULL, rfx_basis_test = NULL, predict_all = F )"},{"path":"https://stochastictree.github.io/stochtree-r/reference/predict.bartmodel.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Predict from a sampled BART model on new data — predict.bartmodel","text":"bart Object type bart containing draws regression forest associated sampling outputs. X_test Covariates used determine tree leaf predictions observation. W_test (Optional) Bases used prediction (e.g. dot product leaf values). Default: NULL. group_ids_test (Optional) Test set group labels used additive random effects model. currently support (plan near future), test set evaluation group labels training set. rfx_basis_test (Optional) Test set basis \"random-slope\" regression additive random effects model. predict_all (Optional) Whether predict model samples stored objects subset burnt-/ GFR samples specified training time. Default FALSE.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/predict.bartmodel.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Predict from a sampled BART model on new data — predict.bartmodel","text":"List prediction matrices. model random effects, list one element -- predictions forest. model random effects, list three elements -- forest predictions, random effects predictions, sum (y_hat).","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/predict.bartmodel.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Predict from a sampled BART model on new data — predict.bartmodel","text":"","code":"n <- 100 p <- 5 X <- matrix(runif(n*p), ncol = p) f_XW <- ( ((0 <= X[,1]) & (0.25 > X[,1])) * (-7.5) + ((0.25 <= X[,1]) & (0.5 > X[,1])) * (-2.5) + ((0.5 <= X[,1]) & (0.75 > X[,1])) * (2.5) + ((0.75 <= X[,1]) & (1 > X[,1])) * (7.5) ) noise_sd <- 1 y <- f_XW + rnorm(n, 0, noise_sd) test_set_pct <- 0.2 n_test <- round(test_set_pct*n) n_train <- n - n_test test_inds <- sort(sample(1:n, n_test, replace = F)) train_inds <- (1:n)[!((1:n) %in% test_inds)] X_test <- X[test_inds,] X_train <- X[train_inds,] y_test <- y[test_inds] y_train <- y[train_inds] bart_model <- bart(X_train = X_train, y_train = y_train) y_hat_test <- predict(bart_model, X_test) # plot(rowMeans(y_hat_test), y_test, xlab = \"predicted\", ylab = \"actual\") # abline(0,1,col=\"red\",lty=3,lwd=3)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/predict.bcf.html","id":null,"dir":"Reference","previous_headings":"","what":"Predict from a sampled BCF model on new data — predict.bcf","title":"Predict from a sampled BCF model on new data — predict.bcf","text":"Predict sampled BCF model new data","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/predict.bcf.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Predict from a sampled BCF model on new data — predict.bcf","text":"","code":"# S3 method for bcf predict( bcf, X_test, Z_test, pi_test = NULL, group_ids_test = NULL, rfx_basis_test = NULL, predict_all = F )"},{"path":"https://stochastictree.github.io/stochtree-r/reference/predict.bcf.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Predict from a sampled BCF model on new data — predict.bcf","text":"bcf Object type bcf containing draws Bayesian causal forest model associated sampling outputs. X_test Covariates used determine tree leaf predictions observation. Z_test Treatments used prediction. pi_test (Optional) Propensities used prediction. group_ids_test (Optional) Test set group labels used additive random effects model. currently support (plan near future), test set evaluation group labels training set. rfx_basis_test (Optional) Test set basis \"random-slope\" regression additive random effects model. predict_all (Optional) Whether predict model samples stored objects subset burnt-/ GFR samples specified training time. Default FALSE.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/predict.bcf.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Predict from a sampled BCF model on new data — predict.bcf","text":"List three (four) nrow(X_test) bcf$num_samples matrices: prognostic function estimates, treatment effect estimates, (possibly) random effects predictions, outcome predictions.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/predict.bcf.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Predict from a sampled BCF model on new data — predict.bcf","text":"","code":"n <- 500 x1 <- rnorm(n) x2 <- rnorm(n) x3 <- rnorm(n) x4 <- as.numeric(rbinom(n,1,0.5)) x5 <- as.numeric(sample(1:3,n,replace=T)) X <- cbind(x1,x2,x3,x4,x5) p <- ncol(X) g <- function(x) {ifelse(x[,5]==1,2,ifelse(x[,5]==2,-1,4))} mu1 <- function(x) {1+g(x)+x[,1]*x[,3]} mu2 <- function(x) {1+g(x)+6*abs(x[,3]-1)} tau1 <- function(x) {rep(3,nrow(x))} tau2 <- function(x) {1+2*x[,2]*x[,4]} mu_x <- mu1(X) tau_x <- tau2(X) pi_x <- 0.8*pnorm((3*mu_x/sd(mu_x)) - 0.5*X[,1]) + 0.05 + runif(n)/10 Z <- rbinom(n,1,pi_x) E_XZ <- mu_x + Z*tau_x snr <- 4 y <- E_XZ + rnorm(n, 0, 1)*(sd(E_XZ)/snr) test_set_pct <- 0.2 n_test <- round(test_set_pct*n) n_train <- n - n_test test_inds <- sort(sample(1:n, n_test, replace = F)) train_inds <- (1:n)[!((1:n) %in% test_inds)] X_test <- X[test_inds,] X_train <- X[train_inds,] pi_test <- pi_x[test_inds] pi_train <- pi_x[train_inds] Z_test <- Z[test_inds] Z_train <- Z[train_inds] y_test <- y[test_inds] y_train <- y[train_inds] mu_test <- mu_x[test_inds] mu_train <- mu_x[train_inds] tau_test <- tau_x[test_inds] tau_train <- tau_x[train_inds] bcf_model <- bcf(X_train = X_train, Z_train = Z_train, y_train = y_train, pi_train = pi_train, ordered_cat_vars = c(4,5)) preds <- predict(bcf_model, X_test, Z_test, pi_test) # plot(rowMeans(preds$mu_hat), mu_test, xlab = \"predicted\", ylab = \"actual\", main = \"Prognostic function\") # abline(0,1,col=\"red\",lty=3,lwd=3) # plot(rowMeans(preds$tau_hat), tau_test, xlab = \"predicted\", ylab = \"actual\", main = \"Treatment effect\") # abline(0,1,col=\"red\",lty=3,lwd=3)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/sample_sigma2_one_iteration.html","id":null,"dir":"Reference","previous_headings":"","what":"Sample one iteration of the global variance model — sample_sigma2_one_iteration","title":"Sample one iteration of the global variance model — sample_sigma2_one_iteration","text":"Sample one iteration global variance model","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/sample_sigma2_one_iteration.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Sample one iteration of the global variance model — sample_sigma2_one_iteration","text":"","code":"sample_sigma2_one_iteration(residual, rng, nu, lambda)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/sample_sigma2_one_iteration.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Sample one iteration of the global variance model — sample_sigma2_one_iteration","text":"residual Outcome class rng C++ random number generator nu Global variance shape parameter lambda Constitutes scale parameter global variance along nu (.e. scale nu*lambda)","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/sample_tau_one_iteration.html","id":null,"dir":"Reference","previous_headings":"","what":"Sample one iteration of the leaf parameter variance model (only for univariate basis and constant leaf!) — sample_tau_one_iteration","title":"Sample one iteration of the leaf parameter variance model (only for univariate basis and constant leaf!) — sample_tau_one_iteration","text":"Sample one iteration leaf parameter variance model (univariate basis constant leaf!)","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/sample_tau_one_iteration.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Sample one iteration of the leaf parameter variance model (only for univariate basis and constant leaf!) — sample_tau_one_iteration","text":"","code":"sample_tau_one_iteration(forest_samples, rng, a, b, sample_num)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/sample_tau_one_iteration.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Sample one iteration of the leaf parameter variance model (only for univariate basis and constant leaf!) — sample_tau_one_iteration","text":"forest_samples Container forest samples rng C++ random number generator Leaf variance shape parameter b Leaf variance scale parameter sample_num Sample index","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/saveToJsonFile.bcf.html","id":null,"dir":"Reference","previous_headings":"","what":"Convert the persistent aspects of a BCF model to (in-memory) JSON and save to a file — saveToJsonFile.bcf","title":"Convert the persistent aspects of a BCF model to (in-memory) JSON and save to a file — saveToJsonFile.bcf","text":"Convert persistent aspects BCF model (-memory) JSON save file","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/saveToJsonFile.bcf.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Convert the persistent aspects of a BCF model to (in-memory) JSON and save to a file — saveToJsonFile.bcf","text":"","code":"# S3 method for bcf saveToJsonFile(object, filename, ...)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/saveToJsonFile.bcf.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Convert the persistent aspects of a BCF model to (in-memory) JSON and save to a file — saveToJsonFile.bcf","text":"object Object type bcf containing draws Bayesian causal forest model associated sampling outputs. filename String filepath, must end \".json\"","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/saveToJsonFile.bcf.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Convert the persistent aspects of a BCF model to (in-memory) JSON and save to a file — saveToJsonFile.bcf","text":"","code":"n <- 500 x1 <- rnorm(n) x2 <- rnorm(n) x3 <- rnorm(n) x4 <- as.numeric(rbinom(n,1,0.5)) x5 <- as.numeric(sample(1:3,n,replace=T)) X <- cbind(x1,x2,x3,x4,x5) p <- ncol(X) g <- function(x) {ifelse(x[,5]==1,2,ifelse(x[,5]==2,-1,4))} mu1 <- function(x) {1+g(x)+x[,1]*x[,3]} mu2 <- function(x) {1+g(x)+6*abs(x[,3]-1)} tau1 <- function(x) {rep(3,nrow(x))} tau2 <- function(x) {1+2*x[,2]*x[,4]} mu_x <- mu1(X) tau_x <- tau2(X) pi_x <- 0.8*pnorm((3*mu_x/sd(mu_x)) - 0.5*X[,1]) + 0.05 + runif(n)/10 Z <- rbinom(n,1,pi_x) E_XZ <- mu_x + Z*tau_x snr <- 3 group_ids <- rep(c(1,2), n %/% 2) rfx_coefs <- matrix(c(-1, -1, 1, 1),nrow=2,byrow=T) rfx_basis <- cbind(1, runif(n, -1, 1)) rfx_term <- rowSums(rfx_coefs[group_ids,] * rfx_basis) y <- E_XZ + rfx_term + rnorm(n, 0, 1)*(sd(E_XZ)/snr) test_set_pct <- 0.2 n_test <- round(test_set_pct*n) n_train <- n - n_test test_inds <- sort(sample(1:n, n_test, replace = F)) train_inds <- (1:n)[!((1:n) %in% test_inds)] X_test <- X[test_inds,] X_train <- X[train_inds,] pi_test <- pi_x[test_inds] pi_train <- pi_x[train_inds] Z_test <- Z[test_inds] Z_train <- Z[train_inds] y_test <- y[test_inds] y_train <- y[train_inds] mu_test <- mu_x[test_inds] mu_train <- mu_x[train_inds] tau_test <- tau_x[test_inds] tau_train <- tau_x[train_inds] group_ids_test <- group_ids[test_inds] group_ids_train <- group_ids[train_inds] rfx_basis_test <- rfx_basis[test_inds,] rfx_basis_train <- rfx_basis[train_inds,] rfx_term_test <- rfx_term[test_inds] rfx_term_train <- rfx_term[train_inds] bcf_model <- bcf(X_train = X_train, Z_train = Z_train, y_train = y_train, pi_train = pi_train, group_ids_train = group_ids_train, rfx_basis_train = rfx_basis_train, X_test = X_test, Z_test = Z_test, pi_test = pi_test, group_ids_test = group_ids_test, rfx_basis_test = rfx_basis_test, ordered_cat_vars = c(4,5), num_gfr = 100, num_burnin = 0, num_mcmc = 100, sample_sigma_leaf_mu = T, sample_sigma_leaf_tau = F) # saveToJsonFile(bcf_model, \"test.json\")"},{"path":"https://stochastictree.github.io/stochtree-r/reference/saveToJsonFile.html","id":null,"dir":"Reference","previous_headings":"","what":"Convert a model object (BCF, BART, etc...) to JSON and save it to a file with a json suffix named filename — saveToJsonFile","title":"Convert a model object (BCF, BART, etc...) to JSON and save it to a file with a json suffix named filename — saveToJsonFile","text":"Convert model object (BCF, BART, etc...) JSON save file json suffix named filename","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/saveToJsonFile.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Convert a model object (BCF, BART, etc...) to JSON and save it to a file with a json suffix named filename — saveToJsonFile","text":"","code":"saveToJsonFile(object, filename, ...)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/stochtree-package.html","id":null,"dir":"Reference","previous_headings":"","what":"stochtree: Stochastic tree ensembles (XBART and BART) for supervised learning and causal inference — stochtree-package","title":"stochtree: Stochastic tree ensembles (XBART and BART) for supervised learning and causal inference — stochtree-package","text":"Stochastic tree ensembles (XBART BART) supervised learning causal inference","code":""},{"path":[]},{"path":"https://stochastictree.github.io/stochtree-r/reference/stochtree-package.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"stochtree: Stochastic tree ensembles (XBART and BART) for supervised learning and causal inference — stochtree-package","text":"Maintainer: Drew Herren drewherrenopensource@gmail.com (ORCID) Authors: Richard Hahn Jared Murray Carlos Carvalho Jingyu ","code":""}] +[{"path":"https://stochastictree.github.io/stochtree-r/LICENSE.html","id":null,"dir":"","previous_headings":"","what":"MIT License","title":"MIT License","text":"Copyright (c) 2024 stochtree authors Permission hereby granted, free charge, person obtaining copy software associated documentation files (“Software”), deal Software without restriction, including without limitation rights use, copy, modify, merge, publish, distribute, sublicense, /sell copies Software, permit persons Software furnished , subject following conditions: copyright notice permission notice shall included copies substantial portions Software. SOFTWARE PROVIDED “”, WITHOUT WARRANTY KIND, EXPRESS IMPLIED, INCLUDING LIMITED WARRANTIES MERCHANTABILITY, FITNESS PARTICULAR PURPOSE NONINFRINGEMENT. EVENT SHALL AUTHORS COPYRIGHT HOLDERS LIABLE CLAIM, DAMAGES LIABILITY, WHETHER ACTION CONTRACT, TORT OTHERWISE, ARISING , CONNECTION SOFTWARE USE DEALINGS SOFTWARE.","code":""},{"path":[]},{"path":"https://stochastictree.github.io/stochtree-r/articles/BayesianSupervisedLearning.html","id":"simulation","dir":"Articles","previous_headings":"Demo 1: Step Function","what":"Simulation","title":"Bayesian Supervised Learning in StochTree","text":", generate data simple step function.","code":"# Generate the data n <- 500 p_x <- 10 snr <- 3 X <- matrix(runif(n*p_x), ncol = p_x) f_XW <- ( ((0 <= X[,1]) & (0.25 > X[,1])) * (-7.5) + ((0.25 <= X[,1]) & (0.5 > X[,1])) * (-2.5) + ((0.5 <= X[,1]) & (0.75 > X[,1])) * (2.5) + ((0.75 <= X[,1]) & (1 > X[,1])) * (7.5) ) noise_sd <- sd(f_XW) / snr y <- f_XW + rnorm(n, 0, 1)*noise_sd # Split data into test and train sets test_set_pct <- 0.2 n_test <- round(test_set_pct*n) n_train <- n - n_test test_inds <- sort(sample(1:n, n_test, replace = F)) train_inds <- (1:n)[!((1:n) %in% test_inds)] X_test <- X[test_inds,] X_train <- X[train_inds,] W_test <- NULL W_train <- NULL y_test <- y[test_inds] y_train <- y[train_inds]"},{"path":[]},{"path":"https://stochastictree.github.io/stochtree-r/articles/BayesianSupervisedLearning.html","id":"warmstart","dir":"Articles","previous_headings":"Demo 1: Step Function > Sampling and Analysis","what":"Warmstart","title":"Bayesian Supervised Learning in StochTree","text":"first sample ensemble model \\(y \\mid X\\) using “warm-start” initialization samples (Hahn (2023)). default stochtree. Inspect MCMC samples","code":"num_gfr <- 10 num_burnin <- 0 num_mcmc <- 100 num_samples <- num_gfr + num_burnin + num_mcmc bart_model_warmstart <- stochtree::bart( X_train = X_train, y_train = y_train, X_test = X_test, num_trees = 100, num_gfr = num_gfr, num_burnin = num_burnin, num_mcmc = num_mcmc, sample_sigma = T, sample_tau = T ) plot(bart_model_warmstart$sigma2_samples, ylab=\"sigma^2\") plot(rowMeans(bart_model_warmstart$y_hat_test), y_test, pch=16, cex=0.75, xlab = \"pred\", ylab = \"actual\") abline(0,1,col=\"red\",lty=2,lwd=2.5)"},{"path":"https://stochastictree.github.io/stochtree-r/articles/BayesianSupervisedLearning.html","id":"bart-mcmc-without-warmstart","dir":"Articles","previous_headings":"Demo 1: Step Function > Sampling and Analysis","what":"BART MCMC without Warmstart","title":"Bayesian Supervised Learning in StochTree","text":"Next, sample ensemble model without warm-start initialization. Inspect MCMC samples","code":"num_gfr <- 0 num_burnin <- 100 num_mcmc <- 100 num_samples <- num_gfr + num_burnin + num_mcmc bart_model_root <- stochtree::bart( X_train = X_train, y_train = y_train, X_test = X_test, num_trees = 100, num_gfr = num_gfr, num_burnin = num_burnin, num_mcmc = num_mcmc, sample_sigma = T, sample_tau = T ) plot(bart_model_root$sigma2_samples, ylab=\"sigma^2\") plot(rowMeans(bart_model_root$y_hat_test), y_test, pch=16, cex=0.75, xlab = \"pred\", ylab = \"actual\") abline(0,1,col=\"red\",lty=2,lwd=2.5)"},{"path":[]},{"path":"https://stochastictree.github.io/stochtree-r/articles/BayesianSupervisedLearning.html","id":"simulation-1","dir":"Articles","previous_headings":"Demo 2: Partitioned Linear Model","what":"Simulation","title":"Bayesian Supervised Learning in StochTree","text":", generate data simple partitioned linear model.","code":"# Generate the data n <- 500 p_x <- 10 p_w <- 1 snr <- 3 X <- matrix(runif(n*p_x), ncol = p_x) W <- matrix(runif(n*p_w), ncol = p_w) f_XW <- ( ((0 <= X[,1]) & (0.25 > X[,1])) * (-7.5*W[,1]) + ((0.25 <= X[,1]) & (0.5 > X[,1])) * (-2.5*W[,1]) + ((0.5 <= X[,1]) & (0.75 > X[,1])) * (2.5*W[,1]) + ((0.75 <= X[,1]) & (1 > X[,1])) * (7.5*W[,1]) ) noise_sd <- sd(f_XW) / snr y <- f_XW + rnorm(n, 0, 1)*noise_sd # Split data into test and train sets test_set_pct <- 0.2 n_test <- round(test_set_pct*n) n_train <- n - n_test test_inds <- sort(sample(1:n, n_test, replace = F)) train_inds <- (1:n)[!((1:n) %in% test_inds)] X_test <- X[test_inds,] X_train <- X[train_inds,] W_test <- W[test_inds,] W_train <- W[train_inds,] y_test <- y[test_inds] y_train <- y[train_inds]"},{"path":[]},{"path":"https://stochastictree.github.io/stochtree-r/articles/BayesianSupervisedLearning.html","id":"warmstart-1","dir":"Articles","previous_headings":"Demo 2: Partitioned Linear Model > Sampling and Analysis","what":"Warmstart","title":"Bayesian Supervised Learning in StochTree","text":"first sample ensemble model \\(y \\mid X\\) using “warm-start” initialization samples (Hahn (2023)). default stochtree. Inspect MCMC samples","code":"num_gfr <- 10 num_burnin <- 0 num_mcmc <- 100 num_samples <- num_gfr + num_burnin + num_mcmc bart_model_warmstart <- stochtree::bart( X_train = X_train, W_train = W_train, y_train = y_train, X_test = X_test, W_test = W_test, num_trees = 100, num_gfr = num_gfr, num_burnin = num_burnin, num_mcmc = num_mcmc, sample_sigma = T, sample_tau = T ) plot(bart_model_warmstart$sigma2_samples, ylab=\"sigma^2\") plot(rowMeans(bart_model_warmstart$y_hat_test), y_test, pch=16, cex=0.75, xlab = \"pred\", ylab = \"actual\") abline(0,1,col=\"red\",lty=2,lwd=2.5)"},{"path":"https://stochastictree.github.io/stochtree-r/articles/BayesianSupervisedLearning.html","id":"bart-mcmc-without-warmstart-1","dir":"Articles","previous_headings":"Demo 2: Partitioned Linear Model > Sampling and Analysis","what":"BART MCMC without Warmstart","title":"Bayesian Supervised Learning in StochTree","text":"Next, sample ensemble model without warm-start initialization. Inspect BART samples burnin.","code":"num_gfr <- 0 num_burnin <- 100 num_mcmc <- 100 num_samples <- num_gfr + num_burnin + num_mcmc bart_model_root <- stochtree::bart( X_train = X_train, W_train = W_train, y_train = y_train, X_test = X_test, W_test = W_test, num_trees = 100, num_gfr = num_gfr, num_burnin = num_burnin, num_mcmc = num_mcmc, sample_sigma = T, sample_tau = T ) plot(bart_model_root$sigma2_samples, ylab=\"sigma^2\") plot(rowMeans(bart_model_root$y_hat_test), y_test, pch=16, cex=0.75, xlab = \"pred\", ylab = \"actual\") abline(0,1,col=\"red\",lty=2,lwd=2.5)"},{"path":[]},{"path":"https://stochastictree.github.io/stochtree-r/articles/BayesianSupervisedLearning.html","id":"simulation-2","dir":"Articles","previous_headings":"Demo 3: Partitioned Linear Model with Random Effects","what":"Simulation","title":"Bayesian Supervised Learning in StochTree","text":", generate data simple partitioned linear model additive random effect structure.","code":"# Generate the data n <- 500 p_x <- 10 p_w <- 1 snr <- 3 X <- matrix(runif(n*p_x), ncol = p_x) W <- matrix(runif(n*p_w), ncol = p_w) group_ids <- rep(c(1,2), n %/% 2) rfx_coefs <- matrix(c(-5, -3, 5, 3),nrow=2,byrow=T) rfx_basis <- cbind(1, runif(n, -1, 1)) f_XW <- ( ((0 <= X[,1]) & (0.25 > X[,1])) * (-7.5*W[,1]) + ((0.25 <= X[,1]) & (0.5 > X[,1])) * (-2.5*W[,1]) + ((0.5 <= X[,1]) & (0.75 > X[,1])) * (2.5*W[,1]) + ((0.75 <= X[,1]) & (1 > X[,1])) * (7.5*W[,1]) ) rfx_term <- rowSums(rfx_coefs[group_ids,] * rfx_basis) noise_sd <- sd(f_XW) / snr y <- f_XW + rfx_term + rnorm(n, 0, 1)*noise_sd # Split data into test and train sets test_set_pct <- 0.2 n_test <- round(test_set_pct*n) n_train <- n - n_test test_inds <- sort(sample(1:n, n_test, replace = F)) train_inds <- (1:n)[!((1:n) %in% test_inds)] X_test <- X[test_inds,] X_train <- X[train_inds,] W_test <- W[test_inds,] W_train <- W[train_inds,] y_test <- y[test_inds] y_train <- y[train_inds] group_ids_test <- group_ids[test_inds] group_ids_train <- group_ids[train_inds] rfx_basis_test <- rfx_basis[test_inds,] rfx_basis_train <- rfx_basis[train_inds,]"},{"path":[]},{"path":"https://stochastictree.github.io/stochtree-r/articles/BayesianSupervisedLearning.html","id":"warmstart-2","dir":"Articles","previous_headings":"Demo 3: Partitioned Linear Model with Random Effects > Sampling and Analysis","what":"Warmstart","title":"Bayesian Supervised Learning in StochTree","text":"first sample ensemble model \\(y \\mid X\\) using “warm-start” initialization samples (Hahn (2023)). default stochtree. Inspect MCMC samples","code":"num_gfr <- 10 num_burnin <- 0 num_mcmc <- 100 num_samples <- num_gfr + num_burnin + num_mcmc bart_model_warmstart <- stochtree::bart( X_train = X_train, W_train = W_train, y_train = y_train, group_ids_train = group_ids_train, rfx_basis_train = rfx_basis_train, X_test = X_test, W_test = W_test, group_ids_test = group_ids_test, rfx_basis_test = rfx_basis_test, num_trees = 100, num_gfr = num_gfr, num_burnin = num_burnin, num_mcmc = num_mcmc, sample_sigma = T, sample_tau = T ) plot(bart_model_warmstart$sigma2_samples, ylab=\"sigma^2\") abline(h=noise_sd^2,col=\"red\",lty=2,lwd=2.5) plot(rowMeans(bart_model_warmstart$y_hat_test), y_test, pch=16, cex=0.75, xlab = \"pred\", ylab = \"actual\") abline(0,1,col=\"red\",lty=2,lwd=2.5)"},{"path":"https://stochastictree.github.io/stochtree-r/articles/BayesianSupervisedLearning.html","id":"bart-mcmc-without-warmstart-2","dir":"Articles","previous_headings":"Demo 3: Partitioned Linear Model with Random Effects > Sampling and Analysis","what":"BART MCMC without Warmstart","title":"Bayesian Supervised Learning in StochTree","text":"Next, sample ensemble model without warm-start initialization. Inspect MCMC samples","code":"num_gfr <- 0 num_burnin <- 100 num_mcmc <- 100 num_samples <- num_gfr + num_burnin + num_mcmc bart_model_root <- stochtree::bart( X_train = X_train, W_train = W_train, y_train = y_train, group_ids_train = group_ids_train, rfx_basis_train = rfx_basis_train, X_test = X_test, W_test = W_test, group_ids_test = group_ids_test, rfx_basis_test = rfx_basis_test, num_trees = 100, num_gfr = num_gfr, num_burnin = num_burnin, num_mcmc = num_mcmc, sample_sigma = T, sample_tau = T ) plot(bart_model_root$sigma2_samples, ylab=\"sigma^2\") abline(h=noise_sd^2,col=\"red\",lty=2,lwd=2.5) plot(rowMeans(bart_model_root$y_hat_test), y_test, pch=16, cex=0.75, xlab = \"pred\", ylab = \"actual\") abline(0,1,col=\"red\",lty=2,lwd=2.5)"},{"path":[]},{"path":"https://stochastictree.github.io/stochtree-r/articles/CausalInference.html","id":"demo-1-nonlinear-outcome-model-heterogeneous-treatment-effect","dir":"Articles","previous_headings":"","what":"Demo 1: Nonlinear Outcome Model, Heterogeneous Treatment Effect","title":"Causal Machine Learning in StochTree","text":"consider following data generating process Hahn, Murray, Carvalho (2020): \\[\\begin{equation*} \\begin{aligned} y &= \\mu(X) + \\tau(X) Z + \\epsilon\\\\ \\epsilon &\\sim N\\left(0,\\sigma^2\\right)\\\\ \\mu(X) &= 1 + g(X) + 6 \\lvert X_3 - 1 \\rvert\\\\ \\tau(X) &= 1 + 2 X_2 X_4\\\\ g(X) &= \\mathbb{}(X_5=1) \\times 2 - \\mathbb{}(X_5=2) \\times 1 - \\mathbb{}(X_5=3) \\times 4\\\\ X_1,X_2,X_3 &\\sim N\\left(0,1\\right)\\\\ X_4 &\\sim \\text{Bernoulli}(1/2)\\\\ X_5 &\\sim \\text{Categorical}(1/3,1/3,1/3)\\\\ \\end{aligned} \\end{equation*}\\]","code":""},{"path":"https://stochastictree.github.io/stochtree-r/articles/CausalInference.html","id":"simulation","dir":"Articles","previous_headings":"Demo 1: Nonlinear Outcome Model, Heterogeneous Treatment Effect","what":"Simulation","title":"Causal Machine Learning in StochTree","text":"draw DGP defined ","code":"n <- 500 snr <- 3 x1 <- rnorm(n) x2 <- rnorm(n) x3 <- rnorm(n) x4 <- as.numeric(rbinom(n,1,0.5)) x5 <- as.numeric(sample(1:3,n,replace=T)) X <- cbind(x1,x2,x3,x4,x5) p <- ncol(X) mu_x <- mu1(X) tau_x <- tau2(X) pi_x <- 0.8*pnorm((3*mu_x/sd(mu_x)) - 0.5*X[,1]) + 0.05 + runif(n)/10 Z <- rbinom(n,1,pi_x) E_XZ <- mu_x + Z*tau_x y <- E_XZ + rnorm(n, 0, 1)*(sd(E_XZ)/snr) # Split data into test and train sets test_set_pct <- 0.2 n_test <- round(test_set_pct*n) n_train <- n - n_test test_inds <- sort(sample(1:n, n_test, replace = F)) train_inds <- (1:n)[!((1:n) %in% test_inds)] X_test <- X[test_inds,] X_train <- X[train_inds,] pi_test <- pi_x[test_inds] pi_train <- pi_x[train_inds] Z_test <- Z[test_inds] Z_train <- Z[train_inds] y_test <- y[test_inds] y_train <- y[train_inds] mu_test <- mu_x[test_inds] mu_train <- mu_x[train_inds] tau_test <- tau_x[test_inds] tau_train <- tau_x[train_inds]"},{"path":[]},{"path":"https://stochastictree.github.io/stochtree-r/articles/CausalInference.html","id":"warmstart","dir":"Articles","previous_headings":"Demo 1: Nonlinear Outcome Model, Heterogeneous Treatment Effect > Sampling and Analysis","what":"Warmstart","title":"Causal Machine Learning in StochTree","text":"first simulate ensemble model \\(y \\mid X\\) using “warm-start” initialization samples (Krantsevich, , Hahn (2023)). default stochtree. Inspect BART samples initialized XBART warm-start Examine test set interval coverage","code":"num_gfr <- 10 num_burnin <- 0 num_mcmc <- 1000 num_samples <- num_gfr + num_burnin + num_mcmc bcf_model_warmstart <- bcf( X_train = X_train, Z_train = Z_train, y_train = y_train, pi_train = pi_train, X_test = X_test, Z_test = Z_test, pi_test = pi_test, ordered_cat_vars = c(4,5), num_gfr = num_gfr, num_burnin = num_burnin, num_mcmc = num_mcmc, sample_sigma_leaf_mu = F, sample_sigma_leaf_tau = F ) plot(rowMeans(bcf_model_warmstart$mu_hat_test), mu_test, xlab = \"predicted\", ylab = \"actual\", main = \"Prognostic function\") abline(0,1,col=\"red\",lty=3,lwd=3) plot(rowMeans(bcf_model_warmstart$tau_hat_test), tau_test, xlab = \"predicted\", ylab = \"actual\", main = \"Treatment effect\") abline(0,1,col=\"red\",lty=3,lwd=3) sigma_observed <- var(y-E_XZ) plot_bounds <- c(min(c(bcf_model_warmstart$sigma2_samples, sigma_observed)), max(c(bcf_model_warmstart$sigma2_samples, sigma_observed))) plot(bcf_model_warmstart$sigma2_samples, ylim = plot_bounds, ylab = \"sigma^2\", xlab = \"Sample\", main = \"Global variance parameter\") abline(h = sigma_observed, lty=3, lwd = 3, col = \"blue\") test_lb <- apply(bcf_model_warmstart$tau_hat_test, 1, quantile, 0.025) test_ub <- apply(bcf_model_warmstart$tau_hat_test, 1, quantile, 0.975) cover <- ( (test_lb <= tau_x[test_inds]) & (test_ub >= tau_x[test_inds]) ) mean(cover) #> [1] 0.98"},{"path":"https://stochastictree.github.io/stochtree-r/articles/CausalInference.html","id":"bart-mcmc-without-warmstart","dir":"Articles","previous_headings":"Demo 1: Nonlinear Outcome Model, Heterogeneous Treatment Effect > Sampling and Analysis","what":"BART MCMC without Warmstart","title":"Causal Machine Learning in StochTree","text":"Next, simulate ensemble model without warm-start initialization. Inspect BART samples burnin Examine test set interval coverage","code":"num_gfr <- 0 num_burnin <- 1000 num_mcmc <- 1000 num_samples <- num_gfr + num_burnin + num_mcmc bcf_model_root <- bcf( X_train = X_train, Z_train = Z_train, y_train = y_train, pi_train = pi_train, X_test = X_test, Z_test = Z_test, pi_test = pi_test, ordered_cat_vars = c(4,5), num_gfr = num_gfr, num_burnin = num_burnin, num_mcmc = num_mcmc, sample_sigma_leaf_mu = F, sample_sigma_leaf_tau = F ) plot(rowMeans(bcf_model_root$mu_hat_test), mu_test, xlab = \"predicted\", ylab = \"actual\", main = \"Prognostic function\") abline(0,1,col=\"red\",lty=3,lwd=3) plot(rowMeans(bcf_model_root$tau_hat_test), tau_test, xlab = \"predicted\", ylab = \"actual\", main = \"Treatment effect\") abline(0,1,col=\"red\",lty=3,lwd=3) sigma_observed <- var(y-E_XZ) plot_bounds <- c(min(c(bcf_model_root$sigma2_samples, sigma_observed)), max(c(bcf_model_root$sigma2_samples, sigma_observed))) plot(bcf_model_root$sigma2_samples, ylim = plot_bounds, ylab = \"sigma^2\", xlab = \"Sample\", main = \"Global variance parameter\") abline(h = sigma_observed, lty=3, lwd = 3, col = \"blue\") test_lb <- apply(bcf_model_root$tau_hat_test, 1, quantile, 0.025) test_ub <- apply(bcf_model_root$tau_hat_test, 1, quantile, 0.975) cover <- ( (test_lb <= tau_x[test_inds]) & (test_ub >= tau_x[test_inds]) ) mean(cover) #> [1] 0.96"},{"path":"https://stochastictree.github.io/stochtree-r/articles/CausalInference.html","id":"demo-2-linear-outcome-model-heterogeneous-treatment-effect","dir":"Articles","previous_headings":"","what":"Demo 2: Linear Outcome Model, Heterogeneous Treatment Effect","title":"Causal Machine Learning in StochTree","text":"consider following data generating process Hahn, Murray, Carvalho (2020): \\[\\begin{equation*} \\begin{aligned} y &= \\mu(X) + \\tau(X) Z + \\epsilon\\\\ \\epsilon &\\sim N\\left(0,\\sigma^2\\right)\\\\ \\mu(X) &= 1 + g(X) + 6 X_1 X_3\\\\ \\tau(X) &= 1 + 2 X_2 X_4\\\\ g(X) &= \\mathbb{}(X_5=1) \\times 2 - \\mathbb{}(X_5=2) \\times 1 - \\mathbb{}(X_5=3) \\times 4\\\\ X_1,X_2,X_3 &\\sim N\\left(0,1\\right)\\\\ X_4 &\\sim \\text{Bernoulli}(1/2)\\\\ X_5 &\\sim \\text{Categorical}(1/3,1/3,1/3)\\\\ \\end{aligned} \\end{equation*}\\]","code":""},{"path":"https://stochastictree.github.io/stochtree-r/articles/CausalInference.html","id":"simulation-1","dir":"Articles","previous_headings":"Demo 2: Linear Outcome Model, Heterogeneous Treatment Effect","what":"Simulation","title":"Causal Machine Learning in StochTree","text":"draw DGP defined ","code":"n <- 500 snr <- 3 x1 <- rnorm(n) x2 <- rnorm(n) x3 <- rnorm(n) x4 <- as.numeric(rbinom(n,1,0.5)) x5 <- as.numeric(sample(1:3,n,replace=T)) X <- cbind(x1,x2,x3,x4,x5) p <- ncol(X) mu_x <- mu2(X) tau_x <- tau2(X) pi_x <- 0.8*pnorm((3*mu_x/sd(mu_x)) - 0.5*X[,1]) + 0.05 + runif(n)/10 Z <- rbinom(n,1,pi_x) E_XZ <- mu_x + Z*tau_x y <- E_XZ + rnorm(n, 0, 1)*(sd(E_XZ)/snr) # Split data into test and train sets test_set_pct <- 0.2 n_test <- round(test_set_pct*n) n_train <- n - n_test test_inds <- sort(sample(1:n, n_test, replace = F)) train_inds <- (1:n)[!((1:n) %in% test_inds)] X_test <- X[test_inds,] X_train <- X[train_inds,] pi_test <- pi_x[test_inds] pi_train <- pi_x[train_inds] Z_test <- Z[test_inds] Z_train <- Z[train_inds] y_test <- y[test_inds] y_train <- y[train_inds] mu_test <- mu_x[test_inds] mu_train <- mu_x[train_inds] tau_test <- tau_x[test_inds] tau_train <- tau_x[train_inds]"},{"path":[]},{"path":"https://stochastictree.github.io/stochtree-r/articles/CausalInference.html","id":"warmstart-1","dir":"Articles","previous_headings":"Demo 2: Linear Outcome Model, Heterogeneous Treatment Effect > Sampling and Analysis","what":"Warmstart","title":"Causal Machine Learning in StochTree","text":"first simulate ensemble model \\(y \\mid X\\) using “warm-start” initialization samples (Krantsevich, , Hahn (2023)). default stochtree. Inspect BART samples initialized XBART warm-start Examine test set interval coverage","code":"num_gfr <- 10 num_burnin <- 0 num_mcmc <- 100 num_samples <- num_gfr + num_burnin + num_mcmc bcf_model_warmstart <- bcf( X_train = X_train, Z_train = Z_train, y_train = y_train, pi_train = pi_train, X_test = X_test, Z_test = Z_test, pi_test = pi_test, ordered_cat_vars = c(4,5), num_gfr = num_gfr, num_burnin = num_burnin, num_mcmc = num_mcmc, sample_sigma_leaf_mu = F, sample_sigma_leaf_tau = F ) plot(rowMeans(bcf_model_warmstart$mu_hat_test), mu_test, xlab = \"predicted\", ylab = \"actual\", main = \"Prognostic function\") abline(0,1,col=\"red\",lty=3,lwd=3) plot(rowMeans(bcf_model_warmstart$tau_hat_test), tau_test, xlab = \"predicted\", ylab = \"actual\", main = \"Treatment effect\") abline(0,1,col=\"red\",lty=3,lwd=3) sigma_observed <- var(y-E_XZ) plot_bounds <- c(min(c(bcf_model_warmstart$sigma2_samples, sigma_observed)), max(c(bcf_model_warmstart$sigma2_samples, sigma_observed))) plot(bcf_model_warmstart$sigma2_samples, ylim = plot_bounds, ylab = \"sigma^2\", xlab = \"Sample\", main = \"Global variance parameter\") abline(h = sigma_observed, lty=3, lwd = 3, col = \"blue\") test_lb <- apply(bcf_model_warmstart$tau_hat_test, 1, quantile, 0.025) test_ub <- apply(bcf_model_warmstart$tau_hat_test, 1, quantile, 0.975) cover <- ( (test_lb <= tau_x[test_inds]) & (test_ub >= tau_x[test_inds]) ) mean(cover) #> [1] 0.56"},{"path":"https://stochastictree.github.io/stochtree-r/articles/CausalInference.html","id":"bart-mcmc-without-warmstart-1","dir":"Articles","previous_headings":"Demo 2: Linear Outcome Model, Heterogeneous Treatment Effect > Sampling and Analysis","what":"BART MCMC without Warmstart","title":"Causal Machine Learning in StochTree","text":"Next, simulate ensemble model without warm-start initialization. Inspect BART samples burnin Examine test set interval coverage","code":"num_gfr <- 0 num_burnin <- 100 num_mcmc <- 100 num_samples <- num_gfr + num_burnin + num_mcmc bcf_model_root <- bcf( X_train = X_train, Z_train = Z_train, y_train = y_train, pi_train = pi_train, X_test = X_test, Z_test = Z_test, pi_test = pi_test, ordered_cat_vars = c(4,5), num_gfr = num_gfr, num_burnin = num_burnin, num_mcmc = num_mcmc, sample_sigma_leaf_mu = F, sample_sigma_leaf_tau = F ) plot(rowMeans(bcf_model_root$mu_hat_test), mu_test, xlab = \"predicted\", ylab = \"actual\", main = \"Prognostic function\") abline(0,1,col=\"red\",lty=3,lwd=3) plot(rowMeans(bcf_model_root$tau_hat_test), tau_test, xlab = \"predicted\", ylab = \"actual\", main = \"Treatment effect\") abline(0,1,col=\"red\",lty=3,lwd=3) sigma_observed <- var(y-E_XZ) plot_bounds <- c(min(c(bcf_model_root$sigma2_samples, sigma_observed)), max(c(bcf_model_root$sigma2_samples, sigma_observed))) plot(bcf_model_root$sigma2_samples, ylim = plot_bounds, ylab = \"sigma^2\", xlab = \"Sample\", main = \"Global variance parameter\") abline(h = sigma_observed, lty=3, lwd = 3, col = \"blue\") test_lb <- apply(bcf_model_root$tau_hat_test, 1, quantile, 0.025) test_ub <- apply(bcf_model_root$tau_hat_test, 1, quantile, 0.975) cover <- ( (test_lb <= tau_x[test_inds]) & (test_ub >= tau_x[test_inds]) ) mean(cover) #> [1] 0.91"},{"path":"https://stochastictree.github.io/stochtree-r/articles/CausalInference.html","id":"demo-3-linear-outcome-model-homogeneous-treatment-effect","dir":"Articles","previous_headings":"","what":"Demo 3: Linear Outcome Model, Homogeneous Treatment Effect","title":"Causal Machine Learning in StochTree","text":"consider following data generating process Hahn, Murray, Carvalho (2020): \\[\\begin{equation*} \\begin{aligned} y &= \\mu(X) + \\tau(X) Z + \\epsilon\\\\ \\epsilon &\\sim N\\left(0,\\sigma^2\\right)\\\\ \\mu(X) &= 1 + g(X) + 6 X_1 X_3\\\\ \\tau(X) &= 3\\\\ g(X) &= \\mathbb{}(X_5=1) \\times 2 - \\mathbb{}(X_5=2) \\times 1 - \\mathbb{}(X_5=3) \\times 4\\\\ X_1,X_2,X_3 &\\sim N\\left(0,1\\right)\\\\ X_4 &\\sim \\text{Bernoulli}(1/2)\\\\ X_5 &\\sim \\text{Categorical}(1/3,1/3,1/3)\\\\ \\end{aligned} \\end{equation*}\\]","code":""},{"path":"https://stochastictree.github.io/stochtree-r/articles/CausalInference.html","id":"simulation-2","dir":"Articles","previous_headings":"Demo 3: Linear Outcome Model, Homogeneous Treatment Effect","what":"Simulation","title":"Causal Machine Learning in StochTree","text":"draw DGP defined ","code":"n <- 500 snr <- 3 x1 <- rnorm(n) x2 <- rnorm(n) x3 <- rnorm(n) x4 <- as.numeric(rbinom(n,1,0.5)) x5 <- as.numeric(sample(1:3,n,replace=T)) X <- cbind(x1,x2,x3,x4,x5) p <- ncol(X) mu_x <- mu2(X) tau_x <- tau1(X) pi_x <- 0.8*pnorm((3*mu_x/sd(mu_x)) - 0.5*X[,1]) + 0.05 + runif(n)/10 Z <- rbinom(n,1,pi_x) E_XZ <- mu_x + Z*tau_x y <- E_XZ + rnorm(n, 0, 1)*(sd(E_XZ)/snr) # Split data into test and train sets test_set_pct <- 0.2 n_test <- round(test_set_pct*n) n_train <- n - n_test test_inds <- sort(sample(1:n, n_test, replace = F)) train_inds <- (1:n)[!((1:n) %in% test_inds)] X_test <- X[test_inds,] X_train <- X[train_inds,] pi_test <- pi_x[test_inds] pi_train <- pi_x[train_inds] Z_test <- Z[test_inds] Z_train <- Z[train_inds] y_test <- y[test_inds] y_train <- y[train_inds] mu_test <- mu_x[test_inds] mu_train <- mu_x[train_inds] tau_test <- tau_x[test_inds] tau_train <- tau_x[train_inds]"},{"path":[]},{"path":"https://stochastictree.github.io/stochtree-r/articles/CausalInference.html","id":"warmstart-2","dir":"Articles","previous_headings":"Demo 3: Linear Outcome Model, Homogeneous Treatment Effect > Sampling and Analysis","what":"Warmstart","title":"Causal Machine Learning in StochTree","text":"first simulate ensemble model \\(y \\mid X\\) using “warm-start” initialization samples (Krantsevich, , Hahn (2023)). default stochtree. Inspect BART samples initialized XBART warm-start Examine test set interval coverage","code":"num_gfr <- 10 num_burnin <- 0 num_mcmc <- 100 num_samples <- num_gfr + num_burnin + num_mcmc bcf_model_warmstart <- bcf( X_train = X_train, Z_train = Z_train, y_train = y_train, pi_train = pi_train, X_test = X_test, Z_test = Z_test, pi_test = pi_test, ordered_cat_vars = c(4,5), num_gfr = num_gfr, num_burnin = num_burnin, num_mcmc = num_mcmc, sample_sigma_leaf_mu = F, sample_sigma_leaf_tau = F ) plot(rowMeans(bcf_model_warmstart$mu_hat_test), mu_test, xlab = \"predicted\", ylab = \"actual\", main = \"Prognostic function\") abline(0,1,col=\"red\",lty=3,lwd=3) plot(rowMeans(bcf_model_warmstart$tau_hat_test), tau_test, xlab = \"predicted\", ylab = \"actual\", main = \"Treatment effect\") abline(0,1,col=\"red\",lty=3,lwd=3) sigma_observed <- var(y-E_XZ) plot_bounds <- c(min(c(bcf_model_warmstart$sigma2_samples, sigma_observed)), max(c(bcf_model_warmstart$sigma2_samples, sigma_observed))) plot(bcf_model_warmstart$sigma2_samples, ylim = plot_bounds, ylab = \"sigma^2\", xlab = \"Sample\", main = \"Global variance parameter\") abline(h = sigma_observed, lty=3, lwd = 3, col = \"blue\") test_lb <- apply(bcf_model_warmstart$tau_hat_test, 1, quantile, 0.025) test_ub <- apply(bcf_model_warmstart$tau_hat_test, 1, quantile, 0.975) cover <- ( (test_lb <= tau_x[test_inds]) & (test_ub >= tau_x[test_inds]) ) mean(cover) #> [1] 1"},{"path":"https://stochastictree.github.io/stochtree-r/articles/CausalInference.html","id":"bart-mcmc-without-warmstart-2","dir":"Articles","previous_headings":"Demo 3: Linear Outcome Model, Homogeneous Treatment Effect > Sampling and Analysis","what":"BART MCMC without Warmstart","title":"Causal Machine Learning in StochTree","text":"Next, simulate ensemble model without warm-start initialization. Inspect BART samples burnin Examine test set interval coverage","code":"num_gfr <- 0 num_burnin <- 100 num_mcmc <- 100 num_samples <- num_gfr + num_burnin + num_mcmc bcf_model_root <- bcf( X_train = X_train, Z_train = Z_train, y_train = y_train, pi_train = pi_train, X_test = X_test, Z_test = Z_test, pi_test = pi_test, ordered_cat_vars = c(4,5), num_gfr = num_gfr, num_burnin = num_burnin, num_mcmc = num_mcmc, sample_sigma_leaf_mu = F, sample_sigma_leaf_tau = F ) plot(rowMeans(bcf_model_root$mu_hat_test), mu_test, xlab = \"predicted\", ylab = \"actual\", main = \"Prognostic function\") abline(0,1,col=\"red\",lty=3,lwd=3) plot(rowMeans(bcf_model_root$tau_hat_test), tau_test, xlab = \"predicted\", ylab = \"actual\", main = \"Treatment effect\") abline(0,1,col=\"red\",lty=3,lwd=3) sigma_observed <- var(y-E_XZ) plot_bounds <- c(min(c(bcf_model_root$sigma2_samples, sigma_observed)), max(c(bcf_model_root$sigma2_samples, sigma_observed))) plot(bcf_model_root$sigma2_samples, ylim = plot_bounds, ylab = \"sigma^2\", xlab = \"Sample\", main = \"Global variance parameter\") abline(h = sigma_observed, lty=3, lwd = 3, col = \"blue\") test_lb <- apply(bcf_model_root$tau_hat_test, 1, quantile, 0.025) test_ub <- apply(bcf_model_root$tau_hat_test, 1, quantile, 0.975) cover <- ( (test_lb <= tau_x[test_inds]) & (test_ub >= tau_x[test_inds]) ) mean(cover) #> [1] 1"},{"path":"https://stochastictree.github.io/stochtree-r/articles/CausalInference.html","id":"demo-4-nonlinear-outcome-model-heterogeneous-treatment-effect","dir":"Articles","previous_headings":"","what":"Demo 4: Nonlinear Outcome Model, Heterogeneous Treatment Effect","title":"Causal Machine Learning in StochTree","text":"consider following data generating process: \\[\\begin{equation*} \\begin{aligned} y &= \\mu(X) + \\tau(X) Z + \\epsilon\\\\ \\epsilon &\\sim N\\left(0,\\sigma^2\\right)\\\\ \\mu(X) &= \\begin{cases} -1.1 & \\text{ } X_1 > X_2\\\\ 0.9 & \\text{ } X_1 \\leq X_2 \\end{cases}\\\\ \\tau(X) &= \\frac{1}{1+\\exp(-X_3)} + \\frac{X_2}{10}\\\\ \\pi(X) &= \\Phi\\left(\\mu(X)\\right)\\\\ Z &\\sim \\text{Bernoulli}\\left(\\pi(X)\\right)\\\\ X_1,X_2,X_3 &\\sim N\\left(0,1\\right)\\\\ X_4 &\\sim N\\left(X_2,1\\right)\\\\ \\end{aligned} \\end{equation*}\\]","code":""},{"path":"https://stochastictree.github.io/stochtree-r/articles/CausalInference.html","id":"simulation-3","dir":"Articles","previous_headings":"Demo 4: Nonlinear Outcome Model, Heterogeneous Treatment Effect","what":"Simulation","title":"Causal Machine Learning in StochTree","text":"draw DGP defined ","code":"n <- 1000 x1 <- rnorm(n) x2 <- rnorm(n) x3 <- rnorm(n) x4 <- rnorm(n,x2,1) X <- cbind(x1,x2,x3,x4) p <- ncol(X) mu <- function(x) {-1*(x[,1]>(x[,2])) + 1*(x[,1]<(x[,2])) - 0.1} tau <- function(x) {1/(1 + exp(-x[,3])) + x[,2]/10} mu_x <- mu(X) tau_x <- tau(X) pi_x <- pnorm(mu_x) Z <- rbinom(n,1,pi_x) E_XZ <- mu_x + Z*tau_x sigma <- diff(range(mu_x + tau_x*pi))/8 y <- E_XZ + sigma*rnorm(n) # Split data into test and train sets test_set_pct <- 0.2 n_test <- round(test_set_pct*n) n_train <- n - n_test test_inds <- sort(sample(1:n, n_test, replace = F)) train_inds <- (1:n)[!((1:n) %in% test_inds)] X_test <- X[test_inds,] X_train <- X[train_inds,] pi_test <- pi_x[test_inds] pi_train <- pi_x[train_inds] Z_test <- Z[test_inds] Z_train <- Z[train_inds] y_test <- y[test_inds] y_train <- y[train_inds] mu_test <- mu_x[test_inds] mu_train <- mu_x[train_inds] tau_test <- tau_x[test_inds] tau_train <- tau_x[train_inds]"},{"path":[]},{"path":"https://stochastictree.github.io/stochtree-r/articles/CausalInference.html","id":"warmstart-3","dir":"Articles","previous_headings":"Demo 4: Nonlinear Outcome Model, Heterogeneous Treatment Effect > Sampling and Analysis","what":"Warmstart","title":"Causal Machine Learning in StochTree","text":"first simulate ensemble model \\(y \\mid X\\) using “warm-start” initialization samples (Krantsevich, , Hahn (2023)). default stochtree. Inspect BART samples initialized XBART warm-start Examine test set interval coverage","code":"num_gfr <- 10 num_burnin <- 0 num_mcmc <- 100 num_samples <- num_gfr + num_burnin + num_mcmc bcf_model_warmstart <- bcf( X_train = X_train, Z_train = Z_train, y_train = y_train, pi_train = pi_train, X_test = X_test, Z_test = Z_test, pi_test = pi_test, num_gfr = num_gfr, num_burnin = num_burnin, num_mcmc = num_mcmc, sample_sigma_leaf_mu = F, sample_sigma_leaf_tau = F ) plot(rowMeans(bcf_model_warmstart$mu_hat_test), mu_test, xlab = \"predicted\", ylab = \"actual\", main = \"Prognostic function\") abline(0,1,col=\"red\",lty=3,lwd=3) plot(rowMeans(bcf_model_warmstart$tau_hat_test), tau_test, xlab = \"predicted\", ylab = \"actual\", main = \"Treatment effect\") abline(0,1,col=\"red\",lty=3,lwd=3) sigma_observed <- var(y-E_XZ) plot_bounds <- c(min(c(bcf_model_warmstart$sigma2_samples, sigma_observed)), max(c(bcf_model_warmstart$sigma2_samples, sigma_observed))) plot(bcf_model_warmstart$sigma2_samples, ylim = plot_bounds, ylab = \"sigma^2\", xlab = \"Sample\", main = \"Global variance parameter\") abline(h = sigma_observed, lty=3, lwd = 3, col = \"blue\") test_lb <- apply(bcf_model_warmstart$tau_hat_test, 1, quantile, 0.025) test_ub <- apply(bcf_model_warmstart$tau_hat_test, 1, quantile, 0.975) cover <- ( (test_lb <= tau_x[test_inds]) & (test_ub >= tau_x[test_inds]) ) mean(cover) #> [1] 0.98"},{"path":"https://stochastictree.github.io/stochtree-r/articles/CausalInference.html","id":"bart-mcmc-without-warmstart-3","dir":"Articles","previous_headings":"Demo 4: Nonlinear Outcome Model, Heterogeneous Treatment Effect > Sampling and Analysis","what":"BART MCMC without Warmstart","title":"Causal Machine Learning in StochTree","text":"Next, simulate ensemble model without warm-start initialization. Inspect BART samples burnin Examine test set interval coverage","code":"num_gfr <- 0 num_burnin <- 100 num_mcmc <- 100 num_samples <- num_gfr + num_burnin + num_mcmc bcf_model_root <- bcf( X_train = X_train, Z_train = Z_train, y_train = y_train, pi_train = pi_train, X_test = X_test, Z_test = Z_test, pi_test = pi_test, num_gfr = num_gfr, num_burnin = num_burnin, num_mcmc = num_mcmc, sample_sigma_leaf_mu = F, sample_sigma_leaf_tau = F ) plot(rowMeans(bcf_model_root$mu_hat_test), mu_test, xlab = \"predicted\", ylab = \"actual\", main = \"Prognostic function\") abline(0,1,col=\"red\",lty=3,lwd=3) plot(rowMeans(bcf_model_root$tau_hat_test), tau_test, xlab = \"predicted\", ylab = \"actual\", main = \"Treatment effect\") abline(0,1,col=\"red\",lty=3,lwd=3) sigma_observed <- var(y-E_XZ) plot_bounds <- c(min(c(bcf_model_root$sigma2_samples, sigma_observed)), max(c(bcf_model_root$sigma2_samples, sigma_observed))) plot(bcf_model_root$sigma2_samples, ylim = plot_bounds, ylab = \"sigma^2\", xlab = \"Sample\", main = \"Global variance parameter\") abline(h = sigma_observed, lty=3, lwd = 3, col = \"blue\") test_lb <- apply(bcf_model_root$tau_hat_test, 1, quantile, 0.025) test_ub <- apply(bcf_model_root$tau_hat_test, 1, quantile, 0.975) cover <- ( (test_lb <= tau_x[test_inds]) & (test_ub >= tau_x[test_inds]) ) mean(cover) #> [1] 0.98"},{"path":"https://stochastictree.github.io/stochtree-r/articles/CausalInference.html","id":"demo-5-nonlinear-outcome-model-heterogeneous-treatment-effect-with-additive-random-effects","dir":"Articles","previous_headings":"","what":"Demo 5: Nonlinear Outcome Model, Heterogeneous Treatment Effect with Additive Random Effects","title":"Causal Machine Learning in StochTree","text":"augment simulated example Demo 1 additive random effect structure show bcf() function can estimate incorporate effects forest sampling procedure.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/articles/CausalInference.html","id":"simulation-4","dir":"Articles","previous_headings":"Demo 5: Nonlinear Outcome Model, Heterogeneous Treatment Effect with Additive Random Effects","what":"Simulation","title":"Causal Machine Learning in StochTree","text":"draw augmented “demo 1” DGP","code":"n <- 500 snr <- 3 x1 <- rnorm(n) x2 <- rnorm(n) x3 <- rnorm(n) x4 <- as.numeric(rbinom(n,1,0.5)) x5 <- as.numeric(sample(1:3,n,replace=T)) X <- cbind(x1,x2,x3,x4,x5) p <- ncol(X) mu_x <- mu1(X) tau_x <- tau2(X) pi_x <- 0.8*pnorm((3*mu_x/sd(mu_x)) - 0.5*X[,1]) + 0.05 + runif(n)/10 Z <- rbinom(n,1,pi_x) E_XZ <- mu_x + Z*tau_x group_ids <- rep(c(1,2), n %/% 2) rfx_coefs <- matrix(c(-1, -1, 1, 1),nrow=2,byrow=T) rfx_basis <- cbind(1, runif(n, -1, 1)) rfx_term <- rowSums(rfx_coefs[group_ids,] * rfx_basis) y <- E_XZ + rfx_term + rnorm(n, 0, 1)*(sd(E_XZ)/snr) # Split data into test and train sets test_set_pct <- 0.2 n_test <- round(test_set_pct*n) n_train <- n - n_test test_inds <- sort(sample(1:n, n_test, replace = F)) train_inds <- (1:n)[!((1:n) %in% test_inds)] X_test <- X[test_inds,] X_train <- X[train_inds,] pi_test <- pi_x[test_inds] pi_train <- pi_x[train_inds] Z_test <- Z[test_inds] Z_train <- Z[train_inds] y_test <- y[test_inds] y_train <- y[train_inds] mu_test <- mu_x[test_inds] mu_train <- mu_x[train_inds] tau_test <- tau_x[test_inds] tau_train <- tau_x[train_inds] group_ids_test <- group_ids[test_inds] group_ids_train <- group_ids[train_inds] rfx_basis_test <- rfx_basis[test_inds,] rfx_basis_train <- rfx_basis[train_inds,] rfx_term_test <- rfx_term[test_inds] rfx_term_train <- rfx_term[train_inds]"},{"path":[]},{"path":"https://stochastictree.github.io/stochtree-r/articles/CausalInference.html","id":"warmstart-4","dir":"Articles","previous_headings":"Demo 5: Nonlinear Outcome Model, Heterogeneous Treatment Effect with Additive Random Effects > Sampling and Analysis","what":"Warmstart","title":"Causal Machine Learning in StochTree","text":"simulate “warm-start” model (running root-MCMC BART random effects simply matter modifying code snippet setting num_gfr <- 0 num_mcmc > 0). Inspect BART samples initialized XBART warm-start Examine test set interval coverage clear causal inference much difficult presence strong covariate-dependent prognostic effects strong group-level random effects. sense, proper prior calibration three \\(\\mu\\), \\(\\tau\\) random effects models crucial.","code":"num_gfr <- 100 num_burnin <- 0 num_mcmc <- 500 num_samples <- num_gfr + num_burnin + num_mcmc bcf_model_warmstart <- bcf( X_train = X_train, Z_train = Z_train, y_train = y_train, pi_train = pi_train, group_ids_train = group_ids_train, rfx_basis_train = rfx_basis_train, X_test = X_test, Z_test = Z_test, pi_test = pi_test, group_ids_test = group_ids_test, rfx_basis_test = rfx_basis_test, ordered_cat_vars = c(4,5), num_gfr = num_gfr, num_burnin = num_burnin, num_mcmc = num_mcmc, sample_sigma_leaf_mu = T, sample_sigma_leaf_tau = F ) plot(rowMeans(bcf_model_warmstart$mu_hat_test), mu_test, xlab = \"predicted\", ylab = \"actual\", main = \"Prognostic function\") abline(0,1,col=\"red\",lty=3,lwd=3) plot(rowMeans(bcf_model_warmstart$tau_hat_test), tau_test, xlab = \"predicted\", ylab = \"actual\", main = \"Treatment effect\") abline(0,1,col=\"red\",lty=3,lwd=3) plot(rowMeans(bcf_model_warmstart$y_hat_test), y_test, xlab = \"predicted\", ylab = \"actual\", main = \"Outcome\") abline(0,1,col=\"red\",lty=3,lwd=3) plot(rowMeans(bcf_model_warmstart$rfx_preds_test), rfx_term_test, xlab = \"predicted\", ylab = \"actual\", main = \"Random effects terms\") abline(0,1,col=\"red\",lty=3,lwd=3) sigma_observed <- var(y-E_XZ-rfx_term) plot_bounds <- c(min(c(bcf_model_warmstart$sigma2_samples, sigma_observed)), max(c(bcf_model_warmstart$sigma2_samples, sigma_observed))) plot(bcf_model_warmstart$sigma2_samples, ylim = plot_bounds, ylab = \"sigma^2\", xlab = \"Sample\", main = \"Global variance parameter\") abline(h = sigma_observed, lty=3, lwd = 3, col = \"blue\") test_lb <- apply(bcf_model_warmstart$tau_hat_test, 1, quantile, 0.025) test_ub <- apply(bcf_model_warmstart$tau_hat_test, 1, quantile, 0.975) cover <- ( (test_lb <= tau_x[test_inds]) & (test_ub >= tau_x[test_inds]) ) mean(cover) #> [1] 0.96"},{"path":[]},{"path":"https://stochastictree.github.io/stochtree-r/articles/CustomSamplingRoutine.html","id":"motivation","dir":"Articles","previous_headings":"","what":"Motivation","title":"Custom Sampling Routines in StochTree","text":"functions bart() bcf() provide simple performant interfaces supervised learning / causal inference, stochtree also offers access many “low-level” data structures typically implemented C++. low-level interface designed performance even simplicity — rather intent provide “prototype” interface C++ code doesn’t require modifying C++. illustrate prototype interface might useful, consider classic BART algorithm:    INPUT: \\(y\\), \\(X\\), \\(\\tau\\), \\(\\nu\\), \\(\\lambda\\), \\(\\alpha\\), \\(\\beta\\)    OUTPUT: \\(m\\) samples decision forest \\(k\\) trees global variance parameter \\(\\sigma^2\\)    Initialize \\(\\sigma^2\\) via default data-dependent calibration exercise    Initialize “forest 0” \\(k\\) trees single root node, referring tree \\(j\\)’s prediction vector \\(f_{0,j}\\)    Compute residual \\(r = y - \\sum_{j=1}^k f_{0,j}\\)    \\(\\) \\(\\left\\{1,\\dots,m\\right\\}\\):       Initialize forest \\(\\) forest \\(-1\\)       \\(j\\) \\(\\left\\{1,\\dots,k\\right\\}\\):          Add predictions tree \\(j\\) residual: \\(r = r + f_{,j}\\)          Update tree \\(j\\) via Metropolis-Hastings \\(r\\) \\(X\\) data tree priors depending (\\(\\tau\\), \\(\\sigma^2\\), \\(\\alpha\\), \\(\\beta\\))          Sample leaf node parameters tree \\(j\\) via Gibbs (leaf node prior \\(N\\left(0,\\tau\\right)\\))          Subtract (updated) predictions tree \\(j\\) residual: \\(r = r - f_{,j}\\)       Sample \\(\\sigma^2\\) via Gibbs (prior \\(IG(\\nu/2,\\nu\\lambda/2)\\)) algorithm conceptually simple, much core computation carried low-level languages C C++ tree data structure. result, changes algorithm, supporting heteroskedasticity (Pratola et al. (2020)), categorical outcomes (Murray (2021)) causal effect estimation (Hahn, Murray, Carvalho (2020)) require modifying low-level code. prototype interface exposes core components loop R level, thus making possible interchange C++ computation steps like “update tree \\(j\\) via Metropolis-Hastings” R computation custom variance model, user-specified additive mean model components, . begin, load stochtree package","code":"library(stochtree)"},{"path":[]},{"path":"https://stochastictree.github.io/stochtree-r/articles/CustomSamplingRoutine.html","id":"simulation","dir":"Articles","previous_headings":"Demo 1: Supervised Learning","what":"Simulation","title":"Custom Sampling Routines in StochTree","text":"Simulate simple partitioned linear model","code":"# Generate the data n <- 500 p_X <- 10 p_W <- 1 X <- matrix(runif(n*p_X), ncol = p_X) W <- matrix(runif(n*p_W), ncol = p_W) f_XW <- ( ((0 <= X[,1]) & (0.25 > X[,1])) * (-3*W[,1]) + ((0.25 <= X[,1]) & (0.5 > X[,1])) * (-1*W[,1]) + ((0.5 <= X[,1]) & (0.75 > X[,1])) * (1*W[,1]) + ((0.75 <= X[,1]) & (1 > X[,1])) * (3*W[,1]) ) y <- f_XW + rnorm(n, 0, 1) # Standardize outcome y_bar <- mean(y) y_std <- sd(y) resid <- (y-y_bar)/y_std"},{"path":"https://stochastictree.github.io/stochtree-r/articles/CustomSamplingRoutine.html","id":"sampling","dir":"Articles","previous_headings":"Demo 1: Supervised Learning","what":"Sampling","title":"Custom Sampling Routines in StochTree","text":"Set parameters inform forest variance parameter samplers Initialize R-level access C++ classes needed sample model Prepare run sampler Run grow--root sampler “warm-start” BART Pick last GFR forest (associated global variance / leaf scale parameters) MCMC sampler Predict rescale samples","code":"alpha <- 0.9 beta <- 1.25 min_samples_leaf <- 1 num_trees <- 100 cutpoint_grid_size = 100 global_variance_init = 1. tau_init = 0.5 leaf_prior_scale = matrix(c(tau_init), ncol = 1) nu <- 4 lambda <- 0.5 a_leaf <- 2. b_leaf <- 0.5 leaf_regression <- T feature_types <- as.integer(rep(0, p_X)) # 0 = numeric var_weights <- rep(1/p_X, p_X) # Data if (leaf_regression) { forest_dataset <- createForestDataset(X, W) outcome_model_type <- 1 } else { forest_dataset <- createForestDataset(X) outcome_model_type <- 0 } outcome <- createOutcome(resid) # Random number generator (std::mt19937) rng <- createRNG() # Sampling data structures forest_model <- createForestModel(forest_dataset, feature_types, num_trees, n, alpha, beta, min_samples_leaf) # Container of forest samples if (leaf_regression) { forest_samples <- createForestContainer(num_trees, 1, F) } else { forest_samples <- createForestContainer(num_trees, 1, T) } num_warmstart <- 10 num_mcmc <- 100 num_samples <- num_warmstart + num_mcmc global_var_samples <- c(global_variance_init, rep(0, num_samples)) leaf_scale_samples <- c(tau_init, rep(0, num_samples)) for (i in 1:num_warmstart) { # Sample forest forest_model$sample_one_iteration( forest_dataset, outcome, forest_samples, rng, feature_types, outcome_model_type, leaf_prior_scale, var_weights, global_var_samples[i], cutpoint_grid_size, gfr = T ) # Sample global variance parameter global_var_samples[i+1] <- sample_sigma2_one_iteration( outcome, rng, nu, lambda ) # Sample leaf node variance parameter and update `leaf_prior_scale` leaf_scale_samples[i+1] <- sample_tau_one_iteration( forest_samples, rng, a_leaf, b_leaf, i-1 ) leaf_prior_scale[1,1] <- leaf_scale_samples[i+1] } for (i in (num_warmstart+1):num_samples) { # Sample forest forest_model$sample_one_iteration( forest_dataset, outcome, forest_samples, rng, feature_types, outcome_model_type, leaf_prior_scale, var_weights, global_var_samples[i], cutpoint_grid_size, gfr = F ) # Sample global variance parameter global_var_samples[i+1] <- sample_sigma2_one_iteration( outcome, rng, nu, lambda ) # Sample leaf node variance parameter and update `leaf_prior_scale` leaf_scale_samples[i+1] <- sample_tau_one_iteration( forest_samples, rng, a_leaf, b_leaf, i-1 ) leaf_prior_scale[1,1] <- leaf_scale_samples[i+1] } # Forest predictions preds <- forest_samples$predict(forest_dataset)*y_std + y_bar # Global error variance sigma_samples <- sqrt(global_var_samples)*y_std"},{"path":"https://stochastictree.github.io/stochtree-r/articles/CustomSamplingRoutine.html","id":"results","dir":"Articles","previous_headings":"Demo 1: Supervised Learning","what":"Results","title":"Custom Sampling Routines in StochTree","text":"Inspect initial samples obtained via “grow--root” (Hahn (2023)) Inspect BART samples obtained “warm-starting”","code":"plot(sigma_samples[1:num_warmstart], ylab=\"sigma\") plot(rowMeans(preds[,1:num_warmstart]), y, pch=16, cex=0.75, xlab = \"pred\", ylab = \"actual\") abline(0,1,col=\"red\",lty=2,lwd=2.5) plot(sigma_samples[(num_warmstart+1):num_samples], ylab=\"sigma\") plot(rowMeans(preds[,(num_warmstart+1):num_samples]), y, pch=16, cex=0.75, xlab = \"pred\", ylab = \"actual\") abline(0,1,col=\"red\",lty=2,lwd=2.5)"},{"path":"https://stochastictree.github.io/stochtree-r/articles/CustomSamplingRoutine.html","id":"demo-2-supervised-learning-with-additive-random-effects","dir":"Articles","previous_headings":"","what":"Demo 2: Supervised Learning with Additive Random Effects","title":"Custom Sampling Routines in StochTree","text":"build example add simple “random effects” structure: every observation either group 1 group 2 random group intercept (simulated quite strong, underscoring need random effects modeling).","code":""},{"path":"https://stochastictree.github.io/stochtree-r/articles/CustomSamplingRoutine.html","id":"simulation-1","dir":"Articles","previous_headings":"Demo 2: Supervised Learning with Additive Random Effects","what":"Simulation","title":"Custom Sampling Routines in StochTree","text":"Simulate partitioned linear model simple additive group random effect structure","code":"# Generate the data n <- 500 p_X <- 10 p_W <- 1 X <- matrix(runif(n*p_X), ncol = p_X) W <- matrix(runif(n*p_W), ncol = p_W) group_ids <- rep(c(1,2), n %/% 2) rfx_coefs <- c(-5, 5) rfx_basis <- rep(1, n) f_XW <- ( ((0 <= X[,1]) & (0.25 > X[,1])) * (-3*W[,1]) + ((0.25 <= X[,1]) & (0.5 > X[,1])) * (-1*W[,1]) + ((0.5 <= X[,1]) & (0.75 > X[,1])) * (1*W[,1]) + ((0.75 <= X[,1]) & (1 > X[,1])) * (3*W[,1]) ) rfx_term <- rfx_coefs[group_ids] * rfx_basis y <- f_XW + rfx_term + rnorm(n, 0, 1) # Standardize outcome y_bar <- mean(y) y_std <- sd(y) resid <- (y-y_bar)/y_std"},{"path":"https://stochastictree.github.io/stochtree-r/articles/CustomSamplingRoutine.html","id":"sampling-1","dir":"Articles","previous_headings":"Demo 2: Supervised Learning with Additive Random Effects","what":"Sampling","title":"Custom Sampling Routines in StochTree","text":"Set parameters inform forest variance parameter samplers Set parameters inform random effects samplers Initialize R-level access C++ classes needed sample model Prepare run sampler Run grow--root sampler “warm-start” BART Pick last GFR forest (associated global variance / leaf scale parameters) MCMC sampler Predict rescale samples","code":"alpha <- 0.9 beta <- 1.25 min_samples_leaf <- 1 num_trees <- 100 cutpoint_grid_size = 100 global_variance_init = 1. tau_init = 0.5 leaf_prior_scale = matrix(c(tau_init), ncol = 1) nu <- 4 lambda <- 0.5 a_leaf <- 2. b_leaf <- 0.5 leaf_regression <- T feature_types <- as.integer(rep(0, p_X)) # 0 = numeric var_weights <- rep(1/p_X, p_X) alpha_init <- c(1) xi_init <- matrix(c(1,1),1,2) sigma_alpha_init <- matrix(c(1),1,1) sigma_xi_init <- matrix(c(1),1,1) sigma_xi_shape <- 1 sigma_xi_scale <- 1 # Data if (leaf_regression) { forest_dataset <- createForestDataset(X, W) outcome_model_type <- 1 } else { forest_dataset <- createForestDataset(X) outcome_model_type <- 0 } outcome <- createOutcome(resid) # Random number generator (std::mt19937) rng <- createRNG() # Sampling data structures forest_model <- createForestModel(forest_dataset, feature_types, num_trees, n, alpha, beta, min_samples_leaf) # Container of forest samples if (leaf_regression) { forest_samples <- createForestContainer(num_trees, 1, F) } else { forest_samples <- createForestContainer(num_trees, 1, T) } # Random effects dataset rfx_basis <- as.matrix(rfx_basis) group_ids <- as.integer(group_ids) rfx_dataset <- createRandomEffectsDataset(group_ids, rfx_basis) # Random effects details num_groups <- length(unique(group_ids)) num_components <- ncol(rfx_basis) # Random effects tracker rfx_tracker <- createRandomEffectsTracker(group_ids) # Random effects model rfx_model <- createRandomEffectsModel(num_components, num_groups) rfx_model$set_working_parameter(alpha_init) rfx_model$set_group_parameters(xi_init) rfx_model$set_working_parameter_cov(sigma_alpha_init) rfx_model$set_group_parameter_cov(sigma_xi_init) rfx_model$set_variance_prior_shape(sigma_xi_shape) rfx_model$set_variance_prior_scale(sigma_xi_scale) # Random effect samples rfx_samples <- createRandomEffectSamples(num_components, num_groups, rfx_tracker) num_warmstart <- 10 num_mcmc <- 100 num_samples <- num_warmstart + num_mcmc global_var_samples <- c(global_variance_init, rep(0, num_samples)) leaf_scale_samples <- c(tau_init, rep(0, num_samples)) for (i in 1:num_warmstart) { # Sample forest forest_model$sample_one_iteration( forest_dataset, outcome, forest_samples, rng, feature_types, outcome_model_type, leaf_prior_scale, var_weights, global_var_samples[i], cutpoint_grid_size, gfr = T ) # Sample global variance parameter global_var_samples[i+1] <- sample_sigma2_one_iteration( outcome, rng, nu, lambda ) # Sample leaf node variance parameter and update `leaf_prior_scale` leaf_scale_samples[i+1] <- sample_tau_one_iteration( forest_samples, rng, a_leaf, b_leaf, i-1 ) leaf_prior_scale[1,1] <- leaf_scale_samples[i+1] # Sample random effects model rfx_model$sample_random_effect(rfx_dataset, outcome, rfx_tracker, rfx_samples, global_var_samples[i+1], rng) } for (i in (num_warmstart+1):num_samples) { # Sample forest forest_model$sample_one_iteration( forest_dataset, outcome, forest_samples, rng, feature_types, outcome_model_type, leaf_prior_scale, var_weights, global_var_samples[i], cutpoint_grid_size, gfr = F ) # Sample global variance parameter global_var_samples[i+1] <- sample_sigma2_one_iteration( outcome, rng, nu, lambda ) # Sample leaf node variance parameter and update `leaf_prior_scale` leaf_scale_samples[i+1] <- sample_tau_one_iteration( forest_samples, rng, a_leaf, b_leaf, i-1 ) leaf_prior_scale[1,1] <- leaf_scale_samples[i+1] # Sample random effects model rfx_model$sample_random_effect(rfx_dataset, outcome, rfx_tracker, rfx_samples, global_var_samples[i+1], rng) } # Forest predictions forest_preds <- forest_samples$predict(forest_dataset)*y_std + y_bar # Random effects predictions rfx_preds <- rfx_samples$predict(group_ids, rfx_basis)*y_std # Overall predictions preds <- forest_preds + rfx_preds # Global error variance sigma_samples <- sqrt(global_var_samples)*y_std"},{"path":"https://stochastictree.github.io/stochtree-r/articles/CustomSamplingRoutine.html","id":"results-1","dir":"Articles","previous_headings":"Demo 2: Supervised Learning with Additive Random Effects","what":"Results","title":"Custom Sampling Routines in StochTree","text":"Inspect initial samples obtained via grow--root additive random effects model Inspect BART samples obtained “warm-starting” plus additive random effects model Now inspect samples BART forest alone (without considering random effect predictions)","code":"plot(sigma_samples[1:num_warmstart], ylab=\"sigma\") plot(rowMeans(preds[,1:num_warmstart]), y, pch=16, cex=0.75, xlab = \"pred\", ylab = \"actual\") abline(0,1,col=\"red\",lty=2,lwd=2.5) plot(sigma_samples[(num_warmstart+1):num_samples], ylab=\"sigma\") plot(rowMeans(preds[,(num_warmstart+1):num_samples]), y, pch=16, cex=0.75, xlab = \"pred\", ylab = \"actual\") abline(0,1,col=\"red\",lty=2,lwd=2.5) plot(rowMeans(forest_preds[,(num_warmstart+1):num_samples]), y, pch=16, cex=0.75, xlab = \"pred\", ylab = \"actual\") abline(0,1,col=\"red\",lty=2,lwd=2.5)"},{"path":"https://stochastictree.github.io/stochtree-r/articles/CustomSamplingRoutine.html","id":"demo-3-supervised-learning-with-additive-multi-component-random-effects","dir":"Articles","previous_headings":"","what":"Demo 3: Supervised Learning with Additive Multi-Component Random Effects","title":"Custom Sampling Routines in StochTree","text":"build example, case allowing random intercept regression coefficient (pre-specified basis) group (1 2).","code":""},{"path":"https://stochastictree.github.io/stochtree-r/articles/CustomSamplingRoutine.html","id":"simulation-2","dir":"Articles","previous_headings":"Demo 3: Supervised Learning with Additive Multi-Component Random Effects","what":"Simulation","title":"Custom Sampling Routines in StochTree","text":"Simulate partitioned linear model simple additive group random effect structure","code":"# Generate the data n <- 500 p_X <- 10 p_W <- 1 X <- matrix(runif(n*p_X), ncol = p_X) W <- matrix(runif(n*p_W), ncol = p_W) group_ids <- rep(c(1,2), n %/% 2) rfx_coefs <- matrix(c(-5, -3, 5, 3),nrow=2,byrow=T) rfx_basis <- cbind(1, runif(n, -1, 1)) f_XW <- ( ((0 <= X[,1]) & (0.25 > X[,1])) * (-3*W[,1]) + ((0.25 <= X[,1]) & (0.5 > X[,1])) * (-1*W[,1]) + ((0.5 <= X[,1]) & (0.75 > X[,1])) * (1*W[,1]) + ((0.75 <= X[,1]) & (1 > X[,1])) * (3*W[,1]) ) rfx_term <- rowSums(rfx_coefs[group_ids,] * rfx_basis) y <- f_XW + rfx_term + rnorm(n, 0, 1) # Standardize outcome y_bar <- mean(y) y_std <- sd(y) resid <- (y-y_bar)/y_std"},{"path":"https://stochastictree.github.io/stochtree-r/articles/CustomSamplingRoutine.html","id":"sampling-2","dir":"Articles","previous_headings":"Demo 3: Supervised Learning with Additive Multi-Component Random Effects","what":"Sampling","title":"Custom Sampling Routines in StochTree","text":"Set parameters inform forest variance parameter samplers Set parameters inform random effects samplers Initialize R-level access C++ classes needed sample model Prepare run sampler Run grow--root sampler “warm-start” BART Pick last GFR forest (associated global variance / leaf scale parameters) MCMC sampler Predict rescale samples","code":"alpha <- 0.9 beta <- 1.25 min_samples_leaf <- 1 num_trees <- 100 cutpoint_grid_size = 100 global_variance_init = 1. tau_init = 0.5 leaf_prior_scale = matrix(c(tau_init), ncol = 1) nu <- 4 lambda <- 0.5 a_leaf <- 2. b_leaf <- 0.5 leaf_regression <- T feature_types <- as.integer(rep(0, p_X)) # 0 = numeric var_weights <- rep(1/p_X, p_X) alpha_init <- c(1,0) xi_init <- matrix(c(1,0,1,0),2,2) sigma_alpha_init <- diag(1,2,2) sigma_xi_init <- diag(1,2,2) sigma_xi_shape <- 1 sigma_xi_scale <- 1 # Data if (leaf_regression) { forest_dataset <- createForestDataset(X, W) outcome_model_type <- 1 } else { forest_dataset <- createForestDataset(X) outcome_model_type <- 0 } outcome <- createOutcome(resid) # Random number generator (std::mt19937) rng <- createRNG() # Sampling data structures forest_model <- createForestModel(forest_dataset, feature_types, num_trees, n, alpha, beta, min_samples_leaf) # Container of forest samples if (leaf_regression) { forest_samples <- createForestContainer(num_trees, 1, F) } else { forest_samples <- createForestContainer(num_trees, 1, T) } # Random effects dataset rfx_basis <- as.matrix(rfx_basis) group_ids <- as.integer(group_ids) rfx_dataset <- createRandomEffectsDataset(group_ids, rfx_basis) # Random effects details num_groups <- length(unique(group_ids)) num_components <- ncol(rfx_basis) # Random effects tracker rfx_tracker <- createRandomEffectsTracker(group_ids) # Random effects model rfx_model <- createRandomEffectsModel(num_components, num_groups) rfx_model$set_working_parameter(alpha_init) rfx_model$set_group_parameters(xi_init) rfx_model$set_working_parameter_cov(sigma_alpha_init) rfx_model$set_group_parameter_cov(sigma_xi_init) rfx_model$set_variance_prior_shape(sigma_xi_shape) rfx_model$set_variance_prior_scale(sigma_xi_scale) # Random effect samples rfx_samples <- createRandomEffectSamples(num_components, num_groups, rfx_tracker) num_warmstart <- 10 num_mcmc <- 100 num_samples <- num_warmstart + num_mcmc global_var_samples <- c(global_variance_init, rep(0, num_samples)) leaf_scale_samples <- c(tau_init, rep(0, num_samples)) for (i in 1:num_warmstart) { # Sample forest forest_model$sample_one_iteration( forest_dataset, outcome, forest_samples, rng, feature_types, outcome_model_type, leaf_prior_scale, var_weights, global_var_samples[i], cutpoint_grid_size, gfr = T ) # Sample global variance parameter global_var_samples[i+1] <- sample_sigma2_one_iteration( outcome, rng, nu, lambda ) # Sample leaf node variance parameter and update `leaf_prior_scale` leaf_scale_samples[i+1] <- sample_tau_one_iteration( forest_samples, rng, a_leaf, b_leaf, i-1 ) leaf_prior_scale[1,1] <- leaf_scale_samples[i+1] # Sample random effects model rfx_model$sample_random_effect(rfx_dataset, outcome, rfx_tracker, rfx_samples, global_var_samples[i+1], rng) } for (i in (num_warmstart+1):num_samples) { # Sample forest forest_model$sample_one_iteration( forest_dataset, outcome, forest_samples, rng, feature_types, outcome_model_type, leaf_prior_scale, var_weights, global_var_samples[i], cutpoint_grid_size, gfr = F ) # Sample global variance parameter global_var_samples[i+1] <- sample_sigma2_one_iteration( outcome, rng, nu, lambda ) # Sample leaf node variance parameter and update `leaf_prior_scale` leaf_scale_samples[i+1] <- sample_tau_one_iteration( forest_samples, rng, a_leaf, b_leaf, i-1 ) leaf_prior_scale[1,1] <- leaf_scale_samples[i+1] # Sample random effects model rfx_model$sample_random_effect(rfx_dataset, outcome, rfx_tracker, rfx_samples, global_var_samples[i+1], rng) } # Forest predictions forest_preds <- forest_samples$predict(forest_dataset)*y_std + y_bar # Random effects predictions rfx_preds <- rfx_samples$predict(group_ids, rfx_basis)*y_std # Overall predictions preds <- forest_preds + rfx_preds # Global error variance sigma_samples <- sqrt(global_var_samples)*y_std"},{"path":"https://stochastictree.github.io/stochtree-r/articles/CustomSamplingRoutine.html","id":"results-2","dir":"Articles","previous_headings":"Demo 3: Supervised Learning with Additive Multi-Component Random Effects","what":"Results","title":"Custom Sampling Routines in StochTree","text":"Inspect initial samples obtained via grow--root additive random effects model Inspect BART samples obtained “warm-starting” plus additive random effects model Now inspect samples BART forest alone (without considering random effect predictions)","code":"plot(sigma_samples[1:num_warmstart], ylab=\"sigma\") plot(rowMeans(preds[,1:num_warmstart]), y, pch=16, cex=0.75, xlab = \"pred\", ylab = \"actual\") abline(0,1,col=\"red\",lty=2,lwd=2.5) plot(sigma_samples[(num_warmstart+1):num_samples], ylab=\"sigma\") plot(rowMeans(preds[,(num_warmstart+1):num_samples]), y, pch=16, cex=0.75, xlab = \"pred\", ylab = \"actual\") abline(0,1,col=\"red\",lty=2,lwd=2.5) plot(rowMeans(forest_preds[,(num_warmstart+1):num_samples]), y, pch=16, cex=0.75, xlab = \"pred\", ylab = \"actual\") abline(0,1,col=\"red\",lty=2,lwd=2.5)"},{"path":"https://stochastictree.github.io/stochtree-r/articles/CustomSamplingRoutine.html","id":"demo-4-causal-inference","dir":"Articles","previous_headings":"","what":"Demo 4: Causal Inference","title":"Custom Sampling Routines in StochTree","text":"show implement Bayesian Causal Forest (BCF) model Hahn, Murray, Carvalho (2020) using stochtree’s prototype API, including demoing non-trivial sampling step done R level.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/articles/CustomSamplingRoutine.html","id":"background","dir":"Articles","previous_headings":"Demo 4: Causal Inference","what":"Background","title":"Custom Sampling Routines in StochTree","text":"supervised learning case previous demo conceptually simple, motivate causal effect estimation task additional notation. Let \\(y\\) refer continuous outcome interest, \\(Z\\) refer binary treatment, \\(X\\) set covariates may influence \\(Y\\), \\(Z\\), . \\(X\\) exhaustive set covariates influence \\(Z\\) \\(Y\\), can specific \\(Y\\) terms causal model (see example Pearl (2009)) \\[\\begin{equation*} \\begin{aligned} Y &= F(Z, X, \\epsilon_Y) \\end{aligned} \\end{equation*}\\] \\(\\epsilon_Y\\) outcome specific random noise \\(F\\) function generates \\(Y\\) (many cases, \\(F\\) can thought inverse CDF conditional \\(X\\) \\(Z\\)). “potential outcomes” (see Imbens Rubin (2015)) can recovered \\(Y^1 = F(1, X, \\epsilon_Y)\\) \\(Y^0 = F(0, X, \\epsilon_Y)\\). causal outcome model can decomposed “mean” “error” terms \\[\\begin{equation*} \\begin{aligned} Y &= \\mu(X) + Z\\tau(X) + \\left[\\eta(X) + Z\\delta(X)\\right]\\\\ \\mu(X) &= \\mathbb{E}_{\\epsilon_Y}\\left[F(0, X, \\epsilon_Y)\\right]\\\\ \\tau(X) &= \\mathbb{E}_{\\epsilon_Y}\\left[F(1, X, \\epsilon_Y) - F(0, X, \\epsilon_Y)\\right]\\\\ \\eta(X) &= F(0, X, \\epsilon_Y) - \\mathbb{E}_{\\epsilon_Y}\\left[F(0, X, \\epsilon_Y)\\right]\\\\ \\delta(X) &= F(1, X, \\epsilon_Y) - F(0, X, \\epsilon_Y) - \\mathbb{E}_{\\epsilon_Y}\\left[F(1, X, \\epsilon_Y) - F(0, X, \\epsilon_Y)\\right] \\end{aligned} \\end{equation*}\\] \\(\\tau(X)\\) precisely conditional average treatment effect (CATE) estimand. Unfortunately, functional form \\(F\\) unavailable analysis, \\(\\tau(X)\\) derived. flexible, regularized nonparametrics enter picture, aim estimate \\(\\mu(X)\\) \\(\\tau(X)\\) data.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/articles/CustomSamplingRoutine.html","id":"bayesian-causal-forest-bcf","dir":"Articles","previous_headings":"Demo 4: Causal Inference > Background","what":"Bayesian Causal Forest (BCF)","title":"Custom Sampling Routines in StochTree","text":"BCF estimates \\(\\mu(X)\\) \\(\\tau(X)\\) using separate BART forests term. Furthermore, rather rely common implicit coding \\(Z\\) 0 control observations 1 treated observations, consider coding control observations parameter \\(b_0\\) treated observations parameter \\(b_1\\). Placing \\(N(0,1/2)\\) prior \\(b_z\\), essentially redefines outcome model \\[\\begin{equation*} \\begin{aligned} y &= \\mu(X) + \\tau(X) f(Z) + \\epsilon\\\\ f(Z) &= b_0(1-Z) + b_1 Z\\\\ \\epsilon &\\sim N\\left(0, \\sigma^2\\right)\\\\ b_0, b_1 &\\sim N\\left(0, 1/2\\right) \\end{aligned} \\end{equation*}\\] Updating \\(b_z\\) requires additional Gibbs step, derive . Conditioning sampled forests \\(\\mu\\) \\(\\tau\\), essentially regressing \\(y - \\mu(Z)\\) \\(\\left[(1-Z)\\tau(X), Z\\tau(X)\\right]\\) closed form posterior \\[\\begin{equation*} \\begin{aligned} b_0 \\mid y, X, \\mu,\\tau &\\sim N\\left(\\frac{s_{y\\tau,0}}{s_{\\tau\\tau,0} + 2\\sigma^2}, \\frac{\\sigma^2}{s_{\\tau\\tau,0} + 2\\sigma^2}\\right)\\\\ b_1 \\mid y, X, \\mu,\\tau &\\sim N\\left(\\frac{s_{y\\tau,1}}{s_{\\tau\\tau,1} + 2\\sigma^2}, \\frac{\\sigma^2}{s_{\\tau\\tau,1} + 2\\sigma^2}\\right) \\end{aligned} \\end{equation*}\\] \\(s_{y\\tau,z} = \\sum_{: Z_i = z} (y_i - \\mu(X_i))\\tau(X_i)\\) \\(s_{\\tau\\tau,z} = \\sum_{: Z_i = z} \\tau(X_i)\\tau(X_i)\\).","code":""},{"path":"https://stochastictree.github.io/stochtree-r/articles/CustomSamplingRoutine.html","id":"simulation-3","dir":"Articles","previous_headings":"Demo 4: Causal Inference","what":"Simulation","title":"Custom Sampling Routines in StochTree","text":"simulated causal DGP mirrors nonlinear, heterogeneous treatment effect DGP presented Hahn, Murray, Carvalho (2020).","code":"n <- 500 x1 <- rnorm(n) x2 <- rnorm(n) x3 <- rnorm(n) x4 <- as.numeric(rbinom(n,1,0.5)) x5 <- as.numeric(sample(1:3,n,replace=T)) X <- cbind(x1,x2,x3,x4,x5) p <- ncol(X) g <- function(x) {ifelse(x[,5]==1,2,ifelse(x[,5]==2,-1,4))} mu1 <- function(x) {1+g(x)+x[,1]*x[,3]} mu2 <- function(x) {1+g(x)+6*abs(x[,3]-1)} tau1 <- function(x) {rep(3,nrow(x))} tau2 <- function(x) {1+2*x[,2]*x[,4]} mu_x <- mu1(X) tau_x <- tau2(X) pi_x <- 0.8*pnorm((3*mu_x/sd(mu_x)) - 0.5*X[,1]) + 0.05 + runif(n)/10 Z <- rbinom(n,1,pi_x) E_XZ <- mu_x + Z*tau_x snr <- 4 y <- E_XZ + rnorm(n, 0, 1)*(sd(E_XZ)/snr) # Standardize outcome y_bar <- mean(y) y_std <- sd(y) resid <- (y-y_bar)/y_std"},{"path":"https://stochastictree.github.io/stochtree-r/articles/CustomSamplingRoutine.html","id":"sampling-3","dir":"Articles","previous_headings":"Demo 4: Causal Inference","what":"Sampling","title":"Custom Sampling Routines in StochTree","text":"Set parameters inform forest variance parameter samplers Prepare run sampler (now must specify initial values \\(b_0\\) \\(b_1\\), choose -1/2 1/2 instead 0 1). Initialize R-level access C++ classes needed sample model Run grow--root sampler “warm-start” BART, also updating adaptive coding parameter \\(b_0\\) \\(b_1\\) Pick last GFR forest (associated global variance / leaf scale parameters) MCMC sampler Predict rescale samples","code":"# Mu forest alpha_mu <- 0.95 beta_mu <- 2.0 min_samples_leaf_mu <- 5 num_trees_mu <- 250 cutpoint_grid_size_mu = 100 tau_init_mu = 1/num_trees_mu leaf_prior_scale_mu = matrix(c(tau_init_mu), ncol = 1) a_leaf_mu <- 3. b_leaf_mu <- var(resid)/(num_trees_mu) leaf_regression_mu <- F sigma_leaf_mu <- var(resid)/(num_trees_mu) current_leaf_scale_mu <- as.matrix(sigma_leaf_mu) # Tau forest alpha_tau <- 0.25 beta_tau <- 3.0 min_samples_leaf_tau <- 5 num_trees_tau <- 50 cutpoint_grid_size_tau = 100 a_leaf_tau <- 3. b_leaf_tau <- var(resid)/(2*num_trees_tau) leaf_regression_tau <- T sigma_leaf_tau <- var(resid)/(2*num_trees_tau) current_leaf_scale_tau <- as.matrix(sigma_leaf_tau) # Common parameters nu <- 3 sigma2hat <- (sigma(lm(resid~X)))^2 quantile_cutoff <- 0.9 if (is.null(lambda)) { lambda <- (sigma2hat*qgamma(1-quantile_cutoff,nu))/nu } sigma2 <- sigma2hat current_sigma2 <- sigma2 # Sampling composition num_gfr <- 20 num_burnin <- 0 num_mcmc <- 100 num_samples <- num_gfr + num_burnin + num_mcmc # Sigma^2 samples global_var_samples <- rep(0, num_samples) # Adaptive coding parameter samples b_0_samples <- rep(0, num_samples) b_1_samples <- rep(0, num_samples) b_0 <- -0.5 b_1 <- 0.5 current_b_0 <- b_0 current_b_1 <- b_1 tau_basis <- (1-Z)*current_b_0 + Z*current_b_1 # Data X_mu <- cbind(X, pi_x) X_tau <- X feature_types <- c(0,0,0,1,1) feature_types_mu <- as.integer(c(feature_types,0)) feature_types_tau <- as.integer(feature_types) variable_weights_mu = rep(1/ncol(X_mu), ncol(X_mu)) variable_weights_tau = rep(1/ncol(X_tau), ncol(X_tau)) forest_dataset_mu <- createForestDataset(X_mu) forest_dataset_tau <- createForestDataset(X_tau, tau_basis) outcome <- createOutcome(resid) # Random number generator (std::mt19937) rng <- createRNG() # Sampling data structures forest_model_mu <- createForestModel( forest_dataset_mu, feature_types_mu, num_trees_mu, nrow(X_mu), alpha_mu, beta_mu, min_samples_leaf_mu ) forest_model_tau <- createForestModel( forest_dataset_tau, feature_types_tau, num_trees_tau, nrow(X_tau), alpha_tau, beta_tau, min_samples_leaf_tau ) # Container of forest samples forest_samples_mu <- createForestContainer(num_trees_mu, 1, T) forest_samples_tau <- createForestContainer(num_trees_tau, 1, F) # Initialize the leaves of each tree in the prognostic forest forest_samples_mu$set_root_leaves(0, mean(resid) / num_trees_mu) forest_samples_mu$update_residual( forest_dataset_mu, outcome, forest_model_mu, F, 0, F ) # Initialize the leaves of each tree in the treatment effect forest forest_samples_tau$set_root_leaves(0, 0.) forest_samples_tau$update_residual( forest_dataset_tau, outcome, forest_model_tau, T, 0, F ) if (num_gfr > 0){ for (i in 1:num_gfr) { # Sample the prognostic forest forest_model_mu$sample_one_iteration( forest_dataset_mu, outcome, forest_samples_mu, rng, feature_types_mu, 0, current_leaf_scale_mu, variable_weights_mu, current_sigma2, cutpoint_grid_size, gfr = T, pre_initialized = T ) # Sample variance parameters (if requested) global_var_samples[i] <- sample_sigma2_one_iteration( outcome, rng, nu, lambda ) current_sigma2 <- global_var_samples[i] # Sample the treatment forest forest_model_tau$sample_one_iteration( forest_dataset_tau, outcome, forest_samples_tau, rng, feature_types_tau, 1, current_leaf_scale_tau, variable_weights_tau, current_sigma2, cutpoint_grid_size, gfr = T, pre_initialized = T ) # Sample adaptive coding parameters mu_x_raw <- forest_samples_mu$predict_raw_single_forest(forest_dataset_mu, i-1) tau_x_raw <- forest_samples_tau$predict_raw_single_forest(forest_dataset_tau, i-1) s_tt0 <- sum(tau_x_raw*tau_x_raw*(Z==0)) s_tt1 <- sum(tau_x_raw*tau_x_raw*(Z==1)) partial_resid_mu <- resid - mu_x_raw s_ty0 <- sum(tau_x_raw*partial_resid_mu*(Z==0)) s_ty1 <- sum(tau_x_raw*partial_resid_mu*(Z==1)) current_b_0 <- rnorm(1, (s_ty0/(s_tt0 + 2*current_sigma2)), sqrt(current_sigma2/(s_tt0 + 2*current_sigma2))) current_b_1 <- rnorm(1, (s_ty1/(s_tt1 + 2*current_sigma2)), sqrt(current_sigma2/(s_tt1 + 2*current_sigma2))) tau_basis <- (1-Z)*current_b_0 + Z*current_b_1 forest_dataset_tau$update_basis(tau_basis) b_0_samples[i] <- current_b_0 b_1_samples[i] <- current_b_1 # Sample variance parameters (if requested) global_var_samples[i] <- sample_sigma2_one_iteration(outcome, rng, nu, lambda) current_sigma2 <- global_var_samples[i] } } if (num_burnin + num_mcmc > 0) { for (i in (num_gfr+1):num_samples) { # Sample the prognostic forest forest_model_mu$sample_one_iteration( forest_dataset_mu, outcome, forest_samples_mu, rng, feature_types_mu, 0, current_leaf_scale_mu, variable_weights_mu, current_sigma2, cutpoint_grid_size, gfr = F, pre_initialized = T ) # Sample global variance parameter global_var_samples[i] <- sample_sigma2_one_iteration(outcome, rng, nu, lambda) current_sigma2 <- global_var_samples[i] # Sample the treatment forest forest_model_tau$sample_one_iteration( forest_dataset_tau, outcome, forest_samples_tau, rng, feature_types_tau, 1, current_leaf_scale_tau, variable_weights_tau, current_sigma2, cutpoint_grid_size, gfr = F, pre_initialized = T ) # Sample coding parameters mu_x_raw <- forest_samples_mu$predict_raw_single_forest(forest_dataset_mu, i-1) tau_x_raw <- forest_samples_tau$predict_raw_single_forest(forest_dataset_tau, i-1) s_tt0 <- sum(tau_x_raw*tau_x_raw*(Z==0)) s_tt1 <- sum(tau_x_raw*tau_x_raw*(Z==1)) partial_resid_mu <- resid - mu_x_raw s_ty0 <- sum(tau_x_raw*partial_resid_mu*(Z==0)) s_ty1 <- sum(tau_x_raw*partial_resid_mu*(Z==1)) current_b_0 <- rnorm(1, (s_ty0/(s_tt0 + 2*current_sigma2)), sqrt(current_sigma2/(s_tt0 + 2*current_sigma2))) current_b_1 <- rnorm(1, (s_ty1/(s_tt1 + 2*current_sigma2)), sqrt(current_sigma2/(s_tt1 + 2*current_sigma2))) tau_basis <- (1-Z)*current_b_0 + Z*current_b_1 forest_dataset_tau$update_basis(tau_basis) b_0_samples[i] <- current_b_0 b_1_samples[i] <- current_b_1 # Sample global variance parameter global_var_samples[i] <- sample_sigma2_one_iteration(outcome, rng, nu, lambda) current_sigma2 <- global_var_samples[i] } } # Forest predictions mu_hat <- forest_samples_mu$predict(forest_dataset_mu)*y_std + y_bar tau_hat_raw <- forest_samples_tau$predict_raw(forest_dataset_tau) tau_hat <- t(t(tau_hat_raw) * (b_1_samples - b_0_samples))*y_std y_hat <- mu_hat + tau_hat * as.numeric(Z) # Global error variance sigma2_samples <- global_var_samples*(y_std^2)"},{"path":"https://stochastictree.github.io/stochtree-r/articles/CustomSamplingRoutine.html","id":"results-3","dir":"Articles","previous_headings":"Demo 4: Causal Inference","what":"Results","title":"Custom Sampling Routines in StochTree","text":"Inspect XBART results Inspect warm start BART results Inspect “adaptive coding” parameters \\(b_0\\) \\(b_1\\).","code":"plot(sigma2_samples[1:num_gfr], ylab=\"sigma^2\") plot(rowMeans(mu_hat[,1:num_gfr]), mu_x, pch=16, cex=0.75, xlab = \"pred\", ylab = \"actual\", main = \"prognostic term\") abline(0,1,col=\"red\",lty=2,lwd=2.5) plot(rowMeans(tau_hat[,1:num_gfr]), tau_x, pch=16, cex=0.75, xlab = \"pred\", ylab = \"actual\", main = \"treatment effect term\") abline(0,1,col=\"red\",lty=2,lwd=2.5) mean((rowMeans(tau_hat[,1:num_gfr]) - tau_x)^2) #> [1] 0.3495556 plot(sigma_samples[(num_gfr+1):num_samples], ylab=\"sigma^2\") plot(rowMeans(mu_hat[,(num_gfr+1):num_samples]), mu_x, pch=16, cex=0.75, xlab = \"pred\", ylab = \"actual\", main = \"prognostic term\") abline(0,1,col=\"red\",lty=2,lwd=2.5) plot(rowMeans(tau_hat[,(num_gfr+1):num_samples]), tau_x, pch=16, cex=0.75, xlab = \"pred\", ylab = \"actual\", main = \"treatment effect term\") abline(0,1,col=\"red\",lty=2,lwd=2.5) mean((rowMeans(tau_hat[,(num_gfr+1):num_samples]) - tau_x)^2) #> [1] 0.4305235 plot(b_0_samples, col = \"blue\", ylab = \"Coding parameter draws\", ylim = c(min(min(b_0_samples), min(b_1_samples)), max(max(b_0_samples), max(b_1_samples)))) points(b_1_samples, col = \"orange\") legend(\"topleft\", legend = c(\"b_0\", \"b_1\"), col = c(\"blue\", \"orange\"), pch = c(1,1))"},{"path":[]},{"path":"https://stochastictree.github.io/stochtree-r/articles/EnsembleKernel.html","id":"motivation","dir":"Articles","previous_headings":"","what":"Motivation","title":"Kernel Methods from Tree Ensembles in StochTree","text":"trained tree ensemble strong --sample performance admits natural motivation “distance” two samples: shared leaf membership. number leaves ensemble 1 \\(s\\) (, tree 1 3 leaves, reserves numbers 1 - 3, turn tree 2 5 leaves, reserves numbers 4 - 8 label leaves, ). dataset \\(n\\) observations, construct matrix \\(W\\) follows:    Initialize \\(W\\) matrix zeroes \\(n\\) rows many columns leaves ensemble    Let s = 0    \\(j\\) \\(\\left\\{1,\\dots,m\\right\\}\\):       Let num_leaves number leaves tree \\(j\\)       \\(\\) \\(\\left\\{1,\\dots,n\\right\\}\\):          Let k leaf tree \\(j\\) maps observation \\(\\)          Set element \\(W_{,k+s} = 1\\)       Let s = s + num_leaves sparse matrix \\(W\\) matrix representation basis predictions ensemble (.e. integrating leaf parameters just analyzing leaf indices). ensemble \\(m\\) trees, can determine proportion trees map observation leaf computing \\(W W^T / m\\). can form basis kernel function used Gaussian process regression, demonstrate . begin, load stochtree package tgp package serve point reference.","code":"library(stochtree) library(tgp) library(MASS) library(mvtnorm)"},{"path":"https://stochastictree.github.io/stochtree-r/articles/EnsembleKernel.html","id":"demo-1-univariate-supervised-learning","dir":"Articles","previous_headings":"","what":"Demo 1: Univariate Supervised Learning","title":"Kernel Methods from Tree Ensembles in StochTree","text":"begin simulated example tgp package (Gramacy Taddy (2010)). data generating process (DGP) non-stationary single numeric covariate. define training set test set evaluate various approaches modeling sample outcome data.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/articles/EnsembleKernel.html","id":"traditional-gaussian-process","dir":"Articles","previous_headings":"Demo 1: Univariate Supervised Learning","what":"Traditional Gaussian Process","title":"Kernel Methods from Tree Ensembles in StochTree","text":"can use tgp package model data classical Gaussian Process. Assess RMSE","code":"# Generate the data X_train <- seq(0,20,length=100) X_test <- seq(0,20,length=99) y_train <- (sin(pi*X_train/5) + 0.2*cos(4*pi*X_train/5)) * (X_train <= 9.6) lin_train <- X_train>9.6; y_train[lin_train] <- -1 + X_train[lin_train]/10 y_train <- y_train + rnorm(length(y_train), sd=0.1) y_test <- (sin(pi*X_test/5) + 0.2*cos(4*pi*X_test/5)) * (X_test <= 9.6) lin_test <- X_test>9.6; y_test[lin_test] <- -1 + X_test[lin_test]/10 # Fit the GP model_gp <- bgp(X=X_train, Z=y_train, XX=X_test) plot(model_gp$ZZ.mean, y_test, xlab = \"predicted\", ylab = \"actual\", main = \"Gaussian process\") abline(0,1,lwd=2.5,lty=3,col=\"red\") sqrt(mean((model_gp$ZZ.mean - y_test)^2)) sqrt(mean((model_gp$ZZ.mean - y_test)^2)) #> [1] 0.0466081"},{"path":"https://stochastictree.github.io/stochtree-r/articles/EnsembleKernel.html","id":"bart-based-gaussian-process","dir":"Articles","previous_headings":"Demo 1: Univariate Supervised Learning","what":"BART-based Gaussian process","title":"Kernel Methods from Tree Ensembles in StochTree","text":"Assess RMSE","code":"# Run BART on the data num_trees <- 200 sigma_leaf <- 1/num_trees bart_model <- bart(X_train=X_train, y_train=y_train, X_test=X_test, num_trees=num_trees) # Extract kernels needed for kriging result_kernels <- computeForestKernels(bart_model=bart_model, X_train=X_train, X_test=X_test) Sigma_11 <- result_kernels$kernel_test Sigma_12 <- result_kernels$kernel_test_train Sigma_22 <- result_kernels$kernel_train Sigma_22_inv <- ginv(Sigma_22) Sigma_21 <- t(Sigma_12) # Compute mean and covariance for the test set posterior mu_tilde <- Sigma_12 %*% Sigma_22_inv %*% y_train Sigma_tilde <- (sigma_leaf)*(Sigma_11 - Sigma_12 %*% Sigma_22_inv %*% Sigma_21) # Sample from f(X_test) | X_test, X_train, f(X_train) gp_samples <- mvtnorm::rmvnorm(1000, mean = mu_tilde, sigma = Sigma_tilde) # Compute posterior mean predictions for f(X_test) yhat_mean_test <- colMeans(gp_samples) plot(yhat_mean_test, y_test, xlab = \"predicted\", ylab = \"actual\", main = \"BART Gaussian process\") abline(0,1,lwd=2.5,lty=3,col=\"red\") sqrt(mean((yhat_mean_test - y_test)^2)) #> [1] 0.09174463"},{"path":"https://stochastictree.github.io/stochtree-r/articles/EnsembleKernel.html","id":"demo-2-multivariate-supervised-learning","dir":"Articles","previous_headings":"","what":"Demo 2: Multivariate Supervised Learning","title":"Kernel Methods from Tree Ensembles in StochTree","text":"proceed simulated “Friedman” dataset, implemented tgp.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/articles/EnsembleKernel.html","id":"traditional-gaussian-process-1","dir":"Articles","previous_headings":"Demo 2: Multivariate Supervised Learning","what":"Traditional Gaussian Process","title":"Kernel Methods from Tree Ensembles in StochTree","text":"can use tgp package model data classical Gaussian Process. Assess RMSE","code":"# Generate the data, add many \"noise variables\" n <- 100 friedman.df <- friedman.1.data(n=n) train_inds <- sort(sample(1:n, floor(0.8*n), replace = F)) test_inds <- (1:n)[!((1:n) %in% train_inds)] X <- as.matrix(friedman.df)[,1:10] X <- cbind(X, matrix(runif(n*10), ncol = 10)) y <- as.matrix(friedman.df)[,12] + rnorm(n,0,1)*(sd(as.matrix(friedman.df)[,11])/2) X_train <- X[train_inds,] X_test <- X[test_inds,] y_train <- y[train_inds] y_test <- y[test_inds] # Fit the GP model_gp <- bgp(X=X_train, Z=y_train, XX=X_test) plot(model_gp$ZZ.mean, y_test, xlab = \"predicted\", ylab = \"actual\", main = \"Gaussian process\") abline(0,1,lwd=2.5,lty=3,col=\"red\") sqrt(mean((model_gp$ZZ.mean - y_test)^2)) #> [1] 5.023593"},{"path":"https://stochastictree.github.io/stochtree-r/articles/EnsembleKernel.html","id":"bart-based-gaussian-process-1","dir":"Articles","previous_headings":"Demo 2: Multivariate Supervised Learning","what":"BART-based Gaussian process","title":"Kernel Methods from Tree Ensembles in StochTree","text":"Assess RMSE use case BART kernel classical kriging perhaps unclear without empirical investigation, see later vignette kernel approach can beneficial causal inference applications.","code":"# Run BART on the data num_trees <- 200 sigma_leaf <- 1/num_trees bart_model <- bart(X_train=X_train, y_train=y_train, X_test=X_test, num_trees=num_trees) # Extract kernels needed for kriging result_kernels <- computeForestKernels(bart_model=bart_model, X_train=X_train, X_test=X_test) Sigma_11 <- result_kernels$kernel_test Sigma_12 <- result_kernels$kernel_test_train Sigma_22 <- result_kernels$kernel_train Sigma_22_inv <- ginv(Sigma_22) Sigma_21 <- t(Sigma_12) # Compute mean and covariance for the test set posterior mu_tilde <- Sigma_12 %*% Sigma_22_inv %*% y_train Sigma_tilde <- (sigma_leaf)*(Sigma_11 - Sigma_12 %*% Sigma_22_inv %*% Sigma_21) # Sample from f(X_test) | X_test, X_train, f(X_train) gp_samples <- mvtnorm::rmvnorm(1000, mean = mu_tilde, sigma = Sigma_tilde) # Compute posterior mean predictions for f(X_test) yhat_mean_test <- colMeans(gp_samples) plot(yhat_mean_test, y_test, xlab = \"predicted\", ylab = \"actual\", main = \"BART Gaussian process\") abline(0,1,lwd=2.5,lty=3,col=\"red\") sqrt(mean((yhat_mean_test - y_test)^2)) #> [1] 5.235603"},{"path":[]},{"path":"https://stochastictree.github.io/stochtree-r/articles/ModelSerialization.html","id":"demo-1-bayesian-causal-forest-bcf","dir":"Articles","previous_headings":"","what":"Demo 1: Bayesian Causal Forest (BCF)","title":"Model Serialization in StochTree","text":"BCF models initially sampled constructed using bcf() function. show save reload models JSON files disk.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/articles/ModelSerialization.html","id":"model-building","dir":"Articles","previous_headings":"Demo 1: Bayesian Causal Forest (BCF)","what":"Model Building","title":"Model Serialization in StochTree","text":"Draw modified version data generating process defined Hahn, Murray, Carvalho (2020). Sample BCF model.","code":"# Generate synthetic data n <- 1000 snr <- 2 x1 <- rnorm(n) x2 <- rnorm(n) x3 <- rnorm(n) x4 <- as.numeric(rbinom(n,1,0.5)) x5 <- as.numeric(sample(1:3,n,replace=T)) X <- cbind(x1,x2,x3,x4,x5) p <- ncol(X) mu_x <- mu1(X) tau_x <- tau2(X) pi_x <- 0.8*pnorm((3*mu_x/sd(mu_x)) - 0.5*X[,1]) + 0.05 + runif(n)/10 Z <- rbinom(n,1,pi_x) E_XZ <- mu_x + Z*tau_x group_ids <- rep(c(1,2), n %/% 2) rfx_coefs <- matrix(c(-1, -1, 1, 1),nrow=2,byrow=T) rfx_basis <- cbind(1, runif(n, -1, 1)) rfx_term <- rowSums(rfx_coefs[group_ids,] * rfx_basis) y <- E_XZ + rfx_term + rnorm(n, 0, 1)*(sd(E_XZ)/snr) # Split data into test and train sets test_set_pct <- 0.2 n_test <- round(test_set_pct*n) n_train <- n - n_test test_inds <- sort(sample(1:n, n_test, replace = F)) train_inds <- (1:n)[!((1:n) %in% test_inds)] X_test <- X[test_inds,] X_train <- X[train_inds,] pi_test <- pi_x[test_inds] pi_train <- pi_x[train_inds] Z_test <- Z[test_inds] Z_train <- Z[train_inds] y_test <- y[test_inds] y_train <- y[train_inds] mu_test <- mu_x[test_inds] mu_train <- mu_x[train_inds] tau_test <- tau_x[test_inds] tau_train <- tau_x[train_inds] group_ids_test <- group_ids[test_inds] group_ids_train <- group_ids[train_inds] rfx_basis_test <- rfx_basis[test_inds,] rfx_basis_train <- rfx_basis[train_inds,] rfx_term_test <- rfx_term[test_inds] rfx_term_train <- rfx_term[train_inds] num_gfr <- 10 num_burnin <- 0 num_mcmc <- 100 num_samples <- num_gfr + num_burnin + num_mcmc bcf_model <- bcf( X_train = X_train, Z_train = Z_train, y_train = y_train, pi_train = pi_train, group_ids_train = group_ids_train, rfx_basis_train = rfx_basis_train, X_test = X_test, Z_test = Z_test, pi_test = pi_test, group_ids_test = group_ids_test, rfx_basis_test = rfx_basis_test, ordered_cat_vars = c(4,5), num_gfr = num_gfr, num_burnin = num_burnin, num_mcmc = num_mcmc, sample_sigma_leaf_mu = F, sample_sigma_leaf_tau = F )"},{"path":"https://stochastictree.github.io/stochtree-r/articles/ModelSerialization.html","id":"serialization","dir":"Articles","previous_headings":"Demo 1: Bayesian Causal Forest (BCF)","what":"Serialization","title":"Model Serialization in StochTree","text":"Save BCF model disk.","code":"saveBCFModelToJsonFile(bcf_model, \"bcf.json\")"},{"path":"https://stochastictree.github.io/stochtree-r/articles/ModelSerialization.html","id":"deserialization","dir":"Articles","previous_headings":"Demo 1: Bayesian Causal Forest (BCF)","what":"Deserialization","title":"Model Serialization in StochTree","text":"Reload BCF model disk. Check predictions align original model.","code":"bcf_model_reload <- createBCFModelFromJsonFile(\"bcf.json\") bcf_preds_reload <- predict(bcf_model_reload, X_train, Z_train, pi_train, group_ids_train, rfx_basis_train) plot(rowMeans(bcf_model$mu_hat_train), rowMeans(bcf_preds_reload$mu_hat), xlab = \"Original\", ylab = \"Deserialized\", main = \"Prognostic forest\") abline(0,1,col=\"red\",lwd=3,lty=3) plot(rowMeans(bcf_model$tau_hat_train), rowMeans(bcf_preds_reload$tau_hat), xlab = \"Original\", ylab = \"Deserialized\", main = \"Treatment forest\") abline(0,1,col=\"red\",lwd=3,lty=3) plot(rowMeans(bcf_model$y_hat_train), rowMeans(bcf_preds_reload$y_hat), xlab = \"Original\", ylab = \"Deserialized\", main = \"Overall outcome\") abline(0,1,col=\"red\",lwd=3,lty=3)"},{"path":[]},{"path":"https://stochastictree.github.io/stochtree-r/authors.html","id":null,"dir":"","previous_headings":"","what":"Authors","title":"Authors and Citation","text":"Drew Herren. Author, maintainer. Richard Hahn. Author. Jared Murray. Author. Carlos Carvalho. Author. Jingyu . Author.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/authors.html","id":"citation","dir":"","previous_headings":"","what":"Citation","title":"Authors and Citation","text":"Herren D, Hahn R, Murray J, Carvalho C, J (2024). stochtree: Stochastic tree ensembles (XBART BART) supervised learning causal inference. R package version 0.0.0.9000, https://stochastictree.github.io/stochtree-r/.","code":"@Manual{, title = {stochtree: Stochastic tree ensembles (XBART and BART) for supervised learning and causal inference}, author = {Drew Herren and Richard Hahn and Jared Murray and Carlos Carvalho and Jingyu He}, year = {2024}, note = {R package version 0.0.0.9000}, url = {https://stochastictree.github.io/stochtree-r/}, }"},{"path":[]},{"path":"https://stochastictree.github.io/stochtree-r/index.html","id":"getting-started","dir":"","previous_headings":"","what":"Getting started","title":"Stochastic tree ensembles (XBART and BART) for supervised learning and causal inference","text":"package can installed R via","code":"remotes::install_github(\"StochasticTree/stochtree-r\")"},{"path":"https://stochastictree.github.io/stochtree-r/reference/BART.html","id":null,"dir":"Reference","previous_headings":"","what":"Run the BART algorithm for supervised learning. — bart","title":"Run the BART algorithm for supervised learning. — bart","text":"Run BART algorithm supervised learning.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/BART.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Run the BART algorithm for supervised learning. — bart","text":"","code":"bart( X_train, y_train, W_train = NULL, group_ids_train = NULL, rfx_basis_train = NULL, X_test = NULL, W_test = NULL, group_ids_test = NULL, rfx_basis_test = NULL, ordered_cat_vars = NULL, unordered_cat_vars = NULL, cutpoint_grid_size = 100, tau_init = NULL, alpha = 0.95, beta = 2, min_samples_leaf = 5, leaf_model = 0, nu = 3, lambda = NULL, a_leaf = 3, b_leaf = NULL, q = 0.9, sigma2_init = NULL, num_trees = 200, num_gfr = 5, num_burnin = 0, num_mcmc = 100, sample_sigma = T, sample_tau = T, random_seed = -1, keep_burnin = F, keep_gfr = F )"},{"path":"https://stochastictree.github.io/stochtree-r/reference/BART.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Run the BART algorithm for supervised learning. — bart","text":"X_train Covariates used split trees ensemble. y_train Outcome modeled ensemble. W_train (Optional) Bases used define regression model y ~ W leaf regression tree. default, BART assumes constant leaf node parameters, implicitly regressing constant basis ones (.e. y ~ 1). group_ids_train (Optional) Group labels used additive random effects model. rfx_basis_train (Optional) Basis \"random-slope\" regression additive random effects model. group_ids_train provided regression basis, intercept-random effects model estimated. X_test (Optional) Test set covariates used define \"sample\" evaluation data. W_test (Optional) Test set bases used define \"sample\" evaluation data. test set optional, structure provided test set must match training set (.e. X_train W_train provided, test set must consist X_test W_test number columns). group_ids_test (Optional) Test set group labels used additive random effects model. currently support (plan near future), test set evaluation group labels training set. rfx_basis_test (Optional) Test set basis \"random-slope\" regression additive random effects model. ordered_cat_vars Vector names ordered categorical variables. unordered_cat_vars Vector names unordered categorical variables. cutpoint_grid_size Maximum size \"grid\" potential cutpoints consider. Default: 100. tau_init Starting value leaf node scale parameter. Calibrated internally 1/num_trees set . alpha Prior probability splitting tree depth 0. Tree split prior combines alpha beta via alpha*(1+node_depth)^-beta. beta Exponent decreases split probabilities nodes depth > 0. Tree split prior combines alpha beta via alpha*(1+node_depth)^-beta. min_samples_leaf Minimum allowable size leaf, terms training samples. Default: 5. nu Shape parameter IG(nu, nu*lambda) global error variance model. Default: 3. lambda Component scale parameter IG(nu, nu*lambda) global error variance prior. specified, calibrated Sparapani et al (2021). a_leaf Shape parameter IG(a_leaf, b_leaf) leaf node parameter variance model. Default: 3. b_leaf Scale parameter IG(a_leaf, b_leaf) leaf node parameter variance model. Calibrated internally 0.5/num_trees set . q Quantile used calibrated lambda Sparapani et al (2021). Default: 0.9. sigma2_init Starting value global variance parameter. Calibrated internally Sparapani et al (2021) set . num_trees Number trees ensemble. Default: 200. num_gfr Number \"warm-start\" iterations run using grow--root algorithm (Hahn, 2021). Default: 5. num_burnin Number \"burn-\" iterations MCMC sampler. Default: 0. num_mcmc Number \"retained\" iterations MCMC sampler. Default: 100. sample_sigma Whether update sigma^2 global error variance parameter based IG(nu, nu*lambda). Default: T. sample_tau Whether update tau leaf scale variance parameter based IG(a_leaf, b_leaf). (currently) set true ncol(W_train)>1. Default: T. random_seed Integer parameterizing C++ random number generator. specified, C++ random number generator seeded according std::random_device. keep_burnin Whether \"burnin\" samples included cached predictions. Default FALSE. Ignored num_mcmc = 0. keep_gfr Whether \"grow--root\" samples included cached predictions. Default TRUE. Ignored num_mcmc = 0. variable_weights Vector length ncol(X_train) indicating \"weight\" placed variable sampling purposes. Default: rep(1/ncol(X_train),ncol(X_train)).","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/BART.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Run the BART algorithm for supervised learning. — bart","text":"List sampling outputs wrapper around sampled forests (can used -memory prediction new data, serialized JSON disk).","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/BART.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Run the BART algorithm for supervised learning. — bart","text":"","code":"n <- 100 p <- 5 X <- matrix(runif(n*p), ncol = p) f_XW <- ( ((0 <= X[,1]) & (0.25 > X[,1])) * (-7.5) + ((0.25 <= X[,1]) & (0.5 > X[,1])) * (-2.5) + ((0.5 <= X[,1]) & (0.75 > X[,1])) * (2.5) + ((0.75 <= X[,1]) & (1 > X[,1])) * (7.5) ) noise_sd <- 1 y <- f_XW + rnorm(n, 0, noise_sd) test_set_pct <- 0.2 n_test <- round(test_set_pct*n) n_train <- n - n_test test_inds <- sort(sample(1:n, n_test, replace = F)) train_inds <- (1:n)[!((1:n) %in% test_inds)] X_test <- X[test_inds,] X_train <- X[train_inds,] y_test <- y[test_inds] y_train <- y[train_inds] bart_model <- bart(X_train = X_train, y_train = y_train, X_test = X_test) # plot(rowMeans(bart_model$y_hat_test), y_test, xlab = \"predicted\", ylab = \"actual\") # abline(0,1,col=\"red\",lty=3,lwd=3)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":null,"dir":"Reference","previous_headings":"","what":"Class that stores draws from an random ensemble of decision trees — CppJson","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"Wrapper around C++ container tree ensembles","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"public-fields","dir":"Reference","previous_headings":"","what":"Public fields","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"json_ptr External pointer C++ nlohmann::json object num_forests Number forests nlohmann::json object forest_labels Names forest objects overall nlohmann::json object num_rfx Number random effects terms nlohman::json object rfx_container_labels Names rfx container objects overall nlohmann::json object rfx_mapper_labels Names rfx label mapper objects overall nlohmann::json object rfx_groupid_labels Names rfx group id objects overall nlohmann::json object","code":""},{"path":[]},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"public-methods","dir":"Reference","previous_headings":"","what":"Public methods","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"CppJson$new() CppJson$add_forest() CppJson$add_random_effects() CppJson$add_scalar() CppJson$add_boolean() CppJson$add_string() CppJson$add_vector() CppJson$add_string_vector() CppJson$add_list() CppJson$add_string_list() CppJson$get_scalar() CppJson$get_boolean() CppJson$get_string() CppJson$get_vector() CppJson$get_string_vector() CppJson$get_numeric_list() CppJson$get_string_list() CppJson$save_file() CppJson$load_from_file()","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"method-new-","dir":"Reference","previous_headings":"","what":"Method new()","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"Create new CppJson object.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"","code":"CppJson$new()"},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"returns","dir":"Reference","previous_headings":"","what":"Returns","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"new CppJson object.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"method-add-forest-","dir":"Reference","previous_headings":"","what":"Method add_forest()","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"Convert forest container json add current CppJson object","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"usage-1","dir":"Reference","previous_headings":"","what":"Usage","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"","code":"CppJson$add_forest(forest_samples)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"forest_samples ForestSamples R class","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"returns-1","dir":"Reference","previous_headings":"","what":"Returns","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"NULL","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"method-add-random-effects-","dir":"Reference","previous_headings":"","what":"Method add_random_effects()","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"Convert random effects container json add current CppJson object","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"usage-2","dir":"Reference","previous_headings":"","what":"Usage","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"","code":"CppJson$add_random_effects(rfx_samples)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"arguments-1","dir":"Reference","previous_headings":"","what":"Arguments","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"rfx_samples RandomEffectSamples R class","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"returns-2","dir":"Reference","previous_headings":"","what":"Returns","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"NULL","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"method-add-scalar-","dir":"Reference","previous_headings":"","what":"Method add_scalar()","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"Add scalar json object name \"field_name\" (optional subfolder \"subfolder_name\")","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"usage-3","dir":"Reference","previous_headings":"","what":"Usage","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"","code":"CppJson$add_scalar(field_name, field_value, subfolder_name = NULL)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"arguments-2","dir":"Reference","previous_headings":"","what":"Arguments","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"field_name name field added json field_value Numeric value field added json subfolder_name (Optional) Name subfolder / hierarchy place value","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"returns-3","dir":"Reference","previous_headings":"","what":"Returns","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"NULL","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"method-add-boolean-","dir":"Reference","previous_headings":"","what":"Method add_boolean()","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"Add boolean value json object name \"field_name\" (optional subfolder \"subfolder_name\")","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"usage-4","dir":"Reference","previous_headings":"","what":"Usage","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"","code":"CppJson$add_boolean(field_name, field_value, subfolder_name = NULL)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"arguments-3","dir":"Reference","previous_headings":"","what":"Arguments","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"field_name name field added json field_value Numeric value field added json subfolder_name (Optional) Name subfolder / hierarchy place value","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"returns-4","dir":"Reference","previous_headings":"","what":"Returns","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"NULL","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"method-add-string-","dir":"Reference","previous_headings":"","what":"Method add_string()","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"Add string value json object name \"field_name\" (optional subfolder \"subfolder_name\")","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"usage-5","dir":"Reference","previous_headings":"","what":"Usage","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"","code":"CppJson$add_string(field_name, field_value, subfolder_name = NULL)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"arguments-4","dir":"Reference","previous_headings":"","what":"Arguments","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"field_name name field added json field_value Numeric value field added json subfolder_name (Optional) Name subfolder / hierarchy place value","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"returns-5","dir":"Reference","previous_headings":"","what":"Returns","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"NULL","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"method-add-vector-","dir":"Reference","previous_headings":"","what":"Method add_vector()","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"Add array json object name \"field_name\" (optional subfolder \"subfolder_name\")","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"usage-6","dir":"Reference","previous_headings":"","what":"Usage","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"","code":"CppJson$add_vector(field_name, field_vector, subfolder_name = NULL)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"arguments-5","dir":"Reference","previous_headings":"","what":"Arguments","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"field_name name field added json field_vector Vector stored json subfolder_name (Optional) Name subfolder / hierarchy place value","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"returns-6","dir":"Reference","previous_headings":"","what":"Returns","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"NULL","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"method-add-string-vector-","dir":"Reference","previous_headings":"","what":"Method add_string_vector()","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"Add array json object name \"field_name\" (optional subfolder \"subfolder_name\")","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"usage-7","dir":"Reference","previous_headings":"","what":"Usage","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"","code":"CppJson$add_string_vector(field_name, field_vector, subfolder_name = NULL)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"arguments-6","dir":"Reference","previous_headings":"","what":"Arguments","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"field_name name field added json field_vector Character vector stored json subfolder_name (Optional) Name subfolder / hierarchy place value","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"returns-7","dir":"Reference","previous_headings":"","what":"Returns","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"NULL","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"method-add-list-","dir":"Reference","previous_headings":"","what":"Method add_list()","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"Add list vectors (object map arrays) json object name \"field_name\"","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"usage-8","dir":"Reference","previous_headings":"","what":"Usage","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"","code":"CppJson$add_list(field_name, field_list)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"arguments-7","dir":"Reference","previous_headings":"","what":"Arguments","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"field_name name field added json field_list List stored json","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"returns-8","dir":"Reference","previous_headings":"","what":"Returns","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"NULL","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"method-add-string-list-","dir":"Reference","previous_headings":"","what":"Method add_string_list()","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"Add list vectors (object map arrays) json object name \"field_name\"","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"usage-9","dir":"Reference","previous_headings":"","what":"Usage","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"","code":"CppJson$add_string_list(field_name, field_list)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"arguments-8","dir":"Reference","previous_headings":"","what":"Arguments","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"field_name name field added json field_list List stored json","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"returns-9","dir":"Reference","previous_headings":"","what":"Returns","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"NULL","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"method-get-scalar-","dir":"Reference","previous_headings":"","what":"Method get_scalar()","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"Retrieve scalar value json object name \"field_name\" (optional subfolder \"subfolder_name\")","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"usage-10","dir":"Reference","previous_headings":"","what":"Usage","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"","code":"CppJson$get_scalar(field_name, subfolder_name = NULL)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"arguments-9","dir":"Reference","previous_headings":"","what":"Arguments","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"field_name name field accessed json subfolder_name (Optional) Name subfolder / hierarchy field stored","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"returns-10","dir":"Reference","previous_headings":"","what":"Returns","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"NULL","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"method-get-boolean-","dir":"Reference","previous_headings":"","what":"Method get_boolean()","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"Retrieve boolean value json object name \"field_name\" (optional subfolder \"subfolder_name\")","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"usage-11","dir":"Reference","previous_headings":"","what":"Usage","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"","code":"CppJson$get_boolean(field_name, subfolder_name = NULL)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"arguments-10","dir":"Reference","previous_headings":"","what":"Arguments","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"field_name name field accessed json subfolder_name (Optional) Name subfolder / hierarchy field stored","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"returns-11","dir":"Reference","previous_headings":"","what":"Returns","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"NULL","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"method-get-string-","dir":"Reference","previous_headings":"","what":"Method get_string()","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"Retrieve string value json object name \"field_name\" (optional subfolder \"subfolder_name\")","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"usage-12","dir":"Reference","previous_headings":"","what":"Usage","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"","code":"CppJson$get_string(field_name, subfolder_name = NULL)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"arguments-11","dir":"Reference","previous_headings":"","what":"Arguments","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"field_name name field accessed json subfolder_name (Optional) Name subfolder / hierarchy field stored","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"returns-12","dir":"Reference","previous_headings":"","what":"Returns","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"NULL","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"method-get-vector-","dir":"Reference","previous_headings":"","what":"Method get_vector()","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"Retrieve vector json object name \"field_name\" (optional subfolder \"subfolder_name\")","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"usage-13","dir":"Reference","previous_headings":"","what":"Usage","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"","code":"CppJson$get_vector(field_name, subfolder_name = NULL)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"arguments-12","dir":"Reference","previous_headings":"","what":"Arguments","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"field_name name field accessed json subfolder_name (Optional) Name subfolder / hierarchy field stored","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"returns-13","dir":"Reference","previous_headings":"","what":"Returns","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"NULL","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"method-get-string-vector-","dir":"Reference","previous_headings":"","what":"Method get_string_vector()","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"Retrieve character vector json object name \"field_name\" (optional subfolder \"subfolder_name\")","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"usage-14","dir":"Reference","previous_headings":"","what":"Usage","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"","code":"CppJson$get_string_vector(field_name, subfolder_name = NULL)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"arguments-13","dir":"Reference","previous_headings":"","what":"Arguments","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"field_name name field accessed json subfolder_name (Optional) Name subfolder / hierarchy field stored","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"returns-14","dir":"Reference","previous_headings":"","what":"Returns","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"NULL","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"method-get-numeric-list-","dir":"Reference","previous_headings":"","what":"Method get_numeric_list()","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"Reconstruct list numeric vectors json object stored \"field_name\"","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"usage-15","dir":"Reference","previous_headings":"","what":"Usage","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"","code":"CppJson$get_numeric_list(field_name, key_names)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"arguments-14","dir":"Reference","previous_headings":"","what":"Arguments","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"field_name name field added json key_names Vector names list elements (vector)","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"returns-15","dir":"Reference","previous_headings":"","what":"Returns","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"NULL","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"method-get-string-list-","dir":"Reference","previous_headings":"","what":"Method get_string_list()","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"Reconstruct list string vectors json object stored \"field_name\"","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"usage-16","dir":"Reference","previous_headings":"","what":"Usage","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"","code":"CppJson$get_string_list(field_name, key_names)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"arguments-15","dir":"Reference","previous_headings":"","what":"Arguments","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"field_name name field added json key_names Vector names list elements (vector)","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"returns-16","dir":"Reference","previous_headings":"","what":"Returns","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"NULL","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"method-save-file-","dir":"Reference","previous_headings":"","what":"Method save_file()","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"Save json object file","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"usage-17","dir":"Reference","previous_headings":"","what":"Usage","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"","code":"CppJson$save_file(filename)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"arguments-16","dir":"Reference","previous_headings":"","what":"Arguments","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"filename String filepath, must end \".json\"","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"returns-17","dir":"Reference","previous_headings":"","what":"Returns","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"NULL","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"method-load-from-file-","dir":"Reference","previous_headings":"","what":"Method load_from_file()","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"Load json object file","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"usage-18","dir":"Reference","previous_headings":"","what":"Usage","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"","code":"CppJson$load_from_file(filename)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"arguments-17","dir":"Reference","previous_headings":"","what":"Arguments","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"filename String filepath, must end \".json\"","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppJson.html","id":"returns-18","dir":"Reference","previous_headings":"","what":"Returns","title":"Class that stores draws from an random ensemble of decision trees — CppJson","text":"NULL","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppRNG.html","id":null,"dir":"Reference","previous_headings":"","what":"Class that wraps a C++ random number generator (for reproducibility) — CppRNG","title":"Class that wraps a C++ random number generator (for reproducibility) — CppRNG","text":"Persists C++ random number generator throughout R session ensure reproducibility given random seed. seed provided, C++ random number generator initialized using std::random_device.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppRNG.html","id":"public-fields","dir":"Reference","previous_headings":"","what":"Public fields","title":"Class that wraps a C++ random number generator (for reproducibility) — CppRNG","text":"rng_ptr External pointer C++ std::mt19937 class","code":""},{"path":[]},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppRNG.html","id":"public-methods","dir":"Reference","previous_headings":"","what":"Public methods","title":"Class that wraps a C++ random number generator (for reproducibility) — CppRNG","text":"CppRNG$new()","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppRNG.html","id":"method-new-","dir":"Reference","previous_headings":"","what":"Method new()","title":"Class that wraps a C++ random number generator (for reproducibility) — CppRNG","text":"Create new CppRNG object.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppRNG.html","id":"usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Class that wraps a C++ random number generator (for reproducibility) — CppRNG","text":"","code":"CppRNG$new(random_seed = -1)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppRNG.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Class that wraps a C++ random number generator (for reproducibility) — CppRNG","text":"random_seed (Optional) random seed sampling","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/CppRNG.html","id":"returns","dir":"Reference","previous_headings":"","what":"Returns","title":"Class that wraps a C++ random number generator (for reproducibility) — CppRNG","text":"new CppRNG object.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestDataset.html","id":null,"dir":"Reference","previous_headings":"","what":"Dataset used to sample a forest — ForestDataset","title":"Dataset used to sample a forest — ForestDataset","text":"dataset consists three matrices / vectors: covariates, bases, variance weights. basis vector variance weights optional.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestDataset.html","id":"public-fields","dir":"Reference","previous_headings":"","what":"Public fields","title":"Dataset used to sample a forest — ForestDataset","text":"data_ptr External pointer C++ ForestDataset class","code":""},{"path":[]},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestDataset.html","id":"public-methods","dir":"Reference","previous_headings":"","what":"Public methods","title":"Dataset used to sample a forest — ForestDataset","text":"ForestDataset$new() ForestDataset$update_basis() ForestDataset$num_observations() ForestDataset$num_covariates() ForestDataset$num_basis() ForestDataset$has_basis() ForestDataset$has_variance_weights()","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestDataset.html","id":"method-new-","dir":"Reference","previous_headings":"","what":"Method new()","title":"Dataset used to sample a forest — ForestDataset","text":"Create new ForestDataset object.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestDataset.html","id":"usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Dataset used to sample a forest — ForestDataset","text":"","code":"ForestDataset$new(covariates, basis = NULL, variance_weights = NULL)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestDataset.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Dataset used to sample a forest — ForestDataset","text":"covariates Matrix covariates basis (Optional) Matrix bases used define leaf regression variance_weights (Optional) Vector observation-specific variance weights","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestDataset.html","id":"returns","dir":"Reference","previous_headings":"","what":"Returns","title":"Dataset used to sample a forest — ForestDataset","text":"new ForestDataset object.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestDataset.html","id":"method-update-basis-","dir":"Reference","previous_headings":"","what":"Method update_basis()","title":"Dataset used to sample a forest — ForestDataset","text":"Update basis matrix dataset","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestDataset.html","id":"usage-1","dir":"Reference","previous_headings":"","what":"Usage","title":"Dataset used to sample a forest — ForestDataset","text":"","code":"ForestDataset$update_basis(basis)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestDataset.html","id":"arguments-1","dir":"Reference","previous_headings":"","what":"Arguments","title":"Dataset used to sample a forest — ForestDataset","text":"basis Updated matrix bases used define leaf regression","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestDataset.html","id":"method-num-observations-","dir":"Reference","previous_headings":"","what":"Method num_observations()","title":"Dataset used to sample a forest — ForestDataset","text":"Return number observations ForestDataset object","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestDataset.html","id":"usage-2","dir":"Reference","previous_headings":"","what":"Usage","title":"Dataset used to sample a forest — ForestDataset","text":"","code":"ForestDataset$num_observations()"},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestDataset.html","id":"returns-1","dir":"Reference","previous_headings":"","what":"Returns","title":"Dataset used to sample a forest — ForestDataset","text":"Observation count","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestDataset.html","id":"method-num-covariates-","dir":"Reference","previous_headings":"","what":"Method num_covariates()","title":"Dataset used to sample a forest — ForestDataset","text":"Return number covariates ForestDataset object","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestDataset.html","id":"usage-3","dir":"Reference","previous_headings":"","what":"Usage","title":"Dataset used to sample a forest — ForestDataset","text":"","code":"ForestDataset$num_covariates()"},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestDataset.html","id":"returns-2","dir":"Reference","previous_headings":"","what":"Returns","title":"Dataset used to sample a forest — ForestDataset","text":"Covariate count","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestDataset.html","id":"method-num-basis-","dir":"Reference","previous_headings":"","what":"Method num_basis()","title":"Dataset used to sample a forest — ForestDataset","text":"Return number bases ForestDataset object","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestDataset.html","id":"usage-4","dir":"Reference","previous_headings":"","what":"Usage","title":"Dataset used to sample a forest — ForestDataset","text":"","code":"ForestDataset$num_basis()"},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestDataset.html","id":"returns-3","dir":"Reference","previous_headings":"","what":"Returns","title":"Dataset used to sample a forest — ForestDataset","text":"Basis count","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestDataset.html","id":"method-has-basis-","dir":"Reference","previous_headings":"","what":"Method has_basis()","title":"Dataset used to sample a forest — ForestDataset","text":"Whether dataset basis matrix","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestDataset.html","id":"usage-5","dir":"Reference","previous_headings":"","what":"Usage","title":"Dataset used to sample a forest — ForestDataset","text":"","code":"ForestDataset$has_basis()"},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestDataset.html","id":"returns-4","dir":"Reference","previous_headings":"","what":"Returns","title":"Dataset used to sample a forest — ForestDataset","text":"True basis matrix loaded, false otherwise","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestDataset.html","id":"method-has-variance-weights-","dir":"Reference","previous_headings":"","what":"Method has_variance_weights()","title":"Dataset used to sample a forest — ForestDataset","text":"Whether dataset variance weights","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestDataset.html","id":"usage-6","dir":"Reference","previous_headings":"","what":"Usage","title":"Dataset used to sample a forest — ForestDataset","text":"","code":"ForestDataset$has_variance_weights()"},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestDataset.html","id":"returns-5","dir":"Reference","previous_headings":"","what":"Returns","title":"Dataset used to sample a forest — ForestDataset","text":"True variance weights loaded, false otherwise","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestKernel.html","id":null,"dir":"Reference","previous_headings":"","what":"Class that provides functionality for statistical kernel definition and computation based on shared leaf membership of observations in a tree ensemble. — ForestKernel","title":"Class that provides functionality for statistical kernel definition and computation based on shared leaf membership of observations in a tree ensemble. — ForestKernel","text":"Computes leaf membership internally sparse matrix also calculates (dense) kernel based sparse matrix C++.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestKernel.html","id":"public-fields","dir":"Reference","previous_headings":"","what":"Public fields","title":"Class that provides functionality for statistical kernel definition and computation based on shared leaf membership of observations in a tree ensemble. — ForestKernel","text":"forest_kernel_ptr External pointer C++ StochTree::ForestKernel class","code":""},{"path":[]},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestKernel.html","id":"public-methods","dir":"Reference","previous_headings":"","what":"Public methods","title":"Class that provides functionality for statistical kernel definition and computation based on shared leaf membership of observations in a tree ensemble. — ForestKernel","text":"ForestKernel$new() ForestKernel$compute_leaf_indices() ForestKernel$compute_kernel()","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestKernel.html","id":"method-new-","dir":"Reference","previous_headings":"","what":"Method new()","title":"Class that provides functionality for statistical kernel definition and computation based on shared leaf membership of observations in a tree ensemble. — ForestKernel","text":"Create new ForestKernel object.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestKernel.html","id":"usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Class that provides functionality for statistical kernel definition and computation based on shared leaf membership of observations in a tree ensemble. — ForestKernel","text":"","code":"ForestKernel$new()"},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestKernel.html","id":"returns","dir":"Reference","previous_headings":"","what":"Returns","title":"Class that provides functionality for statistical kernel definition and computation based on shared leaf membership of observations in a tree ensemble. — ForestKernel","text":"new ForestKernel object.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestKernel.html","id":"method-compute-leaf-indices-","dir":"Reference","previous_headings":"","what":"Method compute_leaf_indices()","title":"Class that provides functionality for statistical kernel definition and computation based on shared leaf membership of observations in a tree ensemble. — ForestKernel","text":"Compute leaf indices tree ensemble every observation dataset. Stores result internally, can extracted class via call get_leaf_indices.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestKernel.html","id":"usage-1","dir":"Reference","previous_headings":"","what":"Usage","title":"Class that provides functionality for statistical kernel definition and computation based on shared leaf membership of observations in a tree ensemble. — ForestKernel","text":"","code":"ForestKernel$compute_leaf_indices( covariates_train, covariates_test = NULL, forest_container, forest_num )"},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestKernel.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Class that provides functionality for statistical kernel definition and computation based on shared leaf membership of observations in a tree ensemble. — ForestKernel","text":"covariates_train Matrix training set covariates compute leaf indices covariates_test (Optional) Matrix test set covariates compute leaf indices forest_container Object type ForestSamples forest_num Index forest forest_container assessed","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestKernel.html","id":"returns-1","dir":"Reference","previous_headings":"","what":"Returns","title":"Class that provides functionality for statistical kernel definition and computation based on shared leaf membership of observations in a tree ensemble. — ForestKernel","text":"List vectors. covariates_test = NULL list one element (train set leaf indices), otherwise list two elements (train test set leaf indices).","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestKernel.html","id":"method-compute-kernel-","dir":"Reference","previous_headings":"","what":"Method compute_kernel()","title":"Class that provides functionality for statistical kernel definition and computation based on shared leaf membership of observations in a tree ensemble. — ForestKernel","text":"Compute kernel implied tree ensemble. function calls compute_leaf_indices, necessary call . compute_leaf_indices exposed class level allow extracting vector leaf indices ensemble directly R.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestKernel.html","id":"usage-2","dir":"Reference","previous_headings":"","what":"Usage","title":"Class that provides functionality for statistical kernel definition and computation based on shared leaf membership of observations in a tree ensemble. — ForestKernel","text":"","code":"ForestKernel$compute_kernel( covariates_train, covariates_test = NULL, forest_container, forest_num )"},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestKernel.html","id":"arguments-1","dir":"Reference","previous_headings":"","what":"Arguments","title":"Class that provides functionality for statistical kernel definition and computation based on shared leaf membership of observations in a tree ensemble. — ForestKernel","text":"covariates_train Matrix training set covariates assess ensemble kernel covariates_test (Optional) Matrix test set covariates assess ensemble kernel forest_container Object type ForestSamples forest_num Index forest forest_container assessed","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestKernel.html","id":"returns-2","dir":"Reference","previous_headings":"","what":"Returns","title":"Class that provides functionality for statistical kernel definition and computation based on shared leaf membership of observations in a tree ensemble. — ForestKernel","text":"List matrices. covariates_test = NULL, list contains one n_train x n_train matrix, n_train = nrow(covariates_train). matrix kernel defined W_train %*% t(W_train) W_train matrix n_train rows many columns total leaves ensemble. covariates_test NULL, list contains two matrices defined W_test %*% t(W_train) W_test %*% t(W_test).","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestModel.html","id":null,"dir":"Reference","previous_headings":"","what":"Class that defines and samples a forest model — ForestModel","title":"Class that defines and samples a forest model — ForestModel","text":"Hosts C++ data structures needed sample ensemble decision trees, exposes functionality run forest sampler (using either MCMC grow--root algorithm).","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestModel.html","id":"public-fields","dir":"Reference","previous_headings":"","what":"Public fields","title":"Class that defines and samples a forest model — ForestModel","text":"tracker_ptr External pointer C++ ForestTracker class tree_prior_ptr External pointer C++ TreePrior class","code":""},{"path":[]},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestModel.html","id":"public-methods","dir":"Reference","previous_headings":"","what":"Public methods","title":"Class that defines and samples a forest model — ForestModel","text":"ForestModel$new() ForestModel$sample_one_iteration()","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestModel.html","id":"method-new-","dir":"Reference","previous_headings":"","what":"Method new()","title":"Class that defines and samples a forest model — ForestModel","text":"Create new ForestModel object.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestModel.html","id":"usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Class that defines and samples a forest model — ForestModel","text":"","code":"ForestModel$new( forest_dataset, feature_types, num_trees, n, alpha, beta, min_samples_leaf )"},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestModel.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Class that defines and samples a forest model — ForestModel","text":"forest_dataset ForestDataset object, used initialize forest sampling data structures feature_types Feature types (integers 0 = numeric, 1 = ordered categorical, 2 = unordered categorical) num_trees Number trees forest sampled n Number observations forest_dataset alpha Root node split probability tree prior beta Depth prior penalty tree prior min_samples_leaf Minimum number samples tree leaf","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestModel.html","id":"returns","dir":"Reference","previous_headings":"","what":"Returns","title":"Class that defines and samples a forest model — ForestModel","text":"new ForestModel object.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestModel.html","id":"method-sample-one-iteration-","dir":"Reference","previous_headings":"","what":"Method sample_one_iteration()","title":"Class that defines and samples a forest model — ForestModel","text":"Run single iteration forest sampling algorithm (MCMC GFR)","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestModel.html","id":"usage-1","dir":"Reference","previous_headings":"","what":"Usage","title":"Class that defines and samples a forest model — ForestModel","text":"","code":"ForestModel$sample_one_iteration( forest_dataset, residual, forest_samples, rng, feature_types, leaf_model_int, leaf_model_scale, variable_weights, global_scale, cutpoint_grid_size = 500, gfr = T, pre_initialized = F )"},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestModel.html","id":"arguments-1","dir":"Reference","previous_headings":"","what":"Arguments","title":"Class that defines and samples a forest model — ForestModel","text":"forest_dataset Dataset used sample forest residual Outcome used sample forest forest_samples Container forest samples rng Wrapper around C++ random number generator feature_types Vector specifying type p covariates forest_dataset (0 = numeric, 1 = ordered categorical, 2 = unordered categorical) leaf_model_int Integer specifying leaf model type (0 = constant leaf, 1 = univariate leaf regression, 2 = multivariate leaf regression) leaf_model_scale Scale parameter used leaf node model (q x q matrix q dimensionality basis >1 leaf_model_int = 2) variable_weights Vector specifying sampling probability p covariates forest_dataset global_scale Global variance parameter cutpoint_grid_size (Optional) Number unique cutpoints consider (default: 500, currently used GFR = TRUE) gfr (Optional) Whether forest sampled using \"grow--root\" (GFR) algorithm pre_initialized (Optional) Whether leaves pre-initialized outside sampling loop (samples drawn). multi-forest implementations like BCF, true, though single-forest supervised learning implementation, can let C++ initialization. Default: F.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestSamples.html","id":null,"dir":"Reference","previous_headings":"","what":"Class that stores draws from an random ensemble of decision trees — ForestSamples","title":"Class that stores draws from an random ensemble of decision trees — ForestSamples","text":"Wrapper around C++ container tree ensembles","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestSamples.html","id":"public-fields","dir":"Reference","previous_headings":"","what":"Public fields","title":"Class that stores draws from an random ensemble of decision trees — ForestSamples","text":"forest_container_ptr External pointer C++ ForestContainer class","code":""},{"path":[]},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestSamples.html","id":"public-methods","dir":"Reference","previous_headings":"","what":"Public methods","title":"Class that stores draws from an random ensemble of decision trees — ForestSamples","text":"ForestSamples$new() ForestSamples$load_from_json() ForestSamples$predict() ForestSamples$predict_raw() ForestSamples$predict_raw_single_forest() ForestSamples$set_root_leaves() ForestSamples$update_residual() ForestSamples$save_json() ForestSamples$load_json() ForestSamples$num_samples() ForestSamples$num_trees() ForestSamples$output_dimension()","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestSamples.html","id":"method-new-","dir":"Reference","previous_headings":"","what":"Method new()","title":"Class that stores draws from an random ensemble of decision trees — ForestSamples","text":"Create new ForestContainer object.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestSamples.html","id":"usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Class that stores draws from an random ensemble of decision trees — ForestSamples","text":"","code":"ForestSamples$new(num_trees, output_dimension = 1, is_leaf_constant = F)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestSamples.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Class that stores draws from an random ensemble of decision trees — ForestSamples","text":"num_trees Number trees output_dimension Dimensionality outcome model is_leaf_constant Whether leaf constant","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestSamples.html","id":"returns","dir":"Reference","previous_headings":"","what":"Returns","title":"Class that stores draws from an random ensemble of decision trees — ForestSamples","text":"new ForestContainer object.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestSamples.html","id":"method-load-from-json-","dir":"Reference","previous_headings":"","what":"Method load_from_json()","title":"Class that stores draws from an random ensemble of decision trees — ForestSamples","text":"Create new ForestContainer object json object","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestSamples.html","id":"usage-1","dir":"Reference","previous_headings":"","what":"Usage","title":"Class that stores draws from an random ensemble of decision trees — ForestSamples","text":"","code":"ForestSamples$load_from_json(json_object, json_forest_label)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestSamples.html","id":"arguments-1","dir":"Reference","previous_headings":"","what":"Arguments","title":"Class that stores draws from an random ensemble of decision trees — ForestSamples","text":"json_object Object class CppJson json_forest_label Label referring particular forest (.e. \"forest_0\") overall json hierarchy","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestSamples.html","id":"returns-1","dir":"Reference","previous_headings":"","what":"Returns","title":"Class that stores draws from an random ensemble of decision trees — ForestSamples","text":"new ForestContainer object.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestSamples.html","id":"method-predict-","dir":"Reference","previous_headings":"","what":"Method predict()","title":"Class that stores draws from an random ensemble of decision trees — ForestSamples","text":"Predict every tree ensemble every sample forest_dataset","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestSamples.html","id":"usage-2","dir":"Reference","previous_headings":"","what":"Usage","title":"Class that stores draws from an random ensemble of decision trees — ForestSamples","text":"","code":"ForestSamples$predict(forest_dataset)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestSamples.html","id":"arguments-2","dir":"Reference","previous_headings":"","what":"Arguments","title":"Class that stores draws from an random ensemble of decision trees — ForestSamples","text":"forest_dataset ForestDataset R class","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestSamples.html","id":"returns-2","dir":"Reference","previous_headings":"","what":"Returns","title":"Class that stores draws from an random ensemble of decision trees — ForestSamples","text":"matrix predictions many rows forest_dataset many columns samples ForestContainer","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestSamples.html","id":"method-predict-raw-","dir":"Reference","previous_headings":"","what":"Method predict_raw()","title":"Class that stores draws from an random ensemble of decision trees — ForestSamples","text":"Predict \"raw\" leaf values (without multiplied basis) every tree ensemble every sample forest_dataset","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestSamples.html","id":"usage-3","dir":"Reference","previous_headings":"","what":"Usage","title":"Class that stores draws from an random ensemble of decision trees — ForestSamples","text":"","code":"ForestSamples$predict_raw(forest_dataset)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestSamples.html","id":"arguments-3","dir":"Reference","previous_headings":"","what":"Arguments","title":"Class that stores draws from an random ensemble of decision trees — ForestSamples","text":"forest_dataset ForestDataset R class","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestSamples.html","id":"returns-3","dir":"Reference","previous_headings":"","what":"Returns","title":"Class that stores draws from an random ensemble of decision trees — ForestSamples","text":"Array predictions observation forest_dataset sample ForestSamples class prediction dimensionality forests' leaf model. case constant leaf model univariate leaf regression, array two-dimensional (number observations, number forest samples). case multivariate leaf regression, array three-dimension (number observations, leaf model dimension, number samples).","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestSamples.html","id":"method-predict-raw-single-forest-","dir":"Reference","previous_headings":"","what":"Method predict_raw_single_forest()","title":"Class that stores draws from an random ensemble of decision trees — ForestSamples","text":"Predict \"raw\" leaf values (without multiplied basis) specific forest every sample forest_dataset","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestSamples.html","id":"usage-4","dir":"Reference","previous_headings":"","what":"Usage","title":"Class that stores draws from an random ensemble of decision trees — ForestSamples","text":"","code":"ForestSamples$predict_raw_single_forest(forest_dataset, forest_num)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestSamples.html","id":"arguments-4","dir":"Reference","previous_headings":"","what":"Arguments","title":"Class that stores draws from an random ensemble of decision trees — ForestSamples","text":"forest_dataset ForestDataset R class forest_num Index forest sample within container","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestSamples.html","id":"returns-4","dir":"Reference","previous_headings":"","what":"Returns","title":"Class that stores draws from an random ensemble of decision trees — ForestSamples","text":"matrix predictions many rows forest_dataset many columns samples ForestContainer","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestSamples.html","id":"method-set-root-leaves-","dir":"Reference","previous_headings":"","what":"Method set_root_leaves()","title":"Class that stores draws from an random ensemble of decision trees — ForestSamples","text":"Set constant predicted value every tree ensemble. Stops program tree root node.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestSamples.html","id":"usage-5","dir":"Reference","previous_headings":"","what":"Usage","title":"Class that stores draws from an random ensemble of decision trees — ForestSamples","text":"","code":"ForestSamples$set_root_leaves(forest_num, leaf_value)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestSamples.html","id":"arguments-5","dir":"Reference","previous_headings":"","what":"Arguments","title":"Class that stores draws from an random ensemble of decision trees — ForestSamples","text":"forest_num Index forest sample within container. leaf_value Constant leaf value(s) fixed tree ensemble indexed forest_num. Can either single number vector, depending forest's leaf dimension.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestSamples.html","id":"method-update-residual-","dir":"Reference","previous_headings":"","what":"Method update_residual()","title":"Class that stores draws from an random ensemble of decision trees — ForestSamples","text":"Updates residual based predictions forest","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestSamples.html","id":"usage-6","dir":"Reference","previous_headings":"","what":"Usage","title":"Class that stores draws from an random ensemble of decision trees — ForestSamples","text":"","code":"ForestSamples$update_residual( dataset, outcome, forest_model, requires_basis, forest_num, add )"},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestSamples.html","id":"arguments-6","dir":"Reference","previous_headings":"","what":"Arguments","title":"Class that stores draws from an random ensemble of decision trees — ForestSamples","text":"dataset ForestDataset object storing covariates bases given forest outcome Outcome object storing residuals updated based forest predictions forest_model ForestModel object storing tracking structures used training / sampling requires_basis Whether forest requires basis prediction forest_num Index forest used update residuals add Whether forest predictions added subtracted residuals","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestSamples.html","id":"method-save-json-","dir":"Reference","previous_headings":"","what":"Method save_json()","title":"Class that stores draws from an random ensemble of decision trees — ForestSamples","text":"Store trees metadata ForestDataset class json file","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestSamples.html","id":"usage-7","dir":"Reference","previous_headings":"","what":"Usage","title":"Class that stores draws from an random ensemble of decision trees — ForestSamples","text":"","code":"ForestSamples$save_json(json_filename)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestSamples.html","id":"arguments-7","dir":"Reference","previous_headings":"","what":"Arguments","title":"Class that stores draws from an random ensemble of decision trees — ForestSamples","text":"json_filename Name output json file (must end \".json\")","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestSamples.html","id":"method-load-json-","dir":"Reference","previous_headings":"","what":"Method load_json()","title":"Class that stores draws from an random ensemble of decision trees — ForestSamples","text":"Load trees metadata ensemble json file. Note trees metadata already present ForestDataset class overwritten.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestSamples.html","id":"usage-8","dir":"Reference","previous_headings":"","what":"Usage","title":"Class that stores draws from an random ensemble of decision trees — ForestSamples","text":"","code":"ForestSamples$load_json(json_filename)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestSamples.html","id":"arguments-8","dir":"Reference","previous_headings":"","what":"Arguments","title":"Class that stores draws from an random ensemble of decision trees — ForestSamples","text":"json_filename Name model input json file (must end \".json\")","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestSamples.html","id":"method-num-samples-","dir":"Reference","previous_headings":"","what":"Method num_samples()","title":"Class that stores draws from an random ensemble of decision trees — ForestSamples","text":"Return number samples ForestContainer object","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestSamples.html","id":"usage-9","dir":"Reference","previous_headings":"","what":"Usage","title":"Class that stores draws from an random ensemble of decision trees — ForestSamples","text":"","code":"ForestSamples$num_samples()"},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestSamples.html","id":"returns-5","dir":"Reference","previous_headings":"","what":"Returns","title":"Class that stores draws from an random ensemble of decision trees — ForestSamples","text":"Sample count","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestSamples.html","id":"method-num-trees-","dir":"Reference","previous_headings":"","what":"Method num_trees()","title":"Class that stores draws from an random ensemble of decision trees — ForestSamples","text":"Return number trees ensemble ForestContainer object","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestSamples.html","id":"usage-10","dir":"Reference","previous_headings":"","what":"Usage","title":"Class that stores draws from an random ensemble of decision trees — ForestSamples","text":"","code":"ForestSamples$num_trees()"},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestSamples.html","id":"returns-6","dir":"Reference","previous_headings":"","what":"Returns","title":"Class that stores draws from an random ensemble of decision trees — ForestSamples","text":"Tree count","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestSamples.html","id":"method-output-dimension-","dir":"Reference","previous_headings":"","what":"Method output_dimension()","title":"Class that stores draws from an random ensemble of decision trees — ForestSamples","text":"Return output dimension trees ForestContainer object","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestSamples.html","id":"usage-11","dir":"Reference","previous_headings":"","what":"Usage","title":"Class that stores draws from an random ensemble of decision trees — ForestSamples","text":"","code":"ForestSamples$output_dimension()"},{"path":"https://stochastictree.github.io/stochtree-r/reference/ForestSamples.html","id":"returns-7","dir":"Reference","previous_headings":"","what":"Returns","title":"Class that stores draws from an random ensemble of decision trees — ForestSamples","text":"Leaf node parameter size","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/Outcome.html","id":null,"dir":"Reference","previous_headings":"","what":"Outcome / partial residual used to sample an additive model. — Outcome","title":"Outcome / partial residual used to sample an additive model. — Outcome","text":"outcome class wrapper around vector (mutable) outcomes ML tasks (supervised learning, causal inference). additive tree ensemble sampled, outcome used sample specific model term \"partial residual\" consisting outcome minus predictions every model term (trees, group random effects, etc...).","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/Outcome.html","id":"public-fields","dir":"Reference","previous_headings":"","what":"Public fields","title":"Outcome / partial residual used to sample an additive model. — Outcome","text":"data_ptr External pointer C++ Outcome class","code":""},{"path":[]},{"path":"https://stochastictree.github.io/stochtree-r/reference/Outcome.html","id":"public-methods","dir":"Reference","previous_headings":"","what":"Public methods","title":"Outcome / partial residual used to sample an additive model. — Outcome","text":"Outcome$new()","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/Outcome.html","id":"method-new-","dir":"Reference","previous_headings":"","what":"Method new()","title":"Outcome / partial residual used to sample an additive model. — Outcome","text":"Create new Outcome object.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/Outcome.html","id":"usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Outcome / partial residual used to sample an additive model. — Outcome","text":"","code":"Outcome$new(outcome)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/Outcome.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Outcome / partial residual used to sample an additive model. — Outcome","text":"outcome Vector outcome values","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/Outcome.html","id":"returns","dir":"Reference","previous_headings":"","what":"Returns","title":"Outcome / partial residual used to sample an additive model. — Outcome","text":"new Outcome object.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectSamples.html","id":null,"dir":"Reference","previous_headings":"","what":"Class that wraps the ","title":"Class that wraps the ","text":"Coordinates various C++ random effects classes persists needed prediction / serialization","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectSamples.html","id":"public-fields","dir":"Reference","previous_headings":"","what":"Public fields","title":"Class that wraps the ","text":"rfx_container_ptr External pointer C++ StochTree::RandomEffectsContainer class label_mapper_ptr External pointer C++ StochTree::LabelMapper class training_group_ids Unique vector group IDs training dataset","code":""},{"path":[]},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectSamples.html","id":"public-methods","dir":"Reference","previous_headings":"","what":"Public methods","title":"Class that wraps the ","text":"RandomEffectSamples$new() RandomEffectSamples$load_in_session() RandomEffectSamples$load_from_json() RandomEffectSamples$predict() RandomEffectSamples$extract_parameter_samples() RandomEffectSamples$extract_label_mapping()","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectSamples.html","id":"method-new-","dir":"Reference","previous_headings":"","what":"Method new()","title":"Class that wraps the ","text":"Create new RandomEffectSamples object.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectSamples.html","id":"usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Class that wraps the ","text":"","code":"RandomEffectSamples$new()"},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectSamples.html","id":"returns","dir":"Reference","previous_headings":"","what":"Returns","title":"Class that wraps the ","text":"new RandomEffectSamples object.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectSamples.html","id":"method-load-in-session-","dir":"Reference","previous_headings":"","what":"Method load_in_session()","title":"Class that wraps the ","text":"Construct RandomEffectSamples object \"-session\" R objects","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectSamples.html","id":"usage-1","dir":"Reference","previous_headings":"","what":"Usage","title":"Class that wraps the ","text":"","code":"RandomEffectSamples$load_in_session( num_components, num_groups, random_effects_tracker )"},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectSamples.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Class that wraps the ","text":"num_components Number \"components\" bases defining random effects regression num_groups Number random effects groups random_effects_tracker Object type RandomEffectsTracker","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectSamples.html","id":"returns-1","dir":"Reference","previous_headings":"","what":"Returns","title":"Class that wraps the ","text":"NULL","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectSamples.html","id":"method-load-from-json-","dir":"Reference","previous_headings":"","what":"Method load_from_json()","title":"Class that wraps the ","text":"Construct RandomEffectSamples object json object","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectSamples.html","id":"usage-2","dir":"Reference","previous_headings":"","what":"Usage","title":"Class that wraps the ","text":"","code":"RandomEffectSamples$load_from_json( json_object, json_rfx_container_label, json_rfx_mapper_label, json_rfx_groupids_label )"},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectSamples.html","id":"arguments-1","dir":"Reference","previous_headings":"","what":"Arguments","title":"Class that wraps the ","text":"json_object Object class CppJson json_rfx_container_label Label referring particular rfx sample container (.e. \"random_effect_container_0\") overall json hierarchy json_rfx_mapper_label Label referring particular rfx label mapper (.e. \"random_effect_label_mapper_0\") overall json hierarchy json_rfx_groupids_label Label referring particular set rfx group IDs (.e. \"random_effect_groupids_0\") overall json hierarchy","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectSamples.html","id":"returns-2","dir":"Reference","previous_headings":"","what":"Returns","title":"Class that wraps the ","text":"new RandomEffectSamples object.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectSamples.html","id":"method-predict-","dir":"Reference","previous_headings":"","what":"Method predict()","title":"Class that wraps the ","text":"Predict random effects observation implied rfx_group_ids rfx_basis. random effects model \"intercept-\" rfx_basis vector ones size length(rfx_group_ids).","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectSamples.html","id":"usage-3","dir":"Reference","previous_headings":"","what":"Usage","title":"Class that wraps the ","text":"","code":"RandomEffectSamples$predict(rfx_group_ids, rfx_basis = NULL)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectSamples.html","id":"arguments-2","dir":"Reference","previous_headings":"","what":"Arguments","title":"Class that wraps the ","text":"rfx_group_ids Indices random effects groups prediction set rfx_basis (Optional ) Basis used random effects prediction","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectSamples.html","id":"returns-3","dir":"Reference","previous_headings":"","what":"Returns","title":"Class that wraps the ","text":"Matrix many rows observations provided many columns samples drawn model.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectSamples.html","id":"method-extract-parameter-samples-","dir":"Reference","previous_headings":"","what":"Method extract_parameter_samples()","title":"Class that wraps the ","text":"Extract random effects parameters sampled. \"redundant parameterization\" Gelman et al (2008), includes four parameters: alpha (\"working parameter\" shared across every group), xi (\"group parameter\" sampled separately group), beta (product alpha xi, corresponds overall group-level random effects), sigma (group-independent prior variance component xi).","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectSamples.html","id":"usage-4","dir":"Reference","previous_headings":"","what":"Usage","title":"Class that wraps the ","text":"","code":"RandomEffectSamples$extract_parameter_samples()"},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectSamples.html","id":"returns-4","dir":"Reference","previous_headings":"","what":"Returns","title":"Class that wraps the ","text":"List arrays. alpha array dimension (num_components, num_samples) simply vector num_components = 1. xi beta arrays dimension (num_components, num_groups, num_samples) simply matrix num_components = 1. sigma array dimension (num_components, num_samples) simply vector num_components = 1.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectSamples.html","id":"method-extract-label-mapping-","dir":"Reference","previous_headings":"","what":"Method extract_label_mapping()","title":"Class that wraps the ","text":"Convert mapping group IDs random effect components indices C++ R native format","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectSamples.html","id":"usage-5","dir":"Reference","previous_headings":"","what":"Usage","title":"Class that wraps the ","text":"","code":"RandomEffectSamples$extract_label_mapping()"},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectSamples.html","id":"returns-5","dir":"Reference","previous_headings":"","what":"Returns","title":"Class that wraps the ","text":"List mapping group ID random effect components.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsDataset.html","id":null,"dir":"Reference","previous_headings":"","what":"Dataset used to sample a random effects model — RandomEffectsDataset","title":"Dataset used to sample a random effects model — RandomEffectsDataset","text":"dataset consists three matrices / vectors: group labels, bases, variance weights. Variance weights optional.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsDataset.html","id":"public-fields","dir":"Reference","previous_headings":"","what":"Public fields","title":"Dataset used to sample a random effects model — RandomEffectsDataset","text":"data_ptr External pointer C++ RandomEffectsDataset class","code":""},{"path":[]},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsDataset.html","id":"public-methods","dir":"Reference","previous_headings":"","what":"Public methods","title":"Dataset used to sample a random effects model — RandomEffectsDataset","text":"RandomEffectsDataset$new() RandomEffectsDataset$num_observations() RandomEffectsDataset$has_group_labels() RandomEffectsDataset$has_basis() RandomEffectsDataset$has_variance_weights()","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsDataset.html","id":"method-new-","dir":"Reference","previous_headings":"","what":"Method new()","title":"Dataset used to sample a random effects model — RandomEffectsDataset","text":"Create new RandomEffectsDataset object.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsDataset.html","id":"usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Dataset used to sample a random effects model — RandomEffectsDataset","text":"","code":"RandomEffectsDataset$new(group_labels, basis, variance_weights = NULL)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsDataset.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Dataset used to sample a random effects model — RandomEffectsDataset","text":"group_labels Vector group labels basis Matrix bases used define random effects regression (intercept-model, pass array ones) variance_weights (Optional) Vector observation-specific variance weights","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsDataset.html","id":"returns","dir":"Reference","previous_headings":"","what":"Returns","title":"Dataset used to sample a random effects model — RandomEffectsDataset","text":"new RandomEffectsDataset object.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsDataset.html","id":"method-num-observations-","dir":"Reference","previous_headings":"","what":"Method num_observations()","title":"Dataset used to sample a random effects model — RandomEffectsDataset","text":"Return number observations RandomEffectsDataset object","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsDataset.html","id":"usage-1","dir":"Reference","previous_headings":"","what":"Usage","title":"Dataset used to sample a random effects model — RandomEffectsDataset","text":"","code":"RandomEffectsDataset$num_observations()"},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsDataset.html","id":"returns-1","dir":"Reference","previous_headings":"","what":"Returns","title":"Dataset used to sample a random effects model — RandomEffectsDataset","text":"Observation count","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsDataset.html","id":"method-has-group-labels-","dir":"Reference","previous_headings":"","what":"Method has_group_labels()","title":"Dataset used to sample a random effects model — RandomEffectsDataset","text":"Whether dataset group label indices","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsDataset.html","id":"usage-2","dir":"Reference","previous_headings":"","what":"Usage","title":"Dataset used to sample a random effects model — RandomEffectsDataset","text":"","code":"RandomEffectsDataset$has_group_labels()"},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsDataset.html","id":"returns-2","dir":"Reference","previous_headings":"","what":"Returns","title":"Dataset used to sample a random effects model — RandomEffectsDataset","text":"True group label vector loaded, false otherwise","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsDataset.html","id":"method-has-basis-","dir":"Reference","previous_headings":"","what":"Method has_basis()","title":"Dataset used to sample a random effects model — RandomEffectsDataset","text":"Whether dataset basis matrix","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsDataset.html","id":"usage-3","dir":"Reference","previous_headings":"","what":"Usage","title":"Dataset used to sample a random effects model — RandomEffectsDataset","text":"","code":"RandomEffectsDataset$has_basis()"},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsDataset.html","id":"returns-3","dir":"Reference","previous_headings":"","what":"Returns","title":"Dataset used to sample a random effects model — RandomEffectsDataset","text":"True basis matrix loaded, false otherwise","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsDataset.html","id":"method-has-variance-weights-","dir":"Reference","previous_headings":"","what":"Method has_variance_weights()","title":"Dataset used to sample a random effects model — RandomEffectsDataset","text":"Whether dataset variance weights","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsDataset.html","id":"usage-4","dir":"Reference","previous_headings":"","what":"Usage","title":"Dataset used to sample a random effects model — RandomEffectsDataset","text":"","code":"RandomEffectsDataset$has_variance_weights()"},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsDataset.html","id":"returns-4","dir":"Reference","previous_headings":"","what":"Returns","title":"Dataset used to sample a random effects model — RandomEffectsDataset","text":"True variance weights loaded, false otherwise","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsModel.html","id":null,"dir":"Reference","previous_headings":"","what":"The core ","title":"The core ","text":"Stores current model state, prior parameters, procedures sampling conditional posterior parameter.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsModel.html","id":"public-fields","dir":"Reference","previous_headings":"","what":"Public fields","title":"The core ","text":"rfx_model_ptr External pointer C++ StochTree::RandomEffectsModel class num_groups Number groups random effects model num_components Number components (.e. dimension basis) random effects model","code":""},{"path":[]},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsModel.html","id":"public-methods","dir":"Reference","previous_headings":"","what":"Public methods","title":"The core ","text":"RandomEffectsModel$new() RandomEffectsModel$sample_random_effect() RandomEffectsModel$predict() RandomEffectsModel$set_working_parameter() RandomEffectsModel$set_group_parameters() RandomEffectsModel$set_working_parameter_cov() RandomEffectsModel$set_group_parameter_cov() RandomEffectsModel$set_variance_prior_shape() RandomEffectsModel$set_variance_prior_scale()","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsModel.html","id":"method-new-","dir":"Reference","previous_headings":"","what":"Method new()","title":"The core ","text":"Create new RandomEffectsModel object.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsModel.html","id":"usage","dir":"Reference","previous_headings":"","what":"Usage","title":"The core ","text":"","code":"RandomEffectsModel$new(num_components, num_groups)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsModel.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"The core ","text":"num_components Number \"components\" bases defining random effects regression num_groups Number random effects groups","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsModel.html","id":"returns","dir":"Reference","previous_headings":"","what":"Returns","title":"The core ","text":"new RandomEffectsModel object.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsModel.html","id":"method-sample-random-effect-","dir":"Reference","previous_headings":"","what":"Method sample_random_effect()","title":"The core ","text":"Sample random effects model.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsModel.html","id":"usage-1","dir":"Reference","previous_headings":"","what":"Usage","title":"The core ","text":"","code":"RandomEffectsModel$sample_random_effect( rfx_dataset, residual, rfx_tracker, rfx_samples, global_variance, rng )"},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsModel.html","id":"arguments-1","dir":"Reference","previous_headings":"","what":"Arguments","title":"The core ","text":"rfx_dataset Object type RandomEffectsDataset residual Object type Outcome rfx_tracker Object type RandomEffectsTracker rfx_samples Object type RandomEffectSamples global_variance Scalar global variance parameter rng Object type CppRNG","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsModel.html","id":"returns-1","dir":"Reference","previous_headings":"","what":"Returns","title":"The core ","text":"None","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsModel.html","id":"method-predict-","dir":"Reference","previous_headings":"","what":"Method predict()","title":"The core ","text":"Predict (single sample ) random effects model.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsModel.html","id":"usage-2","dir":"Reference","previous_headings":"","what":"Usage","title":"The core ","text":"","code":"RandomEffectsModel$predict(rfx_dataset, rfx_tracker)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsModel.html","id":"arguments-2","dir":"Reference","previous_headings":"","what":"Arguments","title":"The core ","text":"rfx_dataset Object type RandomEffectsDataset rfx_tracker Object type RandomEffectsTracker","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsModel.html","id":"returns-2","dir":"Reference","previous_headings":"","what":"Returns","title":"The core ","text":"Vector predictions size matching number observations rfx_dataset","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsModel.html","id":"method-set-working-parameter-","dir":"Reference","previous_headings":"","what":"Method set_working_parameter()","title":"The core ","text":"Set value \"working parameter.\" typically used initialization, also used interrupt override sampler.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsModel.html","id":"usage-3","dir":"Reference","previous_headings":"","what":"Usage","title":"The core ","text":"","code":"RandomEffectsModel$set_working_parameter(value)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsModel.html","id":"arguments-3","dir":"Reference","previous_headings":"","what":"Arguments","title":"The core ","text":"value Parameter input","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsModel.html","id":"returns-3","dir":"Reference","previous_headings":"","what":"Returns","title":"The core ","text":"None","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsModel.html","id":"method-set-group-parameters-","dir":"Reference","previous_headings":"","what":"Method set_group_parameters()","title":"The core ","text":"Set value \"group parameters.\" typically used initialization, also used interrupt override sampler.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsModel.html","id":"usage-4","dir":"Reference","previous_headings":"","what":"Usage","title":"The core ","text":"","code":"RandomEffectsModel$set_group_parameters(value)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsModel.html","id":"arguments-4","dir":"Reference","previous_headings":"","what":"Arguments","title":"The core ","text":"value Parameter input","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsModel.html","id":"returns-4","dir":"Reference","previous_headings":"","what":"Returns","title":"The core ","text":"None","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsModel.html","id":"method-set-working-parameter-cov-","dir":"Reference","previous_headings":"","what":"Method set_working_parameter_cov()","title":"The core ","text":"Set value working parameter covariance. typically used initialization, also used interrupt override sampler.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsModel.html","id":"usage-5","dir":"Reference","previous_headings":"","what":"Usage","title":"The core ","text":"","code":"RandomEffectsModel$set_working_parameter_cov(value)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsModel.html","id":"arguments-5","dir":"Reference","previous_headings":"","what":"Arguments","title":"The core ","text":"value Parameter input","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsModel.html","id":"returns-5","dir":"Reference","previous_headings":"","what":"Returns","title":"The core ","text":"None","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsModel.html","id":"method-set-group-parameter-cov-","dir":"Reference","previous_headings":"","what":"Method set_group_parameter_cov()","title":"The core ","text":"Set value group parameter covariance. typically used initialization, also used interrupt override sampler.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsModel.html","id":"usage-6","dir":"Reference","previous_headings":"","what":"Usage","title":"The core ","text":"","code":"RandomEffectsModel$set_group_parameter_cov(value)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsModel.html","id":"arguments-6","dir":"Reference","previous_headings":"","what":"Arguments","title":"The core ","text":"value Parameter input","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsModel.html","id":"returns-6","dir":"Reference","previous_headings":"","what":"Returns","title":"The core ","text":"None","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsModel.html","id":"method-set-variance-prior-shape-","dir":"Reference","previous_headings":"","what":"Method set_variance_prior_shape()","title":"The core ","text":"Set shape parameter group parameter variance prior.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsModel.html","id":"usage-7","dir":"Reference","previous_headings":"","what":"Usage","title":"The core ","text":"","code":"RandomEffectsModel$set_variance_prior_shape(value)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsModel.html","id":"arguments-7","dir":"Reference","previous_headings":"","what":"Arguments","title":"The core ","text":"value Parameter input","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsModel.html","id":"returns-7","dir":"Reference","previous_headings":"","what":"Returns","title":"The core ","text":"None","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsModel.html","id":"method-set-variance-prior-scale-","dir":"Reference","previous_headings":"","what":"Method set_variance_prior_scale()","title":"The core ","text":"Set shape parameter group parameter variance prior.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsModel.html","id":"usage-8","dir":"Reference","previous_headings":"","what":"Usage","title":"The core ","text":"","code":"RandomEffectsModel$set_variance_prior_scale(value)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsModel.html","id":"arguments-8","dir":"Reference","previous_headings":"","what":"Arguments","title":"The core ","text":"value Parameter input","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsModel.html","id":"returns-8","dir":"Reference","previous_headings":"","what":"Returns","title":"The core ","text":"None","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsTracker.html","id":null,"dir":"Reference","previous_headings":"","what":"Class that defines a ","title":"Class that defines a ","text":"Stores mapping every observation group index, mapping group indices training sample observations available group, predictions observation.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsTracker.html","id":"public-fields","dir":"Reference","previous_headings":"","what":"Public fields","title":"Class that defines a ","text":"rfx_tracker_ptr External pointer C++ StochTree::RandomEffectsTracker class","code":""},{"path":[]},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsTracker.html","id":"public-methods","dir":"Reference","previous_headings":"","what":"Public methods","title":"Class that defines a ","text":"RandomEffectsTracker$new()","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsTracker.html","id":"method-new-","dir":"Reference","previous_headings":"","what":"Method new()","title":"Class that defines a ","text":"Create new RandomEffectsTracker object.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsTracker.html","id":"usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Class that defines a ","text":"","code":"RandomEffectsTracker$new(rfx_group_indices)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsTracker.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Class that defines a ","text":"rfx_group_indices Integer indices indicating groups used define random effects","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/RandomEffectsTracker.html","id":"returns","dir":"Reference","previous_headings":"","what":"Returns","title":"Class that defines a ","text":"new RandomEffectsTracker object.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/bcf.html","id":null,"dir":"Reference","previous_headings":"","what":"Run the Bayesian Causal Forest (BCF) algorithm for regularized causal effect estimation. — bcf","title":"Run the Bayesian Causal Forest (BCF) algorithm for regularized causal effect estimation. — bcf","text":"Run Bayesian Causal Forest (BCF) algorithm regularized causal effect estimation.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/bcf.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Run the Bayesian Causal Forest (BCF) algorithm for regularized causal effect estimation. — bcf","text":"","code":"bcf( X_train, Z_train, y_train, pi_train = NULL, group_ids_train = NULL, rfx_basis_train = NULL, X_test = NULL, Z_test = NULL, pi_test = NULL, group_ids_test = NULL, rfx_basis_test = NULL, ordered_cat_vars = NULL, unordered_cat_vars = NULL, cutpoint_grid_size = 100, sigma_leaf_mu = NULL, sigma_leaf_tau = NULL, alpha_mu = 0.95, alpha_tau = 0.25, beta_mu = 2, beta_tau = 3, min_samples_leaf_mu = 5, min_samples_leaf_tau = 5, nu = 3, lambda = NULL, a_leaf_mu = 3, a_leaf_tau = 3, b_leaf_mu = NULL, b_leaf_tau = NULL, q = 0.9, sigma2 = NULL, num_trees_mu = 250, num_trees_tau = 50, num_gfr = 5, num_burnin = 0, num_mcmc = 100, sample_sigma_global = T, sample_sigma_leaf_mu = T, sample_sigma_leaf_tau = F, propensity_covariate = \"mu\", adaptive_coding = T, b_0 = -0.5, b_1 = 0.5, random_seed = -1, keep_burnin = F, keep_gfr = F )"},{"path":"https://stochastictree.github.io/stochtree-r/reference/bcf.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Run the Bayesian Causal Forest (BCF) algorithm for regularized causal effect estimation. — bcf","text":"X_train Covariates used split trees ensemble. Can passed either matrix dataframe. Z_train Vector (continuous binary) treatment assignments. y_train Outcome modeled ensemble. pi_train (Optional) Vector propensity scores. provided, estimated data. group_ids_train (Optional) Group labels used additive random effects model. rfx_basis_train (Optional) Basis \"random-slope\" regression additive random effects model. group_ids_train provided regression basis, intercept-random effects model estimated. X_test (Optional) Test set covariates used define \"sample\" evaluation data. Can passed either matrix dataframe. Z_test (Optional) Test set (continuous binary) treatment assignments. pi_test (Optional) Vector propensity scores. provided, estimated data. group_ids_test (Optional) Test set group labels used additive random effects model. currently support (plan near future), test set evaluation group labels training set. rfx_basis_test (Optional) Test set basis \"random-slope\" regression additive random effects model. ordered_cat_vars Vector names ordered categorical variables. unordered_cat_vars Vector names unordered categorical variables. cutpoint_grid_size Maximum size \"grid\" potential cutpoints consider. Default: 100. sigma_leaf_mu Starting value leaf node scale parameter prognostic forest. Calibrated internally 2/num_trees_mu set . sigma_leaf_tau Starting value leaf node scale parameter treatment effect forest. Calibrated internally 1/num_trees_tau set . alpha_mu Prior probability splitting tree depth 0 prognostic forest. Tree split prior combines alpha beta via alpha*(1+node_depth)^-beta. Default: 0.95. alpha_tau Prior probability splitting tree depth 0 treatment effect forest. Tree split prior combines alpha beta via alpha*(1+node_depth)^-beta. Default: 0.25. beta_mu Exponent decreases split probabilities nodes depth > 0 prognostic forest. Tree split prior combines alpha beta via alpha*(1+node_depth)^-beta. Default: 2.0. beta_tau Exponent decreases split probabilities nodes depth > 0 treatment effect forest. Tree split prior combines alpha beta via alpha*(1+node_depth)^-beta. Default: 3.0. min_samples_leaf_mu Minimum allowable size leaf, terms training samples, prognostic forest. Default: 5. min_samples_leaf_tau Minimum allowable size leaf, terms training samples, treatment effect forest. Default: 5. nu Shape parameter IG(nu, nu*lambda) global error variance model. Default: 3. lambda Component scale parameter IG(nu, nu*lambda) global error variance prior. specified, calibrated Sparapani et al (2021). a_leaf_mu Shape parameter IG(a_leaf, b_leaf) leaf node parameter variance model prognostic forest. Default: 3. a_leaf_tau Shape parameter IG(a_leaf, b_leaf) leaf node parameter variance model treatment effect forest. Default: 3. b_leaf_mu Scale parameter IG(a_leaf, b_leaf) leaf node parameter variance model prognostic forest. Calibrated internally 0.5/num_trees set . b_leaf_tau Scale parameter IG(a_leaf, b_leaf) leaf node parameter variance model treatment effect forest. Calibrated internally 0.5/num_trees set . q Quantile used calibrated lambda Sparapani et al (2021). Default: 0.9. sigma2 Starting value global variance parameter. Calibrated internally Sparapani et al (2021) set . num_trees_mu Number trees prognostic forest. Default: 200. num_trees_tau Number trees treatment effect forest. Default: 50. num_gfr Number \"warm-start\" iterations run using grow--root algorithm (Hahn, 2021). Default: 5. num_burnin Number \"burn-\" iterations MCMC sampler. Default: 0. num_mcmc Number \"retained\" iterations MCMC sampler. Default: 100. sample_sigma_global Whether update sigma^2 global error variance parameter based IG(nu, nu*lambda). Default: T. sample_sigma_leaf_mu Whether update sigma_leaf_mu leaf scale variance parameter prognostic forest based IG(a_leaf_mu, b_leaf_mu). Default: T. sample_sigma_leaf_tau Whether update sigma_leaf_tau leaf scale variance parameter treatment effect forest based IG(a_leaf_tau, b_leaf_tau). Default: T. propensity_covariate Whether include propensity score covariate either forests. Enter \"none\" neither, \"mu\" prognostic forest, \"tau\" treatment forest, \"\" forests. \"none\" propensity score provided, estimated (X_train, Z_train) using xgboost. Default: \"mu\". adaptive_coding Whether use \"adaptive coding\" scheme binary treatment variable coded manually (0,1) (-1,1) learned via parameters b_0 b_1 attach outcome model [b_0 (1-Z) + b_1 Z] tau(X). ignored Z binary. Default: T. b_0 Initial value \"control\" group coding parameter. ignored Z binary. Default: -0.5. b_1 Initial value \"treatment\" group coding parameter. ignored Z binary. Default: 0.5. random_seed Integer parameterizing C++ random number generator. specified, C++ random number generator seeded according std::random_device. keep_burnin Whether \"burnin\" samples included cached predictions. Default FALSE. Ignored num_mcmc = 0. keep_gfr Whether \"grow--root\" samples included cached predictions. Default FALSE. Ignored num_mcmc = 0.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/bcf.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Run the Bayesian Causal Forest (BCF) algorithm for regularized causal effect estimation. — bcf","text":"List sampling outputs wrapper around sampled forests (can used -memory prediction new data, serialized JSON disk).","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/bcf.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Run the Bayesian Causal Forest (BCF) algorithm for regularized causal effect estimation. — bcf","text":"","code":"n <- 500 x1 <- rnorm(n) x2 <- rnorm(n) x3 <- rnorm(n) x4 <- as.numeric(rbinom(n,1,0.5)) x5 <- as.numeric(sample(1:3,n,replace=T)) X <- cbind(x1,x2,x3,x4,x5) p <- ncol(X) g <- function(x) {ifelse(x[,5]==1,2,ifelse(x[,5]==2,-1,4))} mu1 <- function(x) {1+g(x)+x[,1]*x[,3]} mu2 <- function(x) {1+g(x)+6*abs(x[,3]-1)} tau1 <- function(x) {rep(3,nrow(x))} tau2 <- function(x) {1+2*x[,2]*x[,4]} mu_x <- mu1(X) tau_x <- tau2(X) pi_x <- 0.8*pnorm((3*mu_x/sd(mu_x)) - 0.5*X[,1]) + 0.05 + runif(n)/10 Z <- rbinom(n,1,pi_x) E_XZ <- mu_x + Z*tau_x snr <- 4 y <- E_XZ + rnorm(n, 0, 1)*(sd(E_XZ)/snr) test_set_pct <- 0.2 n_test <- round(test_set_pct*n) n_train <- n - n_test test_inds <- sort(sample(1:n, n_test, replace = F)) train_inds <- (1:n)[!((1:n) %in% test_inds)] X_test <- X[test_inds,] X_train <- X[train_inds,] pi_test <- pi_x[test_inds] pi_train <- pi_x[train_inds] Z_test <- Z[test_inds] Z_train <- Z[train_inds] y_test <- y[test_inds] y_train <- y[train_inds] mu_test <- mu_x[test_inds] mu_train <- mu_x[train_inds] tau_test <- tau_x[test_inds] tau_train <- tau_x[train_inds] bcf_model <- bcf(X_train = X_train, Z_train = Z_train, y_train = y_train, pi_train = pi_train, X_test = X_test, Z_test = Z_test, pi_test = pi_test, ordered_cat_vars = c(4,5)) # plot(rowMeans(bcf_model$mu_hat_test), mu_test, xlab = \"predicted\", ylab = \"actual\", main = \"Prognostic function\") # abline(0,1,col=\"red\",lty=3,lwd=3) # plot(rowMeans(bcf_model$tau_hat_test), tau_test, xlab = \"predicted\", ylab = \"actual\", main = \"Treatment effect\") # abline(0,1,col=\"red\",lty=3,lwd=3)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/computeForestKernels.html","id":null,"dir":"Reference","previous_headings":"","what":"Compute a kernel from a tree ensemble, defined by the fraction of trees of an ensemble in which two observations fall into the same leaf. — computeForestKernels","title":"Compute a kernel from a tree ensemble, defined by the fraction of trees of an ensemble in which two observations fall into the same leaf. — computeForestKernels","text":"Compute kernel tree ensemble, defined fraction trees ensemble two observations fall leaf.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/computeForestKernels.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Compute a kernel from a tree ensemble, defined by the fraction of trees of an ensemble in which two observations fall into the same leaf. — computeForestKernels","text":"","code":"computeForestKernels(bart_model, X_train, X_test = NULL, forest_num = NULL)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/computeForestKernels.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Compute a kernel from a tree ensemble, defined by the fraction of trees of an ensemble in which two observations fall into the same leaf. — computeForestKernels","text":"bart_model Object type bartmodel corresponding BART model least one sample X_train Matrix \"training\" data. traditional Gaussian process kriging context, corresponds observations outcomes observed. X_test (Optional) Matrix \"test\" data. traditional Gaussian process kriging context, corresponds observations outcomes unobserved must estimated based kernels k(X_test,X_test), k(X_test,X_train), k(X_train,X_train). provided, function compute k(X_train, X_train). forest_num (Option) Index forest sample use kernel computation. provided, function use last forest.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/computeForestKernels.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Compute a kernel from a tree ensemble, defined by the fraction of trees of an ensemble in which two observations fall into the same leaf. — computeForestKernels","text":"List kernel matrices. X_test = NULL, list contains one n_train x n_train matrix, n_train = nrow(X_train). matrix kernel defined W_train %*% t(W_train) W_train matrix n_train rows many columns total leaves ensemble. X_test NULL, list contains two matrices defined W_test %*% t(W_train) W_test %*% t(W_test).","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/computeForestLeafIndices.html","id":null,"dir":"Reference","previous_headings":"","what":"Compute and return a vector representation of a forest's leaf predictions for every observation in a dataset. The vector has a ","title":"Compute and return a vector representation of a forest's leaf predictions for every observation in a dataset. The vector has a ","text":"Compute return vector representation forest's leaf predictions every observation dataset. vector \"column-major\" format can easily re-represented CSC sparse matrix: elements organized first n elements correspond leaf predictions n observations dataset first tree ensemble, next n elements correspond predictions second tree . \"data\" element corresponds uniquely mapped column index corresponds single leaf single tree (.e. tree 1 3 leaves, column indices range 0 2, tree 2's leaf indices begin 3, etc...). Users may pass single dataset (refer \"training set\") two datasets (refer \"training test sets\"). verbiage hints one potential use-case matrix leaf indices define ensemble-based kernel kriging.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/computeForestLeafIndices.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Compute and return a vector representation of a forest's leaf predictions for every observation in a dataset. The vector has a ","text":"","code":"computeForestLeafIndices(bart_model, X_train, X_test = NULL, forest_num = NULL)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/computeForestLeafIndices.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Compute and return a vector representation of a forest's leaf predictions for every observation in a dataset. The vector has a ","text":"bart_model Object type bartmodel corresponding BART model least one sample X_train Matrix \"training\" data. traditional Gaussian process kriging context, corresponds observations outcomes observed. X_test (Optional) Matrix \"test\" data. traditional Gaussian process kriging context, corresponds observations outcomes unobserved must estimated based kernels k(X_test,X_test), k(X_test,X_train), k(X_train,X_train). provided, function compute k(X_train, X_train). forest_num (Option) Index forest sample use kernel computation. provided, function use last forest.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/computeForestLeafIndices.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Compute and return a vector representation of a forest's leaf predictions for every observation in a dataset. The vector has a ","text":"List vectors. X_test = NULL, list contains one vector length n_train * num_trees, n_train = nrow(X_train) num_trees number trees bart_model. X_test NULL, list contains another vector length n_test * num_trees.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/convertBCFModelToJson.html","id":null,"dir":"Reference","previous_headings":"","what":"Convert the persistent aspects of a BCF model to (in-memory) JSON — convertBCFModelToJson","title":"Convert the persistent aspects of a BCF model to (in-memory) JSON — convertBCFModelToJson","text":"Convert persistent aspects BCF model (-memory) JSON","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/convertBCFModelToJson.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Convert the persistent aspects of a BCF model to (in-memory) JSON — convertBCFModelToJson","text":"","code":"convertBCFModelToJson(object)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/convertBCFModelToJson.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Convert the persistent aspects of a BCF model to (in-memory) JSON — convertBCFModelToJson","text":"object Object type bcf containing draws Bayesian causal forest model associated sampling outputs.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/convertBCFModelToJson.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Convert the persistent aspects of a BCF model to (in-memory) JSON — convertBCFModelToJson","text":"Object type CppJson","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/convertBCFModelToJson.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Convert the persistent aspects of a BCF model to (in-memory) JSON — convertBCFModelToJson","text":"","code":"n <- 500 x1 <- rnorm(n) x2 <- rnorm(n) x3 <- rnorm(n) x4 <- as.numeric(rbinom(n,1,0.5)) x5 <- as.numeric(sample(1:3,n,replace=T)) X <- cbind(x1,x2,x3,x4,x5) p <- ncol(X) g <- function(x) {ifelse(x[,5]==1,2,ifelse(x[,5]==2,-1,4))} mu1 <- function(x) {1+g(x)+x[,1]*x[,3]} mu2 <- function(x) {1+g(x)+6*abs(x[,3]-1)} tau1 <- function(x) {rep(3,nrow(x))} tau2 <- function(x) {1+2*x[,2]*x[,4]} mu_x <- mu1(X) tau_x <- tau2(X) pi_x <- 0.8*pnorm((3*mu_x/sd(mu_x)) - 0.5*X[,1]) + 0.05 + runif(n)/10 Z <- rbinom(n,1,pi_x) E_XZ <- mu_x + Z*tau_x snr <- 3 group_ids <- rep(c(1,2), n %/% 2) rfx_coefs <- matrix(c(-1, -1, 1, 1),nrow=2,byrow=T) rfx_basis <- cbind(1, runif(n, -1, 1)) rfx_term <- rowSums(rfx_coefs[group_ids,] * rfx_basis) y <- E_XZ + rfx_term + rnorm(n, 0, 1)*(sd(E_XZ)/snr) test_set_pct <- 0.2 n_test <- round(test_set_pct*n) n_train <- n - n_test test_inds <- sort(sample(1:n, n_test, replace = F)) train_inds <- (1:n)[!((1:n) %in% test_inds)] X_test <- X[test_inds,] X_train <- X[train_inds,] pi_test <- pi_x[test_inds] pi_train <- pi_x[train_inds] Z_test <- Z[test_inds] Z_train <- Z[train_inds] y_test <- y[test_inds] y_train <- y[train_inds] mu_test <- mu_x[test_inds] mu_train <- mu_x[train_inds] tau_test <- tau_x[test_inds] tau_train <- tau_x[train_inds] group_ids_test <- group_ids[test_inds] group_ids_train <- group_ids[train_inds] rfx_basis_test <- rfx_basis[test_inds,] rfx_basis_train <- rfx_basis[train_inds,] rfx_term_test <- rfx_term[test_inds] rfx_term_train <- rfx_term[train_inds] bcf_model <- bcf(X_train = X_train, Z_train = Z_train, y_train = y_train, pi_train = pi_train, group_ids_train = group_ids_train, rfx_basis_train = rfx_basis_train, X_test = X_test, Z_test = Z_test, pi_test = pi_test, group_ids_test = group_ids_test, rfx_basis_test = rfx_basis_test, ordered_cat_vars = c(4,5), num_gfr = 100, num_burnin = 0, num_mcmc = 100, sample_sigma_leaf_mu = T, sample_sigma_leaf_tau = F) # bcf_json <- convertBCFModelToJson(bcf_model)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/createBCFModelFromJson.html","id":null,"dir":"Reference","previous_headings":"","what":"Convert an (in-memory) JSON representation of a BCF model to a BCF model object which can be used for prediction, etc... — createBCFModelFromJson","title":"Convert an (in-memory) JSON representation of a BCF model to a BCF model object which can be used for prediction, etc... — createBCFModelFromJson","text":"Convert (-memory) JSON representation BCF model BCF model object can used prediction, etc...","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/createBCFModelFromJson.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Convert an (in-memory) JSON representation of a BCF model to a BCF model object which can be used for prediction, etc... — createBCFModelFromJson","text":"","code":"createBCFModelFromJson(json_object)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/createBCFModelFromJson.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Convert an (in-memory) JSON representation of a BCF model to a BCF model object which can be used for prediction, etc... — createBCFModelFromJson","text":"json_object Object type CppJson containing Json representation BCF model","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/createBCFModelFromJson.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Convert an (in-memory) JSON representation of a BCF model to a BCF model object which can be used for prediction, etc... — createBCFModelFromJson","text":"Object type bcf","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/createBCFModelFromJson.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Convert an (in-memory) JSON representation of a BCF model to a BCF model object which can be used for prediction, etc... — createBCFModelFromJson","text":"","code":"n <- 500 x1 <- rnorm(n) x2 <- rnorm(n) x3 <- rnorm(n) x4 <- as.numeric(rbinom(n,1,0.5)) x5 <- as.numeric(sample(1:3,n,replace=T)) X <- cbind(x1,x2,x3,x4,x5) p <- ncol(X) g <- function(x) {ifelse(x[,5]==1,2,ifelse(x[,5]==2,-1,4))} mu1 <- function(x) {1+g(x)+x[,1]*x[,3]} mu2 <- function(x) {1+g(x)+6*abs(x[,3]-1)} tau1 <- function(x) {rep(3,nrow(x))} tau2 <- function(x) {1+2*x[,2]*x[,4]} mu_x <- mu1(X) tau_x <- tau2(X) pi_x <- 0.8*pnorm((3*mu_x/sd(mu_x)) - 0.5*X[,1]) + 0.05 + runif(n)/10 Z <- rbinom(n,1,pi_x) E_XZ <- mu_x + Z*tau_x snr <- 3 group_ids <- rep(c(1,2), n %/% 2) rfx_coefs <- matrix(c(-1, -1, 1, 1),nrow=2,byrow=T) rfx_basis <- cbind(1, runif(n, -1, 1)) rfx_term <- rowSums(rfx_coefs[group_ids,] * rfx_basis) y <- E_XZ + rfx_term + rnorm(n, 0, 1)*(sd(E_XZ)/snr) test_set_pct <- 0.2 n_test <- round(test_set_pct*n) n_train <- n - n_test test_inds <- sort(sample(1:n, n_test, replace = F)) train_inds <- (1:n)[!((1:n) %in% test_inds)] X_test <- X[test_inds,] X_train <- X[train_inds,] pi_test <- pi_x[test_inds] pi_train <- pi_x[train_inds] Z_test <- Z[test_inds] Z_train <- Z[train_inds] y_test <- y[test_inds] y_train <- y[train_inds] mu_test <- mu_x[test_inds] mu_train <- mu_x[train_inds] tau_test <- tau_x[test_inds] tau_train <- tau_x[train_inds] group_ids_test <- group_ids[test_inds] group_ids_train <- group_ids[train_inds] rfx_basis_test <- rfx_basis[test_inds,] rfx_basis_train <- rfx_basis[train_inds,] rfx_term_test <- rfx_term[test_inds] rfx_term_train <- rfx_term[train_inds] bcf_model <- bcf(X_train = X_train, Z_train = Z_train, y_train = y_train, pi_train = pi_train, group_ids_train = group_ids_train, rfx_basis_train = rfx_basis_train, X_test = X_test, Z_test = Z_test, pi_test = pi_test, group_ids_test = group_ids_test, rfx_basis_test = rfx_basis_test, ordered_cat_vars = c(4,5), num_gfr = 100, num_burnin = 0, num_mcmc = 100, sample_sigma_leaf_mu = T, sample_sigma_leaf_tau = F) # bcf_json <- convertBCFModelToJson(bcf_model) # bcf_model_roundtrip <- createBCFModelFromJson(bcf_json)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/createBCFModelFromJsonFile.html","id":null,"dir":"Reference","previous_headings":"","what":"Convert a JSON file containing sample information on a trained BCF model to a BCF model object which can be used for prediction, etc... — createBCFModelFromJsonFile","title":"Convert a JSON file containing sample information on a trained BCF model to a BCF model object which can be used for prediction, etc... — createBCFModelFromJsonFile","text":"Convert JSON file containing sample information trained BCF model BCF model object can used prediction, etc...","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/createBCFModelFromJsonFile.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Convert a JSON file containing sample information on a trained BCF model to a BCF model object which can be used for prediction, etc... — createBCFModelFromJsonFile","text":"","code":"createBCFModelFromJsonFile(json_filename)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/createBCFModelFromJsonFile.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Convert a JSON file containing sample information on a trained BCF model to a BCF model object which can be used for prediction, etc... — createBCFModelFromJsonFile","text":"json_filename String filepath, must end \".json\"","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/createBCFModelFromJsonFile.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Convert a JSON file containing sample information on a trained BCF model to a BCF model object which can be used for prediction, etc... — createBCFModelFromJsonFile","text":"Object type bcf","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/createBCFModelFromJsonFile.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Convert a JSON file containing sample information on a trained BCF model to a BCF model object which can be used for prediction, etc... — createBCFModelFromJsonFile","text":"","code":"n <- 500 x1 <- rnorm(n) x2 <- rnorm(n) x3 <- rnorm(n) x4 <- as.numeric(rbinom(n,1,0.5)) x5 <- as.numeric(sample(1:3,n,replace=T)) X <- cbind(x1,x2,x3,x4,x5) p <- ncol(X) g <- function(x) {ifelse(x[,5]==1,2,ifelse(x[,5]==2,-1,4))} mu1 <- function(x) {1+g(x)+x[,1]*x[,3]} mu2 <- function(x) {1+g(x)+6*abs(x[,3]-1)} tau1 <- function(x) {rep(3,nrow(x))} tau2 <- function(x) {1+2*x[,2]*x[,4]} mu_x <- mu1(X) tau_x <- tau2(X) pi_x <- 0.8*pnorm((3*mu_x/sd(mu_x)) - 0.5*X[,1]) + 0.05 + runif(n)/10 Z <- rbinom(n,1,pi_x) E_XZ <- mu_x + Z*tau_x snr <- 3 group_ids <- rep(c(1,2), n %/% 2) rfx_coefs <- matrix(c(-1, -1, 1, 1),nrow=2,byrow=T) rfx_basis <- cbind(1, runif(n, -1, 1)) rfx_term <- rowSums(rfx_coefs[group_ids,] * rfx_basis) y <- E_XZ + rfx_term + rnorm(n, 0, 1)*(sd(E_XZ)/snr) test_set_pct <- 0.2 n_test <- round(test_set_pct*n) n_train <- n - n_test test_inds <- sort(sample(1:n, n_test, replace = F)) train_inds <- (1:n)[!((1:n) %in% test_inds)] X_test <- X[test_inds,] X_train <- X[train_inds,] pi_test <- pi_x[test_inds] pi_train <- pi_x[train_inds] Z_test <- Z[test_inds] Z_train <- Z[train_inds] y_test <- y[test_inds] y_train <- y[train_inds] mu_test <- mu_x[test_inds] mu_train <- mu_x[train_inds] tau_test <- tau_x[test_inds] tau_train <- tau_x[train_inds] group_ids_test <- group_ids[test_inds] group_ids_train <- group_ids[train_inds] rfx_basis_test <- rfx_basis[test_inds,] rfx_basis_train <- rfx_basis[train_inds,] rfx_term_test <- rfx_term[test_inds] rfx_term_train <- rfx_term[train_inds] bcf_model <- bcf(X_train = X_train, Z_train = Z_train, y_train = y_train, pi_train = pi_train, group_ids_train = group_ids_train, rfx_basis_train = rfx_basis_train, X_test = X_test, Z_test = Z_test, pi_test = pi_test, group_ids_test = group_ids_test, rfx_basis_test = rfx_basis_test, ordered_cat_vars = c(4,5), num_gfr = 100, num_burnin = 0, num_mcmc = 100, sample_sigma_leaf_mu = T, sample_sigma_leaf_tau = F) # saveBCFModelToJsonFile(bcf_model, \"test.json\") # bcf_model_roundtrip <- createBCFModelFromJsonFile(\"test.json\")"},{"path":"https://stochastictree.github.io/stochtree-r/reference/createCppJson.html","id":null,"dir":"Reference","previous_headings":"","what":"Create a new (empty) C++ Json object — createCppJson","title":"Create a new (empty) C++ Json object — createCppJson","text":"Create new (empty) C++ Json object","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/createCppJson.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create a new (empty) C++ Json object — createCppJson","text":"","code":"createCppJson()"},{"path":"https://stochastictree.github.io/stochtree-r/reference/createCppJson.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Create a new (empty) C++ Json object — createCppJson","text":"CppJson object","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/createCppJsonFile.html","id":null,"dir":"Reference","previous_headings":"","what":"Create a C++ Json object from a Json file — createCppJsonFile","title":"Create a C++ Json object from a Json file — createCppJsonFile","text":"Create C++ Json object Json file","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/createCppJsonFile.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create a C++ Json object from a Json file — createCppJsonFile","text":"","code":"createCppJsonFile(json_filename)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/createCppJsonFile.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Create a C++ Json object from a Json file — createCppJsonFile","text":"CppJson object","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/createForestContainer.html","id":null,"dir":"Reference","previous_headings":"","what":"Create a container of forest samples — createForestContainer","title":"Create a container of forest samples — createForestContainer","text":"Create container forest samples","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/createForestContainer.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create a container of forest samples — createForestContainer","text":"","code":"createForestContainer(num_trees, output_dimension = 1, is_leaf_constant = F)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/createForestContainer.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Create a container of forest samples — createForestContainer","text":"num_trees Number trees output_dimension Dimensionality outcome model is_leaf_constant Whether leaf constant","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/createForestContainer.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Create a container of forest samples — createForestContainer","text":"ForestSamples object","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/createForestCovariates.html","id":null,"dir":"Reference","previous_headings":"","what":"Preprocess a dataframe of covariate values, converting categorical variables to integers and one-hot encoding if need be. Returns a list including a matrix of preprocessed covariate values and associated tracking. — createForestCovariates","title":"Preprocess a dataframe of covariate values, converting categorical variables to integers and one-hot encoding if need be. Returns a list including a matrix of preprocessed covariate values and associated tracking. — createForestCovariates","text":"Preprocess dataframe covariate values, converting categorical variables integers one-hot encoding need . Returns list including matrix preprocessed covariate values associated tracking.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/createForestCovariates.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Preprocess a dataframe of covariate values, converting categorical variables to integers and one-hot encoding if need be. Returns a list including a matrix of preprocessed covariate values and associated tracking. — createForestCovariates","text":"","code":"createForestCovariates( input_data, ordered_cat_vars = NULL, unordered_cat_vars = NULL )"},{"path":"https://stochastictree.github.io/stochtree-r/reference/createForestCovariates.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Preprocess a dataframe of covariate values, converting categorical variables to integers and one-hot encoding if need be. Returns a list including a matrix of preprocessed covariate values and associated tracking. — createForestCovariates","text":"input_data Dataframe matrix covariates. Users may pre-process categorical variables factors necessary. ordered_cat_vars (Optional) Vector names ordered categorical variables, vector column indices input_data matrix. unordered_cat_vars (Optional) Vector names unordered categorical variables, vector column indices input_data matrix.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/createForestCovariates.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Preprocess a dataframe of covariate values, converting categorical variables to integers and one-hot encoding if need be. Returns a list including a matrix of preprocessed covariate values and associated tracking. — createForestCovariates","text":"List preprocessed data details number type variable, unique categories associated categorical variables, vector feature types needed calls BART BCF.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/createForestCovariates.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Preprocess a dataframe of covariate values, converting categorical variables to integers and one-hot encoding if need be. Returns a list including a matrix of preprocessed covariate values and associated tracking. — createForestCovariates","text":"","code":"cov_df <- data.frame(x1 = 1:5, x2 = 5:1, x3 = 6:10) preprocess_list <- createForestCovariates(cov_df) X <- preprocess_list$X"},{"path":"https://stochastictree.github.io/stochtree-r/reference/createForestCovariatesFromMetadata.html","id":null,"dir":"Reference","previous_headings":"","what":"Preprocess a dataframe of covariate values, converting categorical variables to integers and one-hot encoding if need be. Returns a list including a matrix of preprocessed covariate values and associated tracking. — createForestCovariatesFromMetadata","title":"Preprocess a dataframe of covariate values, converting categorical variables to integers and one-hot encoding if need be. Returns a list including a matrix of preprocessed covariate values and associated tracking. — createForestCovariatesFromMetadata","text":"Preprocess dataframe covariate values, converting categorical variables integers one-hot encoding need . Returns list including matrix preprocessed covariate values associated tracking.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/createForestCovariatesFromMetadata.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Preprocess a dataframe of covariate values, converting categorical variables to integers and one-hot encoding if need be. Returns a list including a matrix of preprocessed covariate values and associated tracking. — createForestCovariatesFromMetadata","text":"","code":"createForestCovariatesFromMetadata(input_data, metadata)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/createForestCovariatesFromMetadata.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Preprocess a dataframe of covariate values, converting categorical variables to integers and one-hot encoding if need be. Returns a list including a matrix of preprocessed covariate values and associated tracking. — createForestCovariatesFromMetadata","text":"input_data Dataframe matrix covariates. Users may pre-process categorical variables factors necessary. metadata List containing information variables, including train set categories categorical variables","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/createForestCovariatesFromMetadata.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Preprocess a dataframe of covariate values, converting categorical variables to integers and one-hot encoding if need be. Returns a list including a matrix of preprocessed covariate values and associated tracking. — createForestCovariatesFromMetadata","text":"Preprocessed data categorical variables appropriately preprocessed","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/createForestCovariatesFromMetadata.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Preprocess a dataframe of covariate values, converting categorical variables to integers and one-hot encoding if need be. Returns a list including a matrix of preprocessed covariate values and associated tracking. — createForestCovariatesFromMetadata","text":"","code":"cov_df <- data.frame(x1 = 1:5, x2 = 5:1, x3 = 6:10) metadata <- list(num_ordered_cat_vars = 0, num_unordered_cat_vars = 0, num_numeric_vars = 3) X_preprocessed <- createForestCovariatesFromMetadata(cov_df, metadata) #> Error in `[.data.frame`(numeric_df, , i): undefined columns selected"},{"path":"https://stochastictree.github.io/stochtree-r/reference/createForestDataset.html","id":null,"dir":"Reference","previous_headings":"","what":"Create a forest dataset object — createForestDataset","title":"Create a forest dataset object — createForestDataset","text":"Create forest dataset object","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/createForestDataset.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create a forest dataset object — createForestDataset","text":"","code":"createForestDataset(covariates, basis = NULL, variance_weights = NULL)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/createForestDataset.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Create a forest dataset object — createForestDataset","text":"covariates Matrix covariates basis (Optional) Matrix bases used define leaf regression variance_weights (Optional) Vector observation-specific variance weights","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/createForestDataset.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Create a forest dataset object — createForestDataset","text":"ForestDataset object","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/createForestKernel.html","id":null,"dir":"Reference","previous_headings":"","what":"Create a ForestKernel object — createForestKernel","title":"Create a ForestKernel object — createForestKernel","text":"Create ForestKernel object","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/createForestKernel.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create a ForestKernel object — createForestKernel","text":"","code":"createForestKernel()"},{"path":"https://stochastictree.github.io/stochtree-r/reference/createForestKernel.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Create a ForestKernel object — createForestKernel","text":"ForestKernel object","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/createForestModel.html","id":null,"dir":"Reference","previous_headings":"","what":"Create a forest model object — createForestModel","title":"Create a forest model object — createForestModel","text":"Create forest model object","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/createForestModel.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create a forest model object — createForestModel","text":"","code":"createForestModel( forest_dataset, feature_types, num_trees, n, alpha, beta, min_samples_leaf )"},{"path":"https://stochastictree.github.io/stochtree-r/reference/createForestModel.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Create a forest model object — createForestModel","text":"forest_dataset ForestDataset object, used initialize forest sampling data structures feature_types Feature types (integers 0 = numeric, 1 = ordered categorical, 2 = unordered categorical) num_trees Number trees forest sampled n Number observations forest_dataset alpha Root node split probability tree prior beta Depth prior penalty tree prior min_samples_leaf Minimum number samples tree leaf","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/createForestModel.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Create a forest model object — createForestModel","text":"ForestModel object","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/createOutcome.html","id":null,"dir":"Reference","previous_headings":"","what":"Create an outcome object — createOutcome","title":"Create an outcome object — createOutcome","text":"Create outcome object","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/createOutcome.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create an outcome object — createOutcome","text":"","code":"createOutcome(outcome)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/createOutcome.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Create an outcome object — createOutcome","text":"outcome Vector outcome values","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/createOutcome.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Create an outcome object — createOutcome","text":"Outcome object","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/createRNG.html","id":null,"dir":"Reference","previous_headings":"","what":"Create an R class that wraps a C++ random number generator — createRNG","title":"Create an R class that wraps a C++ random number generator — createRNG","text":"Create R class wraps C++ random number generator","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/createRNG.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create an R class that wraps a C++ random number generator — createRNG","text":"","code":"createRNG(random_seed = -1)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/createRNG.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Create an R class that wraps a C++ random number generator — createRNG","text":"random_seed (Optional) random seed sampling","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/createRNG.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Create an R class that wraps a C++ random number generator — createRNG","text":"CppRng object","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/createRandomEffectSamples.html","id":null,"dir":"Reference","previous_headings":"","what":"Create a RandomEffectSamples object — createRandomEffectSamples","title":"Create a RandomEffectSamples object — createRandomEffectSamples","text":"Create RandomEffectSamples object","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/createRandomEffectSamples.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create a RandomEffectSamples object — createRandomEffectSamples","text":"","code":"createRandomEffectSamples(num_components, num_groups, random_effects_tracker)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/createRandomEffectSamples.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Create a RandomEffectSamples object — createRandomEffectSamples","text":"num_components Number \"components\" bases defining random effects regression num_groups Number random effects groups random_effects_tracker Object type RandomEffectsTracker","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/createRandomEffectSamples.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Create a RandomEffectSamples object — createRandomEffectSamples","text":"RandomEffectSamples object","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/createRandomEffectsDataset.html","id":null,"dir":"Reference","previous_headings":"","what":"Create a random effects dataset object — createRandomEffectsDataset","title":"Create a random effects dataset object — createRandomEffectsDataset","text":"Create random effects dataset object","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/createRandomEffectsDataset.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create a random effects dataset object — createRandomEffectsDataset","text":"","code":"createRandomEffectsDataset(group_labels, basis, variance_weights = NULL)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/createRandomEffectsDataset.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Create a random effects dataset object — createRandomEffectsDataset","text":"group_labels Vector group labels basis Matrix bases used define random effects regression (intercept-model, pass array ones) variance_weights (Optional) Vector observation-specific variance weights","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/createRandomEffectsDataset.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Create a random effects dataset object — createRandomEffectsDataset","text":"RandomEffectsDataset object","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/createRandomEffectsModel.html","id":null,"dir":"Reference","previous_headings":"","what":"Create a RandomEffectsModel object — createRandomEffectsModel","title":"Create a RandomEffectsModel object — createRandomEffectsModel","text":"Create RandomEffectsModel object","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/createRandomEffectsModel.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create a RandomEffectsModel object — createRandomEffectsModel","text":"","code":"createRandomEffectsModel(num_components, num_groups)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/createRandomEffectsModel.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Create a RandomEffectsModel object — createRandomEffectsModel","text":"num_components Number \"components\" bases defining random effects regression num_groups Number random effects groups","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/createRandomEffectsModel.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Create a RandomEffectsModel object — createRandomEffectsModel","text":"RandomEffectsModel object","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/createRandomEffectsTracker.html","id":null,"dir":"Reference","previous_headings":"","what":"Create a RandomEffectsTracker object — createRandomEffectsTracker","title":"Create a RandomEffectsTracker object — createRandomEffectsTracker","text":"Create RandomEffectsTracker object","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/createRandomEffectsTracker.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create a RandomEffectsTracker object — createRandomEffectsTracker","text":"","code":"createRandomEffectsTracker(rfx_group_indices)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/createRandomEffectsTracker.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Create a RandomEffectsTracker object — createRandomEffectsTracker","text":"rfx_group_indices Integer indices indicating groups used define random effects","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/createRandomEffectsTracker.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Create a RandomEffectsTracker object — createRandomEffectsTracker","text":"RandomEffectsTracker object","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/getRandomEffectSamples.bartmodel.html","id":null,"dir":"Reference","previous_headings":"","what":"Extract raw sample values for each of the random effect parameter terms. — getRandomEffectSamples.bartmodel","title":"Extract raw sample values for each of the random effect parameter terms. — getRandomEffectSamples.bartmodel","text":"Extract raw sample values random effect parameter terms.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/getRandomEffectSamples.bartmodel.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Extract raw sample values for each of the random effect parameter terms. — getRandomEffectSamples.bartmodel","text":"","code":"# S3 method for bartmodel getRandomEffectSamples(object, ...)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/getRandomEffectSamples.bartmodel.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Extract raw sample values for each of the random effect parameter terms. — getRandomEffectSamples.bartmodel","text":"object Object type bcf containing draws Bayesian causal forest model associated sampling outputs.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/getRandomEffectSamples.bartmodel.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Extract raw sample values for each of the random effect parameter terms. — getRandomEffectSamples.bartmodel","text":"List arrays. alpha array dimension (num_components, num_samples) simply vector num_components = 1. xi beta arrays dimension (num_components, num_groups, num_samples) simply matrix num_components = 1. sigma array dimension (num_components, num_samples) simply vector num_components = 1.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/getRandomEffectSamples.bartmodel.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Extract raw sample values for each of the random effect parameter terms. — getRandomEffectSamples.bartmodel","text":"","code":"n <- 100 p <- 5 X <- matrix(runif(n*p), ncol = p) f_XW <- ( ((0 <= X[,1]) & (0.25 > X[,1])) * (-7.5) + ((0.25 <= X[,1]) & (0.5 > X[,1])) * (-2.5) + ((0.5 <= X[,1]) & (0.75 > X[,1])) * (2.5) + ((0.75 <= X[,1]) & (1 > X[,1])) * (7.5) ) snr <- 3 group_ids <- rep(c(1,2), n %/% 2) rfx_coefs <- matrix(c(-1, -1, 1, 1),nrow=2,byrow=T) rfx_basis <- cbind(1, runif(n, -1, 1)) rfx_term <- rowSums(rfx_coefs[group_ids,] * rfx_basis) E_y <- f_XW + rfx_term y <- E_y + rnorm(n, 0, 1)*(sd(E_y)/snr) test_set_pct <- 0.2 n_test <- round(test_set_pct*n) n_train <- n - n_test test_inds <- sort(sample(1:n, n_test, replace = F)) train_inds <- (1:n)[!((1:n) %in% test_inds)] X_test <- X[test_inds,] X_train <- X[train_inds,] y_test <- y[test_inds] y_train <- y[train_inds] group_ids_test <- group_ids[test_inds] group_ids_train <- group_ids[train_inds] rfx_basis_test <- rfx_basis[test_inds,] rfx_basis_train <- rfx_basis[train_inds,] rfx_term_test <- rfx_term[test_inds] rfx_term_train <- rfx_term[train_inds] bart_model <- bart(X_train = X_train, y_train = y_train, group_ids_train = group_ids_train, rfx_basis_train = rfx_basis_train, X_test = X_test, group_ids_test = group_ids_test, rfx_basis_test = rfx_basis_test, num_gfr = 100, num_burnin = 0, num_mcmc = 100, sample_tau = T) rfx_samples <- getRandomEffectSamples(bart_model)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/getRandomEffectSamples.bcf.html","id":null,"dir":"Reference","previous_headings":"","what":"Extract raw sample values for each of the random effect parameter terms. — getRandomEffectSamples.bcf","title":"Extract raw sample values for each of the random effect parameter terms. — getRandomEffectSamples.bcf","text":"Extract raw sample values random effect parameter terms.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/getRandomEffectSamples.bcf.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Extract raw sample values for each of the random effect parameter terms. — getRandomEffectSamples.bcf","text":"","code":"# S3 method for bcf getRandomEffectSamples(object, ...)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/getRandomEffectSamples.bcf.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Extract raw sample values for each of the random effect parameter terms. — getRandomEffectSamples.bcf","text":"object Object type bcf containing draws Bayesian causal forest model associated sampling outputs.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/getRandomEffectSamples.bcf.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Extract raw sample values for each of the random effect parameter terms. — getRandomEffectSamples.bcf","text":"List arrays. alpha array dimension (num_components, num_samples) simply vector num_components = 1. xi beta arrays dimension (num_components, num_groups, num_samples) simply matrix num_components = 1. sigma array dimension (num_components, num_samples) simply vector num_components = 1.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/getRandomEffectSamples.bcf.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Extract raw sample values for each of the random effect parameter terms. — getRandomEffectSamples.bcf","text":"","code":"n <- 500 x1 <- rnorm(n) x2 <- rnorm(n) x3 <- rnorm(n) x4 <- as.numeric(rbinom(n,1,0.5)) x5 <- as.numeric(sample(1:3,n,replace=T)) X <- cbind(x1,x2,x3,x4,x5) p <- ncol(X) g <- function(x) {ifelse(x[,5]==1,2,ifelse(x[,5]==2,-1,4))} mu1 <- function(x) {1+g(x)+x[,1]*x[,3]} mu2 <- function(x) {1+g(x)+6*abs(x[,3]-1)} tau1 <- function(x) {rep(3,nrow(x))} tau2 <- function(x) {1+2*x[,2]*x[,4]} mu_x <- mu1(X) tau_x <- tau2(X) pi_x <- 0.8*pnorm((3*mu_x/sd(mu_x)) - 0.5*X[,1]) + 0.05 + runif(n)/10 Z <- rbinom(n,1,pi_x) E_XZ <- mu_x + Z*tau_x snr <- 3 group_ids <- rep(c(1,2), n %/% 2) rfx_coefs <- matrix(c(-1, -1, 1, 1),nrow=2,byrow=T) rfx_basis <- cbind(1, runif(n, -1, 1)) rfx_term <- rowSums(rfx_coefs[group_ids,] * rfx_basis) y <- E_XZ + rfx_term + rnorm(n, 0, 1)*(sd(E_XZ)/snr) test_set_pct <- 0.2 n_test <- round(test_set_pct*n) n_train <- n - n_test test_inds <- sort(sample(1:n, n_test, replace = F)) train_inds <- (1:n)[!((1:n) %in% test_inds)] X_test <- X[test_inds,] X_train <- X[train_inds,] pi_test <- pi_x[test_inds] pi_train <- pi_x[train_inds] Z_test <- Z[test_inds] Z_train <- Z[train_inds] y_test <- y[test_inds] y_train <- y[train_inds] mu_test <- mu_x[test_inds] mu_train <- mu_x[train_inds] tau_test <- tau_x[test_inds] tau_train <- tau_x[train_inds] group_ids_test <- group_ids[test_inds] group_ids_train <- group_ids[train_inds] rfx_basis_test <- rfx_basis[test_inds,] rfx_basis_train <- rfx_basis[train_inds,] rfx_term_test <- rfx_term[test_inds] rfx_term_train <- rfx_term[train_inds] bcf_model <- bcf(X_train = X_train, Z_train = Z_train, y_train = y_train, pi_train = pi_train, group_ids_train = group_ids_train, rfx_basis_train = rfx_basis_train, X_test = X_test, Z_test = Z_test, pi_test = pi_test, group_ids_test = group_ids_test, rfx_basis_test = rfx_basis_test, ordered_cat_vars = c(4,5), num_gfr = 100, num_burnin = 0, num_mcmc = 100, sample_sigma_leaf_mu = T, sample_sigma_leaf_tau = F) rfx_samples <- getRandomEffectSamples(bcf_model)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/getRandomEffectSamples.html","id":null,"dir":"Reference","previous_headings":"","what":"Generic function for extracting random effect samples from a model object (BCF, BART, etc...) — getRandomEffectSamples","title":"Generic function for extracting random effect samples from a model object (BCF, BART, etc...) — getRandomEffectSamples","text":"Generic function extracting random effect samples model object (BCF, BART, etc...)","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/getRandomEffectSamples.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Generic function for extracting random effect samples from a model object (BCF, BART, etc...) — getRandomEffectSamples","text":"","code":"getRandomEffectSamples(object, ...)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/getRandomEffectSamples.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Generic function for extracting random effect samples from a model object (BCF, BART, etc...) — getRandomEffectSamples","text":"List random effect samples","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/loadForestContainerJson.html","id":null,"dir":"Reference","previous_headings":"","what":"Load a container of forest samples from json — loadForestContainerJson","title":"Load a container of forest samples from json — loadForestContainerJson","text":"Load container forest samples json","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/loadForestContainerJson.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Load a container of forest samples from json — loadForestContainerJson","text":"","code":"loadForestContainerJson(json_object, json_forest_label)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/loadForestContainerJson.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Load a container of forest samples from json — loadForestContainerJson","text":"json_object Object class CppJson json_forest_label Label referring particular forest (.e. \"forest_0\") overall json hierarchy","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/loadForestContainerJson.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Load a container of forest samples from json — loadForestContainerJson","text":"ForestSamples object","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/loadRandomEffectSamplesJson.html","id":null,"dir":"Reference","previous_headings":"","what":"Load a container of forest samples from json — loadRandomEffectSamplesJson","title":"Load a container of forest samples from json — loadRandomEffectSamplesJson","text":"Load container forest samples json","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/loadRandomEffectSamplesJson.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Load a container of forest samples from json — loadRandomEffectSamplesJson","text":"","code":"loadRandomEffectSamplesJson(json_object, json_rfx_num)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/loadRandomEffectSamplesJson.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Load a container of forest samples from json — loadRandomEffectSamplesJson","text":"json_object Object class CppJson json_rfx_num Integer index indicating position random effects term unpacked","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/loadRandomEffectSamplesJson.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Load a container of forest samples from json — loadRandomEffectSamplesJson","text":"RandomEffectSamples object","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/loadScalarJson.html","id":null,"dir":"Reference","previous_headings":"","what":"Load a scalar from json — loadScalarJson","title":"Load a scalar from json — loadScalarJson","text":"Load scalar json","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/loadScalarJson.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Load a scalar from json — loadScalarJson","text":"","code":"loadScalarJson(json_object, json_scalar_label, subfolder_name = NULL)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/loadScalarJson.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Load a scalar from json — loadScalarJson","text":"json_object Object class CppJson json_scalar_label Label referring particular scalar / string value (.e. \"num_samples\") overall json hierarchy subfolder_name (Optional) Name subfolder / hierarchy vector sits","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/loadScalarJson.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Load a scalar from json — loadScalarJson","text":"R vector","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/loadVectorJson.html","id":null,"dir":"Reference","previous_headings":"","what":"Load a vector from json — loadVectorJson","title":"Load a vector from json — loadVectorJson","text":"Load vector json","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/loadVectorJson.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Load a vector from json — loadVectorJson","text":"","code":"loadVectorJson(json_object, json_vector_label, subfolder_name = NULL)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/loadVectorJson.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Load a vector from json — loadVectorJson","text":"json_object Object class CppJson json_vector_label Label referring particular vector (.e. \"sigma2_samples\") overall json hierarchy subfolder_name (Optional) Name subfolder / hierarchy vector sits","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/loadVectorJson.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Load a vector from json — loadVectorJson","text":"R vector","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/oneHotEncode.html","id":null,"dir":"Reference","previous_headings":"","what":"Convert a vector of unordered categorical data (either numeric or character labels) to a ","title":"Convert a vector of unordered categorical data (either numeric or character labels) to a ","text":"procedure assumes reference set observations variable (typically training set used sample forest) already one-hot encoded unique levels training set variable available (passed unique_levels). Test set observations contain categories unique_levels mapped last column matrix","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/oneHotEncode.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Convert a vector of unordered categorical data (either numeric or character labels) to a ","text":"","code":"oneHotEncode(x_input, unique_levels)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/oneHotEncode.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Convert a vector of unordered categorical data (either numeric or character labels) to a ","text":"x_input Vector unordered categorical data (typically either strings integers, function also accepts floating point data). unique_levels Unique values categorical variable used create initial one-hot matrix (typically training set)","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/oneHotEncode.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Convert a vector of unordered categorical data (either numeric or character labels) to a ","text":"Binary one-hot matrix","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/oneHotEncode.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Convert a vector of unordered categorical data (either numeric or character labels) to a ","text":"","code":"x <- sample(1:8, 100, T) x_test <- sample(1:9, 10, T) x_onehot <- oneHotEncode(x_test, levels(factor(x)))"},{"path":"https://stochastictree.github.io/stochtree-r/reference/oneHotInitializeAndEncode.html","id":null,"dir":"Reference","previous_headings":"","what":"Convert a vector of unordered categorical data (either numeric or character labels) to a ","title":"Convert a vector of unordered categorical data (either numeric or character labels) to a ","text":"allow prediction \"unseen\" categories test dataset, procedure pads one-hot matrix blank \"\" column. Test set observations contain categories levels(factor(x_input)) mapped column.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/oneHotInitializeAndEncode.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Convert a vector of unordered categorical data (either numeric or character labels) to a ","text":"","code":"oneHotInitializeAndEncode(x_input)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/oneHotInitializeAndEncode.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Convert a vector of unordered categorical data (either numeric or character labels) to a ","text":"x_input Vector unordered categorical data (typically either strings integers, function also accepts floating point data).","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/oneHotInitializeAndEncode.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Convert a vector of unordered categorical data (either numeric or character labels) to a ","text":"List containing binary one-hot matrix unique levels input variable. unique levels used BCF BART functions.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/oneHotInitializeAndEncode.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Convert a vector of unordered categorical data (either numeric or character labels) to a ","text":"","code":"x <- c(\"a\",\"c\",\"b\",\"c\",\"d\",\"a\",\"c\",\"a\",\"b\",\"d\") x_onehot <- oneHotInitializeAndEncode(x)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/orderedCatInitializeAndPreprocess.html","id":null,"dir":"Reference","previous_headings":"","what":"Run some simple preprocessing of ordered categorical variables, converting ordered levels to integers if necessary, and storing the unique levels of a variable. — orderedCatInitializeAndPreprocess","title":"Run some simple preprocessing of ordered categorical variables, converting ordered levels to integers if necessary, and storing the unique levels of a variable. — orderedCatInitializeAndPreprocess","text":"Run simple preprocessing ordered categorical variables, converting ordered levels integers necessary, storing unique levels variable.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/orderedCatInitializeAndPreprocess.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Run some simple preprocessing of ordered categorical variables, converting ordered levels to integers if necessary, and storing the unique levels of a variable. — orderedCatInitializeAndPreprocess","text":"","code":"orderedCatInitializeAndPreprocess(x_input)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/orderedCatInitializeAndPreprocess.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Run some simple preprocessing of ordered categorical variables, converting ordered levels to integers if necessary, and storing the unique levels of a variable. — orderedCatInitializeAndPreprocess","text":"x_input Vector ordered categorical data. data already stored ordered factor, converted one using default sort order.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/orderedCatInitializeAndPreprocess.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Run some simple preprocessing of ordered categorical variables, converting ordered levels to integers if necessary, and storing the unique levels of a variable. — orderedCatInitializeAndPreprocess","text":"List containing preprocessed vector integer-converted ordered categorical observations unique level original ordered categorical feature.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/orderedCatInitializeAndPreprocess.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Run some simple preprocessing of ordered categorical variables, converting ordered levels to integers if necessary, and storing the unique levels of a variable. — orderedCatInitializeAndPreprocess","text":"","code":"x <- c(\"1. Strongly disagree\", \"3. Neither agree nor disagree\", \"2. Disagree\", \"4. Agree\", \"3. Neither agree nor disagree\", \"5. Strongly agree\", \"4. Agree\") preprocess_list <- orderedCatInitializeAndPreprocess(x) x_preprocessed <- preprocess_list$x_preprocessed"},{"path":"https://stochastictree.github.io/stochtree-r/reference/orderedCatPreprocess.html","id":null,"dir":"Reference","previous_headings":"","what":"Run some simple preprocessing of ordered categorical variables, converting ordered levels to integers if necessary, and storing the unique levels of a variable. — orderedCatPreprocess","title":"Run some simple preprocessing of ordered categorical variables, converting ordered levels to integers if necessary, and storing the unique levels of a variable. — orderedCatPreprocess","text":"Run simple preprocessing ordered categorical variables, converting ordered levels integers necessary, storing unique levels variable.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/orderedCatPreprocess.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Run some simple preprocessing of ordered categorical variables, converting ordered levels to integers if necessary, and storing the unique levels of a variable. — orderedCatPreprocess","text":"","code":"orderedCatPreprocess(x_input, unique_levels, var_name = NULL)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/orderedCatPreprocess.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Run some simple preprocessing of ordered categorical variables, converting ordered levels to integers if necessary, and storing the unique levels of a variable. — orderedCatPreprocess","text":"x_input Vector ordered categorical data. data already stored ordered factor, converted one using default sort order.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/orderedCatPreprocess.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Run some simple preprocessing of ordered categorical variables, converting ordered levels to integers if necessary, and storing the unique levels of a variable. — orderedCatPreprocess","text":"List containing preprocessed vector integer-converted ordered categorical observations unique level original ordered categorical feature.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/orderedCatPreprocess.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Run some simple preprocessing of ordered categorical variables, converting ordered levels to integers if necessary, and storing the unique levels of a variable. — orderedCatPreprocess","text":"","code":"x_levels <- c(\"1. Strongly disagree\", \"2. Disagree\", \"3. Neither agree nor disagree\", \"4. Agree\", \"5. Strongly agree\") x <- c(\"1. Strongly disagree\", \"3. Neither agree nor disagree\", \"2. Disagree\", \"4. Agree\", \"3. Neither agree nor disagree\", \"5. Strongly agree\", \"4. Agree\") x_processed <- orderedCatPreprocess(x, x_levels)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/predict.bartmodel.html","id":null,"dir":"Reference","previous_headings":"","what":"Predict from a sampled BART model on new data — predict.bartmodel","title":"Predict from a sampled BART model on new data — predict.bartmodel","text":"Predict sampled BART model new data","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/predict.bartmodel.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Predict from a sampled BART model on new data — predict.bartmodel","text":"","code":"# S3 method for bartmodel predict( bart, X_test, W_test = NULL, group_ids_test = NULL, rfx_basis_test = NULL, predict_all = F )"},{"path":"https://stochastictree.github.io/stochtree-r/reference/predict.bartmodel.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Predict from a sampled BART model on new data — predict.bartmodel","text":"bart Object type bart containing draws regression forest associated sampling outputs. X_test Covariates used determine tree leaf predictions observation. W_test (Optional) Bases used prediction (e.g. dot product leaf values). Default: NULL. group_ids_test (Optional) Test set group labels used additive random effects model. currently support (plan near future), test set evaluation group labels training set. rfx_basis_test (Optional) Test set basis \"random-slope\" regression additive random effects model. predict_all (Optional) Whether predict model samples stored objects subset burnt-/ GFR samples specified training time. Default FALSE.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/predict.bartmodel.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Predict from a sampled BART model on new data — predict.bartmodel","text":"List prediction matrices. model random effects, list one element -- predictions forest. model random effects, list three elements -- forest predictions, random effects predictions, sum (y_hat).","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/predict.bartmodel.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Predict from a sampled BART model on new data — predict.bartmodel","text":"","code":"n <- 100 p <- 5 X <- matrix(runif(n*p), ncol = p) f_XW <- ( ((0 <= X[,1]) & (0.25 > X[,1])) * (-7.5) + ((0.25 <= X[,1]) & (0.5 > X[,1])) * (-2.5) + ((0.5 <= X[,1]) & (0.75 > X[,1])) * (2.5) + ((0.75 <= X[,1]) & (1 > X[,1])) * (7.5) ) noise_sd <- 1 y <- f_XW + rnorm(n, 0, noise_sd) test_set_pct <- 0.2 n_test <- round(test_set_pct*n) n_train <- n - n_test test_inds <- sort(sample(1:n, n_test, replace = F)) train_inds <- (1:n)[!((1:n) %in% test_inds)] X_test <- X[test_inds,] X_train <- X[train_inds,] y_test <- y[test_inds] y_train <- y[train_inds] bart_model <- bart(X_train = X_train, y_train = y_train) y_hat_test <- predict(bart_model, X_test) # plot(rowMeans(y_hat_test), y_test, xlab = \"predicted\", ylab = \"actual\") # abline(0,1,col=\"red\",lty=3,lwd=3)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/predict.bcf.html","id":null,"dir":"Reference","previous_headings":"","what":"Predict from a sampled BCF model on new data — predict.bcf","title":"Predict from a sampled BCF model on new data — predict.bcf","text":"Predict sampled BCF model new data","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/predict.bcf.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Predict from a sampled BCF model on new data — predict.bcf","text":"","code":"# S3 method for bcf predict( bcf, X_test, Z_test, pi_test = NULL, group_ids_test = NULL, rfx_basis_test = NULL, predict_all = F )"},{"path":"https://stochastictree.github.io/stochtree-r/reference/predict.bcf.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Predict from a sampled BCF model on new data — predict.bcf","text":"bcf Object type bcf containing draws Bayesian causal forest model associated sampling outputs. X_test Covariates used determine tree leaf predictions observation. Z_test Treatments used prediction. pi_test (Optional) Propensities used prediction. group_ids_test (Optional) Test set group labels used additive random effects model. currently support (plan near future), test set evaluation group labels training set. rfx_basis_test (Optional) Test set basis \"random-slope\" regression additive random effects model. predict_all (Optional) Whether predict model samples stored objects subset burnt-/ GFR samples specified training time. Default FALSE.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/predict.bcf.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Predict from a sampled BCF model on new data — predict.bcf","text":"List three (four) nrow(X_test) bcf$num_samples matrices: prognostic function estimates, treatment effect estimates, (possibly) random effects predictions, outcome predictions.","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/predict.bcf.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Predict from a sampled BCF model on new data — predict.bcf","text":"","code":"n <- 500 x1 <- rnorm(n) x2 <- rnorm(n) x3 <- rnorm(n) x4 <- as.numeric(rbinom(n,1,0.5)) x5 <- as.numeric(sample(1:3,n,replace=T)) X <- cbind(x1,x2,x3,x4,x5) p <- ncol(X) g <- function(x) {ifelse(x[,5]==1,2,ifelse(x[,5]==2,-1,4))} mu1 <- function(x) {1+g(x)+x[,1]*x[,3]} mu2 <- function(x) {1+g(x)+6*abs(x[,3]-1)} tau1 <- function(x) {rep(3,nrow(x))} tau2 <- function(x) {1+2*x[,2]*x[,4]} mu_x <- mu1(X) tau_x <- tau2(X) pi_x <- 0.8*pnorm((3*mu_x/sd(mu_x)) - 0.5*X[,1]) + 0.05 + runif(n)/10 Z <- rbinom(n,1,pi_x) E_XZ <- mu_x + Z*tau_x snr <- 4 y <- E_XZ + rnorm(n, 0, 1)*(sd(E_XZ)/snr) test_set_pct <- 0.2 n_test <- round(test_set_pct*n) n_train <- n - n_test test_inds <- sort(sample(1:n, n_test, replace = F)) train_inds <- (1:n)[!((1:n) %in% test_inds)] X_test <- X[test_inds,] X_train <- X[train_inds,] pi_test <- pi_x[test_inds] pi_train <- pi_x[train_inds] Z_test <- Z[test_inds] Z_train <- Z[train_inds] y_test <- y[test_inds] y_train <- y[train_inds] mu_test <- mu_x[test_inds] mu_train <- mu_x[train_inds] tau_test <- tau_x[test_inds] tau_train <- tau_x[train_inds] bcf_model <- bcf(X_train = X_train, Z_train = Z_train, y_train = y_train, pi_train = pi_train, ordered_cat_vars = c(4,5)) preds <- predict(bcf_model, X_test, Z_test, pi_test) # plot(rowMeans(preds$mu_hat), mu_test, xlab = \"predicted\", ylab = \"actual\", main = \"Prognostic function\") # abline(0,1,col=\"red\",lty=3,lwd=3) # plot(rowMeans(preds$tau_hat), tau_test, xlab = \"predicted\", ylab = \"actual\", main = \"Treatment effect\") # abline(0,1,col=\"red\",lty=3,lwd=3)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/sample_sigma2_one_iteration.html","id":null,"dir":"Reference","previous_headings":"","what":"Sample one iteration of the global variance model — sample_sigma2_one_iteration","title":"Sample one iteration of the global variance model — sample_sigma2_one_iteration","text":"Sample one iteration global variance model","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/sample_sigma2_one_iteration.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Sample one iteration of the global variance model — sample_sigma2_one_iteration","text":"","code":"sample_sigma2_one_iteration(residual, rng, nu, lambda)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/sample_sigma2_one_iteration.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Sample one iteration of the global variance model — sample_sigma2_one_iteration","text":"residual Outcome class rng C++ random number generator nu Global variance shape parameter lambda Constitutes scale parameter global variance along nu (.e. scale nu*lambda)","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/sample_tau_one_iteration.html","id":null,"dir":"Reference","previous_headings":"","what":"Sample one iteration of the leaf parameter variance model (only for univariate basis and constant leaf!) — sample_tau_one_iteration","title":"Sample one iteration of the leaf parameter variance model (only for univariate basis and constant leaf!) — sample_tau_one_iteration","text":"Sample one iteration leaf parameter variance model (univariate basis constant leaf!)","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/sample_tau_one_iteration.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Sample one iteration of the leaf parameter variance model (only for univariate basis and constant leaf!) — sample_tau_one_iteration","text":"","code":"sample_tau_one_iteration(forest_samples, rng, a, b, sample_num)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/sample_tau_one_iteration.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Sample one iteration of the leaf parameter variance model (only for univariate basis and constant leaf!) — sample_tau_one_iteration","text":"forest_samples Container forest samples rng C++ random number generator Leaf variance shape parameter b Leaf variance scale parameter sample_num Sample index","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/saveBCFModelToJsonFile.html","id":null,"dir":"Reference","previous_headings":"","what":"Convert the persistent aspects of a BCF model to (in-memory) JSON and save to a file — saveBCFModelToJsonFile","title":"Convert the persistent aspects of a BCF model to (in-memory) JSON and save to a file — saveBCFModelToJsonFile","text":"Convert persistent aspects BCF model (-memory) JSON save file","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/saveBCFModelToJsonFile.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Convert the persistent aspects of a BCF model to (in-memory) JSON and save to a file — saveBCFModelToJsonFile","text":"","code":"saveBCFModelToJsonFile(object, filename)"},{"path":"https://stochastictree.github.io/stochtree-r/reference/saveBCFModelToJsonFile.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Convert the persistent aspects of a BCF model to (in-memory) JSON and save to a file — saveBCFModelToJsonFile","text":"object Object type bcf containing draws Bayesian causal forest model associated sampling outputs. filename String filepath, must end \".json\"","code":""},{"path":"https://stochastictree.github.io/stochtree-r/reference/saveBCFModelToJsonFile.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Convert the persistent aspects of a BCF model to (in-memory) JSON and save to a file — saveBCFModelToJsonFile","text":"","code":"n <- 500 x1 <- rnorm(n) x2 <- rnorm(n) x3 <- rnorm(n) x4 <- as.numeric(rbinom(n,1,0.5)) x5 <- as.numeric(sample(1:3,n,replace=T)) X <- cbind(x1,x2,x3,x4,x5) p <- ncol(X) g <- function(x) {ifelse(x[,5]==1,2,ifelse(x[,5]==2,-1,4))} mu1 <- function(x) {1+g(x)+x[,1]*x[,3]} mu2 <- function(x) {1+g(x)+6*abs(x[,3]-1)} tau1 <- function(x) {rep(3,nrow(x))} tau2 <- function(x) {1+2*x[,2]*x[,4]} mu_x <- mu1(X) tau_x <- tau2(X) pi_x <- 0.8*pnorm((3*mu_x/sd(mu_x)) - 0.5*X[,1]) + 0.05 + runif(n)/10 Z <- rbinom(n,1,pi_x) E_XZ <- mu_x + Z*tau_x snr <- 3 group_ids <- rep(c(1,2), n %/% 2) rfx_coefs <- matrix(c(-1, -1, 1, 1),nrow=2,byrow=T) rfx_basis <- cbind(1, runif(n, -1, 1)) rfx_term <- rowSums(rfx_coefs[group_ids,] * rfx_basis) y <- E_XZ + rfx_term + rnorm(n, 0, 1)*(sd(E_XZ)/snr) test_set_pct <- 0.2 n_test <- round(test_set_pct*n) n_train <- n - n_test test_inds <- sort(sample(1:n, n_test, replace = F)) train_inds <- (1:n)[!((1:n) %in% test_inds)] X_test <- X[test_inds,] X_train <- X[train_inds,] pi_test <- pi_x[test_inds] pi_train <- pi_x[train_inds] Z_test <- Z[test_inds] Z_train <- Z[train_inds] y_test <- y[test_inds] y_train <- y[train_inds] mu_test <- mu_x[test_inds] mu_train <- mu_x[train_inds] tau_test <- tau_x[test_inds] tau_train <- tau_x[train_inds] group_ids_test <- group_ids[test_inds] group_ids_train <- group_ids[train_inds] rfx_basis_test <- rfx_basis[test_inds,] rfx_basis_train <- rfx_basis[train_inds,] rfx_term_test <- rfx_term[test_inds] rfx_term_train <- rfx_term[train_inds] bcf_model <- bcf(X_train = X_train, Z_train = Z_train, y_train = y_train, pi_train = pi_train, group_ids_train = group_ids_train, rfx_basis_train = rfx_basis_train, X_test = X_test, Z_test = Z_test, pi_test = pi_test, group_ids_test = group_ids_test, rfx_basis_test = rfx_basis_test, ordered_cat_vars = c(4,5), num_gfr = 100, num_burnin = 0, num_mcmc = 100, sample_sigma_leaf_mu = T, sample_sigma_leaf_tau = F) # saveBCFModelToJsonFile(bcf_model, \"test.json\")"},{"path":"https://stochastictree.github.io/stochtree-r/reference/stochtree-package.html","id":null,"dir":"Reference","previous_headings":"","what":"stochtree: Stochastic tree ensembles (XBART and BART) for supervised learning and causal inference — stochtree-package","title":"stochtree: Stochastic tree ensembles (XBART and BART) for supervised learning and causal inference — stochtree-package","text":"Stochastic tree ensembles (XBART BART) supervised learning causal inference","code":""},{"path":[]},{"path":"https://stochastictree.github.io/stochtree-r/reference/stochtree-package.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"stochtree: Stochastic tree ensembles (XBART and BART) for supervised learning and causal inference — stochtree-package","text":"Maintainer: Drew Herren drewherrenopensource@gmail.com (ORCID) Authors: Richard Hahn Jared Murray Carlos Carvalho Jingyu ","code":""}] diff --git a/sitemap.xml b/sitemap.xml index 16c427d..0ee0684 100644 --- a/sitemap.xml +++ b/sitemap.xml @@ -79,10 +79,7 @@ https://stochastictree.github.io/stochtree-r/reference/computeForestLeafIndices.html - https://stochastictree.github.io/stochtree-r/reference/convertToJson.bcf.html - - - https://stochastictree.github.io/stochtree-r/reference/convertToJson.html + https://stochastictree.github.io/stochtree-r/reference/convertBCFModelToJson.html https://stochastictree.github.io/stochtree-r/reference/createBCFModelFromJson.html @@ -181,10 +178,7 @@ https://stochastictree.github.io/stochtree-r/reference/sample_tau_one_iteration.html - https://stochastictree.github.io/stochtree-r/reference/saveToJsonFile.bcf.html - - - https://stochastictree.github.io/stochtree-r/reference/saveToJsonFile.html + https://stochastictree.github.io/stochtree-r/reference/saveBCFModelToJsonFile.html https://stochastictree.github.io/stochtree-r/reference/stochtree-package.html