Learn R Programming

allometric

allometric is an R package for predicting tree attributes with allometric models. Thousands of allometric models exist in the scientific and technical forestry literature, and allometric is a platform for archiving and using this vast array of models in a robust and structured format. Get started by going to the Installation section or the documentation website.

allometric also provides a structured language for adding models to the package. If you are interested in helping the developer in this process please refer to the Contributing a Model vignette.

In total allometric contains 2118 models across 64 publications, refer to the Current Status for a more complete view of available models.

Installation

Currently allometric can be installed via CRAN:

install.packages("allometric")

For the latest release version, please install directly from GitHub using devtools:

devtools::install_github("allometric/allometric")

Before beginning, make sure to install the models locally by running

library(allometric)
install_models()

This installs all available models from the public models repository.

Finally, load the models using the load_models() function into a variable:

allometric_models <- load_models()
head(allometric_models)
#> # A tibble: 6 × 10
#>   id    model_type country region taxa   pub_id model      family_name covt_name
#>   <chr> <chr>      <list>  <list> <list> <chr>  <list>     <list>      <list>   
#> 1 cc20… site index <chr>   <chr>  <Taxa> barre… <FxdEffcM> <chr [1]>   <chr [2]>
#> 2 f508… stem volu… <chr>   <chr>  <Taxa> bell_… <FxdEffcM> <chr [3]>   <chr [2]>
#> 3 4d35… taper      <chr>   <chr>  <Taxa> bluhm… <FxdEffcM> <chr [3]>   <chr [4]>
#> 4 8d35… stem volu… <chr>   <chr>  <Taxa> brack… <FxdEffcM> <chr [1]>   <chr [2]>
#> 5 8682… stem volu… <chr>   <chr>  <Taxa> brack… <FxdEffcM> <chr [1]>   <chr [2]>
#> 6 7cfc… stem volu… <chr>   <chr>  <Taxa> brack… <FxdEffcM> <chr [1]>   <chr [2]>
#> # ℹ 1 more variable: pub_year <dbl>

Finding a Model

allometric_models is a tibble dataframe. Each row represents one allometric model with various attributes. Users interact with this table the way they would with any other tibble.

For example, we can use dplyr to filter this table to find models for analysis. Let’s say I am interested in finding stem volume models for Tsuga heterophylla. First, let us filter the model_type to include only stem volume models

stemvol_models <- allometric_models %>%
  filter(model_type == "stem volume")

stemvol_models
#> # A tibble: 569 × 10
#>    id       model_type  country   region    taxa   pub_id model      family_name
#>    <chr>    <chr>       <list>    <list>    <list> <chr>  <list>     <list>     
#>  1 f50865ee stem volume <chr [1]> <chr [1]> <Taxa> bell_… <FxdEffcM> <chr [3]>  
#>  2 8d35a7b6 stem volume <chr [1]> <chr [1]> <Taxa> brack… <FxdEffcM> <chr [1]>  
#>  3 8682a321 stem volume <chr [1]> <chr [1]> <Taxa> brack… <FxdEffcM> <chr [1]>  
#>  4 7cfc15b2 stem volume <chr [1]> <chr [1]> <Taxa> brack… <FxdEffcM> <chr [1]>  
#>  5 573c8c1b stem volume <chr [1]> <chr [1]> <Taxa> brack… <FxdEffcM> <chr [1]>  
#>  6 191eaa47 stem volume <chr [1]> <chr [1]> <Taxa> brack… <FxdEffcM> <chr [1]>  
#>  7 ecd1277b stem volume <chr [1]> <chr [1]> <Taxa> brack… <FxdEffcM> <chr [1]>  
#>  8 83b38fb4 stem volume <chr [1]> <chr [1]> <Taxa> brack… <FxdEffcM> <chr [1]>  
#>  9 a69c8b91 stem volume <chr [1]> <chr [1]> <Taxa> brack… <FxdEffcM> <chr [1]>  
#> 10 34575125 stem volume <chr [1]> <chr [1]> <Taxa> brack… <FxdEffcM> <chr [1]>  
#> # ℹ 559 more rows
#> # ℹ 2 more variables: covt_name <list>, pub_year <dbl>

Next, we can filter to include only Tsuga heterophylla using a special specifier called Taxon that enables rigorous searching of species:

tsuga_het_taxon <- Taxon(
  family = "Pinaceae", genus = "Tsuga", species = "heterophylla"
)

tsuga_vol_models <- stemvol_models %>%
  filter(purrr::map_lgl(taxa, ~ tsuga_het_taxon %in% .))

