Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Sep 29, 2023
1 parent 6039335 commit 29bf770
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 21 deletions.
43 changes: 34 additions & 9 deletions R/methods_brglm2.R
Original file line number Diff line number Diff line change
Expand Up @@ -144,19 +144,46 @@ p_value.bracl <- function(model, verbose = TRUE, ...) {


#' @export
model_parameters.multinom <- model_parameters.bracl
model_parameters.multinom <- function(model,
ci = 0.95,
ci_method = "normal",
bootstrap = FALSE,
iterations = 1000,
standardize = NULL,
exponentiate = FALSE,
p_adjust = NULL,
summary = getOption("parameters_summary", FALSE),
keep = NULL,
drop = NULL,
verbose = TRUE,
...) {
model_parameters.bracl(
model,
ci = ci,
ci_method = ci_method,
bootstrap = bootstrap,
iterations = iterations,
standardize = standardize,
exponentiate = exponentiate,
p_adjust = p_adjust,
summary = summary,
keep = keep,
drop = drop,
verbose = verbose,
...
)
}


#' @export
ci.multinom <- ci.bracl



ci.multinom <- function(x, ci = 0.95, method = "normal", verbose = TRUE, ...) {
ci.bracl(x, ci = ci, method = method, verbose = verbose, ...)
}


#' @export
degrees_of_freedom.multinom <- function(model, method = NULL, ...) {
if (identical(method, "normal")) {
if (is.null(method) || identical(method, "normal")) {
Inf
} else {
insight::n_obs(model) - model$edf
Expand All @@ -167,8 +194,6 @@ degrees_of_freedom.multinom <- function(model, method = NULL, ...) {
degrees_of_freedom.nnet <- degrees_of_freedom.multinom




#' @export
standard_error.multinom <- function(model, ...) {
se <- tryCatch(
Expand Down Expand Up @@ -214,7 +239,7 @@ standard_error.multinom <- function(model, ...) {


#' @export
p_value.multinom <- function(model, method = "residual", ...) {
p_value.multinom <- function(model, method = "normal", ...) {
stat <- insight::get_statistic(model)
out <- p_value.default(model, method = method, ...)
if (!is.null(stat$Response)) {
Expand Down
37 changes: 25 additions & 12 deletions tests/testthat/test-model_parameters.nnet.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ cns2$Type <- factor(cns2$Type, levels = unique(cns2$Type))
mnnet1 <- nnet::multinom(Type ~ Water + Work, data = cns2, weights = Freq, trace = FALSE)
mnnet2 <- nnet::multinom(cbind(An, Sp, Other) ~ Water + Work, data = cns, trace = FALSE)

ci1 <- confint(mnnet1)
ci2 <- confint(mnnet2)

test_that("model_parameters.multinom - long and wide", {
mpnnet1 <- model_parameters(mnnet1)
mpnnet2 <- model_parameters(mnnet2)
Expand All @@ -22,7 +25,7 @@ test_that("model_parameters.multinom - long and wide", {
mpnnet1,
c(
"Parameter", "Coefficient", "SE", "CI", "CI_low", "CI_high",
"t", "df_error", "p", "Response"
"z", "df_error", "p", "Response"
)
)
expect_identical(
Expand All @@ -38,12 +41,17 @@ test_that("model_parameters.multinom - long and wide", {
c(0.3752, -0.0013, 0.11576, -1.12255, 0.00218, -0.27028),
tolerance = 1e-4
)
expect_equal(
mpnnet1$CI_low,
as.vector(ci1[1:3, 1, 1:2]),
tolerance = 1e-4
)

expect_named(
mpnnet2,
c(
"Parameter", "Coefficient", "SE", "CI", "CI_low", "CI_high",
"t", "df_error", "p", "Response"
"z", "df_error", "p", "Response"
)
)
expect_identical(
Expand All @@ -59,6 +67,11 @@ test_that("model_parameters.multinom - long and wide", {
c(0.3752, -0.0013, 0.11576, -1.12255, 0.00218, -0.27028),
tolerance = 1e-4
)
expect_equal(
mpnnet2$CI_low,
as.vector(ci2[1:3, 1, 1:2]),
tolerance = 1e-4
)
})


Expand All @@ -74,11 +87,11 @@ test_that("ci.multinom - long and wide", {
cinnet1$Response,
c("Sp", "Sp", "Sp", "Other", "Other", "Other")
)
# expect_equal(
# cinnet1$CI_low,
# c(-0.0083, -0.0054, -0.30539, -1.68673, -0.00366, -0.9256),
# tolerance = 1e-4
# )
expect_equal(
cinnet1$CI_low,
as.vector(ci1[1:3, 1, 1:2]),
tolerance = 1e-4
)

expect_identical(
cinnet2$Parameter,
Expand All @@ -88,9 +101,9 @@ test_that("ci.multinom - long and wide", {
cinnet2$Response,
c("Sp", "Sp", "Sp", "Other", "Other", "Other")
)
# expect_equal(
# cinnet2$CI_low,
# c(-0.0083, -0.0054, -0.30539, -1.68673, -0.00366, -0.9256),
# tolerance = 1e-4
# )
expect_equal(
cinnet2$CI_low,
as.vector(ci1[1:3, 1, 1:2]),
tolerance = 1e-4
)
})

0 comments on commit 29bf770

Please sign in to comment.