Learn R Programming

bivarhr (version 0.1.5)

prewhiten_bin_glm: Pre-whiten binary series with logistic GLM

Description

Fits a logistic regression (binomial GLM with logit link) to a binary 0/1 response and returns Pearson residuals as a pre-whitened series.

Usage

prewhiten_bin_glm(DT, yname)

Value

A numeric vector of Pearson residuals (one per row in DT

used in the fit).

Arguments

DT

A data.frame or data.table containing the binary response and covariates. It must include at least:

  • The binary variable named by yname (values 0/1).

  • t_norm: normalized time index.

  • Regime, EconCycle, PopDensity, Epidemics, Climate, War.

yname

Character scalar; name of the binary response column in DT. The function checks that all values are in c(0, 1) and stops otherwise.

Examples

Run this code
# \donttest{
if (interactive()) {
  n <- 100
  DT <- data.frame(
    t_norm = seq_len(n) / n,
    I_zero = rbinom(n, 1, 0.3),
    Regime = factor(sample(c("A","B"), n, TRUE)),
    EconCycle = rnorm(n), PopDensity = runif(n),
    Epidemics = rbinom(n, 1, 0.1), Climate = rnorm(n), War = rbinom(n, 1, 0.05)
  )
  r_I_zero <- prewhiten_bin_glm(DT, "I_zero")
  head(r_I_zero)
}
# }

Run the code above in your browser using DataLab