## ----include = FALSE---------------------------------------------------------- knitr::opts_chunk$set(collapse = TRUE, comment = "#>") ## ----setup-------------------------------------------------------------------- library(EDI) set.seed(20260916) n = 60 X = data.frame( age = round(rnorm(n, 45, 12)), bmi = round(rnorm(n, 27, 4), 1), male = rbinom(n, 1, 0.5) ) true_effect = 2.5 ## ----fixed-design------------------------------------------------------------- des = DesignFixedBernoulli$new(n = n, response_type = "continuous", verbose = FALSE) des$add_all_subjects_to_experiment(X) des$assign_w_to_all_subjects() w = des$get_w() # 0/1 treatment vector y = 10 + true_effect * w + 0.1 * X$age - 0.3 * X$bmi + rnorm(n, sd = 3) des$add_all_subject_responses(y) ## ----ols---------------------------------------------------------------------- inf = InferenceContinOLS$new(des, verbose = FALSE) inf$num_cores = 1L inf$compute_estimate() inf$compute_asymp_confidence_interval(alpha = 0.05) inf$compute_asymp_two_sided_pval() ## ----ols-rand----------------------------------------------------------------- inf$set_seed(1) inf$compute_rand_two_sided_pval(r = 200, show_progress = FALSE) ## ----ols-boot----------------------------------------------------------------- inf$set_seed(1) inf$compute_bootstrap_confidence_interval(alpha = 0.05, B = 200, show_progress = FALSE) ## ----suite-------------------------------------------------------------------- suite = InferenceSuite$new(des) res = suite$run_all_inference(screen = TRUE, plots = FALSE, num_cores = 1L, methods = c("wald", "score", "lik_ratio"), max_secs_per_class = 15) ## ----seq-design--------------------------------------------------------------- des_seq = DesignSeqOneByOneKK21$new(n = n, response_type = "continuous", verbose = FALSE) for (i in seq_len(n)) { w_i = des_seq$add_one_subject_to_experiment_and_assign(X[i, , drop = FALSE]) y_i = 10 + true_effect * w_i + 0.1 * X$age[i] - 0.3 * X$bmi[i] + rnorm(1, sd = 3) des_seq$add_one_subject_response(i, y_i) } ## ----seq-inference------------------------------------------------------------ inf_seq = InferenceContinKKOLSIVWC$new(des_seq, verbose = FALSE) inf_seq$num_cores = 1L inf_seq$compute_estimate() inf_seq$compute_asymp_confidence_interval(alpha = 0.05) inf_seq$set_seed(1) inf_seq$compute_rand_two_sided_pval(r = 200, show_progress = FALSE)