tsuga_vol_models
#> # A tibble: 4 × 10
#>   id    model_type country region taxa   pub_id model      family_name covt_name
#>   <chr> <chr>      <list>  <list> <list> <chr>  <list>     <list>      <list>   
#> 1 573c… stem volu… <chr>   <chr>  <Taxa> brack… <FxdEffcM> <chr [1]>   <chr [2]>
#> 2 191e… stem volu… <chr>   <chr>  <Taxa> brack… <FxdEffcM> <chr [1]>   <chr [2]>
#> 3 ecd1… stem volu… <chr>   <chr>  <Taxa> brack… <FxdEffcM> <chr [1]>   <chr [2]>
#> 4 9caa… stem volu… <chr>   <chr>  <Taxa> poude… <FxdEffcM> <chr [4]>   <chr [2]>
#> # ℹ 1 more variable: pub_year <dbl>

We can see that we have 4 models to choose from. Let’s select the model from the publication poudel_2019

tsuga_poudel <- tsuga_vol_models %>% select_model("9caa80f2")

This example is very basic, and more complex search examples can be found in the load_models() documentation. Models can be searched not only by their taxonomic information, but also the types of measurements the models require, their geographic region, and other attributes. We highly encourage users review the linked examples for production use of allometric.

Using the Model

tsuga_poudel now represents an allometric model that can be used for prediction. We must next figure out how to use the model.

Using the standard output of tsuga_poudel we obtain a summary of the model form, the response variable, the needed covariates and their units, a summary of the model descriptors (i.e., what makes the model unique within the publication), and estimates of the parameters.

tsuga_poudel
#> Model Call: 
#> vsia = f(dsob, hst) 
#>  
#> vsia [m3]: volume of the entire stem inside bark, including top and stump
#> dsob [cm]: diameter of the stem, outside bark at breast height
#> hst [m]: total height of the stem 
#> 
#> Parameter Estimates: 
#> # A tibble: 1 × 3
#>       a     b     c
#>   <dbl> <dbl> <dbl>
#> 1 -9.98  1.96 0.925
#> 
#> Model Descriptors: 
#> # A tibble: 1 × 3
#>   country   region     taxa  
#>   <list>    <list>     <list>
#> 1 <chr [2]> <chr [10]> <Taxa>

We can see from the Model Call section that tsuga_poudel will require two covariates called dsob, which refers to diameter outside bark at breast height, and hst, the height of the main stem. allometric uses a variable naming system to determine the names of response variables and covariates (refer to the Variable Naming System vignette).

Using the predict() method we can easily use the function as defined by providing values of these two covariates.

predict(tsuga_poudel, 12, 65)
#> 0.2868491 [m^3]

or we can use the prediction function with a data frame of values

my_trees <- data.frame(dias = c(12, 15, 20), heights = c(65, 75, 100))
predict(tsuga_poudel, my_trees$dias, my_trees$heights)
#> Units: [m^3]
#> [1] 0.2868491 0.5068963 1.1618632

or even using the convenience of dplyr

my_trees %>%
  mutate(vols = predict(tsuga_poudel, dias, heights))
#>   dias heights            vols
#> 1   12      65 0.2868491 [m^3]
#> 2   15      75 0.5068963 [m^3]
#> 3   20     100 1.1618632 [m^3]

The above example is a very basic use case for allometric. Please refer to the Common Inventory Use Cases vignette for more complex examples.

Current Status

In total allometric contains 2118 models across 64 publications.

categoryASEUNAAFOCSA
biomass component26136446000
crown diameter01236000
crown height0120000
shrub biomass0190000
shrub biomass increment0280000
shrub diameter0390000
shrub height0280000
site index0055000
stem height7034612217
stem volume405750020
stump volume0064000
taper2018000
tree biomass2369402116
other00168000

How Can I Help?

allometric is a monumental undertaking, and already several people have come forward and added hundreds of models. There are several ways to help out. The following list is ranked from the least to most difficult tasks.

  1. Add missing publications as an Issue. We always need help finding publications to add. If you know of a publication that is missing, feel free to add it as an Issue and we will eventually install the models contained inside.
  2. Find source material for a publication. Some publications are missing their original source material. Usually these are very old legacy publications. If you know where a publication might be found, or who to contact, leave a note on any of these issues.
  3. Help us digitize publications. We always need help digitizing legacy reports, at this link you will find a list of reports that need manual digitization. These can be handled by anyone with Excel and a cup of coffee.
  4. Learn how to install and write models. Motivated users can learn how to install models directly using the package functions and git pull requests. Users comfortable with R and git can handle this task.

Other ideas? Contact bfrank70@gmail.com to help out.

Next Steps

The following vignettes available on the package website provide information to two primary audiences.

Users interested in finding models for analysis will find the following documentation most useful:

Users interested in contributing models to the package will find these vignettes the most useful:

Copy Link

Version

Install

install.packages('allometric')

Monthly Downloads

37

Version

2.1.0

License

MIT + file LICENSE

Maintainer

Bryce Frank

Last Published

November 7th, 2023

Functions in allometric (2.1.0)

