Learn R Programming

bivarhr (version 0.1.5)

prewhiten_rate_glm: Pre-whiten rate series with log-link Gaussian GLM

Description

Fits a Gaussian GLM with log link to a rate variable (count/exposure) without offset, applying a small lower bound to avoid zeros, and returns Pearson residuals as a pre-whitened series.

Usage

prewhiten_rate_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 rate variable and covariates. It must include at least:

  • The rate variable named by yname.

  • t_norm: normalized time index.

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

yname

Character scalar; name of the rate response column in DT.

Details

The response y is first sanitized via y_safe <- pmax(y, 1e-8) to avoid taking logs of zero. The model is then fit with glm(family = gaussian(link = "log")).

Examples

Run this code
# \donttest{
if (interactive()) {
  n <- 100
  DT <- data.frame(
    t_norm = seq_len(n) / n,
    I_rate = rgamma(n, 2, 1),
    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_rate <- prewhiten_rate_glm(DT, "I_rate")
  head(r_I_rate)
}
# }

Run the code above in your browser using DataLab