ss_predict: Make predictions for all species in a dataset using...

View source: R/ss_predict.R

ss_predictR Documentation

Make predictions for all species in a dataset using single-species linear models

Description

Make predictions across rows in a dataset that may contain multiple species. The model associated with each species is used to predict values for the response variable, as well as it's prediction interval. Necessary bias-corrections are made for species with models that have a transformed response variable.

Usage

ss_predict(
  data,
  models,
  ref_table,
  level = 0.95,
  species = "species",
  predictor = "diameter",
  cf = "correctn_factor",
  geom_mean = "response_geom_mean"
)

Arguments

data

Dataframe with columns containing the species and variables of interest. Species names in the species column should be present in those within ref_table, as well as those in models.

models

A named list of each species' linear regression models. names(models) should correspond to species names in data and ref_table.

ref_table

Dataframe containing information to correct bias introduced in models with a transformed response variable. It should include columns for species, cf, and geom_mean.

level

Level of confidence for the prediction interval. Defaults to 0.95.

species

Column name of the species variable in data and ref_table. Defaults to species.

predictor

Column name of the predictor variable in data. Defaults to diameter.

cf

Column name of the bias correction factor in ref_table. Defaults to correctn_factor.

geom_mean

Column name of the geometric mean of response variable in ref_table, that was used in to fit the models. Defaults to response_geom_mean.

Value

Dataframe of input data with columns appended:

fit

Predicted value for the response variable.

lwr

Lower bound of the prediction interval, based on the input argument level.

upr

Upper bound of the prediction interval, based on the input argument level.

See Also

ss_simulate() to run ss_predict() on simulated data.

Other single-species model functions: ss_modelfit_multi(), ss_modelfit(), ss_modelselect_multi(), ss_modelselect(), ss_simulate()

Examples

# first select best-fit model
data(urbantrees)
Alb_sam <- urbantrees[urbantrees$species == 'Albizia saman', ]  # we use one species as an example
results <- ss_modelselect_multi(Alb_sam,
                                response = 'height',
                                predictor = 'diameter')

# generate data for subsequent predictions
newdata <- generate_x(Alb_sam,
                      response = "height", predictor = "diameter")

# run function
predictions <- ss_predict(newdata,
                          models = results$ss_models,
                          ref_table = results$ss_models_info,
                          predictor = "predictor")
head(predictions)


xp-song/allometree documentation built on March 28, 2022, 4:36 a.m.