aggregate_pub_models

Aggregates the set of models in a publication into a model_tbl
allometric-package

allometric: Structured Allometric Models for Trees
check_descriptor_validity

Checks that descriptors are valid
check_parameters_in_mixed_fns

Check if all parameter_names are in predict_fn and predict_ranef
check_parameters_in_predict_fn

Check if all parameter_names are in predict_fn
==,FixedEffectsModel,FixedEffectsModel-method

Check equivalence of fixed effects models
==,MixedEffectsModel,MixedEffectsModel-method

Check equivalence of mixed effects models
check_taxa_unique

Determines if a taxa is composed of unique taxon objects
check_country_in_iso

Checks if a country code is defined in ISO_3166_1$Alpha_2
descriptors_to_S4

Convert the descriptors JSON data to a named list of descriptors
download_models

Download allometric models
check_covariates_equal

Check for equivalence of covariate slots in two models
check_response_equal

Check for equivalence of response slots in two models
descriptors

Get the descriptors of a model
check_res_def_equal

Check for equivalence of the response definition
get_component_defs

Load the component definitions
get_measure_defs

Load the measure definitions
check_ids_equal

Check for equivalence of ID slots in two models
check_descriptor_set

Check validity of descriptors
check_covts_in_args

Check if all covariates in covariates are used as arguments in predict_fn
check_region_in_iso

Checks if a region code is defined in the ISO_3166_2 table
check_taxon_hierarchy

Determines if a taxon has a valid hierarchy
add_model,Publication,FixedEffectsModel-method

Add a model to a publication
descriptors<-

Set the descriptors of a model.
%in%,Taxon,character-method

Check if a Taxon contains a character
%in%,Taxon,Taxa-method

Check if a Taxon is in a Taxa
select_model.model_tbl

Select a model from allometric_models
check_args_in_predict_fn

Check if the arguments of the predict_fn are all in the predict_fn body.
check_list_equal

Check for equivalence of two lists
check_citation_key

Checks if a citation contains a key
toJSON,FixedEffectsModel-method

Convert a fixed effects model to a JSON representation
install_models

Install allometric models from the models repository
get_pub_file_specs

Retrieve all publication file names in the publication subdirectories
get_variable_def

Get the definition of a variable in the variable naming system.
merge.model_tbl

Merge a model_tbl with another data frame.
fia_trees

FIA Trees Data
==,Taxon,Taxon-method

Check equivalence of two Taxon objects
model_call,FixedEffectsModel-method

Get the function call for a model
check_valid_search_str

Check if the search string is valid
%in%,Taxa,Taxon-method

Check if a Taxa is in Taxon
select_model

Select an allometric model
predict_allo

Predict allometric attributes using a column of allometric models
load_models

Load a locally installed table of allometric models
check_models_installed

Check if allometric models are currently installed
model_call

Get the function call for a model
model_call,ParametricSet-method

Get the function call for a model
check_parametric_model

Check validity of parametric model
unnest_taxa.model_tbl

Unnest the taxa column of a model_tbl
predict

Predict with an allometric model
%in%,character,Taxa-method

Check if a character is in a Taxa
%>%

Pipe operator
%in%,character,Taxon-method

Check if a character is in a Taxon
model_call,ParametricModel-method

Get the function call for a model
model_call,MixedEffectsModel-method

Get the function call for a model
%in%,Taxa,character-method

Check if a Taxa contains a character
toJSON

Convert a model or publication to a JSON representation
map_publications

Iteratively process publication files
unnest_taxa

Unnest the taxa column of a model_tbl
load_parameter_frame

Load a parameter frame from the models/parameters directory
unnest_models

Unnest columns of a dataframe
delete_models

Delete the local models directory.
check_predict_fn_equal

Check for equivalence of two rediction functions
create_model_row

Creates a dataframe row from model information
unnest_models.model_tbl

Unnest the columns of model_tbl
get_model_type

Gets the model type for a response name.
get_model_hash

Hashes a function string
ParametricModel

Base class for all parametric models.
FixedEffectsSet

Create a set of fixed effects models
Taxa

Group taxons together
MixedEffectsSet

Create a set of mixed effects models
FixedEffectsModel

Create a fixed effects model
Publication

Create a publication that contains allometric models
MixedEffectsModel

Create a mixed effects model
aggregate_taxa

Aggregate family, genus, and species columns of `tbl_df`` into taxa data structure
Taxon

Create a taxonomic hierarchy
add_set

Add a set of models to a publication
AllometricModel

Base class for allometric models
ParametricSet

Base class for all parametric sets.
ModelSet

Base class for model sets
brackett_acer

Brackett Acer Volume Model
add_model

Add a model to a publication
add_model,Publication,MixedEffectsModel-method

Add a model to a publication
brackett_rubra

An object of class FixedEffectsModel