Learn R Programming

pda (version 1.3.0)

generate_CSU_site: One-shot site summaries for COLA-GLMM

Description

Produces the **lossless**, pattern-level sufficient statistics for a single site: pattern counts `Ck`, outcome sums `Sk = \(\sum y\)`, squared sums `S2k = \(\sum y^2\)`, and the corresponding pattern matrix `X0`. Works for both binomial and Poisson outcomes (for Bernoulli, `S2k == Sk`).

Usage

generate_CSU_site(df_site, x_names, intercept = TRUE)

Value

A list with elements:

  • `Ck` (integer vector) pattern counts

  • `Sk` (numeric vector) sums of y per pattern

  • `S2k` (numeric vector) sums of y^2 per pattern

  • `X0` (matrix) pattern design matrix aligned to `Ck/Sk/S2k`

Arguments

df_site

Data frame for one site. Must include outcome column named `y` and the fixed-effect covariates in `x_names`. If `intercept = TRUE`, the function will add an `Intercept` column when missing.

x_names

Character vector of fixed-effect names (binary covariates; may include `"Intercept"` if `intercept = TRUE`).

intercept

Logical; include a fixed intercept in the pattern matrix.

Examples

Run this code
# df_site$y must exist; x_names are binary
# out <- generate_CSU_site(df_site, c("Intercept","age","sex"), intercept = TRUE)

Run the code above in your browser using DataLab