Skip to contents

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().

Value

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

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.

Examples

data(plants_rf)

# Extract residuals
residuals <- get_residuals(plants_rf)
head(residuals)
#> [1]   -58.03859 -1194.76562  -158.71363  1335.94372   716.88626  -212.86886

# Check basic statistics
summary(residuals)
#>     Min.  1st Qu.   Median     Mean  3rd Qu.     Max. 
#> -3408.93  -847.75  -302.35   -61.71   325.94 11040.86 

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