File: methods_mixor.R

package info (click to toggle)
r-cran-parameters 0.24.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,852 kB
  • sloc: sh: 16; makefile: 2
file content (92 lines) | stat: -rw-r--r-- 2,966 bytes parent folder | download
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
82
83
84
85
86
87
88
89
90
91
92
#' @export
model_parameters.mixor <- function(model,
                                   ci = 0.95,
                                   effects = "all",
                                   bootstrap = FALSE,
                                   iterations = 1000,
                                   standardize = NULL,
                                   exponentiate = FALSE,
                                   include_sigma = FALSE,
                                   p_adjust = NULL,
                                   keep = NULL,
                                   drop = NULL,
                                   verbose = TRUE,
                                   ...) {
  effects <- match.arg(effects, choices = c("all", "fixed", "random"))

  # standardize only works for fixed effects...
  if (!is.null(standardize) && standardize != "refit") {
    if (!missing(effects) && effects != "fixed" && verbose) {
      insight::format_warning(
        "Standardizing coefficients only works for fixed effects of the mixed model."
      )
    }
    effects <- "fixed"
  }

  out <- .model_parameters_generic(
    model = model,
    ci = ci,
    bootstrap = bootstrap,
    iterations = iterations,
    merge_by = c("Parameter", "Effects"),
    standardize = standardize,
    exponentiate = exponentiate,
    effects = effects,
    include_sigma = include_sigma,
    keep_parameters = keep,
    drop_parameters = drop,
    verbose = verbose,
    ...
  )

  attr(out, "object_name") <- insight::safe_deparse_symbol(substitute(model))

  out
}


#' @export
ci.mixor <- function(x, ci = 0.95, effects = "all", ...) {
  effects <- match.arg(effects, choices = c("all", "fixed", "random"))
  .ci_generic(model = x, ci = ci, dof = Inf, effects = effects, ...)
}


#' @export
standard_error.mixor <- function(model, effects = "all", ...) {
  effects <- match.arg(effects, choices = c("all", "fixed", "random"))
  stats <- model$Model[, "Std. Error"]
  parms <- insight::get_parameters(model, effects = effects)

  .data_frame(
    Parameter = parms$Parameter,
    SE = stats[parms$Parameter],
    Effects = parms$Effects
  )
}


#' @export
p_value.mixor <- function(model, effects = "all", ...) {
  effects <- match.arg(effects, choices = c("all", "fixed", "random"))
  stats <- model$Model[, "P(>|z|)"]
  parms <- insight::get_parameters(model, effects = effects)

  .data_frame(
    Parameter = parms$Parameter,
    p = stats[parms$Parameter],
    Effects = parms$Effects
  )
}


#' @export
simulate_model.mixor <- function(model, iterations = 1000, effects = "all", ...) {
  effects <- match.arg(effects, choices = c("all", "fixed", "random"))
  out <- .simulate_model(model, iterations, component = "conditional", effects = effects, ...)

  class(out) <- c("parameters_simulate_model", class(out))
  attr(out, "object_name") <- insight::safe_deparse_symbol(substitute(model))
  out
}