knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  message = FALSE, warning = FALSE
)
library(allometree)
#devtools::load_all() # to knit manually

The allometree package enables you to develop and use allometric equations relating to the size and structure of urban trees. For example, these equations have been used to predict trunk diameter from tree age, as well as to predict tree height, crown height, crown diameter and leaf area from trunk diameter. They are foundational to other models that estimate the benefits and hazards associated with trees as they mature and grow in size.

This document demonstrates the workflow to develop these allometric models, taking the relationship between two size parameters as an example: Predicting tree height from trunk diameter.

Two linear modelling approaches will be introduced:

  1. Regression models developed separately for each species, i.e., single-species models
  2. Mixed-effects model that includes all species as random effects, i.e., mixed-effects model

Example data: urbantrees

We will be using data(urbantrees). It contains five species planted along streets in Singapore, each spanning a wide range of heights and diameter sizes (in metres).

data(urbantrees, package = "allometree")
urbantrees

library(ggplot2)

ggplot(urbantrees, aes(diameter, height)) +
  facet_wrap(~ species, scales = "free") +
  geom_point(size=0.35, alpha = 0.3, color = "grey50") +
  theme_bw() + theme(panel.grid = element_blank())

Allometric equations: eqns_info

Allometric relationships for urban trees can vary drastically from those for forest trees, and are also influenced by human factors such as pruning and fertilisation. Empirical models are developed using six allometric equations used for urban trees (McPherson et al., 2016).

More information can be found in ?eqns_info, as well as in data(eqns_info). The column modelcode shows the unique model code for each equation:

data(eqns_info, package = "allometree")
head(eqns_info)

1. Single-species models

We can run ss_modelselect_multi() to select the best-fit model for each species in the dataset urbantrees. This can also be done for individual species using ss_modelselect(). Note that you can also fit data to specified (i.e. pre-defined) equations, using the functions ss_modelfit() and ss_modelfit_multi(). This can be done, for example, after the removal of outliers from the full dataset. See the vignette Single-species linear models for a full demonstration.

results <- ss_modelselect_multi(urbantrees, 
                                species = "species", # specify colname of species
                                response = "height", predictor = "diameter") # specify colnames of variables

results is a list of 3 elements:

  1. List of tables showing each species' candidate models ranked by Aikake's Information Criterion corrected for small sample sizes (AICc), named ss_models_rank.
  2. List of each species' best-fit model object, named ss_models.
  3. Table showing each species' best-fit model information, named ss_models_info.

 

An overview of the best-fit models across the r nrow(results$ss_models_info) species:

results$ss_models_info

 

We can simulate data across a range of diameter sizes for each species, and use their respective models to make predictions of tree height. The simulated data can also be extrapolated beyond the range used to fit the model, using the argument extrapolate. In this example, we specify that predictions should be made between the range 0 to 1 metre:

predictions_ss <- ss_simulate(ref_table = results$ss_models_info, 
                              models = results$ss_models,
                              extrapolate = c(0,1))
head(predictions_ss)

 

predictions_ss is a dataframe of simulated data for the diameter size (predictor) for each species. Other columns include the predicted height (fit), the lower (lwr) and upper (upr) bounds of the prediction interval, as well as whether the height/diameter variables are extrapolated beyond the original data used to fit the model.

 

Model predictions can be visualised alongside the original data using ggplot2::ggplot():

ggplot() +
  facet_wrap(~ species)+ 

  # raw data
  geom_point(data = urbantrees, 
             aes(x = diameter, y = height),
             size=0.35, alpha = 0.3, color = "grey50") +

  # prediction interval
  geom_ribbon(data = predictions_ss, 
              aes(x = predictor, ymin = lwr, ymax = upr), 
              alpha = 0.10) +

  # regression line
  geom_line(data = predictions_ss, 
            aes(x = predictor, y = fit, lty = extrapolated)) +
  scale_linetype_manual(values=c("No"= 1 , "Low" = 3, "High" = 3), 
                        name = "Extrapolated") +

  # axes
  xlab("Diameter (m)") + ylab("Height (m)") +
  coord_cartesian(ylim=c(0, max(urbantrees$height)), # limit ranges
                  xlim= c(0, max(predictions_ss$predictor))) + 

  theme_bw() + theme(panel.grid = element_blank())

2. Mixed-effects model

Alternatively, the full dataset can be fit to a linear mixed-effects model with 'species' specified as the random effect, using the lme4::lmer function under the hood.

results <- mix_modelselect(urbantrees, 
                           species = "species", 
                           response = "height", predictor = "diameter")

results is a list of 5 elements:

  1. Model selection table showing all the types of mixed-effects models considered, ranked in order of ascending AICc.
  2. The best-fit model object, named best_model.
  3. The conditional and marginal pseudo-\eqn{R^2} of the best-fit model.
  4. Correction factor used to adjust predicted values if response variable is transformed (incorporated into reported parameters).
  5. Warning messages, if any, spit from the models.

 

Simulations can likewise be performed across a range of diameter sizes for each species, and extrapolated beyond the range used to fit the model:

predictions_mix <- mix_simulate(data = urbantrees, 
                                modelselect = results,
                                extrapolate = c(0, 1))
head(predictions_mix)

Model predictions can be visualised alongside the original data using ggplot2::ggplot():

ggplot() +
  facet_wrap(~ species)+ 

  # raw data
  geom_point(data = urbantrees, 
             aes(x = diameter, y = height),
             size=0.35, alpha = 0.3, color = "grey50") +

  # prediction interval
  geom_ribbon(data = predictions_mix, 
              aes(x = predictor, ymin = lwr, ymax = upr), 
              alpha = 0.10) +

  # regression line
  geom_line(data = predictions_mix, 
            aes(x = predictor, y = fit, lty = extrapolated)) +
  scale_linetype_manual(values=c("No"= 1 , "Low" = 3, "High" = 3), 
                        name = "Extrapolated") +

  # axes
  xlab("Diameter (m)") + ylab("Height (m)") +
  coord_cartesian(ylim=c(0, max(urbantrees$height)), # limit ranges
                  xlim= c(0, max(predictions_mix$predictor))) + 

  theme_bw() + theme(panel.grid = element_blank())

 


References

McPherson E. G., van Doorn N. S. & Peper P. J. (2016) Urban Tree Database and Allometric Equations. General Technical Report PSW-GTR-253, USDA Forest Service, 86.

Song, X. P., Lai, H. R., Wijedasa, L. S., Tan, P. Y., Edwards, P. J., & Richards, D. R. (2020), Height–diameter allometry for the management of city trees in the tropics. Environmental Research Letters, 15, 114017. https://doi.org/10.1088/1748-9326/abbbad



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