File: methods_gee.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 (73 lines) | stat: -rw-r--r-- 1,781 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
#' @export
standard_error.geeglm <- standard_error.default


#' @export
standard_error.gee <- function(model, method = NULL, ...) {
  cs <- stats::coef(summary(model))

  if (isTRUE(list(...)$robust) || "vcov" %in% names(list(...))) {
    se <- as.vector(cs[, "Robust S.E."])
  } else {
    se <- as.vector(cs[, "Naive S.E."])
  }

  .data_frame(Parameter = .remove_backticks_from_string(rownames(cs)), SE = se)
}


#' @export
p_value.gee <- function(model, method = NULL, ...) {
  cs <- stats::coef(summary(model))
  if (is.null(method)) {
    method <- "any"
  }

  if (isTRUE(list(...)$robust) || "vcov" %in% names(list(...))) {
    p <- 2 * stats::pt(
      abs(cs[, "Estimate"] / cs[, "Robust S.E."]),
      df = insight::get_df(x = model, type = method),
      lower.tail = FALSE
    )
  } else {
    p <- 2 * stats::pt(
      abs(cs[, "Estimate"] / cs[, "Naive S.E."]),
      df = insight::get_df(x = model, type = method),
      lower.tail = FALSE
    )
  }

  .data_frame(
    Parameter = .remove_backticks_from_string(rownames(cs)),
    p = as.vector(p)
  )
}


#' @export
ci.geeglm <- function(x, ci = 0.95, method = "wald", ...) {
  .ci_generic(x, ci = ci, method = method, ...)
}


#' @export
p_value.geeglm <- function(model, method = "wald", ...) {
  stat <- insight::get_statistic(model)

  if (!is.null(stat)) {
    if (identical(method, "residual")) {
      dof <- insight::get_df(model, type = "residual")
      p <- as.vector(2 * stats::pt(
        sqrt(abs(stat$Statistic)),
        df = dof,
        lower.tail = FALSE
      ))
    } else {
      p <- as.vector(1 - stats::pchisq(stat$Statistic, df = 1))
    }
    .data_frame(
      Parameter = stat$Parameter,
      p = p
    )
  }
}