R/ss_predict.R
ss_predict.Rd
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"
)
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
.
A named list of each species' linear regression models.
names(models)
should correspond to species names in data
and
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 of confidence for the prediction interval. Defaults to
0.95
.
Column name of the species variable in data
and ref_table
.
Defaults to species
.
Column name of the predictor variable in data
. Defaults to
diameter
.
Column name of the bias correction factor in ref_table
. Defaults
to correctn_factor
.
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
.
Dataframe of input data
with columns appended:
Predicted value for the response variable.
Lower
bound of the prediction interval, based on the input argument level
.
Upper bound of the prediction interval, based on the input
argument level
.
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()
# 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