Skip to contents

This function fits PERMANOVA models for all combinations of variables in a given dataset, and arranges the models by Akaike Information Criterion (AICc) score. The function also calculates the maximum variance inflation factor (max_vif) for each model.

Usage

fit_models(
  all_forms,
  com_data,
  env_data,
  method = "bray",
  ncores = 2,
  log = TRUE,
  logfile = "log.txt",
  multiple = 100,
  strata = NULL,
  verbose = FALSE
)

Arguments

all_forms

A data frame generated by make_models

com_data

A dataset with community presence absense or abundance data, you can also use a dist class file generated from vegan, betapart or other packages

env_data

A dataset with the variables described in all_froms

method

method for distance from vegdist, this will be ignored if com_data is a distance file

ncores

An integer specifying the number of cores to use for parallel processing

log

logical if true, a log file will be generated

logfile

the text file that will be generated as a log

multiple

after how many loops to write a log file

strata

a block variable similar to the use in adonis2

verbose

logical, defaults TRUE, sends messages about processing times

Value

A data.frame with fitted models arranged by AICc, including the formula used, the number of explanatory variables, R2, adjusted R2, and the AICc and max VIF.

References

Anderson, M. J. (2001). A new method for non-parametric multivariate analysis of variance. Austral Ecology, 26(1), 32-46. https://doi.org/10.1111/j.1442-9993.2001.01070.pp.x

Examples

# \donttest{
## example with dataframe as community data
library(vegan)
data(dune)
data(dune.env)

AllModels <- make_models(vars = c("A1", "Moisture", "Manure"))
#> 1 of 3 ready 2024-01-22 11:58:04.210656
#> 2 of 3 ready 2024-01-22 11:58:06.963923
#> 3 of 3 ready 2024-01-22 11:58:08.543762

fit_models(
  all_forms = AllModels,
  com_data = dune,
  env_data = dune.env
)
#> Warning: already exporting variable(s): env_data
#>                                form  max_vif      AICc k  N         A1
#> 1               Distance ~ Moisture 0.000000 -30.36319 4 20         NA
#> 2                     Distance ~ A1 0.000000 -29.72347 2 20 0.16816657
#> 3                      Distance ~ 1 0.000000 -28.52467 1 20         NA
#> 4          Distance ~ A1 + Moisture 3.000000 -28.21149 5 20 0.04230343
#> 5                 Distance ~ Manure 0.000000 -25.21490 5 20         NA
#> 6            Distance ~ A1 + Manure 4.000000 -25.18745 6 20 0.12092088
#> 7      Distance ~ Moisture + Manure 4.000000 -22.93984 8 20         NA
#> 8 Distance ~ A1 + Moisture + Manure 4.508169 -18.59078 9 20 0.04145173
#>    Moisture    Manure Model
#> 1 0.4019903        NA    NA
#> 2        NA        NA    NA
#> 3        NA        NA     0
#> 4 0.2761272        NA    NA
#> 5        NA 0.3544714    NA
#> 6        NA 0.3072258    NA
#> 7 0.3005223 0.2530035    NA
#> 8 0.2210532 0.2521518    NA
## example with distance as community data
library(betapart)
Distance <- beta.pair.abund(dune)
Distance <- Distance$beta.bray.bal
fit_models(
  all_forms = AllModels,
  com_data = Distance,
  env_data = dune.env
)
#> Warning: already exporting variable(s): env_data
#>                                form  max_vif      AICc k  N         A1
#> 1               Distance ~ Moisture 0.000000 -36.35514 4 20         NA
#> 2          Distance ~ A1 + Moisture 3.000000 -34.09230 5 20 0.03473680
#> 3                     Distance ~ A1 0.000000 -33.85715 2 20 0.19124904
#> 4                      Distance ~ 1 0.000000 -32.09553 1 20         NA
#> 5            Distance ~ A1 + Manure 4.000000 -29.75194 6 20 0.14829650
#> 6      Distance ~ Moisture + Manure 4.000000 -29.52300 8 20         NA
#> 7                 Distance ~ Manure 0.000000 -28.72546 5 20         NA
#> 8 Distance ~ A1 + Moisture + Manure 4.508169 -25.44522 9 20 0.03917375
#>    Moisture    Manure Model
#> 1 0.4701720        NA    NA
#> 2 0.3136598        NA    NA
#> 3        NA        NA    NA
#> 4        NA        NA     0
#> 5        NA 0.3095700    NA
#> 6 0.3507105 0.2330610    NA
#> 7        NA 0.3525225    NA
#> 8 0.2415877 0.2374979    NA

# }