generate_x: Generate new predictor values for each species in a dataset

View source: R/generate_x.R

generate_xR Documentation

Generate new predictor values for each species in a dataset

Description

Helper function to generate a sequence of new values for each species, based on the range of values for the predictor variable in the data. Upward and downward extrapolation to specified values can be made. Predictions can subsequently be made on the generated values.

Usage

generate_x(
  data,
  response = "height",
  predictor = "diameter",
  species = "species",
  extrapolate = NULL,
  length.out = 100
)

Arguments

data

Dataframe that contains the variables of interest. Each row is a measurement for an individual tree of a particular species.

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.

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 values to generate for each species. Defaults to 100. Set a higher value for greater resolution at the cost of computational time.

Value

A dataframe with columns:

species

Name of tree species.

predictor

Newly generated predictor values.

extrapolated

Indicates whether the predictor (x) values are extrapolated beyond the supplied dataset. Either 'High', 'Low', or 'No' (not extrapolated).

Examples

newdata <- generate_x(urbantrees,
                      extrapolate = c(0,4),
                      response = "height", predictor = "diameter")
head(newdata)


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