Documentation for ForestMensuration.
Reference
ForestMensuration.ForestMensuration
— ModuleDescription:
ForestMensuration.jl is a Julia package that provides a comprehensive set of functions for performing dendrometric and forest inventory calculations. Designed with ease of use in mind, the package offers tools that simplify complex forestry calculations, making it straightforward to:
- Conduct regressions: Easily fit linear models, including transformations and qualitative variables, to find the best relationships in your forestry data.
- Calculate tree and stand volume (cubage): Support for various methods such as Huber, Smalian, and Newton allows precise calculation of tree and stand volumes.
- Classify site productivity: Implement site classification methods to assess the quality and productivity of forest sites.
- Compute dendrometric averages: Calculate essential dendrometric metrics like mean diameter, quadratic mean diameter, and others to understand stand structure.
- Create frequency tables: Generate frequency and diametric tables to analyze the distribution of dendrometric variables such as diameter and height.
- Perform forest inventory: Implement simple random sampling methods to estimate forest parameters and support forest management decisions.
The package facilitates the analysis of dendrometric and forest data, performs complex calculations with simple commands, and offers a user-friendly and intuitive interface.
ForestMensuration.artificial_form_factor
— Methodartificial_form_factor(vt::Real, ht::Real, dbh::Real)
Artificial Form Factor (aff): For the calculation of the artificial form factor, the volume of the reference cylinder will have a diameter equal to the tree's DBH.
- aff = Rigorous Vol / Cylinder Vol 1.3
Where:
- Rigorous Vol = total volume determined by one of the methods: Smalian, Huber, or Newton;
- Cylinder Vol 1.3 = volume of a cylinder with height and diameter equal to the total height and DBH of the tree.
Arguments
vt::Real
: The total volume of the tree.ht::Real
: The total height of the tree.dbh::Real
: The diameter at breast height of the tree.
Returns
Float64
: The artificial form factor.
Example
julia> vt = 0.3378;
julia> ht = 18.5;
julia> dbh = 22.7;
julia> artificial_form_factor(vt, ht, dbh)
0.451176344374475
ForestMensuration.bark_factor
— Methodbark_factor(d::Vector{<:Real}, e::Vector{<:Real})
Calculates the bark factor, used to estimate the volume without bark.
The bark factor is used to estimate the volume without bark by considering the ratio of bark thickness to total diameter.
Arguments
d::Vector{<:Real}
: Vector of diameters.e::Vector{<:Real}
: Vector of bark thicknesses in millimeters.
Returns
Float64
: The bark factor, which represents the proportion of the diameter without bark.
Example
julia> d_values = [30.0, 22.5, 20.2, 15.4, 13.2, 10.9];
julia> e_values = [1.2, 1.1, 0.85, 0.66, 0.48, 0.0];
julia> bark_factor(d_values, e_values)
0.961764705882353
ForestMensuration.basal_area
— Methodbasal_area(d::Real)
Calculates the basal area (g) of a tree given its diameter in centimeters.
Description
This function computes the basal area of a tree, which is the cross-sectional area of the tree trunk at breast height (usually measured at 1.3 meters above ground). Basal area is a critical parameter in forest mensuration, used for estimating stand density, timber volume, and assessing competition among trees in a forest stand.
Arguments
d::Real
: The diameter at breast height (DBH) of the tree in centimeters. The diameter must be a positive value.
Returns
Float64
: The basal area of the tree in square meters.
Example
# Calculate the basal area for a tree with a diameter of 30 cm
julia> basal_area(30.0)
0.07068583470577035
ForestMensuration.bole_volume
— Methodbole_volume(method::Type{<:CubingMethod}, h::Vector{<:Real}, d::Vector{<:Real})
Calculate tree bole volume cubic meters using Smalian, Newton, or Huber methods. The methods involve dividing the tree trunk into n sections (logs). In each section, diameters and lengths are measured at positions that vary according to the technique employed.
Arguments
method::Type{<:CubingMethod}
: The method used for cubing (Smalian, Huber, or Newton).h::Vector{<:Real}
: Vector of heights.d::Vector{<:Real}
: Vector of diameters.
Returns
Float64
: The volume of the bole in cubic meters.
Example
julia> d_values = [9.0, 7.0, 5.8, 5.1, 3.8, 1.9, 0.0];
julia> h_values = [0.3, 1.3, 3.3, 5.3, 7.3, 9.3, 10.8];
julia> bole_volume(Smalian, h_values, d_values)
0.021087744337680632
julia> bole_volume(Huber, h_values, d_values)
0.020708986073382216
julia> bole_volume(Newton, h_values, d_values)
0.015548265641391484
ForestMensuration.cone_volume
— Methodcone_volume(h::Real, d::Real)
Calculates the volume of a cone, used to estimate the final portion (vn) of the tree, typically considered to have a conical shape.
Arguments
h::Real
: The height of the cone in meters.d::Real
: The diameter of the cone in centimeters.
Returns
Float64
: The volume of the cone in cubic meters.
Example
julia> cone_volume(18.5, 30.0)
0.4358959806855838
ForestMensuration.criteria_selection
— Methodcriteria_selection(model::Vector{<:TableRegressionModel}, criteria::Symbol...)
The criteria_selection
function evaluates and ranks a vector of regression models based on specified criteria, returning the best model according to the combined ranking.
Parameters:
model::Vector{<:TableRegressionModel}
: A vector of linear regression models to be evaluated and compared.criteria::Symbol...
: A variable number of symbols representing the evaluation criteria to include. Possible values include::adjr2
: Adjusted R², a measure of the model's explanatory power, adjusted for the number of predictors.:syx
: Standard error of the estimate as a percentage of the mean ofy
.:rmse
: Root Mean Squared Error, indicating the average magnitude of residuals.:mae
: Mean Absolute Error, another accuracy measure based on average absolute residuals.:aic
: Akaike Information Criterion, balancing goodness of fit with model complexity.:significance
: Evaluates whether model coefficients are statistically significant.:normality
: Assesses the normality of residuals, an assumption in linear regression.:homoscedasticity
: Checks for constant variance in residuals, another key regression assumption.
If no criteria are specified, the function will use all available criteria by default.
Returns:
TableRegressionModel
: The best model based on the combined ranking of the specified criteria.
ForestMensuration.criteria_table
— Methodcriteria_table(model::Vector{<:TableRegressionModel}, criteria::Symbol...; best::Union{Bool,Int}=10)
The criteria_table
function evaluates and ranks multiple regression models based on specified criteria. It generates a comprehensive table of performance metrics for each model, calculates ranks for these metrics, and combines them into a final score. The function allows for flexible selection of evaluation criteria and can return either all models or only the top models based on the combined ranking.
Parameters:
model
: The regression model(s) to be evaluated and compared. This parameter can accept:- Single Linear Regression Model (
TableRegressionModel
): Evaluates a single linear regression model. - Vector of Linear Regression Models (
Vector{<:TableRegressionModel}
): Evaluates and compares multiple linear regression models.
- Single Linear Regression Model (
criteria::Symbol...
: A variable number of symbols representing the evaluation criteria to include. Possible values include::adjr2
: Adjusted R², a measure of the model's explanatory power, adjusted for the number of predictors.:syx
: Standard error of the estimate (Syx) expressed as a percentage of the mean of the dependent
variable (y), indicating the precision of the model's predictions.
:rmse
: Root Mean Squared Error, indicating the average magnitude of residuals.:mae
: Mean Absolute Error, another accuracy measure based on average absolute residuals.:aic
: Akaike Information Criterion, balancing goodness of fit with model complexity.:normality
: Assesses the normality of residuals using the Kolmogorov-Smirnov test, ensuring that residuals follow a normal distribution.:significance
: Evaluates whether model coefficients are statistically significant.
If no criteria are specified, the function will use all available criteria by default.
best::Union{Bool, Int}=10
: Specifies the number of top models to return based on the combined ranking.false
: Returns the full table with all models ranked.- Integer value: If less than the total number of models, returns only the top
best
models.
Returns:
DataFrame
: A sorted table with the evaluated models and their respective metrics. Includes a combined rank based on the selected criteria.
Examples:
- Single Model:
criteria_table(model, :adjr2, :rmse)
- Vector of Models:
criteria_table([model1, model2], :aic, :mae)
ForestMensuration.cubage
— Functioncubage(method::Type{<:CubingMethod}, h::Vector{<:Real}, d::Vector{<:Real},
d_limit::Union{Real,Nothing}=nothing; dbh::Real=1.3)
Calculate tree cubage using Smalian, Newton, or Huber methods. The methods involve dividing the tree trunk into n sections (logs). In each section, diameters and lengths are measured at positions that vary according to the technique employed. Thus, the volume of the sections and the total volume are determined by summing the volume of the sections. Determination can be carried out on felled trees or standing trees using equipment such as the Bitterlich relascope.
Arguments
method::Type{<:CubingMethod}
: The method used for cubing (Smalian, Huber, or Newton).h::Vector{<:Real}
: Vector of heights.d::Vector{<:Real}
: Vector of diameters.d_limit::Union{Float64, Nothing}
: Comercial diameter limit to be used in calculations (optional).dbh::Float64
: Diameter at breast height (default is 1.3 meters).
Returns
DataFrame
: A DataFrame with the calculated volumes and form factors.
Example
ForestMensuration.cubage
— Functioncubage(method::Type{<:CubingMethod}, h::Vector{<:Real}, d::Vector{<:Real}, e::Vector{<:Real},
d_limit::Union{Real,Nothing}=nothing; dbh::Float64=1.3)
Calculate tree cubage including bark factor. The methods involve dividing the tree trunk into n sections (logs). In each section, diameters and lengths are measured at positions that vary according to the technique employed.
Arguments
method::Type{<:CubingMethod}
: The method used for cubing (Smalian, Huber, or Newton).h::Vector{<:Real}
: Vector of heights.d::Vector{<:Real}
: Vector of diameters.e::Vector{<:Real}
: Vector of bark thicknesses.d_limit::Union{Float64, Nothing}
: Comercial diameter limit to be used in calculations (optional).dbh::Float64
: Diameter at breast height (default is 1.3 meters).
Returns
DataFrame
: A DataFrame with the calculated volumes, form factors, and bark-adjusted volumes.
Example
ForestMensuration.cubage
— Functioncubage(method::Type{<:CubingMethod}, tree::Symbol, h::Symbol, d::Symbol,
data::AbstractDataFrame, d_limit::Union{Real,Nothing}=nothing; dbh::Float64=1.3)
Calculate tree cubage using grouped data from a DataFrame. The methods involve dividing the tree trunk into n sections (logs). In each section, diameters and lengths are measured at positions that vary according to the technique employed.
Arguments
method::Type{<:CubingMethod}
: The method used for cubing (Smalian, Huber, or Newton).tree::Symbol
: The symbol representing the tree identifier.h::Symbol
: The symbol representing the heights in the DataFrame.d::Symbol
: The symbol representing the diameters in the DataFrame.data::AbstractDataFrame
: The DataFrame containing the tree data.d_limit::Union{Float64, Nothing}
: Comercial diameter limit to be used in calculations (optional).dbh::Float64
: Diameter at breast height (default is 1.3 meters).
Returns
DataFrame
: A DataFrame with the calculated volumes and form factors for each tree.
Example
ForestMensuration.cubage
— Functioncubage(method::Type{<:CubingMethod}, tree::Symbol, h::Symbol, d::Symbol, e::Symbol,
data::AbstractDataFrame, d_limit::Union{Real,Nothing}=nothing; dbh::Float64=1.3)
Calculate tree cubage including bark factor using grouped data from a DataFrame. The methods involve dividing the tree trunk into n sections (logs). In each section, diameters and lengths are measured at positions that vary according to the technique employed.
Arguments
method::Type{<:CubingMethod}
: The method used for cubing (Smalian, Huber, or Newton).tree::Symbol
: The symbol representing the tree identifier.h::Symbol
: The symbol representing the heights in the DataFrame.d::Symbol
: The symbol representing the diameters in the DataFrame.e::Symbol
: The symbol representing the bark thicknesses in the DataFrame.data::AbstractDataFrame
: The DataFrame containing the tree data.d_limit::Union{Float64, Nothing}
: Comercial diameter limit to be used in calculations (optional).dbh::Float64
: Diameter at breast height (default is 1.3 meters).
Returns
DataFrame
: A DataFrame with the calculated volumes, form factors, and bark-adjusted volumes for each tree.
Example
ForestMensuration.cylinder_volume
— Methodcylinder_volume(h::Real, d::Real)
Calculates the volume of a cylinder, used to estimate the volume (v0) of the tree stump remaining after clear-cutting.
Arguments
h::Real
: The height of the cylinder in meters.d::Real
: The diameter of the cylinder in centimeters.
Returns
Float64
: The volume of the cylinder in cubic meters.
Example
julia> cylinder_volume(18.5, 30.0)
1.3076879420567515
ForestMensuration.dendrometric_averages
— Methoddendrometric_averages(p::Symbol, d::Symbol, data::AbstractDataFrame; area::Real=1.0)
Calculates various dendrometric averages for each group in a dataset, grouping by a specified column, and using the diameters specified in another column.
Description
This function computes several dendrometric averages based on a specified diameter column in a DataFrame, grouped by another specified column. These metrics are essential for forest inventory and management, providing insights into the stand structure, volume estimation, and growth patterns for each group.
Arguments
p::Symbol
: The symbol representing the column name indata
used to group the data.d::Symbol
: The symbol representing the column name indata
that contains the diameters at breast height (DBH) of the trees in centimeters. All diameters must be positive values.data::AbstractDataFrame
: The DataFrame containing the dataset with at least the columns specified byp
andd
.area::Real=1.0
: The area in hectares over which the diameters were measured. Default is 1.0 hectare.
Returns
DataFrame
: A DataFrame containing the calculated dendrometric averages for each group defined byp
.
Example
julia> using DataFrames
# Sample data
julia> data = DataFrame(
species = ["Oak", "Oak", "Oak", "Pine", "Pine", "Pine"],
diameter = [10.5, 12.0, 13.5, 15.0, 16.5, 18.0]
);
# Calculate dendrometric averages grouped by species
julia> dendrometric_averages(:species, :diameter, data; area=0.05)
2×8 DataFrame
Row │ species d₋ d̅ dg dw dz d₁₀₀ d₊
│ String Float64 Float64 Float64 Float64 Float64 Float64 Float64
─────┼────────────────────────────────────────────────────────────────────────
1 │ Oak 10.5 12.0 12.0623 12.3 12.0 NaN 13.5
2 │ Pine 15.0 16.5 16.5454 16.8 16.5 NaN 18.0
ForestMensuration.dendrometric_averages
— Methoddendrometric_averages(model::TableRegressionModel; area::Real=1.0)
Calculates various dendrometric averages of a forest stand and estimates the corresponding heights for each diameter using a regression model.
Description
This function computes several dendrometric averages based on a regression model and estimates the heights associated with each calculated diameter using the provided regression model. These metrics are essential for forest inventory and management, providing insights into the stand structure, volume estimation, and growth patterns.
Arguments
model::TableRegressionModel
: A regression model used to predict heights from diameters. The model should be trained with diameters as predictors and heights as the response variable.area::Real=1.0
: The area in hectares over which the diameters were measured. Default is 1.0 hectare.
Returns
DataFrame
: A DataFrame containing the calculated dendrometric averages and the estimated heights. Heights are estimated by applying the regression model to each calculated diameter.h₋
: Estimated height corresponding tod₋
.h̄
: Estimated height corresponding tod̄
.hg
: Estimated height corresponding todg
.hw
: Estimated height corresponding todw
,.hz
: Estimated height corresponding todz
.d₁₀₀
: Estimated height corresponding tod₁₀₀
.h₊
: Estimated height corresponding tod₊
.
Example
julia> using DataFrames
# Assume we have a trained regression model `height_model` that predicts height from diameter
# Sample data for the regression model
julia> heights = [8.0, 9.5, 11.0, 12.5, 14.0, 15.5, 17.0, 18.5, 20.0, 21.5];
julia> diameters = [10.5, 12.0, 13.5, 15.0, 16.5, 18.0, 19.5, 21.0, 22.5, 24.0];
julia> data = DataFrame(h = heights, d = diameters);
# Fit a linear regression model
julia> height_models = regression(:h, :d, data);
julia> best_model = criteria_selection(height_models);
# Calculate dendrometric averages and estimate heights
julia> dendrometric_averages(best_model; area=0.05)
1×14 DataFrame
Row │ d₋ d̅ dg dw dz d₁₀₀ d₊ h₋ h̅ hg hw hz h₊ h₁₀₀
│ Float64 Float64 Float64 Float64 Float64 Float64 Float64 Float64 Float64 Float64 Float64 Float64 Float64 Float64
─────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
1 │ 12.7085 17.25 17.7799 18.6 17.2663 21.0 21.7915 10.2085 14.75 15.2799 16.1 14.7663 18.5 19.2915
ForestMensuration.dendrometric_averages
— Methoddendrometric_averages(d::Vector; area::Real=1.0)
Calculates various dendrometric averages of a forest stand, including mean diameter, quadratic mean diameter, Hohenadl's diameters, Weise's diameter, diameter of the tree with central basal area, and the mean diameter of the 100 largest trees per hectare.
Description
This function computes several dendrometric averages based on a vector of tree diameters. These metrics are essential for forest inventory and management, providing insights into the stand structure, volume estimation, and growth patterns.
Arguments
d::Vector{<:Real}
: A vector of diameters at breast height (DBH) of the trees in centimeters. All diameters must be positive values.area::Real=1.0
: The area in hectares over which the diameters were measured. Default is 1.0 hectare.
Returns
DataFrame
: A DataFrame containing the calculated dendrometric averages:d₋
: Lower Hohenadl's diameter, calculated as (d̄ - s), where d̄ is the mean diameter and s is the standard deviation. Approximately 16% of the trees have diameters belowd₋
. This metric represents one standard deviation below the mean diameter and is useful for understanding the variability and distribution of diameters within the stand.d̄
: Mean diameter, the arithmetic mean of the diameters. It is a basic measure of central tendency but can be influenced by thinning practices. The mean diameter is a fundamental measure but can be significantly affected by the removal of smaller or larger trees during thinning operations.dg
: Quadratic mean diameter, calculated using the mean basal area asdg = sqrt((40000 * mean(g)) / π)
, whereg
is the basal area of each tree. It closely approximates the diameter of the tree with mean basal area and is less affected by extreme values or thinning. This metric provides a better estimate for volume calculations and is less sensitive to variations in the data.dw
: Weise's diameter, the diameter at which 60% of the trees have smaller diameters (the 60th percentile). It approximates the diameter of the tree with mean volume. Weise's diameter is considered a good approximation of the diameter of the tree with mean volume and is less influenced by thinning practices.dz
: Diameter of the tree with central basal area, calculated from the median basal area asdz = sqrt((40000 * median(g)) / π)
. It represents the diameter that divides the stand's total basal area into two equal parts, effectively splitting the cumulative basal area. This metric is less influenced by the removal of smaller trees and provides insight into the stand's structure.d₁₀₀
: Mean diameter of the 100 largest trees per hectare. If there are fewer than 100 trees per hectare, it returnsNaN
. This metric provides insight into the size of the largest trees in the stand, which can be important for management objectives like timber production.d₊
: Upper Hohenadl's diameter, calculated as (d̄ + s). Approximately 84% of the trees have diameters belowd₊
. This metric represents one standard deviation above the mean diameter and is useful for understanding the variability and distribution of diameters within the stand.
Example
julia> using DataFrames
# Sample diameters in centimeters
julia> diameters = [10.5, 12.0, 13.5, 15.0, 16.5, 18.0, 19.5, 21.0, 22.5, 24.0];
# Calculate dendrometric averages
julia> dendrometric_averages(diameters, area=0.05)
1×7 DataFrame
Row │ d₋ d̅ dg dw dz d₁₀₀ d₊
│ Float64 Float64 Float64 Float64 Float64 Float64 Float64
─────┼───────────────────────────────────────────────────────────────
1 │ 12.7085 17.25 17.7799 18.6 17.2663 21.0 21.7915
ForestMensuration.diametric_table
— Methoddiametric_table(g::Symbol, d::Symbol, data::AbstractDataFrame; plot_area::Real=1.0)
Creates a diametric table for grouped data in a DataFrame.
Arguments
g::S
: The symbol representing the grouping variable.d::S
: The symbol representing the diameter values variable.data::AbstractDataFrame
: The DataFrame containing the data.plot_area::Real=1.0
: The plot area in hectares (default is 1.0).
Returns
DataFrame
: A DataFrame containing the diametric table for each group.
Example
julia> using DataFrames
# Define the data'
julia> diameters = [10.5, 12.0, 13.5, 15.0, 16.5, 18.0, 19.5, 21.0, 22.5, 24.0];
julia> species = ["Oak", "Oak", "Oak", "Oak", "Oak", "Pine", "Pine", "Pine", "Pine", "Pine"];
julia> data = DataFrame(species=species, diameters=diameters);
# Calculate the diametric table by group with with auto class width and plot area of 0.05 ha (500 m²)
julia> diametric_table(:species, :diameters, data, plot_area=0.05)
8×15 DataFrame
Row │ species LI Xi LS fi Fi fri Fri g ng ∑ng fi_ha Fi_ha ng_ha ∑ng_ha
│ String Float64 Float64 Float64 Int64 Int64 Float64 Float64 Float64 Float64 Float64 Float64 Float64 Float64 Float64
─────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
1 │ Oak 10.0 11.0 12.0 1 1 20.0 20.0 0.00950332 0.00950332 0.00950332 20.0 20.0 0.190066 0.190066
2 │ Oak 12.0 13.0 14.0 1 2 20.0 40.0 0.0132732 0.0132732 0.0227765 20.0 40.0 0.265465 0.455531
3 │ Oak 14.0 15.0 16.0 1 3 20.0 60.0 0.0176715 0.0176715 0.040448 20.0 60.0 0.353429 0.80896
4 │ Oak 16.0 17.0 18.0 2 5 40.0 100.0 0.022698 0.045396 0.085844 40.0 100.0 0.90792 1.71688
5 │ Pine 18.0 19.0 20.0 1 1 20.0 20.0 0.0283529 0.0283529 0.0283529 20.0 20.0 0.567057 0.567057
6 │ Pine 20.0 21.0 22.0 2 3 40.0 60.0 0.0346361 0.0692721 0.097625 40.0 60.0 1.38544 1.9525
7 │ Pine 22.0 23.0 24.0 1 4 20.0 80.0 0.0415476 0.0415476 0.139173 20.0 80.0 0.830951 2.78345
8 │ Pine 24.0 25.0 26.0 1 5 20.0 100.0 0.0490874 0.0490874 0.18826 20.0 100.0 0.981748 3.7652
ForestMensuration.diametric_table
— Methoddiametric_table(g::Symbol, d::Symbol, hi::Real, data::AbstractDataFrame; plot_area::Real=1.0)
Creates a diametric table for grouped data in a DataFrame with a specified class width.
Arguments
g::S
: The symbol representing the grouping variable.d::S
: The symbol representing the diameter values variable.hi::Real
: The class width.data::AbstractDataFrame
: The DataFrame containing the data.plot_area::Real=1.0
: The plot area in hectares (default is 1.0).
Returns
DataFrame
: A DataFrame containing the diametric table for each group.
Example
julia> using DataFrames
# Define the data'
julia> diameters = [10.5, 12.0, 13.5, 15.0, 16.5, 18.0, 19.5, 21.0, 22.5, 24.0];
julia> species = ["Oak", "Oak", "Oak", "Oak", "Oak", "Pine", "Pine", "Pine", "Pine", "Pine"];
julia> data = DataFrame(species=species, diameters=diameters);
# Calculate the diametric table by group with with The class width of 3 and plot area of 0.05 ha (500 m²)
julia> diametric_table(:species, :diameters, 3, data, plot_area=0.05)
6×15 DataFrame
Row │ species LI Xi LS fi Fi fri Fri g ng ∑ng fi_ha Fi_ha ng_ha ∑ng_ha
│ String Float64 Float64 Float64 Int64 Int64 Float64 Float64 Float64 Float64 Float64 Float64 Float64 Float64 Float64
─────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
1 │ Oak 12.0 13.5 15.0 3 3 60.0 60.0 0.0143139 0.0429416 0.0429416 60.0 60.0 0.858833 0.858833
2 │ Oak 15.0 16.5 18.0 1 4 20.0 80.0 0.0213825 0.0213825 0.0643241 20.0 80.0 0.427649 1.28648
3 │ Oak 18.0 19.5 21.0 1 5 20.0 100.0 0.0298648 0.0298648 0.0941889 20.0 100.0 0.597295 1.88378
4 │ Pine 18.0 19.5 21.0 2 2 40.0 40.0 0.0298648 0.0597295 0.0597295 40.0 40.0 1.19459 1.19459
5 │ Pine 21.0 22.5 24.0 1 3 20.0 60.0 0.0397608 0.0397608 0.0994903 20.0 60.0 0.795216 1.98981
6 │ Pine 24.0 25.5 27.0 2 5 40.0 100.0 0.0510705 0.102141 0.201631 40.0 100.0 2.04282 4.03263
ForestMensuration.diametric_table
— Methoddiametric_table(d::Vector{<:Real}, hi::Real; plot_area::Real=1.0)
Creates a diametric table for a vector of diameter values given a class width and plot area.
Arguments
d::Vector{<:Real}
: The vector of diameter values.hi::Real
: The class width.plot_area::Real=1.0
: The plot area in hectares (default is 1.0).
Returns
DataFrame
: A DataFrame containing the diametric table.
Example
# Define the vector of diameter values
julia> diameters = [10.5, 12.0, 13.5, 15.0, 16.5, 18.0, 19.5, 21.0, 22.5, 24.0];
# Calculate the diametric table with with The class width of 2 and plot area of 0.05 ha (500 m²)
julia> diametric_table(diameters, 2, plot_area=0.05)
8×14 DataFrame
Row │ LI Xi LS fi Fi fri Fri g ng ∑ng fi_ha Fi_ha ng_ha ∑ng_ha
│ Float64 Float64 Float64 Int64 Int64 Float64 Float64 Float64 Float64 Float64 Float64 Float64 Float64 Float64
─────┼─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
1 │ 10.0 11.0 12.0 1 1 10.0 10.0 0.00950332 0.00950332 0.00950332 20.0 20.0 0.190066 0.190066
2 │ 12.0 13.0 14.0 1 2 10.0 20.0 0.0132732 0.0132732 0.0227765 20.0 40.0 0.265465 0.455531
3 │ 14.0 15.0 16.0 1 3 10.0 30.0 0.0176715 0.0176715 0.040448 20.0 60.0 0.353429 0.80896
4 │ 16.0 17.0 18.0 2 5 20.0 50.0 0.022698 0.045396 0.085844 40.0 100.0 0.90792 1.71688
5 │ 18.0 19.0 20.0 1 6 10.0 60.0 0.0283529 0.0283529 0.114197 20.0 120.0 0.567057 2.28394
6 │ 20.0 21.0 22.0 2 8 20.0 80.0 0.0346361 0.0692721 0.183469 40.0 160.0 1.38544 3.66938
7 │ 22.0 23.0 24.0 1 9 10.0 90.0 0.0415476 0.0415476 0.225017 20.0 180.0 0.830951 4.50033
8 │ 24.0 25.0 26.0 1 10 10.0 100.0 0.0490874 0.0490874 0.274104 20.0 200.0 0.981748 5.48208
ForestMensuration.diametric_table
— Methoddiametric_table(d::Vector{<:Real}; plot_area::Real=1.0)
Creates a diametric table for a vector of diameter values.
Arguments
d::Vector{<:Real}
: The vector of diameter values.plot_area::Real=1.0
: The plot area in hectares (default is 1.0).
Returns
DataFrame
: A DataFrame containing the diametric table.
Example
# Define the vector of diameter values
julia> diameters = [10.5, 12.0, 13.5, 15.0, 16.5, 18.0, 19.5, 21.0, 22.5, 24.0];
# Calculate the diametric table with with auto class width and plot area of 0.05 ha (500 m²)
4×14 DataFrame
Row │ LI Xi LS fi Fi fri Fri g ng ∑ng fi_ha Fi_ha ng_ha ∑ng_ha
│ Float64 Float64 Float64 Int64 Int64 Float64 Float64 Float64 Float64 Float64 Float64 Float64 Float64 Float64
─────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
1 │ 10.0 12.5 15.0 2 2 20.0 20.0 0.0122718 0.0245437 0.0245437 40.0 40.0 0.490874 0.490874
2 │ 15.0 17.5 20.0 3 5 30.0 50.0 0.0240528 0.0721585 0.0967021 60.0 100.0 1.44317 1.93404
3 │ 20.0 22.5 25.0 4 9 40.0 90.0 0.0397608 0.159043 0.255745 80.0 180.0 3.18086 5.11491
4 │ 25.0 27.5 30.0 1 10 10.0 100.0 0.0593957 0.0593957 0.315141 20.0 200.0 1.18791 6.30282
ForestMensuration.frequency_table
— Methodfrequency_table(g::Symbol, x::Symbol, data::AbstractDataFrame)
Creates a frequency table for grouped data in a DataFrame.
Arguments
g::S
: The symbol representing the grouping variable.x::S
: The symbol representing the values variable.data::AbstractDataFrame
: The DataFrame containing the data.
Returns
DataFrame
: A DataFrame containing the frequency table for each group.
Example
julia> using DataFrames
# Define the data'
julia> diameters = [10.5, 12.0, 13.5, 15.0, 16.5, 18.0, 19.5, 21.0, 22.5, 24.0];
julia> species = ["Oak", "Oak", "Oak", "Oak", "Oak", "Pine", "Pine", "Pine", "Pine", "Pine"];
julia> data = DataFrame(species=species, diameters=diameters);
# Calculate the frequency table by group with auto class width
julia> frequency_table(:species, :diameters, data)
8×8 DataFrame
Row │ species LI Xi LS fi Fi fri Fri
│ String Float64 Float64 Float64 Int64 Int64 Float64 Float64
─────┼────────────────────────────────────────────────────────────────────
1 │ Oak 10.0 11.0 12.0 1 1 20.0 20.0
2 │ Oak 12.0 13.0 14.0 1 2 20.0 40.0
3 │ Oak 14.0 15.0 16.0 1 3 20.0 60.0
4 │ Oak 16.0 17.0 18.0 2 5 40.0 100.0
5 │ Pine 18.0 19.0 20.0 1 1 20.0 20.0
6 │ Pine 20.0 21.0 22.0 2 3 40.0 60.0
7 │ Pine 22.0 23.0 24.0 1 4 20.0 80.0
8 │ Pine 24.0 25.0 26.0 1 5 20.0 100.0
ForestMensuration.frequency_table
— Methodfrequency_table(g::Symbol, x::Symbol, hi::Real, data::AbstractDataFrame)
Creates a frequency table for grouped data in a DataFrame with a specified class width.
Arguments
g::S
: The symbol representing the grouping variable.x::S
: The symbol representing the values variable.hi::Real
: The class width.data::AbstractDataFrame
: The DataFrame containing the data.
Returns
DataFrame
: A DataFrame containing the frequency table for each group.
Example
julia> using DataFrames
# Define the data'
julia> diameters = [10.5, 12.0, 13.5, 15.0, 16.5, 18.0, 19.5, 21.0, 22.5, 24.0];
julia> species = ["Oak", "Oak", "Oak", "Oak", "Oak", "Pine", "Pine", "Pine", "Pine", "Pine"];
julia> data = DataFrame(species=species, diameters=diameters);
# Calculate the frequency table by group with with The class width of 2
julia> frequency_table(:species, :diameters, 2, data)
8×8 DataFrame
Row │ species LI Xi LS fi Fi fri Fri
│ String Float64 Float64 Float64 Int64 Int64 Float64 Float64
─────┼────────────────────────────────────────────────────────────────────
1 │ Oak 10.0 11.0 12.0 1 1 20.0 20.0
2 │ Oak 12.0 13.0 14.0 1 2 20.0 40.0
3 │ Oak 14.0 15.0 16.0 1 3 20.0 60.0
4 │ Oak 16.0 17.0 18.0 2 5 40.0 100.0
5 │ Pine 18.0 19.0 20.0 1 1 20.0 20.0
6 │ Pine 20.0 21.0 22.0 2 3 40.0 60.0
7 │ Pine 22.0 23.0 24.0 1 4 20.0 80.0
8 │ Pine 24.0 25.0 26.0 1 5 20.0 100.0
ForestMensuration.frequency_table
— Methodfrequency_table(x::Vector{<:Real}, hi::Real)
Creates a frequency table for a vector of values given a class width.
Arguments
x::Vector{<:Real}
: The vector of values.hi::Real
: The class width.
Returns
DataFrame
: A DataFrame containing the frequency table.
Example
# Define the vector of values
julia> x = [10.5, 12.0, 13.5, 15.0, 16.5, 18.0, 19.5, 21.0, 22.5, 24.0];
# Calculate the frequency table with The class width of 2
julia> frequency_table(x, 2)
8×7 DataFrame
Row │ LI Xi LS fi Fi fri Fri
│ Float64 Float64 Float64 Int64 Int64 Float64 Float64
─────┼───────────────────────────────────────────────────────────
1 │ 10.0 11.0 12.0 1 1 10.0 10.0
2 │ 12.0 13.0 14.0 1 2 10.0 20.0
3 │ 14.0 15.0 16.0 1 3 10.0 30.0
4 │ 16.0 17.0 18.0 2 5 20.0 50.0
5 │ 18.0 19.0 20.0 1 6 10.0 60.0
6 │ 20.0 21.0 22.0 2 8 20.0 80.0
7 │ 22.0 23.0 24.0 1 9 10.0 90.0
8 │ 24.0 25.0 26.0 1 10 10.0 100.0
ForestMensuration.frequency_table
— Methodfrequency_table(x::Vector{<:Real})
Creates a frequency table for a vector of values.
Arguments
x::Vector{<:Real}
: The vector of values.
Returns
DataFrame
: A DataFrame containing the frequency table.
Example
# Define the vector of values
julia> x = [10.5, 12.0, 13.5, 15.0, 16.5, 18.0, 19.5, 21.0, 22.5, 24.0];
# Calculate the frequency table with auto class width
julia> frequency_table(x)
4×7 DataFrame
Row │ LI Xi LS fi Fi fri Fri
│ Float64 Float64 Float64 Int64 Int64 Float64 Float64
─────┼───────────────────────────────────────────────────────────
1 │ 10.0 12.5 15.0 2 2 20.0 20.0
2 │ 15.0 17.5 20.0 3 5 30.0 50.0
3 │ 20.0 22.5 25.0 4 9 40.0 90.0
4 │ 25.0 27.5 30.0 1 10 10.0 100.0
ForestMensuration.hdom_classification
— Methodhdom_classification(model::TableRegressionModel, data_age::AbstractDataFrame, index_age::Real, site::Vector{<:Real})
Calculate the dominant height for each observation given the site classification, a fitted model, and an index age.
Description:
The hdom_classification
function calculates the dominant height for each observation based on the provided site classification values, using a fitted growth model and the index age. This function essentially works in the reverse direction of site classification; given the site index (site classification) and the ages, it predicts the dominant heights. It is useful for forecasting tree growth and estimating future stand development based on site productivity classes.
- Dominant Height: The expected average height of the tallest trees in a stand at a given age.
- Age: The current age of the trees for which the dominant height is to be calculated.
- Index Age: A standard age used as a reference point in the growth model.
- Site Classification (Site Index): Values representing the site productivity class, typically the expected dominant height at the index age.
Arguments:
model::StatsModels.TableRegressionModel
: The fitted regression model relating dominant height to age and site index. This model is used to predict heights based on site classes.data_age::AbstractDataFrame
: A DataFrame containing the current age data. It should include anage
column representing the ages for which the dominant height is to be calculated.index_age::Real
: The index age used in the growth model. It serves as the reference age for site index calculations.site::Vector{<:Real}
: A vector containing the site classification values (site indices) for each observation. Each value corresponds to an expected dominant height at the index age.
Returns:
hdom::Vector{Real}
: A vector containing the predicted dominant heights for each observation at their respective ages.
Exemple
julia> using DataFrames
using DataFrames
# Create a DataFrame containing tree plot data
julia> data = DataFrame(
plot = repeat(1:6, inner=5),
age = repeat([36, 48, 60, 72, 84], outer=6),
h = [13.6, 17.8, 21.5, 21.5, 21.8,
14.3, 17.8, 21.0, 21.0, 21.4,
14.0, 17.5, 21.2, 21.2, 21.4,
13.4, 18.0, 20.8, 20.8, 23.2,
13.2, 17.4, 20.3, 20.3, 22.0,
13.2, 17.8, 21.3, 21.3, 22.5]
);
# Perform regression to model the relationship between height (h) and age (age)
# criteria_selection selects the best regression model based on predefined criteria
julia> reg = regression(:h, :age, data) |> criteria_selection;
# Define the data set to predict the site classification
julia> data_to_predict = DataFrame(
plot = repeat(7:8, inner=5),
age = repeat([36, 48, 60, 72, 84], outer=2),
h = [13.1, 17.4, 20.8, 20.8, 22.6,
14.3, 17.3, 20.4, 20.4, 20.9]
);
# Use the selected regression model to classify site quality for each plot
# at an age of 60 months (5 years). Returns a vector of predicted site classification.
julia> sites = site_classification(reg, data_to_predict, 60);
# The predicted dominant height for each observation
julia> hdom_classification(reg, data_to_predict, 60, sites)
10-element Vector{Float64}:
13.1
17.4
20.8
20.9
22.7
14.3
17.3
20.4
20.4
20.9
ForestMensuration.natural_form_factor
— Methodnatural_form_factor(vt::Real, ht::Real, h::Vector{<:Real}, d::Vector{<:Real})
Natural Form Factor (nff): For the calculation of the natural form factor, the volume of the reference cylinder will have a diameter equal to the diameter taken at 1/10 of the total height.
- f0.1h = Rigorous Vol / Cylinder Vol 0.1
Where:
- Rigorous Vol = total volume determined by one of the methods: Smalian, Huber, or Newton;
- Cylinder Vol 0.1 = volume of a cylinder with height equal to the total height of the tree and diameter taken at 1/10 of the total height. Interpolate diameter at a given height using linear interpolation.
Arguments
vt::Real
: The total volume of the tree.ht::Real
: The total height of the tree.h::Vector{<:Real}
: Vector of heights.d::Vector{<:Real}
: Vector of diameters.
Returns
Float64
: The natural form factor.
Example
julia> vt = 0.3378;
julia> ht = 18.5;
julia> d_values = [9.0, 7.0, 5.8, 5.1, 3.8, 1.9, 0.0];
julia> h_values = [0.3, 1.3, 3.3, 5.3, 7.3, 9.3, 10.8];
julia> natural_form_factor(vt, ht, h_values, d_values)
8.951469588617691
ForestMensuration.plot_regression
— Methodplot_regression(model::RegressionModel)
The plot_regression
function generates four essential diagnostic plots to analyze the performance and validity of a linear regression model in Julia. These plots help in assessing the goodness-of-fit, the distribution of residuals, and the assumptions underlying linear regression, such as homoscedasticity and normality. The function is particularly useful for ensuring that the regression model meets the assumptions required for reliable inference and prediction.
Parameters:
model::TableRegressionModel
: The fitted linear regression model. This model is analyzed to generate the diagnostic plots.
Functionality:
Observed vs Fitted Values: This scatter plot compares the observed data points with the values predicted by the model. It is useful for visually assessing the accuracy of the model's predictions.
Residuals vs Fitted Values: This plot shows the residuals (errors) against the fitted values. Ideally, residuals should be randomly scattered around zero without any apparent pattern, indicating a good model fit.
Histogram of Residuals: This histogram displays the distribution of residuals. A normal distribution of residuals is one of the key assumptions of linear regression, and this plot helps verify it.
Normal Q-Q Plot: This plot compares the quantiles of the residuals to the quantiles of a normal distribution. It is used to check the assumption of normality in the residuals.
The function automatically applies color schemes and adjusts plot aesthetics to enhance the clarity of the visualizations. The plots are combined into a single layout for easy comparison and interpretation. Additionally, the function adjusts dynamically based on the number of groups in the data, making it versatile for different datasets and models.
Examples:
# Generate diagnostic plots for a fitted regression model
plots = plot_regression(model)
ForestMensuration.prediction!
— Methodprediction!(model::TableRegressionModel, data::AbstractDataFrame)
The prediction!
function computes predictions from a regression model and adds these predictions directly to the provided data frame as new columns. It is particularly useful in forest inventory data where not all trees have been measured for a specific variable, allowing the model to estimate these missing values.
Parameters:
model
: A single linear regression model.data
: The data frame (AbstractDataFrame
) containing the input data. The function will add new columns to this data frame.
Functionality:
Predicted Values Column (
_prediction
): The function calculates the predicted values for the dependent variable (y
) based on the input model and appends these values as a new column in the data frame with the suffix_prediction
.Real or Estimated Values Column (
_real
): The function also creates a_real
column where the actual measured values ofy
are preserved if they exist. For observations wherey
is missing (or set to0.0
), the predicted value from the model is used instead.This setup is ideal for forest inventory datasets where certain tree attributes (like height or volume) might not be measured for every tree, and predictions need to be filled in for these gaps.
Examples:
# Apply predictions to a data frame
prediction!(model, forest_inventory_data)
ForestMensuration.prediction
— Methodprediction(model::TableRegressionModel)
prediction(model::TableRegressionModel, data::AbstractDataFrame)
prediction(model::TableRegressionModel, data::DataFrameRow)
The prediction
function family provides a versatile way to generate predictions from regression models, supporting both individual and grouped models. It handles predictions on the original scale even if the dependent variable (y
) has been transformed (e.g., log(y)
), ensuring that any transformations applied during model fitting are correctly reversed, including the application of Meyer correction factors for logarithmic transformations.
Parameters:
model
: A single linear regression model.data
: The input data for which predictions are needed. This parameter can be:AbstractDataFrame
: A data frame containing the input data.DataFrameRow
: A single row of data from a data frame.
Returns:
Vector{<:Real}
orVector{Union{Missing, <:Real}}
: The predicted values on the original scale ofy
, adjusted for any transformations and corrected using the Meyer factor for logarithmic transformations.
Key Features:
- Handles Transformed Dependent Variables: If the dependent variable was transformed (e.g., using log transformations), the function correctly inverts the transformation to return predictions on the original scale.
- Applies Meyer Correction Factor: For models using logarithmic transformations, the Meyer correction factor is applied to the predictions to correct for the bias introduced by the log transformation.
- Supports Grouped Models: When using grouped models, the function automatically selects and applies the correct model for each data point based on its group membership.
Examples:
- Single Model Prediction:
y_pred = prediction(model, data)
ForestMensuration.quotient_form
— Methodquotient_form(ht::Real, dbh::Real, h::Vector{<:Real}, d::Vector{<:Real})
Form Quotient (qf): The natural decrease in diameter along the trunk defines the so-called form quotient, which is a ratio between diameters. An example of a form quotient is the Schiffel form quotient, given by:
- Q = D(1/2H) / DBH
Where:
- Q < 1
- D(1/2H) = diameter measured at half the total height of the tree.
Similar to the form factor, the volume of a tree, with or without bark, can be obtained by multiplying the volume of a cylinder by the average form quotient, suitable for the species and the desired volume to be estimated.
Arguments
ht::Real
: The total height of the tree.dbh::Real
: The diameter at breast height of the tree.h::Vector{<:Real}
: Vector of heights.d::Vector{<:Real}
: Vector of diameters.
Returns
Float64
: The form quotient.
Example
julia> ht = 18.5;
julia> dbh = 22.7;
julia> d_values = [9.0, 7.0, 5.8, 5.1, 3.8, 1.9, 0.0];
julia> h_values = [0.3, 1.3, 3.3, 5.3, 7.3, 9.3, 10.8];
julia> quotient_form(ht, dbh, h_values, d_values)
0.08579295154185025
ForestMensuration.regression
— Methodregression(y::Symbol, x::Symbol, data::AbstractDataFrame, q::Symbol...)
The regression
function in Julia automatically generates and evaluates multiple simple regression models based on the provided data, including both continuous and categorical variables. This function significantly expands the traditional analysis typically applied in forest biometrics, such as the relationship between tree height and diameter at breast height (DBH), by automatically generating and evaluating 240 unique combinations of dependent and independent variable transformations.
Parameters:
y::Symbol
: The dependent variable (response variable) for the regression model. Typically represents a continuous measure such as tree height or volume in forestry studies.x::Symbol
: The independent variable (predictor variable) used to explain variations in the dependent variable. Often represents a measure like diameter at breast height (DBH) in forestry.data::AbstractDataFrame
: The dataset containing the variables for regression. The data frame must include all variables specified iny
,x
, andq
, and it will automatically remove any rows with missing values before performing the regression.q::Symbol...
(optional): A variable number of symbols representing additional categorical variables (qualitative factors) to include in the regression model. These are treated as factors and can influence the model differently based on their levels.
Functionality:
Dependent Variable Transformations: The function generates multiple transformations of the dependent variable (
y
), including logarithmic and inverse functions. Specifically, the following transformations are created:log(y)
: Logarithm ofy
.log_minus(y)
: Logarithm ofy - 1.3
.log1p(y)
: Logarithm of1 + y
.1/y
: Inverse ofy
.1/(y - 1.3)
: Inverse ofy - 1.3
.1/√y
: Inverse of the square root ofy
.1/√(y - 1.3)
: Inverse of the square root ofy - 1.3
.x/√y
: Ratio ofx
to the square root ofy
.x/√(y - 1.3)
: Ratio ofx
to the square root ofy - 1.3
.x²/y
: Square ofx
divided byy
.x²/(y - 1.3)
: Square ofx
divided byy - 1.3
.
Independent Variable Transformations: Similarly, multiple transformations of the independent variable (
x
) are created:x²
: Square ofx
.log(x)
: Logarithm ofx
.log(x)²
: Square of the logarithm ofx
.1/x
: Inverse ofx
.1/x²
: Inverse of Square ofx
.
Combined Model Formulations: The function creates a total of 240 combinations of these transformations by pairing the various forms of
y
andx
. For example, the function considers combinations such as:y ~ x + x²
y ~ x + log(x)
log(y) ~ log(x) + 1/x
(x / y) ~ x + log(x)²
- And many more.
This comprehensive set of models extends beyond the typical scope of forest biometrics, where usually only a few standard models (around five) are tested. By automatically exploring a wide array of potential relationships, this method allows for a more thorough investigation of the possible functional forms that describe the relationship between tree height and DBH or other relevant variables.
Standard Regression: The function performs a regression analysis by automatically generating a wide array of possible models. It creates multiple transformations of the dependent and independent variables, combining them into various model forms. The results can be evaluated, and the best models can be selected based on criteria such as adjusted R², RMSE, AIC, and more, using the
criteria_table
function.Qualitative Variables: The function allows the inclusion of categorical variables (
q
) in the regression model. These variables are automatically treated as factors and can be used to capture variations in the dependent variable that are related to these qualitative factors.
Applications:
This method is ideal for forestry researchers and practitioners who want to ensure they are not overlooking any potentially significant models by expanding their analysis to include a broader range of possible relationships between the variables.
Examples:
# Perform standard regression without grouping
models = regression(:height, :diameter, data)
# View the top models based on a specific criteria
best_models = criteria_table(models, :adjr2, :rmse)
ForestMensuration.simple_casual_sampling
— Methodsimple_casual_sampling(volume::Vector{<:Real}, plot_area::Real, total_area::Real;
e::Real=10, α::Real=0.95, lg::Symbol=:en)
Performs simple random sampling for forest inventory analysis with specified plot area and total area.
Description:
The simple_casual_sampling
function calculates various statistical parameters for a forest inventory using simple random sampling methodology. It is designed to estimate the total volume of timber within a forest area by analyzing volume measurements from sample plots.
Simple random sampling is a statistical method where each unit (in this case, a plot) has an equal chance of being selected. This method is commonly used in forest inventories to estimate parameters like mean volume per hectare, total volume, and confidence intervals.
The function computes key statistics such as:
- Mean plot volume
- Coefficient of variation
- Variance and standard error of the mean
- Absolute and relative errors
- Volume per hectare
- Total estimated volume
- Confidence intervals for the total volume
- Required number of plots to achieve a desired error margin
- Number of missing plots to be measured
Arguments:
volume::Vector{<:Real}
: A vector containing the volume measurements from each sampled plot (e.g., in cubic meters per plot).plot_area::Real
: The area of each sample plot (e.g., in hectares). All plots are assumed to have the same area.total_area::Real
: The total area of the forest or stand being inventoried (e.g., in hectares).e::Real=10
: The desired relative error margin as a percentage (default is 10%). This represents the maximum acceptable error in the estimate relative to the true mean.α::Real=0.95
: The confidence level for the statistical estimates (default is 95%). This determines the confidence interval for the total volume estimate.lg::Symbol=:en
: Language for the report output (default is English). Supported options are:en
for English and:pt
for Portuguese.
Returns:
report::DataFrame
: A DataFrame containing the inventory report with calculated statistical parameters and their values, including units of measurement.
Example:
# Define the volumes measured in each sample plot (e.g., in cubic meters)
julia> v = [381.7, 458.9, 468.2, 531.7, 474.1, 401.9, 469.1, 437.4, 435.3, 403.2, 397.1];
# Define the area of each plot (in hectares)
julia> plot_area = 0.05 # hectares
# Define the total area of the forest (in hectares)
julia> total_area = 10 # hectares
# Perform the simple random sampling analysis
julia> simple_casual_sampling(v, plot_area, total_area; e=10, α=0.95, lg=:en)
15×3 DataFrame
Row │ Parameters Values Units
│ String Float64 String
─────┼─────────────────────────────────────────────────────
1 │ plot volume 441.691 m³/0.05ha
2 │ coefficient of variation 10.03 %
3 │ mean variance 168.498 (m³/0.05ha)²
4 │ standard error 12.9807 m³/0.05ha
5 │ absolute error 28.9227 m³/0.05ha
6 │ relative error 6.55 %
7 │ hectare volume 8833.82 m³ha⁻¹
8 │ Total Volume 88338.2 m³
9 │ confidence interval lower 82553.6 m³
10 │ confidence interval upper 94122.7 m³
11 │ population 0.945 finite
12 │ measured plots 11.0 n
13 │ required plots 7.0 n
14 │ missing plots 0.0 n
15 │ possible plots 200.0 N
ForestMensuration.site_classification
— Methodsite_classification(model::TableRegressionModel, data_age::AbstractDataFrame, index_age::Real)
Calculate the site classification (site index) for each observation given a fitted model, a table do predict and an index age.
Description:
Site classification is a method used in forestry to evaluate the productivity and quality of a forest site. It is based on the relationship between the dominant height of trees and their age. By comparing the current dominant height and age of trees to the expected height at a standard reference age (known as the index age), we can classify the site into different productivity classes.
- Dominant Height: The average height of the tallest trees in a stand, considered indicators of site productivity.
- Age: The current age of the trees in the stand.
- Index Age: A standard age used for comparison, often corresponding to the rotation age.
By predicting the dominant height at the index age using a fitted growth model, we obtain the site index. This index reflects the potential height growth of trees on that site and is a key parameter for forest management, aiding in decision-making regarding thinning, harvesting, and sustainability practices.
Arguments:
model::StatsModels.TableRegressionModel
: The fitted regression model that relates dominant height to age. This model is typically derived from empirical data and captures the growth patterns of the species in question.data_age::AbstractDataFrame
: A data frame containing the current age data for each observation. It should include anage
column representing the age of the trees.index_age::Real
: The index age (reference or rotation age) used for site classification. This is the age at which the site index is evaluated and compared.
Returns
site::Vector{Real}
: A vector containing the site classification (site index) for each observation. Each element represents the expected dominant height at the index age, providing a measure of site productivity.
Exemple
julia> using DataFrames
using DataFrames
# Create a DataFrame containing tree plot data
julia> data = DataFrame(
plot = repeat(1:6, inner=5),
age = repeat([36, 48, 60, 72, 84], outer=6),
h = [13.6, 17.8, 21.5, 21.5, 21.8,
14.3, 17.8, 21.0, 21.0, 21.4,
14.0, 17.5, 21.2, 21.2, 21.4,
13.4, 18.0, 20.8, 20.8, 23.2,
13.2, 17.4, 20.3, 20.3, 22.0,
13.2, 17.8, 21.3, 21.3, 22.5]
);
# Perform regression to model the relationship between height (h) and age (age)
# criteria_selection selects the best regression model based on predefined criteria
julia> reg = regression(:h, :age, data) |> criteria_selection;
# Define the data set to predict the site classification
julia> data_to_predict = DataFrame(
plot = repeat(7:8, inner=5),
age = repeat([36, 48, 60, 72, 84], outer=2),
h = [13.1, 17.4, 20.8, 20.8, 22.6,
14.3, 17.3, 20.4, 20.4, 20.9]
);
# Use the selected regression model to classify site quality for each plot
# at an age of 60 months (5 years). Returns a vector of predicted site classification.
julia> site_classification(reg, data_to_predict, 60)
10-element Vector{Float64}:
19.3
19.7
20.8
19.8
21.1
22.2
19.6
20.4
19.4
19.6
)
ForestMensuration.site_classification
— Methodsite_classification(model::TableRegressionModel, index_age::Real)
Calculate the site classification (site index) for each observation given a fitted model and an index age.
Description:
Site classification is a method used in forestry to evaluate the productivity and quality of a forest site. It is based on the relationship between the dominant height of trees and their age. By comparing the current dominant height and age of trees to the expected height at a standard reference age (known as the index age), we can classify the site into different productivity classes.
- Dominant Height: The average height of the tallest trees in a stand, considered indicators of site productivity.
- Age: The current age of the trees in the stand.
- Index Age: A standard age used for comparison, often corresponding to the rotation age.
By predicting the dominant height at the index age using a fitted growth model, we obtain the site index. This index reflects the potential height growth of trees on that site and is a key parameter for forest management, aiding in decision-making regarding thinning, harvesting, and sustainability practices.
Arguments:
model::StatsModels.TableRegressionModel
: The fitted regression model that relates dominant height to age. This model is typically derived from empirical data and captures the growth patterns of the species in question.index_age::Real
: The index age (reference or rotation age) used for site classification. This is the age at which the site index is evaluated and compared.
Returns
site::Vector{Real}
: A vector containing the site classification (site index) for each observation. Each element represents the expected dominant height at the index age, providing a measure of site productivity.
Exemple
julia> using DataFrames
using DataFrames
# Create a DataFrame containing tree plot data
julia> data = DataFrame(
plot = repeat(1:6, inner=5),
age = repeat([36, 48, 60, 72, 84], outer=6),
h = [13.6, 17.8, 21.5, 21.5, 21.8,
14.3, 17.8, 21.0, 21.0, 21.4,
14.0, 17.5, 21.2, 21.2, 21.4,
13.4, 18.0, 20.8, 20.8, 23.2,
13.2, 17.4, 20.3, 20.3, 22.0,
13.2, 17.8, 21.3, 21.3, 22.5]
);
# Perform regression to model the relationship between height (h) and age (age)
# criteria_selection selects the best regression model based on predefined criteria
julia> reg = regression(:h, :age, data) |> criteria_selection;
# Use the selected regression model to classify site quality for each plot
# at an age of 60 months (5 years). Returns a vector of predicted site classification.
julia> site_classification(reg, 60)
30-element Vector{Float64}:
20.5
20.3
21.5
20.4
20.4
22.2
20.3
21.0
19.9
20.0
21.4
19.9
21.2
20.1
20.0
20.0
20.5
20.8
19.8
21.6
19.5
19.7
20.3
19.3
20.5
19.5
20.3
21.3
20.2
21.0
)
ForestMensuration.site_table
— Methodsite_table(model::TableRegressionModel, index_age::Real)
site_table(model::TableRegressionModel, index_age::Real, hi::Real)
Calculate the site table and plot a site graph given a fitted model, index age, and height increment.
Description:
The site_table
function generates a site table based on a fitted growth model, an index age, and a specified height increment. A site table is a tool used in forestry to estimate the expected dominant height of trees at various ages for different site quality classes. It provides a tabulated representation of height growth over time, allowing foresters to assess site productivity and make informed management decisions.
- Site Quality Classes: These are categories that represent different levels of site productivity, typically based on the site index (the expected dominant height at the index age).
- Index Age: A standard reference age used for site classification and comparison between different sites.
- Height Increment (
hi
): The increment by which site index classes are divided. It determines the range and granularity of the site quality classes in the table.
By using the fitted model to predict dominant heights at various ages and site indices, the site table provides a comprehensive overview of growth patterns across different site qualities.
Arguments
model::StatsModels.TableRegressionModel
: The fitted regression model.index_age::Real
: The index age for site classification.hi::Real
: The height increment for site classification.
Returns
SiteAnalysis
: A struct containing a dataFrame containing the site table with predicted dominant heights at various ages for different site index classes and a site plot.
Exemple
julia> using DataFrames
using DataFrames
# Create a DataFrame containing tree plot data
julia> data = DataFrame(
plot = repeat(1:6, inner=5),
age = repeat([36, 48, 60, 72, 84], outer=6),
h = [13.6, 17.8, 21.5, 21.5, 21.8,
14.3, 17.8, 21.0, 21.0, 21.4,
14.0, 17.5, 21.2, 21.2, 21.4,
13.4, 18.0, 20.8, 20.8, 23.2,
13.2, 17.4, 20.3, 20.3, 22.0,
13.2, 17.8, 21.3, 21.3, 22.5]
);
# Perform regression to model the relationship between height (h) and age (age)
# criteria_selection selects the best regression model based on predefined criteria
julia> reg = regression(:h, :age, data) |> criteria_selection;
# Use the selected regression model to generate the site table and site plot
julia> site_table(reg, 60, 1)
5×5 DataFrame
Row │ age S_19.5 S_20.5 S_21.5 S_22.5
│ Float64 Float64 Float64 Float64 Float64
─────┼─────────────────────────────────────────────
1 │ 36.0 13.2 13.6 14.0 14.4
2 │ 48.0 17.2 18.0 18.7 19.5
3 │ 60.0 19.5 20.5 21.5 22.5
4 │ 72.0 20.5 21.6 22.8 23.9
5 │ 84.0 20.8 22.0 23.1 24.3
ForestMensuration.CubingMethod
— Typeabstract type CubingMethod
Abstract type representing a method for cubing (calculating volume).
Subtypes
- Smalian
- Huber
- Newton
ForestMensuration.Huber
— Typeabstract type Huber <: CubingMethod
Huber Method: The Huber method measures the diameter or circumference at the midpoint of the section, and the volume is determined by:
- v = v0 + Σi=1:n(vi) + vt
- vi = gi * li
Where:
- v0 = volume of the stump;
- vi = volume of intermediate sections;
- vt = volume of the cone;
- g = basal area;
- l = length.
ForestMensuration.ModelEquation
— Typestruct ModelEquation
Define ModelEquation struct to store the regression results
Fields
- output::String
- model::TableRegressionModel
ForestMensuration.Newton
— Typeabstract type Newton <: CubingMethod
Newton Method: The Newton method involves measuring at 3 positions along each section (at the ends and in the middle of the logs). Therefore, it is a more laborious method than the others, but the estimated volume will be more accurate.
- v = v0 + Σi=1:n(vi) + vt
- vi = (gi + gm + gi+1)/2 * li
Where:
- v0 = volume of the stump;
- vi = volume of intermediate sections;
- vt = volume of the cone;
- g = basal area;
- gm = basal area at the midpoint of the section;
- l = length.
ForestMensuration.SiteAnalysis
— Typestruct SiteAnalysis
Define SiteAnalysis struct to store the analysis results
Fields
- site_table::DataFrame
- site_plot::Plots.Plot
ForestMensuration.Smalian
— Typeabstract type Smalian <: CubingMethod
Smalian Method: The Smalian method measures diameters or circumferences at the ends of each section and calculates the total volume by:
- Vt = v0 + Σi=1:n(vi) + vt
- v0 = g0 * l0
- vi = (gi + gi+1)/2 * li
- vt = (1/3) * gn * ln
Where:
- v0 = volume of the stump;
- vi = volume of intermediate sections;
- vt = volume of the cone;
- g = basal area;
- l = length.
ForestMensuration.MixTerm
— Typeconst MixTerm = Union{AbstractTerm,Tuple{AbstractTerm,Vararg{AbstractTerm}}}
Union type representing a mixed term, which can be a single AbstractTerm
or a tuple of AbstractTerm
s.
ForestMensuration.emptySchema
— Constantconst emptySchema = Schema()
Represents a default schema used for modeling operations.
ForestMensuration.β0
— Constantconst β0 = InterceptTerm{true}()
Represents an intercept term for linear models.