Skip to contents

Plot State Frequencies as a Mosaic Between Two Groups

Usage

# S3 method for class 'group_tna'
plot_mosaic(x, label, actor = NULL, ...)

Arguments

x

A group_tna object.

label

An optional character string that can be provided to specify the grouping factor name if x was not constructed using a column name of the original data.

actor

An optional actor identifier for sequences nested in actors (for example, sessions in students or students in teams): a column name of the non-sequence data the model was built from, or a vector with one value per sequence of the grouped data. When given, the residuals allow for the nesting; see Details.

...

Ignored.

Value

A ggplot object.

Nested data

The fill of each tile is its standardized (adjusted) Pearson residual, which treats every state occurrence as an independent observation. When the sequences are nested in actors, the occurrences of one actor resemble each other and these residuals are too large. With actor, the counts are taken actor by actor and each residual is divided by the square root of its design effect (the actor-level variance of the cell's contrast p_ij - p_i. p_.j over its variance under simple random sampling), and the subtitle reports the second-order Rao-Scott test, an F statistic on fractional degrees of freedom, with the mean design effect (Rao & Scott, 1984). A design effect of 1 means the nesting costs nothing. The method is ported from mosaic_analysis(nested = TRUE) of the Nestimate package. Missing states are left out of the nested counts.

References

Rao, J. N. K., & Scott, A. J. (1984). On chi-squared tests for multiway contingency tables with cell proportions estimated from survey data. The Annals of Statistics, 12(1), 46–60. doi:10.1214/aos/1176346391

Examples

model <- group_model(engagement, group = rep(1:3, length.out = 1000))
plot_mosaic(model)


# Sequences nested in 50 actors of 20 sequences each
plot_mosaic(model, actor = rep(1:50, each = 20))