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 |
env_var |
Name of the environmental variable (e.g., "precip"). |
transform_fun |
Optional transformation function for environmental variable (e.g., |
inv_transform_fun |
Optional inverse transformation for environmental variable (e.g., |
grid_bins_1 |
Number of bins for the first trait axis. If |
grid_bins_2 |
Number of bins for the second trait axis. If |
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:
|
eco_space |
Raster-format data frame representing trait space bins with estimated environmental values. |
model |
Linear model object ( |
correlation |
Output from |
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)