cluster_size | R Documentation |
This function counts the number of unique observations within
each of the user-defined clusters in the context of multilevel
(i.e., clustered or nested) data with an arbitrary number of hierarchical
levels (L).
For example, when students at L1 are nested within classrooms at L2, which
are in turn nested within schools at L3, the function computes the cluster
size at L2 (i.e., number of students per classroom) and the cluster sizes
at L3 (i.e., number of students per school and number of classrooms per
school).
By default, cluster sizes are returned broken down by L1 unit.
Instead of returning cluster sizes broken down by L1 unit, it is also
possible to compute summary statistics by supplying the respective summary
functions to the .fns
argument.
Total sample sizes at each hierarchical level can be included via the
.total
argument.
cluster_size(data, ..., .fns, .total = FALSE)
data |
A data frame. |
... |
< |
.fns |
Optional. A list of function/s to compute summary statistics
across cluster sizes (e.g., median cluster size:
|
.total |
Optional. A logical indicating whether the number of unique observations at each hierarchical level should be summed up. If TRUE, the total sample size at each hierarchical level is included in the new data frame. The default is FALSE. |
A data frame.
# compute cluster sizes in a three-level design
# (e.g., students within classrooms within schools)
cluster_size(studach, id_stu, id_cla, id_sch)
# compute median cluster sizes in a two-level design
# (e.g., students within schools) and include total
# and include total sample sizes at each hierarchical level
cluster_size(studach, id_stu, id_sch,
.fns = list("mdn" = median),
.total = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.