User Tools

Site Tools


Section: Analysis of species attributes

Community-weighted mean approach (CWM) and the fourth-corner approach

R functions

  • fourthcorner (library ade4) - calculates the fourth corner analysis between species attributes and environmental variables.
  • cwm (library weimea) - calculates community weighted mean (CWM) of species attributes (argument traits) using data about species composition (argument com) and created object of the class cwm.
  • test_cwm (library weimea) - calculates correlation, regression or ANOVA, and tests it by standard or permutation test (including Pmax test)
  • test_fourth (library weimea) - calculates fourth corner and tests it by P max test
  • test_wreg (library weimea) - calculates weighted regression of CWM on environmental variables (weighted standardized) and SNC (species niche centroids) on traits (weighted standardized), where CWM and SNC are calculated from weighted standardized traits and environmental variables, respectively. Offers parametric test of the regression, combined into P max test (sensu ter Braak et al. 2018).
  • envfit_cwm (library weimea) - fits CWM onto ordination diagram, and tests the significance by modified test (permuting columns in species composition matrix).

About the weimea package

The package weimea (community weighted mean approach, Zelený 2018) is focused on relating community-level species attributes (traits, indicator values) to sample attribute (environmental variables). The current distribution (in beta release) is on GitHub (; see the installation instructions below (these are different for Windows, Mac OS and Linux).


Windows binary (for R 4.0.3):

To directly install weimea in R for Windows, use the following:

download.file ('', '')
install.packages (paste (getwd (), '', sep = '/'), repos = NULL, type = 'win.binary')

Try library (weimea) to open the package. If you get the error message Error: package or namespace load failed for ‘weimea’... there is no package called ‘RcppArmadillo’, then you need to install.packages (“RcppArmadillo”) and try library (weimea) again. If you get another error message, you may be missing yet another library on which weimea depends - follow error messages and install them one by one manually using install.packages. To ensure the library is correctly installed, you should not get any error message once you type library (weimea). You can try to run some of the example codes, e.g. example (test_cwm), to see whether the package works.

Alternatively, you can install the package directly from GitHub. For this, make sure you have the latest version of Rtools.exe, compatible with your R version, installed on your computer and added to your program path (check here for details), and that you installed the latest version of the package devtools.

devtools::install_github ('zdealveindy/weimea')

See the explanation of error messages above to see what to do (install manually additional packages).


MacOS binary: weimea_0.1.18.tgz - this is updated version for R 4.1.0 (thanks to Cheng-Tao Lin for compiling!)

You may need to install gfortran binary (follow instructions here)


Linux binary: weimea_0.1.18_r_x86_64-pc-linux-gnu.tar.gz (thanks to Cheng-Tao Lin for compiling!)

en/cwm_fc_r.txt · Last modified: 2021/06/19 15:50 by David Zelený