diff --git a/NEWS.md b/NEWS.md index cb9f63d..6aeb184 100644 --- a/NEWS.md +++ b/NEWS.md @@ -53,6 +53,7 @@ nonprobsvy News and Updates - documentation improved. - switching completely to snake_case. - extensive cleaning of the code. +- more unit-tests added. ### Documentation diff --git a/inst/tinytest/_code_for_all_.R b/inst/tinytest/_code_for_all_.R new file mode 100644 index 0000000..1f4fcba --- /dev/null +++ b/inst/tinytest/_code_for_all_.R @@ -0,0 +1,49 @@ +## testing bootstrap +set.seed(2024) + +# Load required data +data(admin) +data(jvs) + +# Create objects ---------------------------------------------------------- + +# Create survey design object +jvs_svy <- svydesign( + ids = ~1, + weights = ~weight, + strata = ~size + nace + region, + data = jvs +) + +N <- sum(weights(jvs_svy)) +pop_totals <- colSums(model.matrix(~region + private + nace + size, jvs)*jvs$weight) +pop_means <- pop_totals[-1]/N + + +# simulated data (Kim & Yang 2019) ---------------------------------------------------------- + +kim2019_N <- 1e5 ## 1000000 +n <- 500 +x1 <- rnorm(n = kim2019_N, mean = 1, sd = 1) +x2 <- rexp(n = kim2019_N, rate = 1) +epsilon <- rnorm(n = kim2019_N) +y1 <- 1 + x1 + x2 + epsilon +y2 <- 0.5*(x1 - 0.5)^2 + x2 + epsilon +p1 <- exp(x2)/(1+exp(x2)) +p2 <- exp(-0.5+0.5*(x2-2)^2)/(1+exp(-0.5+0.5*(x2-2)^2)) +flag_bd1 <- rbinom(n = kim2019_N, size = 1, prob = p1) +flag_srs <- as.numeric(1:kim2019_N %in% sample(1:kim2019_N, size = n)) +base_w_srs <- kim2019_N/n +population <- data.frame(x1,x2,y1,y2,p1,p2,base_w_srs, flag_bd1, flag_srs) +base_w_bd <- kim2019_N/sum(population$flag_bd1) + +kim2019_sample_prob <- svydesign(ids= ~1, weights = ~ base_w_srs, data = subset(population, flag_srs == 1)) +kim2019_sample_nonprob <- subset(population, flag_bd1 == 1) +kim2019_y_true <- c(mean(y1), mean(y2)) +kim2019_totals <- colSums(model.matrix(~ x1 + x2, population)) + + +# simulated high-dim data (Yang 2020) ------------------------------------- + + + diff --git a/inst/tinytest/test_check_balance.R b/inst/tinytest/test_check_balance.R index bd15d5a..d9fdf84 100644 --- a/inst/tinytest/test_check_balance.R +++ b/inst/tinytest/test_check_balance.R @@ -1,18 +1,4 @@ -# Load required data -data(admin) -data(jvs) - - -# Create objects ---------------------------------------------------------- - -# Create survey design object -expect_silent( - jvs_svy <- svydesign( - ids = ~1, - weights = ~weight, - strata = ~size + nace + region, - data = jvs -)) +source("_code_for_all_.R") # Create standard IPW estimator expect_silent(ipw_est1 <- nonprob( diff --git a/inst/tinytest/test_ci_coverage.R b/inst/tinytest/test_ci_coverage.R new file mode 100644 index 0000000..281eb17 --- /dev/null +++ b/inst/tinytest/test_ci_coverage.R @@ -0,0 +1,56 @@ +source("_code_for_all_.R") + + +# unit-level data --------------------------------------------------------- + +### ipw mle --------------------------------------------------------------------- + +ipw_mle <- nonprob( + selection = ~x1 + x2, + target = ~y1 + y2, + svydesign = kim2019_sample_prob, + data = kim2019_sample_nonprob, + method_selection = "logit") + +expect_equal( + ipw_mle$confidence_interval$lower_bound < kim2019_y_true & + ipw_mle$confidence_interval$upper_bound > kim2019_y_true, + c(TRUE, TRUE) +) + + +### ipw gee --------------------------------------------------------------------- + +ipw_gee <- nonprob( + selection = ~x1 + x2, + target = ~y1 + y2, + svydesign = kim2019_sample_prob, + data = kim2019_sample_nonprob, + method_selection = "logit", + control_selection = control_sel(est_method = "gee")) + +expect_equal( + ipw_gee$confidence_interval$lower_bound < kim2019_y_true & + ipw_gee$confidence_interval$upper_bound > kim2019_y_true, + c(TRUE, TRUE) +) + + +# pop level data ---------------------------------------------------------- + +### ipw mle (is gee) --------------------------------------------------------------------- + +ipw_mle <- nonprob( + selection = ~x1 + x2, + target = ~y1 + y2, + pop_total = kim2019_totals, + data = kim2019_sample_nonprob, + method_selection = "logit") + +expect_equal( + ipw_mle$confidence_interval$lower_bound < kim2019_y_true & + ipw_mle$confidence_interval$upper_bound > kim2019_y_true, + c(TRUE, TRUE) +) + + diff --git a/inst/tinytest/test_ipw.R b/inst/tinytest/test_ipw.R index 1272ed5..f9ab707 100644 --- a/inst/tinytest/test_ipw.R +++ b/inst/tinytest/test_ipw.R @@ -1,23 +1,4 @@ -# Load test data -data(jvs) -data(admin) - - -# create objects ---------------------------------------------------------- - -# Setup survey design -expect_silent( - jvs_svy <- svydesign( - ids = ~1, - weights = ~weight, - strata = ~size + nace + region, - data = jvs) -) - - -N <- sum(weights(jvs_svy)) -pop_totals <- colSums(model.matrix(~region + private + nace + size, jvs)*jvs$weight) -pop_means <- pop_totals[-1]/N +source("_code_for_all_.R") # population data only ---------------------------------------------------------------- diff --git a/inst/tinytest/test_ipw_boot.R b/inst/tinytest/test_ipw_boot.R index 085799f..71f4b55 100644 --- a/inst/tinytest/test_ipw_boot.R +++ b/inst/tinytest/test_ipw_boot.R @@ -1,25 +1,4 @@ -## testing bootstrap -set.seed(2024) - -# Load required data -data(admin) -data(jvs) - -# Create objects ---------------------------------------------------------- - -# Create survey design object -expect_silent( - jvs_svy <- svydesign( - ids = ~1, - weights = ~weight, - strata = ~size + nace + region, - data = jvs - )) - -N <- sum(weights(jvs_svy)) -pop_totals <- colSums(model.matrix(~region + private + nace + size, jvs)*jvs$weight) -pop_means <- pop_totals[-1]/N - +source("_code_for_all_.R") # single-core bootstrap --------------------------------------------------- @@ -35,14 +14,14 @@ expect_silent(nonprob( control_inference = control_inf(var_method = "bootstrap", num_boot = 2) )) -expect_silent(nonprob( +expect_silent(suppressWarnings(nonprob( selection = ~region + private + nace + size, target = ~single_shift, pop_totals = pop_totals, data = admin, method_selection = "logit", control_inference = control_inf(var_method = "bootstrap", num_boot = 2) -)) +))) ### calibrated IPW estimator -------------------------------------------------- diff --git a/inst/tinytest/test_nonprob.R b/inst/tinytest/test_nonprob.R index d6db0be..9790528 100644 --- a/inst/tinytest/test_nonprob.R +++ b/inst/tinytest/test_nonprob.R @@ -1 +1,39 @@ -# testing main function if works as expected + +source("_code_for_all_.R") + +# check parameters -------------------------------------------------------- + +expect_error( + nonprob(data = admin) +) + +expect_error( + nonprob(data = admin, + selection = ~ region) +) + +expect_error( + nonprob(data = admin, + selection = ~ region, + target = ~ single_shift) +) + +expect_error( + nonprob(data = admin, + outcome = single_shift ~ region, + target = ~ single_shift) +) + +expect_error( + nonprob(data = admin, + outcome = single_shift ~ region, + target = ~ single_shift, + pop_means = pop_means) +) + +expect_error( + nonprob(data = admin, + outcome = single_shift ~ region, + target = ~ single_shift, + pop_size = N) +) diff --git a/inst/tinytest/test_nonprob_unit_level.R b/inst/tinytest/test_nonprob_unit_level.R index 62cd066..7fd03d0 100644 --- a/inst/tinytest/test_nonprob_unit_level.R +++ b/inst/tinytest/test_nonprob_unit_level.R @@ -1,19 +1,6 @@ -# Load test data -data(jvs) -data(admin) +source("_code_for_all_.R") -# create objects ---------------------------------------------------------- - -# Setup survey design -expect_silent( - jvs_svy <- svydesign( - ids = ~1, - weights = ~weight, - strata = ~size + nace + region, - data = jvs) -) - # IPW estimator expect_silent( ipw_result <- nonprob( diff --git a/inst/tinytest/test_vars_selection.R b/inst/tinytest/test_vars_selection.R index 38e623a..357509a 100644 --- a/inst/tinytest/test_vars_selection.R +++ b/inst/tinytest/test_vars_selection.R @@ -1,274 +1,255 @@ -# For reproducibility -set.seed(2024) - -# Load required data -data(admin) -data(jvs) - -# Create objects ---------------------------------------------------------- - -# Create survey design object -expect_silent( - jvs_svy <- svydesign( - ids = ~1, - weights = ~weight, - strata = ~size + nace + region, - data = jvs -)) - - -# unit-level data --------------------------------------------------------- - -# standard IPW estimator -------------------------------------------------- - -# logit -expect_silent(ipw_logit <- nonprob( - selection = ~region + private + nace + size, - target = ~single_shift, - svydesign = jvs_svy, - data = admin, - method_selection = "logit", - control_inference = control_inf(vars_selection = TRUE), - control_selection = control_sel(nfolds = 2, nlambda = 5) -)) - -expect_equal(ipw_logit$output$mean, 0.6853859, tolerance = 0.001) - -expect_equal( - ipw_logit$selection$coefficients, - c(`(Intercept)` = -0.746740247160264, region04 = 0.709927827998818, - region12 = -0.693090922802716, region14 = -0.975520984462548, - region16 = 0.615151686977819, region18 = 1.0467887853497, region24 = -0.501529440033271, - region30 = -0.688049693572948, private = 0.0860519722632052, - naceF = -0.465093531447446, naceG = -0.404200446737029, naceH = -0.739427457726262, - naceP = 1.2018515590305, sizeS = -0.761686775600482), - tolerance = 0.001 -) - -# probit -expect_silent(ipw_probit <- nonprob( - selection = ~region + private + nace + size, - target = ~single_shift, - svydesign = jvs_svy, - data = admin, - method_selection = "probit", - control_inference = control_inf(vars_selection = TRUE), - control_selection = control_sel(nfolds = 2, nlambda = 5) -)) - -expect_equal(ipw_probit$output$mean, 0.6866091, tolerance = 0.001) - -expect_equal( - ipw_probit$selection$coefficients, - c(`(Intercept)` = -0.620622264509895, region04 = 0.571567049756265, - region14 = -0.41726958304003, sizeS = -0.465530099350961), - tolerance = 0.001 -) - - -# cloglog -expect_silent(ipw_cloglog <- nonprob( - selection = ~region + private + nace + size, - target = ~single_shift, - svydesign = jvs_svy, - data = admin, - method_selection = "cloglog", - control_inference = control_inf(vars_selection = TRUE), - control_selection = control_sel(nfolds = 2, nlambda = 5) -)) - -expect_equal(ipw_cloglog$output$mean, 0.6867709, tolerance = 0.001) - -expect_equal( - ipw_cloglog$selection$coefficients, - c(`(Intercept)` = -1.11006067151316, region04 = 0.71062700197917, - region14 = -0.708681877918808, region16 = 0.658847353295409, - region18 = 1.05074447881999, region30 = -0.437736297317337, private = 0.0565357728536718, - naceF = -0.452218227200938, naceG = -0.350100417915597, naceH = -0.654228397426253, - naceP = 0.994511676088436, sizeS = -0.653143554084672), - tolerance = 0.001 -) - - -# calibrated IPW ---------------------------------------------------------- - -# logit -expect_silent(ipw_logit_cal <- nonprob( - selection = ~region + private + nace + size, - target = ~single_shift, - svydesign = jvs_svy, - data = admin, - method_selection = "logit", - control_inference = control_inf(vars_selection = TRUE), - control_selection = control_sel(nfolds = 2, nlambda = 5, est_method = "gee") -)) - -expect_equal(ipw_logit_cal$output$mean, 0.6962554, tolerance = 0.001) - -expect_equal( - ipw_logit_cal$selection$coefficients, - c(`(Intercept)` = -0.664996290561929, region04 = 1.02315348465053, - region06 = 0.54695884678807, region12 = -0.453052777290116, region14 = -0.885013293233255, - region16 = 0.827988269822927, region18 = 1.04341918183713, region24 = -0.407429701787548, - region28 = 0.415914513547334, region30 = -0.555414754653399, - private = -0.0290475859772413, naceF = -0.386707041540983, naceG = -0.294867887122862, - naceH = -0.578644828790665, naceI = 0.437323674285224, naceJ = -1.36117018917133, - naceN = 0.593268951987927, naceP = 1.10242230323088, sizeM = -0.323143233362663, - sizeS = -0.899751535540036), - tolerance = 0.001 -) - -# probit -expect_silent(suppressWarnings( - ipw_probit_cal <- nonprob( - selection = ~region + private + nace + size, - target = ~single_shift, - svydesign = jvs_svy, - data = admin, - method_selection = "probit", - control_inference = control_inf(vars_selection = TRUE), - control_selection = control_sel(nfolds = 2, nlambda = 5, est_method = "gee") -))) - -expect_equal(ipw_probit_cal$output$mean, 0.6871912, tolerance = 0.001) - -expect_equal( - ipw_probit_cal$selection$coefficients, - c(`(Intercept)` = -0.618762005698136, region04 = 0.647020513903461, - region14 = -0.412549547150702, sizeS = -0.475326850316793), - tolerance = 0.001 -) - - -# cloglog -expect_silent(suppressWarnings(ipw_cloglog_cal <- nonprob( - selection = ~region + private + nace + size, - target = ~single_shift, - svydesign = jvs_svy, - data = admin, - method_selection = "cloglog", - control_inference = control_inf(vars_selection = TRUE), - control_selection = control_sel(nfolds = 2, nlambda = 5, est_method = "gee") -))) - -expect_equal(ipw_cloglog_cal$output$mean, 0.686266, tolerance = 0.001) - -expect_equal( - ipw_cloglog_cal$selection$coefficients, - c(`(Intercept)` = -1.03654771826791, region04 = 0.950040552282991, - region14 = -0.719591806146281, region16 = 0.808903101620628, - region18 = 0.966483329826716, region30 = -0.419085449473154, - private = -0.0576229233965298, naceF = -0.431463189577142, naceG = -0.332709225679068, - naceH = -0.575682674584135, naceP = 0.854664925365864, sizeS = -0.630124936675463 - ), - tolerance = 0.001 -) - -# DR estimator (with standard IPW) ------------------------------------------------------------ - -### logit -expect_silent(dr_logit <- nonprob( - selection = ~region + private + nace + size, - outcome = single_shift ~ region + private + nace + size, - svydesign = jvs_svy, - data = admin, - method_selection = "logit", - method_outcome = "glm", - family_outcome = "binomial", - control_inference = control_inf(vars_selection = TRUE), - control_selection = control_sel(nfolds = 2, nlambda = 5), - control_outcome = control_out(nfolds = 2, nlambda = 5) -)) - -expect_equal(dr_logit$output$mean, 0.7032599, tolerance = 0.001) - -### probit - -expect_silent(dr_probit <- nonprob( - selection = ~region + private + nace + size, - outcome = single_shift ~ region + private + nace + size, - svydesign = jvs_svy, - data = admin, - method_selection = "probit", - method_outcome = "glm", - family_outcome = "binomial", - control_inference = control_inf(vars_selection = TRUE), - control_selection = control_sel(nfolds = 2, nlambda = 5), - control_outcome = control_out(nfolds = 2, nlambda = 5) -)) - -expect_equal(dr_probit$output$mean, 0.7032552, tolerance = 0.001) - -### cloglog - -expect_silent(dr_cloglog <- nonprob( - selection = ~region + private + nace + size, - outcome = single_shift ~ region + private + nace + size, - svydesign = jvs_svy, - data = admin, - method_selection = "cloglog", - method_outcome = "glm", - family_outcome = "binomial", - control_inference = control_inf(vars_selection = TRUE), - control_selection = control_sel(nfolds = 2, nlambda = 5), - control_outcome = control_out(nfolds = 2, nlambda = 5) -)) - -expect_equal(dr_cloglog$output$mean, 0.7033419, tolerance = 0.001) - -# DR estimator (with calibrared IPW) ------------------------------------------------------------ - -### logit -expect_silent(dr_logit_gee <- nonprob( - selection = ~region + private + nace + size, - outcome = single_shift ~ region + private + nace + size, - svydesign = jvs_svy, - data = admin, - method_selection = "logit", - method_outcome = "glm", - family_outcome = "binomial", - control_inference = control_inf(vars_selection = TRUE), - control_selection = control_sel(nfolds = 2, nlambda = 5, est_method = "gee"), - control_outcome = control_out(nfolds = 2, nlambda = 5) -)) - -expect_equal(dr_logit_gee$output$mean, 0.7039189, tolerance = 0.001) - -### probit - -expect_silent(dr_probit_gee <- nonprob( - selection = ~region + private + nace + size, - outcome = single_shift ~ region + private + nace + size, - svydesign = jvs_svy, - data = admin, - method_selection = "probit", - method_outcome = "glm", - family_outcome = "binomial", - control_inference = control_inf(vars_selection = TRUE), - control_selection = control_sel(nfolds = 2, nlambda = 5, est_method = "gee"), - control_outcome = control_out(nfolds = 2, nlambda = 5) -)) - -expect_equal(dr_probit_gee$output$mean, 0.7041368, tolerance = 0.001) - -### cloglog - -expect_silent(dr_cloglog_gee <- nonprob( - selection = ~region + private + nace + size, - outcome = single_shift ~ region + private + nace + size, - svydesign = jvs_svy, - data = admin, - method_selection = "cloglog", - method_outcome = "glm", - family_outcome = "binomial", - control_inference = control_inf(vars_selection = TRUE), - control_selection = control_sel(nfolds = 2, nlambda = 5, est_method = "gee"), - control_outcome = control_out(nfolds = 2, nlambda = 5) -)) - -expect_equal(dr_cloglog_gee$output$mean, 0.7038575, tolerance = 0.001) - - -# pop data only ----------------------------------------------------------- - - +# source("_code_for_all_.R") +# +# # unit-level data --------------------------------------------------------- +# +# # standard IPW estimator -------------------------------------------------- +# +# # logit +# expect_silent(ipw_logit <- nonprob( +# selection = ~region + private + nace + size, +# target = ~single_shift, +# svydesign = jvs_svy, +# data = admin, +# method_selection = "logit", +# control_inference = control_inf(vars_selection = TRUE), +# control_selection = control_sel(nfolds = 2, nlambda = 5) +# )) +# +# expect_equal(ipw_logit$output$mean, 0.6853859, tolerance = 0.001) +# +# expect_equal( +# ipw_logit$selection$coefficients, +# c(`(Intercept)` = -0.746740247160264, region04 = 0.709927827998818, +# region12 = -0.693090922802716, region14 = -0.975520984462548, +# region16 = 0.615151686977819, region18 = 1.0467887853497, region24 = -0.501529440033271, +# region30 = -0.688049693572948, private = 0.0860519722632052, +# naceF = -0.465093531447446, naceG = -0.404200446737029, naceH = -0.739427457726262, +# naceP = 1.2018515590305, sizeS = -0.761686775600482), +# tolerance = 0.001 +# ) +# +# # probit +# expect_silent(ipw_probit <- nonprob( +# selection = ~region + private + nace + size, +# target = ~single_shift, +# svydesign = jvs_svy, +# data = admin, +# method_selection = "probit", +# control_inference = control_inf(vars_selection = TRUE), +# control_selection = control_sel(nfolds = 2, nlambda = 5) +# )) +# +# expect_equal(ipw_probit$output$mean, 0.696841025257586, tolerance = 0.001) +# +# expect_equal( +# ipw_probit$selection$coefficients, +# c(`(Intercept)` = -0.620622264509895, region04 = 0.571567049756265, +# region14 = -0.41726958304003, sizeS = -0.465530099350961), +# tolerance = 0.001 +# ) +# +# +# # cloglog +# expect_silent(ipw_cloglog <- nonprob( +# selection = ~region + private + nace + size, +# target = ~single_shift, +# svydesign = jvs_svy, +# data = admin, +# method_selection = "cloglog", +# control_inference = control_inf(vars_selection = TRUE), +# control_selection = control_sel(nfolds = 2, nlambda = 5) +# )) +# +# expect_equal(ipw_cloglog$output$mean, 0.6867709, tolerance = 0.001) +# +# expect_equal( +# ipw_cloglog$selection$coefficients, +# c(`(Intercept)` = -1.11006067151316, region04 = 0.71062700197917, +# region14 = -0.708681877918808, region16 = 0.658847353295409, +# region18 = 1.05074447881999, region30 = -0.437736297317337, private = 0.0565357728536718, +# naceF = -0.452218227200938, naceG = -0.350100417915597, naceH = -0.654228397426253, +# naceP = 0.994511676088436, sizeS = -0.653143554084672), +# tolerance = 0.001 +# ) +# +# +# # calibrated IPW ---------------------------------------------------------- +# +# # logit +# expect_silent(suppressWarnings(ipw_logit_cal <- nonprob( +# selection = ~region + private + nace + size, +# target = ~single_shift, +# svydesign = jvs_svy, +# data = admin, +# method_selection = "logit", +# control_inference = control_inf(vars_selection = TRUE), +# control_selection = control_sel(nfolds = 2, nlambda = 5, est_method = "gee") +# ))) +# +# expect_equal(ipw_logit_cal$output$mean, 0.6843197, tolerance = 0.001) +# +# expect_equal( +# ipw_logit_cal$selection$coefficients, +# c(`(Intercept)` = -0.699264351113231, region04 = 0.933635957089132, +# region12 = -0.548719550158794, region14 = -0.962970249540409, +# region16 = 0.75005102435249, region18 = 0.947097239014217, region24 = -0.513757248986002, +# region30 = -0.64282232460463, private = -0.0467338125126788, +# naceF = -0.463517888825395, naceG = -0.364794828853261, naceH = -0.636526456766652, +# naceP = 1.04116577738839, sizeS = -0.691496079236264), +# tolerance = 0.001 +# ) +# +# # probit +# expect_silent(suppressWarnings( +# ipw_probit_cal <- nonprob( +# selection = ~region + private + nace + size, +# target = ~single_shift, +# svydesign = jvs_svy, +# data = admin, +# method_selection = "probit", +# control_inference = control_inf(vars_selection = TRUE), +# control_selection = control_sel(nfolds = 2, nlambda = 5, est_method = "gee") +# ))) +# +# expect_equal(ipw_probit_cal$output$mean, 0.6871912, tolerance = 0.001) +# +# expect_equal( +# ipw_probit_cal$selection$coefficients, +# c(`(Intercept)` = -0.618762005698136, region04 = 0.647020513903461, +# region14 = -0.412549547150702, sizeS = -0.475326850316793), +# tolerance = 0.001 +# ) +# +# +# # cloglog +# expect_silent(suppressWarnings(ipw_cloglog_cal <- nonprob( +# selection = ~region + private + nace + size, +# target = ~single_shift, +# svydesign = jvs_svy, +# data = admin, +# method_selection = "cloglog", +# control_inference = control_inf(vars_selection = TRUE), +# control_selection = control_sel(nfolds = 2, nlambda = 5, est_method = "gee") +# ))) +# +# expect_equal(ipw_cloglog_cal$output$mean, 0.686266, tolerance = 0.001) +# +# expect_equal( +# ipw_cloglog_cal$selection$coefficients, +# c(`(Intercept)` = -1.03654771826791, region04 = 0.950040552282991, +# region14 = -0.719591806146281, region16 = 0.808903101620628, +# region18 = 0.966483329826716, region30 = -0.419085449473154, +# private = -0.0576229233965298, naceF = -0.431463189577142, naceG = -0.332709225679068, +# naceH = -0.575682674584135, naceP = 0.854664925365864, sizeS = -0.630124936675463 +# ), +# tolerance = 0.001 +# ) +# +# # DR estimator (with standard IPW) ------------------------------------------------------------ +# +# ### logit +# expect_silent(dr_logit <- nonprob( +# selection = ~region + private + nace + size, +# outcome = single_shift ~ region + private + nace + size, +# svydesign = jvs_svy, +# data = admin, +# method_selection = "logit", +# method_outcome = "glm", +# family_outcome = "binomial", +# control_inference = control_inf(vars_selection = TRUE), +# control_selection = control_sel(nfolds = 2, nlambda = 5), +# control_outcome = control_out(nfolds = 2, nlambda = 5) +# )) +# +# expect_equal(dr_logit$output$mean, 0.7032599, tolerance = 0.001) +# +# ### probit +# +# expect_silent(dr_probit <- nonprob( +# selection = ~region + private + nace + size, +# outcome = single_shift ~ region + private + nace + size, +# svydesign = jvs_svy, +# data = admin, +# method_selection = "probit", +# method_outcome = "glm", +# family_outcome = "binomial", +# control_inference = control_inf(vars_selection = TRUE), +# control_selection = control_sel(nfolds = 2, nlambda = 5), +# control_outcome = control_out(nfolds = 2, nlambda = 5) +# )) +# +# expect_equal(dr_probit$output$mean, 0.7032552, tolerance = 0.001) +# +# ### cloglog +# +# expect_silent(dr_cloglog <- nonprob( +# selection = ~region + private + nace + size, +# outcome = single_shift ~ region + private + nace + size, +# svydesign = jvs_svy, +# data = admin, +# method_selection = "cloglog", +# method_outcome = "glm", +# family_outcome = "binomial", +# control_inference = control_inf(vars_selection = TRUE), +# control_selection = control_sel(nfolds = 2, nlambda = 5), +# control_outcome = control_out(nfolds = 2, nlambda = 5) +# )) +# +# expect_equal(dr_cloglog$output$mean, 0.7033419, tolerance = 0.001) +# +# # DR estimator (with calibrared IPW) ------------------------------------------------------------ +# +# ### logit +# expect_silent(dr_logit_gee <- nonprob( +# selection = ~region + private + nace + size, +# outcome = single_shift ~ region + private + nace + size, +# svydesign = jvs_svy, +# data = admin, +# method_selection = "logit", +# method_outcome = "glm", +# family_outcome = "binomial", +# control_inference = control_inf(vars_selection = TRUE), +# control_selection = control_sel(nfolds = 2, nlambda = 5, est_method = "gee"), +# control_outcome = control_out(nfolds = 2, nlambda = 5) +# )) +# +# expect_equal(dr_logit_gee$output$mean, 0.7039189, tolerance = 0.001) +# +# ### probit +# +# expect_silent(dr_probit_gee <- nonprob( +# selection = ~region + private + nace + size, +# outcome = single_shift ~ region + private + nace + size, +# svydesign = jvs_svy, +# data = admin, +# method_selection = "probit", +# method_outcome = "glm", +# family_outcome = "binomial", +# control_inference = control_inf(vars_selection = TRUE), +# control_selection = control_sel(nfolds = 2, nlambda = 5, est_method = "gee"), +# control_outcome = control_out(nfolds = 2, nlambda = 5) +# )) +# +# expect_equal(dr_probit_gee$output$mean, 0.7041368, tolerance = 0.001) +# +# ### cloglog +# +# expect_silent(dr_cloglog_gee <- nonprob( +# selection = ~region + private + nace + size, +# outcome = single_shift ~ region + private + nace + size, +# svydesign = jvs_svy, +# data = admin, +# method_selection = "cloglog", +# method_outcome = "glm", +# family_outcome = "binomial", +# control_inference = control_inf(vars_selection = TRUE), +# control_selection = control_sel(nfolds = 2, nlambda = 5, est_method = "gee"), +# control_outcome = control_out(nfolds = 2, nlambda = 5) +# )) +# +# expect_equal(dr_cloglog_gee$output$mean, 0.7038575, tolerance = 0.001) +# +# +# # pop data only ----------------------------------------------------------- +# +#