View source: R/cluster.scores.R
cluster.scores | R Documentation |
This function computes group means by default.
cluster.scores(data, ..., cluster,
fun = c("mean", "sum", "median", "var", "sd", "min", "max"),
expand = TRUE, append = TRUE, name = ".a", as.na = NULL,
check = TRUE)
data |
a numeric vector for centering a predictor variable, or a data frame for centering more than one predictor variable. |
... |
an expression indicating the variable names in |
cluster |
a character string indicating the variable name of
the cluster variable in |
fun |
character string indicating the function used to compute group
scores, default: |
expand |
logical: if |
append |
logical: if |
name |
a character string or character vector indicating the names
of the computed variables. By default, variables are named with the ending
|
as.na |
a numeric vector indicating user-defined missing values, i.e.
these values are converted to |
check |
logical: if |
Returns a numeric vector or data frame containing cluster scores with the same
length or same number of rows as data
if expand = TRUE
or with the
length or number of rows as length(unique(cluster))
if expand = FALSE
.
Takuya Yanagida takuya.yanagida@univie.ac.at
Hox, J., Moerbeek, M., & van de Schoot, R. (2018). Multilevel analysis: Techniques and applications (3rd. ed.). Routledge.
Snijders, T. A. B., & Bosker, R. J. (2012). Multilevel analysis: An introduction to basic and advanced multilevel modeling (2nd ed.). Sage Publishers.
item.scores
, multilevel.descript
,
multilevel.icc
# Load data set "Demo.twolevel" in the lavaan package
data("Demo.twolevel", package = "lavaan")
# Example 1: Compute cluster means for 'y1' and expand to match the input 'y1'
cluster.scores(Demo.twolevel, y1, cluster = "cluster", append = FALSE)
# Alternative specification without using the '...' argument
cluster.scores(Demo.twolevel$y1, cluster = Demo.twolevel$cluster)
# Example 2: Compute standard deviation for each cluster
# and expand to match the input x
cluster.scores(Demo.twolevel, cluster = "cluster", fun = "sd")
# Example 3: Compute cluster means without expanding the vector
cluster.scores(Demo.twolevel, cluster = "cluster", expand = FALSE)
# Example 4: Compute cluster means for 'y1' and 'y2' and append to 'Demo.twolevel'
cluster.scores(Demo.twolevel, y1, y2, cluster = "cluster")
# Alternative specification without using the '...' argument
cbind(Demo.twolevel,
cluster.scores(Demo.twolevel[, c("y1", "y2")], cluster = Demo.twolevel$cluster))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.