CRAN Package Check Results for Package MRStdCRT

Last updated on 2026-11-28 08:49:20 CET.

Flavor Version Tinstall Tcheck Ttotal Status Flags
r-devel-linux-x86_64-debian-clang 0.1.3 10.70 597.80 608.50 OK
r-devel-linux-x86_64-debian-gcc 0.1.3 8.41 120.06 128.47 ERROR
r-devel-linux-x86_64-fedora-clang 0.1.3 119.76 ERROR
r-devel-linux-x86_64-fedora-gcc 0.1.3 118.07 ERROR
r-devel-windows-x86_64 0.1.3 12.00 504.00 516.00 OK
r-patched-linux-x86_64 0.1.3 11.07 647.74 658.81 OK
r-release-linux-x86_64 0.1.3 10.79 649.82 660.61 OK
r-release-macos-arm64 0.1.3 3.00 134.00 137.00 OK
r-release-macos-x86_64 0.1.3 8.00 1051.00 1059.00 OK
r-release-windows-x86_64 0.1.3 12.00 527.00 539.00 OK
r-oldrel-macos-arm64 0.1.3 4.00 148.00 152.00 OK
r-oldrel-macos-x86_64 0.1.3 8.00 694.00 702.00 OK
r-oldrel-windows-x86_64 0.1.3 17.00 813.00 830.00 OK

Check Details

