File: methods_DirichletReg.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 (125 lines) | stat: -rw-r--r-- 3,370 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#' @export
model_parameters.DirichletRegModel <- function(model,
                                               ci = 0.95,
                                               bootstrap = FALSE,
                                               iterations = 1000,
                                               component = "all",
                                               standardize = NULL,
                                               exponentiate = FALSE,
                                               p_adjust = NULL,
                                               keep = NULL,
                                               drop = NULL,
                                               verbose = TRUE,
                                               ...) {
  component <- insight::validate_argument(
    component,
    c("all", "conditional", "precision")
  )
  if (component == "all") {
    merge_by <- c("Parameter", "Component", "Response")
  } else {
    merge_by <- c("Parameter", "Response")
  }

  ## TODO check merge by

  junk <- utils::capture.output({
    out <- .model_parameters_generic(
      model = model,
      ci = ci,
      component = component,
      bootstrap = bootstrap,
      iterations = iterations,
      merge_by = merge_by,
      standardize = standardize,
      exponentiate = exponentiate,
      p_adjust = p_adjust,
      keep_parameters = keep,
      drop_parameters = drop,
      ...
    )
  })

  out$Response[is.na(out$Response)] <- ""
  attr(out, "object_name") <- insight::safe_deparse_symbol(substitute(model))
  out
}


#' @export
ci.DirichletRegModel <- function(x, ci = 0.95, component = "all", ...) {
  component <- insight::validate_argument(
    component,
    c("all", "conditional", "precision")
  )
  params <- insight::get_parameters(x, component = component)
  out <- .ci_generic(model = x, ci = ci, dof = Inf, ...)

  if (is.null(out$Component)) {
    component <- "all"
  }
  if ("Response" %in% colnames(params)) {
    out$Response <- params$Response
  }
  if (component != "all") {
    out <- out[out$Component == component, ]
  }

  out
}


#' @export
standard_error.DirichletRegModel <- function(model, component = "all", ...) {
  component <- insight::validate_argument(
    component,
    c("all", "conditional", "precision")
  )
  params <- insight::get_parameters(model)

  out <- .data_frame(
    Parameter = params$Parameter,
    Response = params$Response,
    SE = as.vector(model$se)
  )

  if (is.null(params$Component)) {
    component <- "all"
  } else {
    out$Component <- params$Component
  }

  if (component != "all") {
    out <- out[out$Component == component, ]
  }

  out
}


#' @export
p_value.DirichletRegModel <- function(model, component = "all", ...) {
  component <- insight::validate_argument(
    component,
    c("all", "conditional", "precision")
  )
  params <- insight::get_parameters(model)

  out <- .data_frame(
    Parameter = params$Parameter,
    Response = params$Response,
    p = as.vector(2 * stats::pnorm(-abs(params$Estimate / model$se)))
  )

  if (is.null(params$Component)) {
    component <- "all"
  } else {
    out$Component <- params$Component
  }

  if (component != "all") {
    out <- out[out$Component == component, ]
  }

  out
}