Learn R Programming

flexFitR (version 1.2.2)

metrics: Metrics for an object of class modeler

Description

Computes various performance metrics for a modeler object. The function calculates Sum of Squared Errors (SSE), Mean Absolute Error (MAE), Mean Squared Error (MSE), Root Mean Squared Error (RMSE), and the Coefficient of Determination (R-squared).

Usage

metrics(x, by_grp = TRUE)

Value

A data frame containing the calculated metrics grouped by uid, metadata, and variables.

Arguments

x

An object of class `modeler` containing the necessary data to compute the metrics.

by_grp

Return the metrics by id? TRUE by default.

Details

Sum of Squared Errors (SSE): $$SSE = \sum_{i=1}^{n} (y_i - \hat{y}_i)^2$$Mean Absolute Error (MAE): $$MAE = \frac{1}{n} \sum_{i=1}^{n} |y_i - \hat{y}_i|$$Mean Squared Error (MSE): $$MSE = \frac{1}{n} \sum_{i=1}^{n} (y_i - \hat{y}_i)^2$$Root Mean Squared Error (RMSE): $$RMSE = \sqrt{\frac{1}{n} \sum_{i=1}^{n} (y_i - \hat{y}_i)^2}$$Coefficient of Determination (R-squared): $$R^2 = 1 - \frac{\sum_{i=1}^{n} (y_i - \hat{y}_i)^2}{\sum_{i=1}^{n} (y_i - \bar{y})^2}$$

Examples

Run this code
library(flexFitR)
data(dt_potato)
mod_1 <- dt_potato |>
  modeler(
    x = DAP,
    y = Canopy,
    grp = Plot,
    fn = "fn_lin_plat",
    parameters = c(t1 = 45, t2 = 80, k = 0.9),
    subset = c(1:2)
  )
plot(mod_1, id = c(1:2))
print(mod_1)
metrics(mod_1)

Run the code above in your browser using DataLab