get_residuals: Extract model residuals

View source: R/get_residuals.R

get_residualsR Documentation

Extract model residuals

Description

Extracts residuals (observed - predicted values) from models fitted with rf(), rf_repeat(), or rf_spatial().

Usage

get_residuals(model)

Arguments

model

Model object from rf(), rf_repeat(), or rf_spatial().

Details

Residuals are calculated as observed minus predicted values. They can be used to assess model fit, check assumptions, and diagnose patterns such as spatial autocorrelation (see get_moran()). Ideally, residuals should be randomly distributed with no systematic patterns.

Value

Numeric vector of residuals with length equal to the number of training observations. For rf_repeat() models, returns the median residual across repetitions.

See Also

rf(), rf_repeat(), rf_spatial(), get_predictions(), get_moran(), plot_residuals_diagnostics()

Other model_info: get_evaluation(), get_importance(), get_importance_local(), get_moran(), get_performance(), get_predictions(), get_response_curves(), get_spatial_predictors(), print.rf(), print_evaluation(), print_importance(), print_moran(), print_performance()

Examples

data(plants_rf)

# Extract residuals
residuals <- get_residuals(plants_rf)
head(residuals)

# Check basic statistics
summary(residuals)

# Plot distribution to check for patterns
hist(residuals, main = "Residual Distribution", xlab = "Residuals")


spatialRF documentation built on Dec. 20, 2025, 1:07 a.m.