Version: 0.1.3
Check: tests
Result: ERROR Running ‘estimand-specific.R’ [3s/3s] Running ‘input-encoding.R’ [3s/3s] Running ‘log-inference.R’ [14s/18s] Running ‘regression.R’ [12s/16s] Running ‘weighted-models.R’ [3s/3s] Running the tests in ‘tests/estimand-specific.R’ failed. Complete output: > library(MRStdCRT) > source(file.path("helpers", "weighted-reference.R")) > > specific_unweighted_reference <- function(data, method, family, corstr, + probability, interactions = FALSE) { + d <- reference_data(data, probability) + fixed <- outcome ~ intervention + within_x + between_x + H + if (interactions) fixed <- update(fixed, . ~ . + intervention:within_x + + intervention:between_x) + mixed <- update(fixed, . ~ . + (1 | reference_id)) + model <- switch(method, + GEE = geepack::geeglm(fixed, d, id = reference_id, + family = family, corstr = corstr), + LMM = nlme::lme(fixed, random = ~ 1 | reference_id, data = d), + GLMM = if (family$family == "gaussian") + lme4::lmer(mixed, data = d, REML = FALSE) else + lme4::glmer(mixed, data = d, family = family)) + beta <- if (method == "GEE") coef(model) else lme4::fixef(model) + tau2 <- if (method == "GLMM") + as.data.frame(lme4::VarCorr(model))$vcov[1] else NA_real_ + predictions <- vapply(c(1, 0), function(a) { + nd <- d + nd$intervention <- a + design <- model.matrix(fixed, nd) + stopifnot(setequal(colnames(design), names(beta))) + lp <- drop(design[, names(beta), drop = FALSE] %*% beta) + if (method == "GEE") family$linkinv(lp) + else if (method == "LMM" || family$family == "gaussian") lp + else if (family$family == "binomial") + plogis(lp / sqrt(1 + 3 * tau2 / pi^2)) + else exp(lp + tau2 / 2) + }, numeric(nrow(d))) + reference_aggregate(list(data = d, predictions = predictions)) + } > > specific_reference <- function(data, method, family, corstr, scale, + probability = NULL, interactions = FALSE) { + if (is.null(probability)) { + assignments <- data$intervention[!duplicated(data$cluster)] + probability <- rep(mean(assignments), nrow(data)) + } + weighted <- reference_aggregate(reference_fitting(data, method, family, + corstr, interactions = interactions, probability = probability)) + unweighted <- specific_unweighted_reference(data, method, family, corstr, + probability, interactions) + means <- rbind(cATE = weighted$means["cATE", ], + iATE = unweighted$means["iATE", ]) + list(effect = reference_effect(means, scale), means = means) + } > > specific_deleted_reference <- function(data, method, family, corstr, scale, + probability = NULL, + interactions = FALSE) { + t(vapply(unique(data$cluster), function(id) { + keep <- data$cluster != id + specific_reference(data[keep, ], method, family, corstr, scale, + if (is.null(probability)) NULL else probability[keep], interactions)$effect + }, numeric(3))) + } > > specific_check <- function(data, corstr, scale, probability = NULL, + row_probability = probability, + interactions = FALSE) { + family <- gaussian() + alpha <- .10 + full <- specific_reference(data, "GEE", family, corstr, scale, + row_probability, interactions) + deleted <- specific_deleted_reference(data, "GEE", family, corstr, scale, + row_probability, interactions) + expected <- reference_inference(full$effect, deleted, scale, alpha) + formula <- if (interactions) outcome ~ intervention * x + H else + outcome ~ intervention + x + H + fit <- MRStdCRT_fit(formula, data, "cluster", "intervention", probability, + family = family, method = "GEE", corstr = corstr, scale = scale, + alpha = alpha, model_weights = "estimand_specific") + assert_close(fit$estimate, expected$estimate) + assert_close(fit$ics, expected$ics) + stopifnot(identical(names(fit$ics), c("statistic", "p.value")), + identical(fit$model_weights, "estimand_specific"), + identical(rownames(fit$estimate), c("cATE", "iATE")), + fit$m == length(unique(data$cluster))) + # The paired difference retains covariance between the two model fits. + naive_se <- sqrt(sum(expected$se[1:2]^2)) + stopifnot(abs(expected$se[3] - naive_se) > 1e-4) + if (scale == "RR") { + logged <- MRStdCRT_fit(formula, data, "cluster", "intervention", probability, + family = family, method = "GEE", corstr = corstr, scale = scale, + alpha = alpha, model_weights = "estimand_specific", inference_scale = "log") + m <- nrow(deleted) + log_deleted <- log(deleted[, 1:2, drop = FALSE]) + log_se <- sqrt((m - 1) / m * + colSums(sweep(log_deleted, 2, colMeans(log_deleted))^2)) + cutoff <- qt(1 - alpha / 2, m - 1) + assert_close(logged$log_se, log_se) + assert_close(logged$estimate[["CI lower"]], + exp(log(full$effect[1:2]) - cutoff * log_se)) + assert_close(logged$estimate[["CI upper"]], + exp(log(full$effect[1:2]) + cutoff * log_se)) + assert_close(logged$estimate[["p-value"]], + 2 * pt(abs(log(full$effect[1:2]) / log_se), m - 1, lower.tail = FALSE)) + stopifnot(identical(logged$ics, fit$ics), + identical(logged$estimate[, 1:2], fit$estimate[, 1:2])) + } + invisible(fit) + } > > # Named probabilities follow cluster IDs despite shuffled rows and names. > d <- weighted_fixture() > d$outcome <- d$continuous + .25 * d$intervention * d$x > set.seed(1892) > d <- d[sample(nrow(d)), ] > p <- setNames(seq(.4, .65, length.out = 12), as.character(1:12)) > specific_check(d, "exchangeable", "RR", probability = p[12:1], + row_probability = unname(p[as.character(d$cluster)]), + interactions = TRUE) Error: 'passing a bare name as 'component' to model.extract()' is deprecated. Use 'the string "id"' instead. See help("Deprecated") Execution halted Running the tests in ‘tests/input-encoding.R’ failed. Complete output: > library(MRStdCRT) > source(file.path("helpers", "weighted-reference.R")) > > # Encodings and user column labels must not change the statistical analysis. > # In particular, passing character IDs directly to geeglm can silently coerce > # them to NA; comparison of both point estimates and paired inference catches > # that problem rather than merely checking whether the call succeeds. > encoding_no_warning <- function(expr) { + withCallingHandlers(force(expr), warning = function(w) { + stop("Unexpected input-encoding warning: ", conditionMessage(w), + call. = FALSE) + }) + } > > encoding_point <- function(data, weights, method = "GEE", family = gaussian(), + formula = outcome ~ intervention * x + H, + cluster = "cluster") { + point <- getFromNamespace(if (weights == "estimand_specific") + "mrs_estimand_specific_point" else "MRStdCRT_point", "MRStdCRT") + args <- list(formula = formula, data = data, cluster = cluster, + trt = "intervention", trtprob = rep(.5, nrow(data)), + family = family, corstr = "exchangeable", method = method, + scale = "RD") + if (weights != "estimand_specific") args$model_weights <- weights + encoding_no_warning(do.call(point, args))[[3L]] + } > > encoding_weights <- c("none", "inverse_cluster_size", "estimand_specific") > encoding_data <- weighted_fixture() > encoding_configs <- list( + list(method = "GEE", family = gaussian(), outcome = "continuous"), + list(method = "GEE", family = binomial(), outcome = "binary"), + list(method = "LMM", family = gaussian(), outcome = "continuous"), + list(method = "GLMM", family = gaussian(), outcome = "continuous"), + list(method = "GLMM", family = binomial(), outcome = "binary")) > > # TRUE/FALSE is an explicitly supported representation of the 0/1 assignment. > # Exercise prediction as well as fitting, including treatment interactions. > for (config in encoding_configs) { + numeric_data <- encoding_data + numeric_data$outcome <- numeric_data[[config$outcome]] + logical_data <- numeric_data + logical_data$intervention <- as.logical(logical_data$intervention) + for (weights in encoding_weights) { + expected <- encoding_point(numeric_data, weights, config$method, + config$family) + actual <- encoding_point(logical_data, weights, config$method, + config$family) + assert_close(actual, expected, label = paste(config$method, weights, + "logical treatment")) + } + } Error: Unexpected input-encoding warning: 'passing a bare name as 'component' to model.extract()' is deprecated. Use 'the string "id"' instead. See help("Deprecated") Execution halted Running the tests in ‘tests/weighted-models.R’ failed. Complete output: > library(MRStdCRT) > source(file.path("helpers", "weighted-reference.R")) > > d <- weighted_fixture() > configurations <- list( + list(method = "GEE", family = gaussian(), outcome = "continuous"), + list(method = "GEE", family = binomial(), outcome = "binary"), + list(method = "GEE", family = poisson(), outcome = "count"), + list(method = "LMM", family = gaussian(), outcome = "continuous"), + list(method = "GLMM", family = gaussian(), outcome = "continuous"), + list(method = "GLMM", family = binomial(), outcome = "binary"), + list(method = "GLMM", family = poisson(), outcome = "count")) > for (config in configurations) { + d$outcome <- d[[config$outcome]] + correlations <- if (config$method == "GEE") + c("independence", "exchangeable") else "exchangeable" + for (correlation in correlations) { + ref <- reference_fitting(d, config$method, config$family, correlation) + compare_internal_predictions(ref, config$method, config$family, correlation) + aggregation <- reference_aggregate(ref) + actual <- package_point(d, config$method, config$family, correlation) + assert_close(actual, reference_effect(aggregation$means), 1e-7, 1e-7) + stopifnot(max(abs(aggregation$correction)) > 1e-6) + } + } Error: 'passing a bare name as 'component' to model.extract()' is deprecated. Use 'the string "id"' instead. See help("Deprecated") Execution halted Flavor: r-devel-linux-x86_64-debian-gcc

Version: 0.1.3
Check: re-building of vignette outputs
Result: ERROR Error(s) in re-building vignettes: ... --- re-building ‘introduction.Rmd’ using rmarkdown Quitting from introduction.Rmd:475-482 [weighted-gee-example] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ <error/rlang_error> Error: ! Full-data fit [weighted GEE, gaussian(identity)]: GEE backend warning: 'passing a bare name as 'component' to model.extract()' is deprecated. Use 'the string "id"' instead. See help("Deprecated") --- Backtrace: ▆ 1. └─MRStdCRT::MRStdCRT_fit(...) 2. └─base::tryCatch(...) 3. └─base (local) tryCatchList(expr, classes, parentenv, handlers) 4. └─base (local) tryCatchOne(expr, names, parentenv, handlers[[1L]]) 5. └─value[[3L]](cond) 6. └─MRStdCRT (local) point_error(e, "Full-data fit") ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Error: processing vignette 'introduction.Rmd' failed with diagnostics: Full-data fit [weighted GEE, gaussian(identity)]: GEE backend warning: 'passing a bare name as 'component' to model.extract()' is deprecated. Use 'the string "id"' instead. See help("Deprecated") --- failed re-building ‘introduction.Rmd’ SUMMARY: processing the following file failed: ‘introduction.Rmd’ Error: Vignette re-building failed. Execution halted Flavor: r-devel-linux-x86_64-debian-gcc

Version: 0.1.3
Check: tests
Result: ERROR Running ‘estimand-specific.R’ Running ‘input-encoding.R’ Running ‘log-inference.R’ [14s/15s] Running ‘regression.R’ [12s/12s] Running ‘weighted-models.R’ Running the tests in ‘tests/estimand-specific.R’ failed. Complete output: > library(MRStdCRT) > source(file.path("helpers", "weighted-reference.R")) > > specific_unweighted_reference <- function(data, method, family, corstr, + probability, interactions = FALSE) { + d <- reference_data(data, probability) + fixed <- outcome ~ intervention + within_x + between_x + H + if (interactions) fixed <- update(fixed, . ~ . + intervention:within_x + + intervention:between_x) + mixed <- update(fixed, . ~ . + (1 | reference_id)) + model <- switch(method, + GEE = geepack::geeglm(fixed, d, id = reference_id, + family = family, corstr = corstr), + LMM = nlme::lme(fixed, random = ~ 1 | reference_id, data = d), + GLMM = if (family$family == "gaussian") + lme4::lmer(mixed, data = d, REML = FALSE) else + lme4::glmer(mixed, data = d, family = family)) + beta <- if (method == "GEE") coef(model) else lme4::fixef(model) + tau2 <- if (method == "GLMM") + as.data.frame(lme4::VarCorr(model))$vcov[1] else NA_real_ + predictions <- vapply(c(1, 0), function(a) { + nd <- d + nd$intervention <- a + design <- model.matrix(fixed, nd) + stopifnot(setequal(colnames(design), names(beta))) + lp <- drop(design[, names(beta), drop = FALSE] %*% beta) + if (method == "GEE") family$linkinv(lp) + else if (method == "LMM" || family$family == "gaussian") lp + else if (family$family == "binomial") + plogis(lp / sqrt(1 + 3 * tau2 / pi^2)) + else exp(lp + tau2 / 2) + }, numeric(nrow(d))) + reference_aggregate(list(data = d, predictions = predictions)) + } > > specific_reference <- function(data, method, family, corstr, scale, + probability = NULL, interactions = FALSE) { + if (is.null(probability)) { + assignments <- data$intervention[!duplicated(data$cluster)] + probability <- rep(mean(assignments), nrow(data)) + } + weighted <- reference_aggregate(reference_fitting(data, method, family, + corstr, interactions = interactions, probability = probability)) + unweighted <- specific_unweighted_reference(data, method, family, corstr, + probability, interactions) + means <- rbind(cATE = weighted$means["cATE", ], + iATE = unweighted$means["iATE", ]) + list(effect = reference_effect(means, scale), means = means) + } > > specific_deleted_reference <- function(data, method, family, corstr, scale, + probability = NULL, + interactions = FALSE) { + t(vapply(unique(data$cluster), function(id) { + keep <- data$cluster != id + specific_reference(data[keep, ], method, family, corstr, scale, + if (is.null(probability)) NULL else probability[keep], interactions)$effect + }, numeric(3))) + } > > specific_check <- function(data, corstr, scale, probability = NULL, + row_probability = probability, + interactions = FALSE) { + family <- gaussian() + alpha <- .10 + full <- specific_reference(data, "GEE", family, corstr, scale, + row_probability, interactions) + deleted <- specific_deleted_reference(data, "GEE", family, corstr, scale, + row_probability, interactions) + expected <- reference_inference(full$effect, deleted, scale, alpha) + formula <- if (interactions) outcome ~ intervention * x + H else + outcome ~ intervention + x + H + fit <- MRStdCRT_fit(formula, data, "cluster", "intervention", probability, + family = family, method = "GEE", corstr = corstr, scale = scale, + alpha = alpha, model_weights = "estimand_specific") + assert_close(fit$estimate, expected$estimate) + assert_close(fit$ics, expected$ics) + stopifnot(identical(names(fit$ics), c("statistic", "p.value")), + identical(fit$model_weights, "estimand_specific"), + identical(rownames(fit$estimate), c("cATE", "iATE")), + fit$m == length(unique(data$cluster))) + # The paired difference retains covariance between the two model fits. + naive_se <- sqrt(sum(expected$se[1:2]^2)) + stopifnot(abs(expected$se[3] - naive_se) > 1e-4) + if (scale == "RR") { + logged <- MRStdCRT_fit(formula, data, "cluster", "intervention", probability, + family = family, method = "GEE", corstr = corstr, scale = scale, + alpha = alpha, model_weights = "estimand_specific", inference_scale = "log") + m <- nrow(deleted) + log_deleted <- log(deleted[, 1:2, drop = FALSE]) + log_se <- sqrt((m - 1) / m * + colSums(sweep(log_deleted, 2, colMeans(log_deleted))^2)) + cutoff <- qt(1 - alpha / 2, m - 1) + assert_close(logged$log_se, log_se) + assert_close(logged$estimate[["CI lower"]], + exp(log(full$effect[1:2]) - cutoff * log_se)) + assert_close(logged$estimate[["CI upper"]], + exp(log(full$effect[1:2]) + cutoff * log_se)) + assert_close(logged$estimate[["p-value"]], + 2 * pt(abs(log(full$effect[1:2]) / log_se), m - 1, lower.tail = FALSE)) + stopifnot(identical(logged$ics, fit$ics), + identical(logged$estimate[, 1:2], fit$estimate[, 1:2])) + } + invisible(fit) + } > > # Named probabilities follow cluster IDs despite shuffled rows and names. > d <- weighted_fixture() > d$outcome <- d$continuous + .25 * d$intervention * d$x > set.seed(1892) > d <- d[sample(nrow(d)), ] > p <- setNames(seq(.4, .65, length.out = 12), as.character(1:12)) > specific_check(d, "exchangeable", "RR", probability = p[12:1], + row_probability = unname(p[as.character(d$cluster)]), + interactions = TRUE) Error: 'passing a bare name as 'component' to model.extract()' is deprecated. Use 'the string "id"' instead. See help("Deprecated") Execution halted Running the tests in ‘tests/input-encoding.R’ failed. Complete output: > library(MRStdCRT) > source(file.path("helpers", "weighted-reference.R")) > > # Encodings and user column labels must not change the statistical analysis. > # In particular, passing character IDs directly to geeglm can silently coerce > # them to NA; comparison of both point estimates and paired inference catches > # that problem rather than merely checking whether the call succeeds. > encoding_no_warning <- function(expr) { + withCallingHandlers(force(expr), warning = function(w) { + stop("Unexpected input-encoding warning: ", conditionMessage(w), + call. = FALSE) + }) + } > > encoding_point <- function(data, weights, method = "GEE", family = gaussian(), + formula = outcome ~ intervention * x + H, + cluster = "cluster") { + point <- getFromNamespace(if (weights == "estimand_specific") + "mrs_estimand_specific_point" else "MRStdCRT_point", "MRStdCRT") + args <- list(formula = formula, data = data, cluster = cluster, + trt = "intervention", trtprob = rep(.5, nrow(data)), + family = family, corstr = "exchangeable", method = method, + scale = "RD") + if (weights != "estimand_specific") args$model_weights <- weights + encoding_no_warning(do.call(point, args))[[3L]] + } > > encoding_weights <- c("none", "inverse_cluster_size", "estimand_specific") > encoding_data <- weighted_fixture() > encoding_configs <- list( + list(method = "GEE", family = gaussian(), outcome = "continuous"), + list(method = "GEE", family = binomial(), outcome = "binary"), + list(method = "LMM", family = gaussian(), outcome = "continuous"), + list(method = "GLMM", family = gaussian(), outcome = "continuous"), + list(method = "GLMM", family = binomial(), outcome = "binary")) > > # TRUE/FALSE is an explicitly supported representation of the 0/1 assignment. > # Exercise prediction as well as fitting, including treatment interactions. > for (config in encoding_configs) { + numeric_data <- encoding_data + numeric_data$outcome <- numeric_data[[config$outcome]] + logical_data <- numeric_data + logical_data$intervention <- as.logical(logical_data$intervention) + for (weights in encoding_weights) { + expected <- encoding_point(numeric_data, weights, config$method, + config$family) + actual <- encoding_point(logical_data, weights, config$method, + config$family) + assert_close(actual, expected, label = paste(config$method, weights, + "logical treatment")) + } + } Error: Unexpected input-encoding warning: 'passing a bare name as 'component' to model.extract()' is deprecated. Use 'the string "id"' instead. See help("Deprecated") Execution halted Running the tests in ‘tests/weighted-models.R’ failed. Complete output: > library(MRStdCRT) > source(file.path("helpers", "weighted-reference.R")) > > d <- weighted_fixture() > configurations <- list( + list(method = "GEE", family = gaussian(), outcome = "continuous"), + list(method = "GEE", family = binomial(), outcome = "binary"), + list(method = "GEE", family = poisson(), outcome = "count"), + list(method = "LMM", family = gaussian(), outcome = "continuous"), + list(method = "GLMM", family = gaussian(), outcome = "continuous"), + list(method = "GLMM", family = binomial(), outcome = "binary"), + list(method = "GLMM", family = poisson(), outcome = "count")) > for (config in configurations) { + d$outcome <- d[[config$outcome]] + correlations <- if (config$method == "GEE") + c("independence", "exchangeable") else "exchangeable" + for (correlation in correlations) { + ref <- reference_fitting(d, config$method, config$family, correlation) + compare_internal_predictions(ref, config$method, config$family, correlation) + aggregation <- reference_aggregate(ref) + actual <- package_point(d, config$method, config$family, correlation) + assert_close(actual, reference_effect(aggregation$means), 1e-7, 1e-7) + stopifnot(max(abs(aggregation$correction)) > 1e-6) + } + } Error: 'passing a bare name as 'component' to model.extract()' is deprecated. Use 'the string "id"' instead. See help("Deprecated") Execution halted Flavor: r-devel-linux-x86_64-fedora-clang

Version: 0.1.3
Check: re-building of vignette outputs
Result: ERROR Error(s) in re-building vignettes: --- re-building ‘introduction.Rmd’ using rmarkdown Quitting from introduction.Rmd:475-482 [weighted-gee-example] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ <error/rlang_error> Error: ! Full-data fit [weighted GEE, gaussian(identity)]: GEE backend warning: 'passing a bare name as 'component' to model.extract()' is deprecated. Use 'the string "id"' instead. See help("Deprecated") --- Backtrace: ▆ 1. └─MRStdCRT::MRStdCRT_fit(...) 2. └─base::tryCatch(...) 3. └─base (local) tryCatchList(expr, classes, parentenv, handlers) 4. └─base (local) tryCatchOne(expr, names, parentenv, handlers[[1L]]) 5. └─value[[3L]](cond) 6. └─MRStdCRT (local) point_error(e, "Full-data fit") ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Error: processing vignette 'introduction.Rmd' failed with diagnostics: Full-data fit [weighted GEE, gaussian(identity)]: GEE backend warning: 'passing a bare name as 'component' to model.extract()' is deprecated. Use 'the string "id"' instead. See help("Deprecated") --- failed re-building ‘introduction.Rmd’ SUMMARY: processing the following file failed: ‘introduction.Rmd’ Error: Vignette re-building failed. Execution halted Flavors: r-devel-linux-x86_64-fedora-clang, r-devel-linux-x86_64-fedora-gcc

Version: 0.1.3
Check: tests
Result: ERROR Running ‘estimand-specific.R’ Running ‘input-encoding.R’ Running ‘log-inference.R’ [13s/13s] Running ‘regression.R’ [11s/11s] Running ‘weighted-models.R’ Running the tests in ‘tests/estimand-specific.R’ failed. Complete output: > library(MRStdCRT) > source(file.path("helpers", "weighted-reference.R")) > > specific_unweighted_reference <- function(data, method, family, corstr, + probability, interactions = FALSE) { + d <- reference_data(data, probability) + fixed <- outcome ~ intervention + within_x + between_x + H + if (interactions) fixed <- update(fixed, . ~ . + intervention:within_x + + intervention:between_x) + mixed <- update(fixed, . ~ . + (1 | reference_id)) + model <- switch(method, + GEE = geepack::geeglm(fixed, d, id = reference_id, + family = family, corstr = corstr), + LMM = nlme::lme(fixed, random = ~ 1 | reference_id, data = d), + GLMM = if (family$family == "gaussian") + lme4::lmer(mixed, data = d, REML = FALSE) else + lme4::glmer(mixed, data = d, family = family)) + beta <- if (method == "GEE") coef(model) else lme4::fixef(model) + tau2 <- if (method == "GLMM") + as.data.frame(lme4::VarCorr(model))$vcov[1] else NA_real_ + predictions <- vapply(c(1, 0), function(a) { + nd <- d + nd$intervention <- a + design <- model.matrix(fixed, nd) + stopifnot(setequal(colnames(design), names(beta))) + lp <- drop(design[, names(beta), drop = FALSE] %*% beta) + if (method == "GEE") family$linkinv(lp) + else if (method == "LMM" || family$family == "gaussian") lp + else if (family$family == "binomial") + plogis(lp / sqrt(1 + 3 * tau2 / pi^2)) + else exp(lp + tau2 / 2) + }, numeric(nrow(d))) + reference_aggregate(list(data = d, predictions = predictions)) + } > > specific_reference <- function(data, method, family, corstr, scale, + probability = NULL, interactions = FALSE) { + if (is.null(probability)) { + assignments <- data$intervention[!duplicated(data$cluster)] + probability <- rep(mean(assignments), nrow(data)) + } + weighted <- reference_aggregate(reference_fitting(data, method, family, + corstr, interactions = interactions, probability = probability)) + unweighted <- specific_unweighted_reference(data, method, family, corstr, + probability, interactions) + means <- rbind(cATE = weighted$means["cATE", ], + iATE = unweighted$means["iATE", ]) + list(effect = reference_effect(means, scale), means = means) + } > > specific_deleted_reference <- function(data, method, family, corstr, scale, + probability = NULL, + interactions = FALSE) { + t(vapply(unique(data$cluster), function(id) { + keep <- data$cluster != id + specific_reference(data[keep, ], method, family, corstr, scale, + if (is.null(probability)) NULL else probability[keep], interactions)$effect + }, numeric(3))) + } > > specific_check <- function(data, corstr, scale, probability = NULL, + row_probability = probability, + interactions = FALSE) { + family <- gaussian() + alpha <- .10 + full <- specific_reference(data, "GEE", family, corstr, scale, + row_probability, interactions) + deleted <- specific_deleted_reference(data, "GEE", family, corstr, scale, + row_probability, interactions) + expected <- reference_inference(full$effect, deleted, scale, alpha) + formula <- if (interactions) outcome ~ intervention * x + H else + outcome ~ intervention + x + H + fit <- MRStdCRT_fit(formula, data, "cluster", "intervention", probability, + family = family, method = "GEE", corstr = corstr, scale = scale, + alpha = alpha, model_weights = "estimand_specific") + assert_close(fit$estimate, expected$estimate) + assert_close(fit$ics, expected$ics) + stopifnot(identical(names(fit$ics), c("statistic", "p.value")), + identical(fit$model_weights, "estimand_specific"), + identical(rownames(fit$estimate), c("cATE", "iATE")), + fit$m == length(unique(data$cluster))) + # The paired difference retains covariance between the two model fits. + naive_se <- sqrt(sum(expected$se[1:2]^2)) + stopifnot(abs(expected$se[3] - naive_se) > 1e-4) + if (scale == "RR") { + logged <- MRStdCRT_fit(formula, data, "cluster", "intervention", probability, + family = family, method = "GEE", corstr = corstr, scale = scale, + alpha = alpha, model_weights = "estimand_specific", inference_scale = "log") + m <- nrow(deleted) + log_deleted <- log(deleted[, 1:2, drop = FALSE]) + log_se <- sqrt((m - 1) / m * + colSums(sweep(log_deleted, 2, colMeans(log_deleted))^2)) + cutoff <- qt(1 - alpha / 2, m - 1) + assert_close(logged$log_se, log_se) + assert_close(logged$estimate[["CI lower"]], + exp(log(full$effect[1:2]) - cutoff * log_se)) + assert_close(logged$estimate[["CI upper"]], + exp(log(full$effect[1:2]) + cutoff * log_se)) + assert_close(logged$estimate[["p-value"]], + 2 * pt(abs(log(full$effect[1:2]) / log_se), m - 1, lower.tail = FALSE)) + stopifnot(identical(logged$ics, fit$ics), + identical(logged$estimate[, 1:2], fit$estimate[, 1:2])) + } + invisible(fit) + } > > # Named probabilities follow cluster IDs despite shuffled rows and names. > d <- weighted_fixture() > d$outcome <- d$continuous + .25 * d$intervention * d$x > set.seed(1892) > d <- d[sample(nrow(d)), ] > p <- setNames(seq(.4, .65, length.out = 12), as.character(1:12)) > specific_check(d, "exchangeable", "RR", probability = p[12:1], + row_probability = unname(p[as.character(d$cluster)]), + interactions = TRUE) Error: 'passing a bare name as 'component' to model.extract()' is deprecated. Use 'the string "id"' instead. See help("Deprecated") Execution halted Running the tests in ‘tests/input-encoding.R’ failed. Complete output: > library(MRStdCRT) > source(file.path("helpers", "weighted-reference.R")) > > # Encodings and user column labels must not change the statistical analysis. > # In particular, passing character IDs directly to geeglm can silently coerce > # them to NA; comparison of both point estimates and paired inference catches > # that problem rather than merely checking whether the call succeeds. > encoding_no_warning <- function(expr) { + withCallingHandlers(force(expr), warning = function(w) { + stop("Unexpected input-encoding warning: ", conditionMessage(w), + call. = FALSE) + }) + } > > encoding_point <- function(data, weights, method = "GEE", family = gaussian(), + formula = outcome ~ intervention * x + H, + cluster = "cluster") { + point <- getFromNamespace(if (weights == "estimand_specific") + "mrs_estimand_specific_point" else "MRStdCRT_point", "MRStdCRT") + args <- list(formula = formula, data = data, cluster = cluster, + trt = "intervention", trtprob = rep(.5, nrow(data)), + family = family, corstr = "exchangeable", method = method, + scale = "RD") + if (weights != "estimand_specific") args$model_weights <- weights + encoding_no_warning(do.call(point, args))[[3L]] + } > > encoding_weights <- c("none", "inverse_cluster_size", "estimand_specific") > encoding_data <- weighted_fixture() > encoding_configs <- list( + list(method = "GEE", family = gaussian(), outcome = "continuous"), + list(method = "GEE", family = binomial(), outcome = "binary"), + list(method = "LMM", family = gaussian(), outcome = "continuous"), + list(method = "GLMM", family = gaussian(), outcome = "continuous"), + list(method = "GLMM", family = binomial(), outcome = "binary")) > > # TRUE/FALSE is an explicitly supported representation of the 0/1 assignment. > # Exercise prediction as well as fitting, including treatment interactions. > for (config in encoding_configs) { + numeric_data <- encoding_data + numeric_data$outcome <- numeric_data[[config$outcome]] + logical_data <- numeric_data + logical_data$intervention <- as.logical(logical_data$intervention) + for (weights in encoding_weights) { + expected <- encoding_point(numeric_data, weights, config$method, + config$family) + actual <- encoding_point(logical_data, weights, config$method, + config$family) + assert_close(actual, expected, label = paste(config$method, weights, + "logical treatment")) + } + } Error: Unexpected input-encoding warning: 'passing a bare name as 'component' to model.extract()' is deprecated. Use 'the string "id"' instead. See help("Deprecated") Execution halted Running the tests in ‘tests/weighted-models.R’ failed. Complete output: > library(MRStdCRT) > source(file.path("helpers", "weighted-reference.R")) > > d <- weighted_fixture() > configurations <- list( + list(method = "GEE", family = gaussian(), outcome = "continuous"), + list(method = "GEE", family = binomial(), outcome = "binary"), + list(method = "GEE", family = poisson(), outcome = "count"), + list(method = "LMM", family = gaussian(), outcome = "continuous"), + list(method = "GLMM", family = gaussian(), outcome = "continuous"), + list(method = "GLMM", family = binomial(), outcome = "binary"), + list(method = "GLMM", family = poisson(), outcome = "count")) > for (config in configurations) { + d$outcome <- d[[config$outcome]] + correlations <- if (config$method == "GEE") + c("independence", "exchangeable") else "exchangeable" + for (correlation in correlations) { + ref <- reference_fitting(d, config$method, config$family, correlation) + compare_internal_predictions(ref, config$method, config$family, correlation) + aggregation <- reference_aggregate(ref) + actual <- package_point(d, config$method, config$family, correlation) + assert_close(actual, reference_effect(aggregation$means), 1e-7, 1e-7) + stopifnot(max(abs(aggregation$correction)) > 1e-6) + } + } Error: 'passing a bare name as 'component' to model.extract()' is deprecated. Use 'the string "id"' instead. See help("Deprecated") Execution halted Flavor: r-devel-linux-x86_64-fedora-gcc