expand4glmm: Utility function expand4glmm

View source: R/expand4glmm.r

expand4glmmR Documentation

Utility function expand4glmm

Description

expand4glmm inflates a TE_obj object (see make_obj_for_traitenv), which consists of trait, environment and abundance data, into a format for glm, glmer and glmmTMB.

Usage

expand4glmm(obj, K = 0)

Arguments

obj

an object of class TE_obj, usually the output of function make_obj_for_traitenv.

K

scalar, 0 for count-like data and the binomial total for data that you like to analyse using logit models (1 for presence-absence).

Details

With single trait and single environment variable data (ncol(obj$T)== ncol(obj$E)==1), the names of the trait and environmental variables are changed to trait and env (to allow identical MLM formulas for different data and variables ). In the multi-variable case, the original names are kept and all interactions are added. expand4glmm is used repeatedly in the model-based permutational max test using function MLM3_p_max. In this function, obj is extended with list elements trait0 and env0 to allow for the detail needed in the model-based permutational max test. If used in this way, the internal logical inPermut_r_c is set to TRUE.

Value

A data frame. For single trat and enviornmental variable data:

y

the response; the abuncance values in obj$L

site

a factor indicating the site corresponding to each value of y

species

a factor indicating the species corresponding to each value of y

obs

integer 1 to N, the length of y

trait

trait

env

environmental variable

trait.env

the product

In the multi-trait environment case: all traits and environmental variables and all pairwise interactions

References

ter Braak (2019) New robust weighted averaging- and model-based methods for assessing trait-environment relationships. Methods in Ecology and Evolution (https://doi.org/10.1111/2041-210X.13278 )

ter Braak, C.J.F., Peres-Neto, P. & Dray, S. (2017) A critical issue in model-based inference for studying trait-based community assembly and a solution. PeerJ, 5, e2885. https://doi.org/10.7717/peerj.2885

Examples

## Not run: 
data("aravo",  package = "ade4")
Y <-aravo$spe
trait <- scale(aravo$traits$SLA)
env <- scale(aravo$env$Snow)
obj <- make_obj_for_traitenv(env,Y, trait, cutoff=0)
K  = 0 # 0 for non-binomial models
dat <- expand4glmm(obj, K = K)
names(dat)
library(glmmTMB)
formula.MLM3 <- y ~ poly(env,2) + poly(trait,2) +
 env : trait  + (1 + env|species) + (1 + trait| site)
MLM3 <- glmmTMB(formula.MLM3, family = betabinomial,  data=dat)
summary(MLM3)
plot_MLM3(MLM3)

## End(Not run)

CajoterBraak/TraitEnvMLMWA documentation built on Jan. 25, 2023, 7:36 p.m.