prewhiten_bin_glm: Pre-whiten binary series with logistic GLM

View source: R/transfer-entropy.R

prewhiten_bin_glmR Documentation

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)

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.

Value

A numeric vector of Pearson residuals (one per row in DT used in the fit).

Examples


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)
}


bivarhr documentation built on July 7, 2026, 1:06 a.m.