
Build residents-by-sites long table and fit the residents-only GLMM
Source:R/prep_resident_glmm.R
prep_resident_glmm.RdCreates a long data set with one row per (site, resident) pair, attaches standardized environment and resident traits, then fits a GLMM for residents. Also returns fixed-effect predictions on the link scale as a site×resident matrix (r_js) and the response-scale mean (mu_js).
Usage
prep_resident_glmm(
comm_res,
env_df_z,
traits_res_glmm,
fml,
family = glmmTMB::tweedie(link = "log"),
seed = 123,
fit_model = TRUE
)Arguments
- comm_res
Numeric matrix (sites × residents) of observed counts or abundance. Row names are site IDs; column names are resident species IDs.
- env_df_z
Data frame of standardized site-level environment. Row names are site IDs and must match
rownames(comm_res).- traits_res_glmm
Data frame of standardized resident traits used in the GLMM. Row names are resident IDs and must match
colnames(comm_res).- fml
A model formula for
glmmTMB::glmmTMB(e.g., frombuild_model_formula()).- family
A
glmmTMBfamily object. Default isglmmTMB::tweedie(link="log").- seed
Integer. Random seed.
- fit_model
logical; if FALSE, return dat_r/fml without fitting.