Computes goodness-of-fit metrics from fitted(object) against the
observed response, and prints them with what they are to be read
against. A character or factor response is an error; a logical response
is scored as 0/1.
Usage
# S3 method for class 'spatial_fit'
summary(object, ...)Value
An object of class summary.spatial_fit: a list with
class, formula, n, response_var,
predictor_vars, info and in_sample (the metric
data.frame, out-of-bag for an rf_fit).
What the metrics are computed on
For a GWR or a Bayesian GP fit these are in-sample metrics:
fitted() returns values computed at the training locations from
the model that saw them. For a random forest they are out-of-bag,
because fitted() on an rf_fit returns out-of-bag
predictions (see fit_rf_model()). The two are not
comparable, and print() on the result says which one it holds,
from $info$fitted_are_oob. Use compare_models_cv() to
compare backends.
Adjusted \(R^2\) is not computed: a GWR's effective number of
parameters far exceeds the global predictor count, and a GP model has no
simple p.
For a GWR, print() on the result adds what the in-sample metrics
are to be read against: the effective number of parameters and residual
degrees of freedom, the number of local windows of deficient rank, the
number of locations when observations share one, and the AICc and RMSE of
one global least-squares regression on the same rows beside the fit's own
AICc ($info$global_ols; see fit_gwr_model()).
MAPE and SMAPE skip rows whose denominator is zero;
n_MAPE and n_SMAPE count the rows they used (see
"Percentage errors on responses with zeros" in
model_metrics()).
See also
model_metrics() for the metrics alone, and on new
data.
Other fit methods:
plot.spatial_fit(),
print.spatial_fit(),
spatial_fit-coef,
spatial_fit-fitted,
spatial_fit-predict,
spatial_fit-residuals
Examples
library(sf)
set.seed(1)
pts <- st_as_sf(
data.frame(x = 5e5 + runif(60, 0, 1000), y = 5e6 + runif(60, 0, 1000),
a = rnorm(60)),
coords = c("x", "y"), crs = 32632
)
pts$z <- 10 + 2 * pts$a + rnorm(60, 0, 0.3)
fit <- fit_rf_model(pts, "z", "a", num_trees = 50, seed = 1)
summary(fit) # out-of-bag metrics for a forest
#> Summary of <rf_fit> fit (n = 60)
#>
#> Formula: z ~ a
#>
#> Out-of-bag metrics (NOT in-sample; see ?fit_rf_model):
#> RMSE = 0.4094
#> MAE = 0.3270
#> R^2 = 0.9493
#> SMAPE = 3.33%