r_squared: Model prediction error

View source: R/NullModel.R

r_squaredR Documentation

Model prediction error

Description

r_squared evaluates R^2 for our simulated dynamics.
simulated_model Error of the stochastic model.
null_model Error of the null model.

Usage

r_squared(observed, simulated, sp)

null_model(observed, sp)

simulated_model(observed, simulated)

Arguments

observed

A vector with the actual observed species richness.

simulated

A vector with the simulated species richness.

sp

Number of species in the species pool.

Details

The importance of assessing how well a model predicts new data is paramount. The most used metric to assess this model error is R^2. R^2 is always refered to a null model and is defined as follows:

R^2 = 1 - ε^2 / ε^2_0

where ε^2 is the prediction error defined as the mean squared deviation of model predictions from actual observations, and ε^2_0 is a null model error, in example, an average of squared deviations evaluated with a null model.

Our null model corresponds with a random species model with no time correlations, in which we draw randomly from a uniform distribution a number of species between 0 and number of species observed in the species pool. The expectation of the sum of squared errors under the null model is evaluated analytically in Alonso et al. (2015).

Value

r_squared gives the value of R^2 for the predictions of the model.

null_model gives the average of squared deviations of the null model predictions from actual observations, ε^2_0.

simulated_model gives the average of squared deviations of the model predictions from the actual observations, ε^2.

Note

The value of R^2 depends critically on the definition of the null model. Note that different definitions of the null model will lead to different values of R^2.

References

Alonso, D., Pinyol-Gallemi, A., Alcoverro T. and Arthur, R.. (2015) Fish community reassembly after a coral mass mortality: higher trophic groups are subject to increased rates of extinction. Ecology Letters, 18, 451–461.

Examples

idaho.sim <- data_generation(as.data.frame(c(rep(0, 163),
rep(1, 57))), 1, matrix(c(0.162599, 0.111252), ncol = 2), 250, 20)
idaho.me <- c(57, apply(idaho.sim, 1, quantile, 0.5))
r_squared(colSums(idaho[[1]][,3:23]), idaho.me, 220)

null_model(colSums(idaho[[1]][,3:23]), 220)

simulated_model(colSums(idaho[[1]][,3:23]), idaho.me)


island documentation built on Jan. 23, 2023, 5:30 p.m.