R/methods_gee.R

Defines functions p_value.geeglm ci.geeglm p_value.gee standard_error.gee

#' @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 = degrees_of_freedom(model, method = method),
      lower.tail = FALSE
    )
  } else {
    p <- 2 * stats::pt(
      abs(cs[, "Estimate"] / cs[, "Naive S.E."]),
      df = degrees_of_freedom(model, method = 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 <- degrees_of_freedom(model, method = "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
    )
  }
}

Try the parameters package in your browser

Any scripts or data that you put into this service are public.

parameters documentation built on Nov. 2, 2023, 6:13 p.m.