View source: R/cluster.scores.R
cluster.scores | R Documentation |
This function computes group means by default.
cluster.scores(..., data = NULL, cluster,
fun = c("mean", "sum", "median", "var", "sd", "min", "max"),
expand = TRUE, append = TRUE, name = ".a", as.na = NULL,
check = TRUE)
... |
a numeric vector for computing cluster scores for a variable,
matrix or data frame for computing cluster scores for more than
one variable. Alternatively, an expression indicating the variable
names in |
data |
a data frame when specifying one or more variables in the
argument |
cluster |
either 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 x
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 1a: Compute cluster means for 'y1' and expand to match the input 'y1'
cluster.scores(Demo.twolevel$y1, cluster = Demo.twolevel$cluster)
# Example 1b: Alternative specification using the 'data' argument
cluster.scores(y1, data = Demo.twolevel, cluster = "cluster")
# Example 2: Compute standard deviation for each cluster
# and expand to match the input x
cluster.scores(Demo.twolevel$y1, cluster = Demo.twolevel$cluster, fun = "sd")
# Example 3: Compute cluster means without expanding the vector
cluster.scores(Demo.twolevel$y1, cluster = Demo.twolevel$cluster, expand = FALSE)
# Example 4a: Compute cluster means for 'y1' and 'y2' and append to 'Demo.twolevel'
cbind(Demo.twolevel,
cluster.scores(Demo.twolevel[, c("y1", "y2")], cluster = Demo.twolevel$cluster))
# Example 4b: Alternative specification using the 'data' argument
cluster.scores(y1, y2, data = Demo.twolevel, cluster = "cluster")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.