Clear cached fitted values for a Bayesian spatial model
Source:R/model-classes.R
clear_fitted_cache.RdRemoves the lazily-cached fitted() result so that the next call
recomputes from the posterior. This is only necessary if the underlying
brmsfit engine has been manually mutated after fitting. A change to
data_sf invalidates the entry on its own, because the cached value
carries a digest of the data it was computed from (see
fitted.bayesian_fit). Normal usage never requires it.
Details
The cache environment is shared by every copy of a fit, so clearing it through one copy clears it for all of them. That is harmless: the others recompute.
See also
Other package options and caches:
clear_grid_cache(),
create_grid_polygons_cached(),
spatialkit_quiet()
Examples
# Only a bayesian_fit carries the cache; on any other fit this is a no-op.
if (requireNamespace("ranger", quietly = TRUE)) {
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 <- 2 * pts$a + rnorm(60, 0, 0.3)
fit <- fit_rf_model(pts, "z", "a", num_trees = 50, seed = 1)
clear_fitted_cache(fit)
}