View source: R/sfclust-methods.R
fitted.sfclust | R Documentation |
sfclust
ObjectsThis function calculates the fitted values for a specific clustering sample in an
sfclust
object, based on the estimated models for each cluster. The fitted
values are computed using the membership assignments and model parameters
associated with the selected clustering sample.
## S3 method for class 'sfclust'
fitted(object, sample = object$clust$id, sort = FALSE, aggregate = FALSE, ...)
object |
An object of class 'sfclust', containing clustering results and models. |
sample |
An integer specifying the clustering sample number for which
the fitted values should be computed. The default is the |
sort |
Logical value indicating if clusters should be relabel based on number of elements. |
aggregate |
Logical value indicating if fitted values are desired at cluster level. |
... |
Additional arguments, currently not used. |
The function first checks if the provided sample
value is valid (i.e., it is
within the range of available clustering samples). If the specified sample
does not match the current clustering id
, the sfclust
object is updated
accordingly. It then retrieves the membership assignments and cluster models
for the selected sample, calculates the linear predictions for each cluster,
and combines them into a matrix of fitted values.
A stars
object with linear predictor fitted values at regions levels. In case
aggregate = TRUE
, the output
produces an stars
objecto at cluster levels.
library(sfclust)
data(stgaus)
result <- sfclust(stgaus, formula = y ~ f(idt, model = "rw1"), niter = 10,
nmessage = 1)
# Estimated values ordering clusters by size
df_est <- fitted(result, sort = TRUE)
# Estimated values aggregated by cluster
df_est <- fitted(result, aggregate = TRUE)
# Estimated values using a particular clustering sample
df_est <- fitted(result, sample = 3)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.