WA_p_max: Max test for the joint association between multiple traits...

View source: R/WA_p_max.r

WA_p_maxR Documentation

Max test for the joint association between multiple traits and environmental variables (incl. nominal variables) using weighted averaging methods (CWM/SNC regression)

Description

For the test on multi-trait multi-environment association, two test statistics are available, one which accounts for correlations among the traits and among the environmental variables (score_test == TRUE) and one which does not. The former is related to double constrained correspondence analysis (ter Braak et al. 2018) and the latter to RLQ (Dray et al. 2014). created using make_obj_for_traitenv. If E is a TE_obj, the arguments L and T are ignored.

Usage

WA_p_max(
  E,
  L = 0,
  T = 0,
  nrepet = 19,
  weighing = "N2",
  type = "joint",
  score_test = TRUE,
  cutoff = 0,
  fast = TRUE
)

Arguments

E

a data frame, numeric n-vector, factor or n-by-p matrix, containing the values of the environmentalvariables in n sites, or a TE_obj object containing the trait, environment and abundance data,

L

a n by m matrix or data frame of abundance values of m species in n sites

T

a data frame, numeric m-vector, factor or m-by-q matrix, containing the values of the trait(s) for m species

nrepet

number of permutations

weighing

type of weights used in the regression of CWM on E and SNC on T; "unw", "FC" or "N2" (default)

type

'joint' testing of the association between a set of traits and a set environmental variables (default) or 'onebyone' 1-1 tests for each pair of trait and environmental variable

score_test

logical. TRUE for the score test statistic, which accounts for correlations (default) and FALSE without accounting for correlations among traits and among environmental variables

cutoff

minimal number of occurrences of species

fast

logical, whether the fast version is used or the slow version (default TRUE). For multi-trait-environment data, fast is set to TRUE.

Details

Nomimal traits and environmental variables (factors) are expanded into dummy variables if E and/or T are data frames. Set E or T to a data frame with a single factor to obtain test of association with the factor. For multi-trait, multi-environment data and score_test==TRUE, the trait and environment data are internally transformed to normalized singular vectors. If score_test== FALSE, the variables are standardized internally to weighted mean 0 and variance 1. The permutation tests is carried out by the max test. This test takes the maximum of the p-values of the CWM-E regression and the SNC-T regression. Both p-values are obtained by permutation. In the former, the rows of E are permuted, in the latter the rows of T are permuted. The slow version recomputes the CWM and SNC and the associated regression from scratch for each permutation and is available only with single numberic trait and environmental variable. The fast version precomputes the CWM and SNC and computes the test statistic by a matrix product in which the permuted traits or environmental variables are rescaled to weigthed mean 0 and variance 1 using the precomputed weights (determined by the weighing option).

Value

A named list, among which,

p_values

five p-values: permutational, site-based and species-based and its maximum, and the parametric ones

obs

values of the test statistic for sites (first row) and species (second row)

sim.row

values of the test statistic for the nrepet data in which the rows of E are permuted

sim.col

values of the test statistic for the nrepet data in which the rows of T are permuted

nrepet

number of permutations

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., Šmilauer, P. & Dray, S. (2018) Algorithms and biplots for double constrained correspondence analysis. Environmental and Ecological Statistics, 25, 171-197. https://doi.org/10.1007/s10651-017-0395-x

Dray, S., Choler, P., Dolédec, S., Peres-Neto, P.R., Thuiller, W., Pavoine, S. & ter Braak, C.J.F. (2014) Combining the fourth-corner and the RLQ methods for assessing trait responses to environmental variation. Ecology, 95, 14-21. http://dx.doi.org/10.1890/13-0196.1

Examples

# get Aravo data set ----------------------------------------------------------
data("aravo",  package = "ade4")
Y <- aravo$spe
# Aravo data set: multi-trait multi-env test -----------------------------------
summary(aravo$env)
#E <- aravo$env[,-c(5,6)] # without Snow, without ZoogD
E <- aravo$env[,-c(5)] # without Snow, without ZoogD
# Slope is positive and very skew; therefore we logtransform, but there are zeroes
# add minimum non-zero value before taking logs
a <- min(E[E[,"Slope"]>0, "Slope"])
E[,"Slope"] <- log(E[,"Slope"]+ a)
summary(E)
T <- aravo$traits #[, -6 ] # without SLA
# all traits are skew; therefore we logtransform
T[,c(1,3)] <- log(T[,c(1,3)]+ 1) # traits with zeroes
T[,-c(1,3)] <- log(T[,-c(1,3)]) # traits without zeroes
summary(T)

set.seed(1231)
# score_test = TRUE gives the score test which
# takes intra-trait and intra-env correlations into account
#          If weighing == "FC", it give the test used
#              in double constrained correspondence analysis  )
# score_test = FALSE ignores such correlations.
#              If weighing == "FC", it give the gives the test used in RLQ

E<- aravo$env[,c(1,6,2)]
T <- aravo$traits[,c(2,6)]
nrepet <- 99 # change to e.g. 499 or 999
cc<- WA_p_max(E, Y, T, nrepet =nrepet, weighing = "N2", type = "onebyone")
cc$p_values



dd<- CWMSNC_regressions(E, Y, T, nrepet =nrepet, weighing = "N2")


aa<- WA_p_max(E, Y, T, nrepet =nrepet, weighing = "N2", score_test = TRUE)
aa$p_values

# Explicit conversion to dummy variables as performed in WA_p_max  -------
# convert any factor into dummy variables
E <-  model.matrix(as.formula(paste("~ 0", paste(names(E),  collapse= "+"), sep= "+")), data = E)
summary(E)
# convert any factor into dummy variables
T <-  model.matrix(as.formula(paste("~ 0", paste(names(T),  collapse= "+"), sep= "+")), data = T)
summary(T)
obj <- make_obj_for_traitenv(E,Y, T, cutoff=0)
set.seed(1231)

bb<- WA_p_max(obj, nrepet =nrepet, weighing = "N2", score_test = TRUE)
bb$p_values










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