ecometric_model_qual {commecometrics}R Documentation

Run an ecometric model for qualitative environmental variables

Description

Builds an ecometric trait space for qualitative environmental variables, estimating the most probable category and the probability of each category at each trait bin combination. Also calculates prediction accuracy and anomalies for each point.

Usage

ecometric_model_qual(
  points_df,
  category_col,
  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.

category_col

Name of the column containing the categorical trait.

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 with trait data per point (default = 3).

Value

A list containing:

points_df

Filtered input data frame with the following added columns:

bin_1

Bin assignment code for first trait axis.

bin_2

Bin assignment code for second trait axis.

prob_category

Estimated probability of each environmental category per trait bin (e.g., prob_1, prob_2, etc.).

observed_probability

Probability assigned to the observed category for each point.

predicted_probability

Probability assigned to the predicted (most likely) category for each point.

predicted_category

Predicted environmental category for each point.

correct_prediction

Indicator for whether the predicted category matches the observed category ("Yes" or "No").

env_anom

Difference between predicted and observed category probabilities.

eco_space

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

diagnostics

Summary stats about bin usage and data coverage.

settings

Metadata including the modeled trait.

prediction_accuracy

Overall percentage of correct predictions.

Examples


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

# Step 1: 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
)

# Step 2: Run ecometric model using land cover class as qualitative variable
modelResult <- ecometric_model_qual(
  points_df = traitsByPoint$points,
  category_col = "vegetation",
  min_species = 3
)

# View the percentage of correctly predicted categories
print(modelResult$prediction_accuracy)


[Package commecometrics version 1.0.0 Index]