Nothing
test_that("standard methods return named estimates, covariance and intervals", {
z <- small_inputs()
result <- ijse_draws(z$draws, z$ll)
expect_equal(coef(result), colMeans(z$draws))
expect_equal(vcov(result), result$vcov)
ci <- confint(result, parm = c("b", "a"), level = 0.9)
expect_equal(rownames(ci), c("b", "a"))
expect_equal(unname(ci[, 2] - ci[, 1]), 2 * qnorm(0.95) * unname(result$se[c("b", "a")]))
expect_equal(confint(result, parm = 1), confint(result, parm = "a"))
expect_s3_class(summary(result), "summary.ijse")
expect_output(print(result), "normal approximation")
expect_equal(summary(result)$coefficients[, "IJ_SE"], result$se)
for (level in list(0, 1, NA_real_, Inf, c(0.8, 0.9), "95%")) {
expect_error(confint(result, level = level), "level")
}
for (parm in list(0, -1, 3, 1.5, c(1, 1), "missing", NA_integer_)) {
expect_error(confint(result, parm = parm), "parm")
}
expect_error(vcov(result, typo = TRUE), "Unused")
})
test_that("chain diagnostics preserve single-parameter matrix dimensions", {
z <- small_inputs(48)
ids <- rep(c("chain-a", "chain-b"), each = 24)
for (vars in list("a", c("a", "b"))) {
result <- ijse_draws(z$draws, z$ll, variables = vars, chain_id = ids)
expect_equal(dim(result$diagnostics$chain_se), c(2L, length(vars)))
expect_named(result$diagnostics$rhat, vars)
for (i in seq_along(unique(ids))) {
rows <- which(ids == unique(ids)[i])
separate <- ijse_draws(z$draws[rows, , drop = FALSE], z$ll[rows, , drop = FALSE],
variables = vars)
expect_equal(unname(result$diagnostics$chain_se[i, ]), unname(separate$se))
}
}
result <- ijse_draws(z$draws, z$ll, chain_id = c(rep("a", 20), rep("b", 28)))
expect_null(result$diagnostics$rhat)
expect_error(ijse_draws(z$draws, z$ll, chain_id = c("a", rep("b", 47))), "at least two")
expect_error(ijse_draws(z$draws, z$ll, chain_id = c(NA, rep("b", 47))), "non-missing")
})
test_that("posterior draws arrays retain the correct chain and draw order", {
z <- small_inputs(48)
arr <- array(z$draws, dim = c(24, 2, 2),
dimnames = list(NULL, NULL, c("a", "b")))
arr <- posterior::as_draws_array(arr)
result <- ijse_draws(arr, z$ll)
baseline <- ijse_draws(z$draws, z$ll, chain_id = rep(1:2, each = 24))
expect_equal(vcov(result), vcov(baseline))
expect_equal(result$diagnostics$chain_se, baseline$diagnostics$chain_se)
for (converter in list(posterior::as_draws_df, posterior::as_draws_list,
posterior::as_draws_rvars)) {
converted <- ijse_draws(converter(arr), z$ll)
expect_equal(vcov(converted), vcov(baseline))
expect_equal(converted$diagnostics$chain_se, baseline$diagnostics$chain_se)
}
single_chain <- ijse_draws(z$draws[, "a", drop = FALSE], z$ll,
chain_id = rep(1L, nrow(z$draws)))
expect_equal(dim(single_chain$diagnostics$chain_se), c(1L, 1L))
})
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.