mix_simulate: Make predictions on simulated data using linear mixed-effects...

View source: R/mix_simulate.R

mix_simulateR Documentation

Make predictions on simulated data using linear mixed-effects model

Description

Wrapper function that runs mix_predict() on simulated data from generate_x(). Data is generated for each species based on their respective ranges of the predictor variable, which can be extrapolated to values defined by the user. The mixed-effects model is used to predict values for the response variable, as well as it's prediction interval. Necessary bias-corrections are made if the mixed-effects model has a transformed response variable.

Usage

mix_simulate(
  data,
  modelselect,
  level = 0.95,
  extrapolate = NULL,
  length.out = 100,
  stat = "median",
  n.sims = 1000,
  response = "height",
  predictor = "diameter",
  species = "species",
  ...
)

Arguments

data

Dataframe used to generate data and their predictions the using mixed-effects model. Columns should contain the species and variables of interest. Each row is a measurement for an individual tree.

modelselect

Output from the mix_modelselect() function.

level

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

extrapolate

Numeric vector of 2 elements (e.g. c(0,4)), representing the upper and lower bounds of extrapolation. Defaults to NULL for no extrapolation.

length.out

Number of new predictor values to generate for each species. Defaults to 100. Set a higher value for greater resolution at the cost of computational time.

stat

Specify whether the "median" or "mean" of simulated intervals are used.

n.sims

Number of bootstrapped simulations to generate the prediction intervals. Defaults to 1000.

response

Column name of the response variable in data. Defaults to height.

predictor

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

species

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

...

Additional arguments passed to merTools::predictInterval()

Value

A dataframe with columns:

species

Name of tree species.

predictor

Variable used to make predictions.

fit

Predicted value.

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.

extrapolated

Indicates whether the predictions are based on extrapolated values. Either 'High', 'Low', or 'No' (not extrapolated).

See Also

generate_x() to generate new values for each species in a dataset.

mix_predict() to make predictions for all species in a dataset using linear mixed-effects model.

merTools::predictInterval() to make predictions from models fit with the lme4 package.

Other mixed-effects model functions: mix_modelselect(), mix_predict()

Examples

data(urbantrees)

## Not run: 
model <- mix_modelselect(urbantrees)
results <- mix_simulate(data = urbantrees, modelselect = model)
head(results)

## End(Not run)


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