| Title: | Leaf Area Modeling, Evaluation, and Prediction |
|---|---|
| Description: | Tools for leaf area estimation based on leaf length, leaf width, and observed leaf area. The package supports data validation, predictor generation, descriptive statistics, exploratory graphics, scatterplot matrices, linear models, nonlinear models, mixed models, model evaluation, ranking, equation generation, prediction, export of results and plots, and an interactive 'shiny' application. Methods implemented in the package are aligned with non-destructive allometric workflows described by Ribeiro et al. (2024) <doi:10.1016/j.sajb.2024.07.006>, Ribeiro et al. (2023) <doi:10.1590/1807-1929/agriambi.v27n3p209-215>, and Ribeiro et al. (2025) <doi:10.1590/0103-8478cr20230550>. |
| Authors: | Joao Everthon da Silva Ribeiro [aut, cre], Ester dos Santos Coelho [aut], Toshik Iarley da Silva [aut] |
| Maintainer: | Joao Everthon da Silva Ribeiro <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 0.0.1 |
| Built: | 2026-07-07 08:17:34 UTC |
| Source: | https://github.com/agrobioestat/leafarear |
Calculate absolute bias
la_abs_bias_metric(observed, predicted)la_abs_bias_metric(observed, predicted)
observed |
Numeric vector of observed values. |
predicted |
Numeric vector of predicted values. |
A numeric value.
obs <- c(10, 12, 15, 18) pred <- c(9.8, 12.1, 14.7, 18.4) la_abs_bias_metric(obs, pred)obs <- c(10, 12, 15, 18) pred <- c(9.8, 12.1, 14.7, 18.4) la_abs_bias_metric(obs, pred)
Adds equation, coefficients_text, and random_effect columns to the
results or summary table returned by a model-fitting function.
la_add_equation_to_results(fit_object, digits = 4)la_add_equation_to_results(fit_object, digits = 4)
fit_object |
A fit object containing |
digits |
Number of decimal places used in displayed equations. |
A data.frame.
Calculate prediction bias
la_bias(observed, predicted)la_bias(observed, predicted)
observed |
Numeric vector of observed values. |
predicted |
Numeric vector of predicted values. |
A numeric value.
obs <- c(10, 12, 15, 18) pred <- c(9.8, 12.1, 14.7, 18.4) la_bias(obs, pred)obs <- c(10, 12, 15, 18) pred <- c(9.8, 12.1, 14.7, 18.4) la_bias(obs, pred)
Returns a readable equation starting with LA =.
la_build_equation(model, digits = 4)la_build_equation(model, digits = 4)
model |
A fitted model object. |
digits |
Number of decimal places used in the displayed equation. |
A character string.
Calculate Lin's concordance correlation coefficient
la_ccc(observed, predicted)la_ccc(observed, predicted)
observed |
Numeric vector of observed values. |
predicted |
Numeric vector of predicted values. |
A numeric value.
obs <- c(10, 12, 15, 18) pred <- c(9.8, 12.1, 14.7, 18.4) la_ccc(obs, pred)obs <- c(10, 12, 15, 18) pred <- c(9.8, 12.1, 14.7, 18.4) la_ccc(obs, pred)
Generates derived variables from leaf length (L) and leaf width (W) to
support leaf area (LA) modeling.
la_create_derived(data, variables = "all", keep_original = TRUE)la_create_derived(data, variables = "all", keep_original = TRUE)
data |
A data.frame containing at least |
variables |
Character vector with the derived variables to create.
Use |
keep_original |
Logical. If |
A data.frame with derived variables added.
data(leafarea_sample) head(la_create_derived(leafarea_sample, variables = c("LW", "L2", "W2")))data(leafarea_sample) head(la_create_derived(leafarea_sample, variables = c("LW", "L2", "W2")))
Calculate Willmott's index of agreement
la_d(observed, predicted)la_d(observed, predicted)
observed |
Numeric vector of observed values. |
predicted |
Numeric vector of predicted values. |
A numeric value.
obs <- c(10, 12, 15, 18) pred <- c(9.8, 12.1, 14.7, 18.4) la_d(obs, pred)obs <- c(10, 12, 15, 18) pred <- c(9.8, 12.1, 14.7, 18.4) la_d(obs, pred)
Returns descriptive statistics for the default variables available in a
leafareaR dataset, using any combination of L, W, and LA found in
the supplied data.frame.
la_descriptive_default(data, na.rm = TRUE, digits = 4)la_descriptive_default(data, na.rm = TRUE, digits = 4)
data |
A data.frame containing at least one of |
na.rm |
Logical. If |
digits |
Number of decimal places used to round the output. |
A data.frame with descriptive statistics for the available default variables.
data(leafarea_sample) la_descriptive_default(leafarea_sample)data(leafarea_sample) la_descriptive_default(leafarea_sample)
Computes a descriptive summary for selected numeric variables in a leaf area dataset. The output is intended to support data exploration before model fitting and can be applied to the original measurements as well as derived predictors.
la_descriptive_stats(data, variables = NULL, na.rm = TRUE, digits = 4)la_descriptive_stats(data, variables = NULL, na.rm = TRUE, digits = 4)
data |
A data.frame containing numeric variables. |
variables |
Character vector with variable names to summarize. If |
na.rm |
Logical. If |
digits |
Number of decimal places used to round the output. |
A data.frame with descriptive statistics for each selected variable.
data(leafarea_sample) la_descriptive_stats(leafarea_sample, variables = c("L", "W", "LA"))data(leafarea_sample) la_descriptive_stats(leafarea_sample, variables = c("L", "W", "LA"))
la_fit_linear_models() objectEvaluate all linear models from a la_fit_linear_models() object
la_evaluate_linear_models(fit_object, digits = 4)la_evaluate_linear_models(fit_object, digits = 4)
fit_object |
Object returned by |
digits |
Number of decimal places for rounding. |
A data.frame with metrics for all candidate linear models.
data(leafarea_sample) fit <- la_fit_linear_models(leafarea_sample) met <- la_evaluate_linear_models(fit) met[, c("model_id", "RMSE", "R2")]data(leafarea_sample) fit <- la_fit_linear_models(leafarea_sample) met <- la_evaluate_linear_models(fit) met[, c("model_id", "RMSE", "R2")]
la_fit_mixed_models() objectEvaluate all mixed models from a la_fit_mixed_models() object
la_evaluate_mixed_models(fit_object, digits = 4)la_evaluate_mixed_models(fit_object, digits = 4)
fit_object |
Object returned by |
digits |
Number of decimal places for rounding. |
A data.frame with metrics for all candidate mixed models.
data(leafarea_sample) fit <- la_fit_mixed_models(leafarea_sample, group_var = "species") la_evaluate_mixed_models(fit)[, c("model_id", "RMSE", "R2")]data(leafarea_sample) fit <- la_fit_mixed_models(leafarea_sample, group_var = "species") la_evaluate_mixed_models(fit)[, c("model_id", "RMSE", "R2")]
Evaluate a single fitted model
la_evaluate_model( model, data = NULL, response = "LA", model_id = NA_character_, model_type = NA_character_, digits = 4 )la_evaluate_model( model, data = NULL, response = "LA", model_id = NA_character_, model_type = NA_character_, digits = 4 )
model |
A fitted model object ( |
data |
Optional data.frame used to fit the model. Required for |
response |
Character string with the response variable name. |
model_id |
Optional model identifier. |
model_type |
Optional model type label. |
digits |
Number of decimal places for rounding. |
A one-row data.frame.
data(leafarea_sample) dat <- la_create_derived(leafarea_sample, variables = "LW") m <- lm(LA ~ LW, data = dat) la_evaluate_model(m, model_id = "lm_LW", model_type = "linear")data(leafarea_sample) dat <- la_create_derived(leafarea_sample, variables = "LW") m <- lm(LA ~ LW, data = dat) la_evaluate_model(m, model_id = "lm_LW", model_type = "linear")
la_fit_nonlinear_models() objectEvaluate all nonlinear models from a la_fit_nonlinear_models() object
la_evaluate_nonlinear_models(fit_object, digits = 4)la_evaluate_nonlinear_models(fit_object, digits = 4)
fit_object |
Object returned by |
digits |
Number of decimal places for rounding. |
A data.frame with metrics for all candidate nonlinear models.
data(leafarea_sample) fit <- la_fit_nonlinear_models(leafarea_sample, models = c("power_LW", "exponential_LW")) la_evaluate_nonlinear_models(fit)[, c("model_id", "RMSE", "R2")]data(leafarea_sample) fit <- la_fit_nonlinear_models(leafarea_sample, models = c("power_LW", "exponential_LW")) la_evaluate_nonlinear_models(fit)[, c("model_id", "RMSE", "R2")]
Returns a coefficient table from a fitted linear, nonlinear, or mixed model.
la_extract_coefficients(model)la_extract_coefficients(model)
model |
A fitted model object. |
A data.frame with coefficient names and estimates.
Returns user-friendly labels as either a named character vector or a plain character vector.
la_feature_display_names(named = FALSE)la_feature_display_names(named = FALSE)
named |
Logical. If |
A character vector.
Returns a table of internal variable names and user-friendly labels used throughout the package interface.
la_feature_labels()la_feature_labels()
A data.frame with internal names and display labels.
Fits a default or user-supplied set of linear models using L, W, LA,
and derived variables created automatically when needed.
la_fit_linear_models( data, formulas = NULL, include_no_intercept = TRUE, include_multiple = TRUE, include_polynomial = TRUE )la_fit_linear_models( data, formulas = NULL, include_no_intercept = TRUE, include_multiple = TRUE, include_polynomial = TRUE )
data |
A data.frame containing at least |
formulas |
Optional named list of formulas. If |
include_no_intercept |
Logical. Only used when |
include_multiple |
Logical. Only used when |
include_polynomial |
Logical. Only used when |
A list with fitted models, formulas, modeling data, and a summary table enriched with equation information.
data(leafarea_sample) fit <- la_fit_linear_models(leafarea_sample) names(fit$models)data(leafarea_sample) fit <- la_fit_linear_models(leafarea_sample) names(fit$models)
Fits a default or user-supplied set of linear mixed-effects models using
L, W, LA, derived variables created automatically when needed, and a
user-supplied grouping variable.
la_fit_mixed_models( data, group_var, formulas = NULL, random_slope = FALSE, include_multiple = TRUE, include_polynomial = TRUE, REML = FALSE, control = NULL )la_fit_mixed_models( data, group_var, formulas = NULL, random_slope = FALSE, include_multiple = TRUE, include_polynomial = TRUE, REML = FALSE, control = NULL )
data |
A data.frame containing at least |
group_var |
Character string with the grouping variable name. |
formulas |
Optional named list of formulas. If |
random_slope |
Logical. Only used when |
include_multiple |
Logical. Only used when |
include_polynomial |
Logical. Only used when |
REML |
Logical passed to |
control |
Optional control object passed to |
A list with fitted models, formulas, modeling data, and a summary table enriched with equation information.
data(leafarea_sample) fit <- la_fit_mixed_models(leafarea_sample, group_var = "species") names(fit$models)data(leafarea_sample) fit <- la_fit_mixed_models(leafarea_sample, group_var = "species") names(fit$models)
Fits built-in or user-supplied nonlinear model specifications.
la_fit_nonlinear_models( data, models = NULL, specs = NULL, control = stats::nls.control(maxiter = 200, warnOnly = TRUE) )la_fit_nonlinear_models( data, models = NULL, specs = NULL, control = stats::nls.control(maxiter = 200, warnOnly = TRUE) )
data |
A data.frame containing at least |
models |
Optional character vector of model IDs. Used only when |
specs |
Optional named list of nonlinear model specifications. |
control |
Control list passed to |
A list containing fitted models, specifications, data, and summary.
data(leafarea_sample) fit <- la_fit_nonlinear_models(leafarea_sample, models = c("power_LW", "exponential_LW")) names(fit$models) fit$summary[, c("model_id", "converged")]data(leafarea_sample) fit <- la_fit_nonlinear_models(leafarea_sample, models = c("power_LW", "exponential_LW")) names(fit$models) fit$summary[, c("model_id", "converged")]
Produces a concise overview of a validated dataset, including its
dimensions, variable names, and summary statistics for L, W, and LA.
This function is useful as a quick check before creating derived variables
or fitting candidate models.
la_input_overview(data)la_input_overview(data)
data |
A validated data.frame containing |
A list with the number of rows and columns, variable names, and a summary of the main measurement variables.
data(leafarea_sample) validated_data <- la_validate_input(leafarea_sample) overview <- la_input_overview(validated_data) overview$n_rows overview$summarydata(leafarea_sample) validated_data <- la_validate_input(leafarea_sample) overview <- la_input_overview(validated_data) overview$n_rows overview$summary
Extracts observed and fitted values for one selected linear model from the
object returned by la_fit_linear_models().
la_linear_fitted_values(fit_object, model_id)la_linear_fitted_values(fit_object, model_id)
fit_object |
Object returned by |
model_id |
Character string with the model identifier. |
A data.frame with observed, fitted, and residual values.
data(leafarea_sample) fit <- la_fit_linear_models(leafarea_sample) head(la_linear_fitted_values(fit, "lm_LW"))data(leafarea_sample) fit <- la_fit_linear_models(leafarea_sample) head(la_linear_fitted_values(fit, "lm_LW"))
Returns the default set of candidate linear formulas used by
la_fit_linear_models().
la_linear_formulas( include_no_intercept = TRUE, include_multiple = TRUE, include_polynomial = TRUE )la_linear_formulas( include_no_intercept = TRUE, include_multiple = TRUE, include_polynomial = TRUE )
include_no_intercept |
Logical. If |
include_multiple |
Logical. If |
include_polynomial |
Logical. If |
A named list of formulas.
names(la_linear_formulas())names(la_linear_formulas())
Returns the default derived variables available in leafareaR.
la_list_derived()la_list_derived()
A character vector.
la_list_derived()la_list_derived()
Calculate mean absolute error
la_mae(observed, predicted)la_mae(observed, predicted)
observed |
Numeric vector of observed values. |
predicted |
Numeric vector of predicted values. |
A numeric value.
obs <- c(10, 12, 15, 18) pred <- c(9.8, 12.1, 14.7, 18.4) la_mae(obs, pred)obs <- c(10, 12, 15, 18) pred <- c(9.8, 12.1, 14.7, 18.4) la_mae(obs, pred)
Calculate mean absolute percentage error
la_mape(observed, predicted)la_mape(observed, predicted)
observed |
Numeric vector of observed values. |
predicted |
Numeric vector of predicted values. |
A numeric value in percentage.
obs <- c(10, 12, 15, 18) pred <- c(9.8, 12.1, 14.7, 18.4) la_mape(obs, pred)obs <- c(10, 12, 15, 18) pred <- c(9.8, 12.1, 14.7, 18.4) la_mape(obs, pred)
Generates a scatterplot matrix for selected numeric variables.
la_matrixplot( data, variables = NULL, hist = TRUE, pch = 19, cex = 0.6, col = "darkgreen", main = NULL )la_matrixplot( data, variables = NULL, hist = TRUE, pch = 19, cex = 0.6, col = "darkgreen", main = NULL )
data |
A data.frame containing numeric variables. |
variables |
Character vector with variable names to include. If NULL, uses available default variables among L, W, LA. |
hist |
Logical; if TRUE, draws histograms on the diagonal. |
pch |
Plotting character for points. |
cex |
Point size. |
col |
Point color. |
main |
Optional main title. |
Invisibly returns the selected data used in the matrix plot.
data(leafarea_sample) # To display the plot in an interactive R session, run: # la_matrixplot(leafarea_sample, variables = c("L", "W", "LA")) # CRAN-safe example: grDevices::pdf(NULL) la_matrixplot(leafarea_sample, variables = c("L", "W", "LA")) grDevices::dev.off()data(leafarea_sample) # To display the plot in an interactive R session, run: # la_matrixplot(leafarea_sample, variables = c("L", "W", "LA")) # CRAN-safe example: grDevices::pdf(NULL) la_matrixplot(leafarea_sample, variables = c("L", "W", "LA")) grDevices::dev.off()
Generates a matrix plot using available default variables among L, W, and LA.
la_matrixplot_default( data, hist = TRUE, pch = 19, cex = 0.6, col = "darkgreen", main = "Matrix plot of leaf variables" )la_matrixplot_default( data, hist = TRUE, pch = 19, cex = 0.6, col = "darkgreen", main = "Matrix plot of leaf variables" )
data |
A data.frame containing leaf measurements. |
hist |
Logical; if TRUE, draws histograms on the diagonal. |
pch |
Plotting character for points. |
cex |
Point size. |
col |
Point color. |
main |
Optional main title. |
Invisibly returns the selected data used in the matrix plot.
data(leafarea_sample) # To display the plot in an interactive R session, run: # la_matrixplot_default(leafarea_sample) # CRAN-safe example: grDevices::pdf(NULL) la_matrixplot_default(leafarea_sample) grDevices::dev.off()data(leafarea_sample) # To display the plot in an interactive R session, run: # la_matrixplot_default(leafarea_sample) # CRAN-safe example: grDevices::pdf(NULL) la_matrixplot_default(leafarea_sample) grDevices::dev.off()
Calculate a standard metric table from observed and predicted values
la_metric_table( observed, predicted, n_parameters = NA_integer_, model_object = NULL, digits = 4 )la_metric_table( observed, predicted, n_parameters = NA_integer_, model_object = NULL, digits = 4 )
observed |
Numeric vector of observed values. |
predicted |
Numeric vector of predicted values. |
n_parameters |
Optional number of estimated parameters. |
model_object |
Optional fitted model object used to extract AIC and BIC. |
digits |
Number of decimal places for rounding. |
A one-row data.frame.
obs <- c(10, 12, 15, 18) pred <- c(9.8, 12.1, 14.7, 18.4) la_metric_table(obs, pred)obs <- c(10, 12, 15, 18) pred <- c(9.8, 12.1, 14.7, 18.4) la_metric_table(obs, pred)
Extract coefficients from a mixed model
la_mixed_coefficients(fit_object, model_id)la_mixed_coefficients(fit_object, model_id)
fit_object |
Object returned by |
model_id |
Character string with the model identifier. |
A data.frame with fixed-effect coefficients.
data(leafarea_sample) fit <- la_fit_mixed_models(leafarea_sample, group_var = "species") la_mixed_coefficients(fit, names(fit$models)[1])data(leafarea_sample) fit <- la_fit_mixed_models(leafarea_sample, group_var = "species") la_mixed_coefficients(fit, names(fit$models)[1])
Extract fitted values from mixed-model results
la_mixed_fitted_values(fit_object, model_id)la_mixed_fitted_values(fit_object, model_id)
fit_object |
Object returned by |
model_id |
Character string with the model identifier. |
A data.frame with observed, fitted, residual, and group values.
data(leafarea_sample) fit <- la_fit_mixed_models(leafarea_sample, group_var = "species") head(la_mixed_fitted_values(fit, names(fit$models)[1]))data(leafarea_sample) fit <- la_fit_mixed_models(leafarea_sample, group_var = "species") head(la_mixed_fitted_values(fit, names(fit$models)[1]))
Returns the default set of candidate mixed-model formulas used by
la_fit_mixed_models().
la_mixed_formulas( group_var, random_slope = FALSE, include_multiple = TRUE, include_polynomial = TRUE )la_mixed_formulas( group_var, random_slope = FALSE, include_multiple = TRUE, include_polynomial = TRUE )
group_var |
Character string with the grouping variable name. |
random_slope |
Logical. If |
include_multiple |
Logical. If |
include_polynomial |
Logical. If |
A named list of formulas.
names(la_mixed_formulas("species"))names(la_mixed_formulas("species"))
Calculate mean squared error
la_mse(observed, predicted)la_mse(observed, predicted)
observed |
Numeric vector of observed values. |
predicted |
Numeric vector of predicted values. |
A numeric value.
obs <- c(10, 12, 15, 18) pred <- c(9.8, 12.1, 14.7, 18.4) la_mse(obs, pred)obs <- c(10, 12, 15, 18) pred <- c(9.8, 12.1, 14.7, 18.4) la_mse(obs, pred)
Return coefficients from a selected nonlinear model
la_nonlinear_coefficients(fit_object, model_id)la_nonlinear_coefficients(fit_object, model_id)
fit_object |
Object returned by |
model_id |
Character string with the model identifier. |
A data.frame with parameter estimates.
data(leafarea_sample) fit <- la_fit_nonlinear_models(leafarea_sample, models = c("power_LW")) la_nonlinear_coefficients(fit, "power_LW")data(leafarea_sample) fit <- la_fit_nonlinear_models(leafarea_sample, models = c("power_LW")) la_nonlinear_coefficients(fit, "power_LW")
Extract observed, fitted values and residuals for a selected nonlinear model
la_nonlinear_fitted_values(fit_object, model_id)la_nonlinear_fitted_values(fit_object, model_id)
fit_object |
Object returned by |
model_id |
Character string with the model identifier. |
A data.frame with observed, fitted, and residual values.
data(leafarea_sample) fit <- la_fit_nonlinear_models(leafarea_sample, models = c("power_LW")) head(la_nonlinear_fitted_values(fit, "power_LW"))data(leafarea_sample) fit <- la_fit_nonlinear_models(leafarea_sample, models = c("power_LW")) head(la_nonlinear_fitted_values(fit, "power_LW"))
Returns the default built-in nonlinear candidate specifications.
la_nonlinear_specs()la_nonlinear_specs()
A named list of nonlinear model specifications.
names(la_nonlinear_specs())names(la_nonlinear_specs())
Calculate Nash-Sutcliffe efficiency
la_nse(observed, predicted)la_nse(observed, predicted)
observed |
Numeric vector of observed values. |
predicted |
Numeric vector of predicted values. |
A numeric value.
obs <- c(10, 12, 15, 18) pred <- c(9.8, 12.1, 14.7, 18.4) la_nse(obs, pred)obs <- c(10, 12, 15, 18) pred <- c(9.8, 12.1, 14.7, 18.4) la_nse(obs, pred)
Creates a plot comparing observed and predicted leaf area values.
la_plot_observed_predicted( observed, predicted, model_name = "Selected model", point_size = 2.2, alpha = 0.75 )la_plot_observed_predicted( observed, predicted, model_name = "Selected model", point_size = 2.2, alpha = 0.75 )
observed |
Numeric vector of observed values. |
predicted |
Numeric vector of predicted values. |
model_name |
Character. Label used in the plot title. |
point_size |
Numeric. Point size. |
alpha |
Numeric. Point transparency. |
A ggplot object.
if (requireNamespace("ggplot2", quietly = TRUE)) { data(leafarea_sample) fit <- la_fit_linear_models(leafarea_sample) vals <- la_linear_fitted_values(fit, model_id = "lm_LW") p <- la_plot_observed_predicted(vals$observed, vals$fitted, model_name = "lm_LW") print(p) }if (requireNamespace("ggplot2", quietly = TRUE)) { data(leafarea_sample) fit <- la_fit_linear_models(leafarea_sample) vals <- la_linear_fitted_values(fit, model_id = "lm_LW") p <- la_plot_observed_predicted(vals$observed, vals$fitted, model_name = "lm_LW") print(p) }
Creates a histogram of residuals from observed and predicted values.
la_plot_residual_histogram( observed, predicted, bins = 30, model_name = "Selected model" )la_plot_residual_histogram( observed, predicted, bins = 30, model_name = "Selected model" )
observed |
Numeric vector of observed values. |
predicted |
Numeric vector of predicted values. |
bins |
Number of histogram bins. |
model_name |
Character. Label used in the plot title. |
A ggplot object.
if (requireNamespace("ggplot2", quietly = TRUE)) { data(leafarea_sample) fit <- la_fit_linear_models(leafarea_sample) vals <- la_linear_fitted_values(fit, model_id = "lm_LW") p <- la_plot_residual_histogram(vals$observed, vals$fitted, model_name = "lm_LW") print(p) }if (requireNamespace("ggplot2", quietly = TRUE)) { data(leafarea_sample) fit <- la_fit_linear_models(leafarea_sample) vals <- la_linear_fitted_values(fit, model_id = "lm_LW") p <- la_plot_residual_histogram(vals$observed, vals$fitted, model_name = "lm_LW") print(p) }
Creates a QQ plot of residuals from observed and predicted values.
la_plot_residual_qq(observed, predicted, model_name = "Selected model")la_plot_residual_qq(observed, predicted, model_name = "Selected model")
observed |
Numeric vector of observed values. |
predicted |
Numeric vector of predicted values. |
model_name |
Character. Label used in the plot title. |
A ggplot object.
if (requireNamespace("ggplot2", quietly = TRUE)) { data(leafarea_sample) fit <- la_fit_linear_models(leafarea_sample) vals <- la_linear_fitted_values(fit, model_id = "lm_LW") p <- la_plot_residual_qq(vals$observed, vals$fitted, model_name = "lm_LW") print(p) }if (requireNamespace("ggplot2", quietly = TRUE)) { data(leafarea_sample) fit <- la_fit_linear_models(leafarea_sample) vals <- la_linear_fitted_values(fit, model_id = "lm_LW") p <- la_plot_residual_qq(vals$observed, vals$fitted, model_name = "lm_LW") print(p) }
Creates a residual diagnostic plot from observed and predicted values.
la_plot_residuals( observed, predicted, model_name = "Selected model", point_size = 2.2, alpha = 0.75 )la_plot_residuals( observed, predicted, model_name = "Selected model", point_size = 2.2, alpha = 0.75 )
observed |
Numeric vector of observed values. |
predicted |
Numeric vector of predicted values. |
model_name |
Character. Label used in the plot title. |
point_size |
Numeric. Point size. |
alpha |
Numeric. Point transparency. |
A ggplot object.
if (requireNamespace("ggplot2", quietly = TRUE)) { data(leafarea_sample) fit <- la_fit_linear_models(leafarea_sample) vals <- la_linear_fitted_values(fit, model_id = "lm_LW") p <- la_plot_residuals(vals$observed, vals$fitted, model_name = "lm_LW") print(p) }if (requireNamespace("ggplot2", quietly = TRUE)) { data(leafarea_sample) fit <- la_fit_linear_models(leafarea_sample) vals <- la_linear_fitted_values(fit, model_id = "lm_LW") p <- la_plot_residuals(vals$observed, vals$fitted, model_name = "lm_LW") print(p) }
Creates a scatter plot for two selected variables in a leaf area dataset.
la_plot_scatter( data, x, y = "LA", color_var = NULL, add_smooth = TRUE, point_size = 2.2, alpha = 0.75 )la_plot_scatter( data, x, y = "LA", color_var = NULL, add_smooth = TRUE, point_size = 2.2, alpha = 0.75 )
data |
A data.frame containing the selected variables. |
x |
Character. Name of the x-axis variable. |
y |
Character. Name of the y-axis variable. Default is |
color_var |
Optional character. Grouping variable used for point color. |
add_smooth |
Logical. If |
point_size |
Numeric. Point size. |
alpha |
Numeric. Point transparency. |
A ggplot object.
if (requireNamespace("ggplot2", quietly = TRUE)) { data(leafarea_sample) p <- la_plot_scatter(leafarea_sample, x = "L", y = "LA") print(p) }if (requireNamespace("ggplot2", quietly = TRUE)) { data(leafarea_sample) p <- la_plot_scatter(leafarea_sample, x = "L", y = "LA") print(p) }
Creates a list of scatter plots using the selected predictors against the response variable.
la_plot_scatter_set( data, predictors = c("L", "W", "LW"), response = "LA", add_smooth = TRUE, point_size = 2.2, alpha = 0.75 )la_plot_scatter_set( data, predictors = c("L", "W", "LW"), response = "LA", add_smooth = TRUE, point_size = 2.2, alpha = 0.75 )
data |
A data.frame containing the selected variables. |
predictors |
Character vector of predictor names. |
response |
Character. Name of the response variable. |
add_smooth |
Logical. If |
point_size |
Numeric. Point size. |
alpha |
Numeric. Point transparency. |
A named list of ggplot objects.
if (requireNamespace("ggplot2", quietly = TRUE)) { data(leafarea_sample) dat <- la_create_derived(leafarea_sample, variables = c("LW")) plots <- la_plot_scatter_set(dat, predictors = c("L", "W", "LW")) print(plots[[1]]) }if (requireNamespace("ggplot2", quietly = TRUE)) { data(leafarea_sample) dat <- la_create_derived(leafarea_sample, variables = c("LW")) plots <- la_plot_scatter_set(dat, predictors = c("L", "W", "LW")) print(plots[[1]]) }
Predict using one selected model from a fit object
la_predict_from_results( fit_object, model_id = 1, newdata, allow_new_levels = TRUE, re_form = NULL )la_predict_from_results( fit_object, model_id = 1, newdata, allow_new_levels = TRUE, re_form = NULL )
fit_object |
A fitted-model result object containing |
model_id |
Model position or model name. |
newdata |
A data.frame for prediction. |
allow_new_levels |
Logical used for mixed models. |
re_form |
Optional random-effects structure used for mixed models. |
A data.frame.
data(leafarea_sample) fit <- la_fit_linear_models(leafarea_sample) newdata_ex <- leafarea_sample[1:5, c("L", "W", "LA")] la_predict_from_results(fit, model_id = "lm_LW", newdata = newdata_ex)data(leafarea_sample) fit <- la_fit_linear_models(leafarea_sample) newdata_ex <- leafarea_sample[1:5, c("L", "W", "LA")] la_predict_from_results(fit, model_id = "lm_LW", newdata = newdata_ex)
Predict from a linear model
la_predict_linear_model(model, newdata)la_predict_linear_model(model, newdata)
model |
An object of class |
newdata |
A data.frame for prediction. |
A data.frame.
data(leafarea_sample) fit <- la_fit_linear_models(leafarea_sample) newdata_ex <- leafarea_sample[1:5, c("L", "W", "LA")] la_predict_linear_model(fit$models[["lm_LW"]], newdata_ex)data(leafarea_sample) fit <- la_fit_linear_models(leafarea_sample) newdata_ex <- leafarea_sample[1:5, c("L", "W", "LA")] la_predict_linear_model(fit$models[["lm_LW"]], newdata_ex)
Predict from a mixed model
la_predict_mixed_model(model, newdata, allow_new_levels = TRUE, re_form = NULL)la_predict_mixed_model(model, newdata, allow_new_levels = TRUE, re_form = NULL)
model |
An object of class |
newdata |
A data.frame for prediction. |
allow_new_levels |
Logical used for mixed models. |
re_form |
Optional random-effects structure used for mixed models. |
A data.frame.
data(leafarea_sample) fit <- la_fit_mixed_models(leafarea_sample, group_var = "species") newdata_ex <- leafarea_sample[1:5, c("L", "W", "LA", "species")] la_predict_mixed_model(fit$models[[names(fit$models)[1]]], newdata_ex)data(leafarea_sample) fit <- la_fit_mixed_models(leafarea_sample, group_var = "species") newdata_ex <- leafarea_sample[1:5, c("L", "W", "LA", "species")] la_predict_mixed_model(fit$models[[names(fit$models)[1]]], newdata_ex)
Generic dispatcher for prediction from linear, nonlinear, or mixed models.
la_predict_model( model, newdata, model_type = c("auto", "linear", "nonlinear", "mixed"), allow_new_levels = TRUE, re_form = NULL )la_predict_model( model, newdata, model_type = c("auto", "linear", "nonlinear", "mixed"), allow_new_levels = TRUE, re_form = NULL )
model |
A fitted model object. |
newdata |
A data.frame for prediction. |
model_type |
One of |
allow_new_levels |
Logical used for mixed models. |
re_form |
Optional random-effects structure used for mixed models. |
A data.frame containing the prediction columns.
data(leafarea_sample) fit <- la_fit_linear_models(leafarea_sample) newdata_ex <- leafarea_sample[1:5, c("L", "W", "LA")] la_predict_model(fit$models[["lm_LW"]], newdata_ex)data(leafarea_sample) fit <- la_fit_linear_models(leafarea_sample) newdata_ex <- leafarea_sample[1:5, c("L", "W", "LA")] la_predict_model(fit$models[["lm_LW"]], newdata_ex)
Predict from a nonlinear model
la_predict_nonlinear_model(model, newdata)la_predict_nonlinear_model(model, newdata)
model |
An object of class |
newdata |
A data.frame for prediction. |
A data.frame.
data(leafarea_sample) fit <- la_fit_nonlinear_models(leafarea_sample, models = c("power_LW")) newdata_ex <- leafarea_sample[1:5, c("L", "W", "LA")] la_predict_nonlinear_model(fit$models[["power_LW"]], newdata_ex)data(leafarea_sample) fit <- la_fit_nonlinear_models(leafarea_sample, models = c("power_LW")) newdata_ex <- leafarea_sample[1:5, c("L", "W", "LA")] la_predict_nonlinear_model(fit$models[["power_LW"]], newdata_ex)
Predict from the top-ranked model
la_predict_top_ranked( ranked_table, fit_object, rank_position = 1, newdata, allow_new_levels = TRUE, re_form = NULL )la_predict_top_ranked( ranked_table, fit_object, rank_position = 1, newdata, allow_new_levels = TRUE, re_form = NULL )
ranked_table |
A ranked data.frame containing |
fit_object |
A fitted-model result object containing |
rank_position |
Row position within |
newdata |
A data.frame for prediction. |
allow_new_levels |
Logical used for mixed models. |
re_form |
Optional random-effects structure used for mixed models. |
A data.frame.
data(leafarea_sample) fit <- la_fit_linear_models(leafarea_sample) met <- la_evaluate_linear_models(fit) ranked <- la_rank_models(met) newdata_ex <- leafarea_sample[1:5, c("L", "W", "LA")] la_predict_top_ranked( ranked, fit, rank_position = 1, newdata = newdata_ex )data(leafarea_sample) fit <- la_fit_linear_models(leafarea_sample) met <- la_evaluate_linear_models(fit) ranked <- la_rank_models(met) newdata_ex <- leafarea_sample[1:5, c("L", "W", "LA")] la_predict_top_ranked( ranked, fit, rank_position = 1, newdata = newdata_ex )
Calculate Pearson correlation coefficient
la_r(observed, predicted)la_r(observed, predicted)
observed |
Numeric vector of observed values. |
predicted |
Numeric vector of predicted values. |
A numeric value.
obs <- c(10, 12, 15, 18) pred <- c(9.8, 12.1, 14.7, 18.4) la_r(obs, pred)obs <- c(10, 12, 15, 18) pred <- c(9.8, 12.1, 14.7, 18.4) la_r(obs, pred)
Calculate coefficient of determination
la_r_squared(observed, predicted)la_r_squared(observed, predicted)
observed |
Numeric vector of observed values. |
predicted |
Numeric vector of predicted values. |
A numeric value.
obs <- c(10, 12, 15, 18) pred <- c(9.8, 12.1, 14.7, 18.4) la_r_squared(obs, pred)obs <- c(10, 12, 15, 18) pred <- c(9.8, 12.1, 14.7, 18.4) la_r_squared(obs, pred)
Orders models according to a sequence of evaluation criteria.
la_rank_models( metrics_table, sort_by = c("RMSE", "MAE", "CCC", "R2", "ABS_BIAS"), ascending = c(TRUE, TRUE, FALSE, FALSE, TRUE) )la_rank_models( metrics_table, sort_by = c("RMSE", "MAE", "CCC", "R2", "ABS_BIAS"), ascending = c(TRUE, TRUE, FALSE, FALSE, TRUE) )
metrics_table |
A data.frame containing model metrics. |
sort_by |
Character vector with metric names used for ordering. |
ascending |
Logical vector indicating whether each metric should be sorted in ascending order. |
A ranked data.frame.
data(leafarea_sample) fit <- la_fit_linear_models(leafarea_sample) met <- la_evaluate_linear_models(fit) la_rank_models(met)data(leafarea_sample) fit <- la_fit_linear_models(leafarea_sample) met <- la_evaluate_linear_models(fit) la_rank_models(met)
Computes metric-wise ranks and aggregates them using the mean rank.
la_rank_models_by_metrics(metrics_table)la_rank_models_by_metrics(metrics_table)
metrics_table |
A data.frame containing model metrics. |
A ranked data.frame.
data(leafarea_sample) fit <- la_fit_linear_models(leafarea_sample) met <- la_evaluate_linear_models(fit) la_rank_models_by_metrics(met)data(leafarea_sample) fit <- la_fit_linear_models(leafarea_sample) met <- la_evaluate_linear_models(fit) la_rank_models_by_metrics(met)
Computes a weighted score from selected metrics after min-max scaling.
la_rank_models_weighted( metrics_table, weights = list(RMSE = 0.3, MAE = 0.2, CCC = 0.2, R2 = 0.15, ABS_BIAS = 0.1, d = 0.05) )la_rank_models_weighted( metrics_table, weights = list(RMSE = 0.3, MAE = 0.2, CCC = 0.2, R2 = 0.15, ABS_BIAS = 0.1, d = 0.05) )
metrics_table |
A data.frame containing model metrics. |
weights |
Named list of metric weights. |
A ranked data.frame.
data(leafarea_sample) fit <- la_fit_linear_models(leafarea_sample) met <- la_evaluate_linear_models(fit) la_rank_models_weighted(met)data(leafarea_sample) fit <- la_fit_linear_models(leafarea_sample) met <- la_evaluate_linear_models(fit) la_rank_models_weighted(met)
Calculate root mean squared error
la_rmse(observed, predicted)la_rmse(observed, predicted)
observed |
Numeric vector of observed values. |
predicted |
Numeric vector of predicted values. |
A numeric value.
obs <- c(10, 12, 15, 18) pred <- c(9.8, 12.1, 14.7, 18.4) la_rmse(obs, pred)obs <- c(10, 12, 15, 18) pred <- c(9.8, 12.1, 14.7, 18.4) la_rmse(obs, pred)
Returns the first n rows from a ranked table.
la_top_models( ranking_table, n = 5, rank_column = c("rank_simple", "rank_weighted", "rank_mean") )la_top_models( ranking_table, n = 5, rank_column = c("rank_simple", "rank_weighted", "rank_mean") )
ranking_table |
A ranked data.frame. |
n |
Number of rows to return. |
rank_column |
Column used to order the rows. |
A data.frame.
data(leafarea_sample) fit <- la_fit_linear_models(leafarea_sample) met <- la_evaluate_linear_models(fit) ranked <- la_rank_models(met) la_top_models(ranked, n = 3)data(leafarea_sample) fit <- la_fit_linear_models(leafarea_sample) met <- la_evaluate_linear_models(fit) ranked <- la_rank_models(met) la_top_models(ranked, n = 3)
Checks that the selected leaf length, leaf width, and observed leaf area
columns are present and numeric, applies optional cleaning rules, and
standardizes their names to L, W, and LA for downstream use in
leafareaR.
la_validate_input( data, l_col = "L", w_col = "W", la_col = "LA", remove_na = TRUE, remove_nonpositive = TRUE, standardize_names = TRUE, keep_all_columns = FALSE )la_validate_input( data, l_col = "L", w_col = "W", la_col = "LA", remove_na = TRUE, remove_nonpositive = TRUE, standardize_names = TRUE, keep_all_columns = FALSE )
data |
A data.frame containing at least the columns |
l_col |
Character. Name of the column containing leaf length. |
w_col |
Character. Name of the column containing leaf width. |
la_col |
Character. Name of the column containing observed leaf area. |
remove_na |
Logical. If |
remove_nonpositive |
Logical. If |
standardize_names |
Logical. If |
keep_all_columns |
Logical. If |
A validated data.frame ready for descriptive analysis, model fitting,
prediction, and visualization in the leafareaR workflow.
data(leafarea_sample) validated_data <- la_validate_input(leafarea_sample) head(validated_data) validated_with_groups <- la_validate_input( data = leafarea_sample, keep_all_columns = TRUE ) head(validated_with_groups)data(leafarea_sample) validated_data <- la_validate_input(leafarea_sample) head(validated_data) validated_with_groups <- la_validate_input( data = leafarea_sample, keep_all_columns = TRUE ) head(validated_with_groups)
A sample dataset included in leafareaR for testing data validation,
descriptive statistics, derived variables, plotting, linear models,
nonlinear models, mixed models, ranking, and prediction.
data(leafarea_sample)data(leafarea_sample)
A data.frame with 9999 rows and 6 variables:
Leaf length.
Leaf width.
Observed leaf area.
Species identifier.
Block identifier.
Genotype identifier.
data(leafarea_sample) head(leafarea_sample)data(leafarea_sample) head(leafarea_sample)
Opens the interactive leafareaR Shiny app, which provides a graphical
interface for loading example data or uploading user data, exploratory
analysis, model fitting, evaluation, ranking, and prediction.
run_leafareaR_app(...)run_leafareaR_app(...)
... |
Additional arguments passed to |
Launches the application.
app_dir <- system.file("shiny", "leafareaR-app", package = "leafareaR") dir.exists(app_dir) if (interactive()) { run_leafareaR_app() }app_dir <- system.file("shiny", "leafareaR-app", package = "leafareaR") dir.exists(app_dir) if (interactive()) { run_leafareaR_app() }