File: methods_averaging.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 (91 lines) | stat: -rw-r--r-- 2,743 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
# classes: .averaging

#################### .averaging

#' @export
model_parameters.averaging <- function(model,
                                       ci = 0.95,
                                       component = "conditional",
                                       exponentiate = FALSE,
                                       p_adjust = NULL,
                                       include_info = getOption("parameters_info", FALSE),
                                       keep = NULL,
                                       drop = NULL,
                                       verbose = TRUE,
                                       ...) {
  component <- insight::validate_argument(component, c("conditional", "full"))

  out <- .model_parameters_generic(
    model = model,
    ci = ci,
    merge_by = "Parameter",
    exponentiate = exponentiate,
    component = component,
    p_adjust = p_adjust,
    keep_parameters = keep,
    drop_parameters = drop,
    include_info = include_info,
    ...
  )

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


#' @export
standard_error.averaging <- function(model, component = "conditional", ...) {
  component <- insight::validate_argument(component, c("conditional", "full"))
  params <- insight::get_parameters(model, component = component)
  if (component == "full") {
    s <- summary(model)$coefmat.full
  } else {
    s <- summary(model)$coefmat.subset
  }
  .data_frame(
    Parameter = .remove_backticks_from_string(params$Parameter),
    SE = as.vector(s[, 3])
  )
}


#' @export
p_value.averaging <- function(model, component = "conditional", ...) {
  component <- insight::validate_argument(component, c("conditional", "full"))
  params <- insight::get_parameters(model, component = component)
  if (component == "full") {
    s <- summary(model)$coefmat.full
  } else {
    s <- summary(model)$coefmat.subset
  }

  # to data frame
  s <- as.data.frame(s)

  # do we have a p-value column based on t?
  pvcn <- which(colnames(s) == "Pr(>|t|)")
  # if not, do we have a p-value column based on z?
  if (length(pvcn) == 0) {
    pvcn <- which(colnames(s) == "Pr(>|z|)")
  }
  # if not, default to ncol
  if (length(pvcn) == 0) {
    if (ncol(s) > 4) {
      pvcn <- 5
    } else {
      pvcn <- 4
    }
  }

  .data_frame(
    Parameter = .remove_backticks_from_string(params$Parameter),
    p = as.vector(s[, pvcn])
  )
}


#' @export
ci.averaging <- function(x, ci = 0.95, component = "conditional", ...) {
  component <- insight::validate_argument(component, c("conditional", "full"))
  .ci_generic(model = x, ci = ci, dof = Inf, component = component)
}