1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
#' @export
model_parameters.MixMod <- model_parameters.glmmTMB
#' @export
ci.MixMod <- function(x,
ci = 0.95,
component = c("all", "conditional", "zi", "zero_inflated"),
verbose = TRUE,
...) {
component <- match.arg(component)
if (is.null(.check_component(x, component, verbose = verbose))) {
return(NULL)
}
.ci_generic(
model = x,
ci = ci,
dof = Inf,
component = component,
...
)
}
#' @export
standard_error.MixMod <- function(model,
effects = "fixed",
component = "all",
verbose = TRUE,
...) {
component <- match.arg(component, choices = c("all", "conditional", "zi", "zero_inflated"))
effects <- match.arg(effects, choices = c("fixed", "random"))
if (effects == "random") {
insight::check_if_installed("lme4")
rand.se <- lme4::ranef(model, post_vars = TRUE)
vars.m <- attr(rand.se, "post_vars")
all_names <- attributes(rand.se)$dimnames
if (dim(vars.m[[1]])[1] == 1) {
rand.se <- sqrt(unlist(vars.m))
} else {
rand.se <- do.call(
rbind,
lapply(vars.m, function(.x) t(as.data.frame(sqrt(diag(.x)))))
)
rownames(rand.se) <- all_names[[1]]
colnames(rand.se) <- all_names[[2]]
rand.se <- list(rand.se)
names(rand.se) <- insight::find_random(model, flatten = TRUE)
}
rand.se
} else {
if (is.null(.check_component(model, component, verbose = verbose))) {
return(NULL)
}
vc <- insight::get_varcov(model, effects = "fixed", component = "all", ...)
se <- sqrt(diag(vc))
x <- .data_frame(
Parameter = names(se),
SE = as.vector(se),
Component = "conditional"
)
zi_parms <- startsWith(x$Parameter, "zi_")
if (any(zi_parms)) {
x$Component[zi_parms] <- "zero_inflated"
x$Parameter[zi_parms] <- gsub("^zi_(.*)", "\\1", x$Parameter[zi_parms])
}
.filter_component(x, component)
}
}
#' @export
simulate_model.MixMod <- simulate_model.glmmTMB
|