Prepares long/tidy repeated measures data for analysis by keeping only the
subjects observed in every level of x. This is the listwise deletion step
that long_to_wide_converter() applies when paired = TRUE, and thus the
data that two_sample_test(), oneway_anova(), and
pairwise_comparisons() analyze for within-subjects designs.
The following steps are carried out:
Rows with a missing x or subject.id are dropped, since they cannot be
paired.
An error is thrown if any subject has more than one row in a level of x.
Subjects with a missing y value, or without a row, in any level of x
are removed entirely.
complete_subjects(data, x, y, subject.id = NULL)A tibble in long format with columns .rowid (the subject
identifier, or an internal row identifier when subject.id is NULL),
x (as a factor with unused levels dropped), and y, sorted by .rowid.
A data frame (or a tibble) from which variables specified are to
be taken. Other data types (e.g., matrix, table, array, etc.) will not
be accepted. Additionally, grouped data frames from {dplyr} should be
ungrouped before they are entered as data.
The grouping (or independent) variable from data. For repeated
measures designs, see the note on ordering in subject.id.
The response (or outcome or dependent) variable from data.
Relevant in case of a repeated measures or within-subjects
design (i.e., paired = TRUE), it specifies the subject or repeated
measures identifier. Important: If this argument is NULL (which is
the default), observations are paired by their row order within each level
of x (i.e., the data is assumed to be sorted in a subject-1, subject-2,
... pattern within every level). If the data is not sorted this way,
the paired results will be silently incorrect, so it is safest to always
specify subject.id. For paired designs, each subject must have at most
one row per level of x (an error is thrown otherwise), and rows with a
missing subject.id are dropped because they cannot be paired (see
complete_subjects()).
Patil, I., (2021). statsExpressions: R Package for Tidy Dataframes and Expressions with Statistical Details. Journal of Open Source Software, 6(61), 3236, https://doi.org/10.21105/joss.03236
# subjects with a missing rating in any condition are removed
complete_subjects(bugs_long, condition, desire, subject.id = subject)
Run the code above in your browser using DataLab