Error in `h(simpleError(msg, call))`: error in evaluating the argument 'x' in selecting a method for function 'as.matrix': 'crossprod' is not an exported object from 'namespace:Matrix'

TOTCIR = ifelse(is.na(TOTCIR), 0, TOTCIR),
TOTSTAFF = ifelse(is.na(TOTSTAFF), 0, TOTSTAFF)
# Same results from conversion vs. creating from scratch ----
"Horvitz-Thompson: Same results from conversion vs. creating from scratch", {
## Convert to generalized bootstrap replicate design
orig_result <- make_quad_form_matrix(variance_estimator = "Horvitz-Thompson",
make_gen_boot_factors(num_replicates = 5, tau = "auto")
"Yates-Grundy: Same results from conversion vs. creating from scratch", {
orig_result <- make_quad_form_matrix(variance_estimator = "Yates-Grundy",
"Ultimate Cluster: Same results from conversion vs. creating from scratch", {
orig_result <- make_quad_form_matrix(variance_estimator = "Ultimate Cluster",
"Multistage Stratified SRS: Same results from conversion vs. creating from scratch", {
as_gen_boot_design(variance_estimator = "Stratified Multistage SRS",
orig_result <- make_quad_form_matrix(variance_estimator = "Stratified Multistage SRS",
"SD1: Same results from conversion vs. creating from scratch", {
orig_result <- make_quad_form_matrix(variance_estimator = "SD1",
"SD2: Same results from conversion vs. creating from scratch", {
orig_result <- make_quad_form_matrix(variance_estimator = "SD2",
"Two-phase Design: Same results from conversion vs. creating from scratch", {
regexp = "The sample quadratic form matrix for this design and variance estimator is not positive semidefinite.", object = {
variance_estimator = list('SD2', 'Ultimate Cluster'),
variance_estimator = list('SD2', 'Ultimate Cluster')
# Rescaling functions work as expected ----
"Rescaling functions work as expected", {
rescale_reps(tau = "auto", min_wgt = 0.05)
object = rescaled_design |> weights(type = "replication"),
object = min(rescaled_matrix), expected = 0.05
desc = "`exact_vcov = TRUE` gives exact variance estimate for totals", {
svytotal(x = ~ Bush + Kerry) |> vcov() |>
expect_equal(object = gen_boot_est, expected = exact_est)
desc = "`exact_vcov = TRUE` throws informative error message if there too few replicates", {
"Bootstrap estimate with many replicates close to expected value", {
exp_value <- svytotal(x = ~ Bush, design = pps_design_yg) |> vcov() |>
svytotal(x = ~ Bush) |> vcov() |> as.numeric()
## Check that variance estimate from bootstrap is similar to expected value
## Check that the average replicate's estimate is similar to expected value
svytotal(x = ~ Bush, return.replicates = TRUE) |>
t.test(mu = coef(svytotal(x = ~ Bush, design = pps_design_yg))) |>
# Works for more specialized classes of survey designs ----
desc = "Returns `tbl_svy` if the input is a `tbl_svy` and 'srvyr' is loaded", {