View source: R/transfer-entropy.R
| prewhiten_rate_glm | R Documentation |
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.
prewhiten_rate_glm(DT, yname)
DT |
A
|
yname |
Character scalar; name of the rate response column in
|
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")).
A numeric vector of Pearson residuals (one per row in DT
used in the fit).
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)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.