calc_r2: Calculate R-Squared for a Model

View source: R/utils.R

calc_r2R Documentation

Calculate R-Squared for a Model

Description

This function calculates the coefficient of determination (R^2) for a given model by comparing the sum of squared errors (SSE) to the total sum of squares (SST).

Usage

calc_r2(model)

Arguments

model

A fitted model object. The model must have resid() and fitted() methods to extract residuals and fitted values.

Value

A numeric value representing the R^2 value of the model. Returns NA if the model is NULL.

Examples

# Example using a simple linear model
data <- data.frame(x = 1:10, y = c(1, 2, 3, 4, 5, 6, 7, 9, 10, 11))
lm_model <- lm(y ~ x, data = data)
calc_r2(lm_model)

beezdiscounting documentation built on April 4, 2025, 4:44 a.m.