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.
generate_x(
data,
response = "height",
predictor = "diameter",
species = "species",
extrapolate = NULL,
length.out = 100
)
Dataframe that contains the variables of interest. Each row is a measurement for an individual tree of a particular species.
Column name of the response variable in data
. Defaults to
height
.
Column name of the predictor variable in data
. Defaults to
diameter
.
Column name of the species variable in data
. Defaults to species
.
Numeric vector of 2 elements (e.g. c(0,4)
), representing
the upper and lower bounds of extrapolation. Defaults to NULL
for no
extrapolation.
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.
A dataframe with columns:
Name of tree species.
Newly generated predictor values.
Indicates whether the predictor (x) values are extrapolated beyond the supplied dataset. Either 'High', 'Low', or 'No' (not extrapolated).
newdata <- generate_x(urbantrees,
extrapolate = c(0,4),
response = "height", predictor = "diameter")
head(newdata)
#> # A tibble: 6 × 3
#> species predictor extrapolated
#> <chr> <dbl> <chr>
#> 1 Albizia saman 0 Low
#> 2 Albizia saman 0.00315 Low
#> 3 Albizia saman 0.00630 Low
#> 4 Albizia saman 0.00945 Low
#> 5 Albizia saman 0.0126 Low
#> 6 Albizia saman 0.0158 Low