Learn R Programming

beezdiscounting (version 0.3.2)

calc_r2: 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)

Value

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

Arguments

model

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

Examples

Run this code
# 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)

Run the code above in your browser using DataLab