ecometric_model {commecometrics}R Documentation

Run an ecometric model for quantitative environmental variables

Description

Builds an ecometric trait space for quantitative environmental variables, estimating environmental values of each category at each trait bin combination. Also calculates anomalies based on observed values for each point.

Usage

ecometric_model(
  points_df,
  env_var = "env_var",
  transform_fun = function(x) x,
  inv_transform_fun = function(x) x,
  grid_bins_1 = NULL,
  grid_bins_2 = NULL,
  min_species = 3
)

Arguments

points_df

Output first element of the list from summarize_traits_by_point(). A data frame with columns: summ_trait_1, summ_trait_2, count_trait, and the environmental variable.

env_var

Name of the environmental variable (e.g., "precip").

transform_fun

Optional transformation function for environmental variable (e.g., log(x + 1)).

inv_transform_fun

Optional inverse transformation for environmental variable (e.g., exp(x) - 1).

grid_bins_1

Number of bins for the first trait axis. If NULL (default), the number is calculated automatically using Scott's rule via optimal_bins().

grid_bins_2

Number of bins for the second trait axis. If NULL (default), the number is calculated automatically using Scott's rule via optimal_bins().

min_species

Minimum number of species per point (default = 3).

Value

A list containing:

points_df

Filtered input data frame with the following added columns:

env_trans

Transformed environmental variable (if a transformation function is used).

bin_1

Bin assignment code for mean trait value.

bin_2

Bin assignment code for standard deviation of trait.

env_est

Predicted (maximum likelihood) environmental value on transformed scale.

env_anom

Difference between observed and predicted environmental values (transformed scale).

env_est_UN

Inverse-transformed predicted value (if inv_transform_fun is provided).

env_anom_UN

Inverse-transformed anomaly value (if inv_transform_fun is provided).

eco_space

Raster-format data frame representing trait space bins with estimated environmental values.

model

Linear model object (lm) relating predicted environmental values to observed environmental values (transformed scale when used).

correlation

Output from cor.test, reporting the Pearson correlation between predicted and observed environmental values (transformed scale when used).

diagnostics

Summary stats about bin usage and data coverage.

settings

Metadata including the modeled trait and transformation functions.

prediction_accuracy

Overall percentage of correct predictions.

Examples


# Load internal dataset
data("geoPoints", package = "commecometrics")
data("traits", package = "commecometrics")
data("spRanges", package = "commecometrics")

# Summarize trait values at sampling points
traitsByPoint <- summarize_traits_by_point(
  points_df = geoPoints,
  trait_df = traits,
  species_polygons = spRanges,
  trait_column = "RBL",
  species_name_col = "sci_name",
  continent = FALSE,
  parallel = FALSE
)

# Fit an ecometric model using annual precipitation (BIO12)
modelResult <- ecometric_model(
  points_df = traitsByPoint$points,
  env_var = "precip",
  transform_fun = function(x) log(x + 1),
  inv_transform_fun = function(x) exp(x) - 1,
  min_species = 3
)

# View correlation between predicted and observed values
print(modelResult$correlation)

# View summary of the linear model fit
summary(modelResult$model)


[Package commecometrics version 1.0.0 Index]