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.

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)
#>         species predictor extrapolated       fit      lwr      upr
#> 1 Albizia saman 0.3119437           No  9.669697 5.212233 14.12716
#> 2 Albizia saman 0.3242260           No  9.785937 5.332736 14.23914
#> 3 Albizia saman 0.3365082           No  9.902177 5.453124 14.35123
#> 4 Albizia saman 0.3487905           No 10.018418 5.573397 14.46344
#> 5 Albizia saman 0.3610727           No 10.134658 5.693553 14.57576
#> 6 Albizia saman 0.3733550           No 10.250899 5.813594 14.68820