| prepare_dyad_data | R Documentation |
Validates dyadic data, records the structural variables, and adds metadata and model-ready columns for dyadic multilevel model parameterizations.
prepare_dyad_data(
data,
dyad,
member,
role = NULL,
time = NULL,
predictors = NULL,
lag1_predictors = NULL,
model_types = "apim",
dsm_role_order = NULL,
temporal_decomposition = c("auto", "2l", "none"),
set_exchangeable_compositions = NULL,
keep_compositions = NULL,
pool_compositions = NULL,
incomplete_dyads = c("error", "drop"),
missing_role = c("error", "drop"),
seed = NULL,
short_colnames = TRUE,
include_arbitrary_member_contrast = FALSE,
add_apim_gmc_predictors = FALSE
)
data |
A data frame or tibble. Data must be in long format. For cross-sectional dyadic data, each observed member of each dyad has one row. For intensive longitudinal dyadic data, each observed member of each dyad has one row per observed time point. |
dyad |
Column identifying the dyad. |
member |
Column identifying a person or the member within dyad. |
role |
Optional column identifying a stable member role, such as gender.
Non-missing values must be consistent within each |
time |
Optional column identifying time or measurement order of repeated measures. |
predictors |
Optional variables to use for temporal predictor decomposition and model-ready predictor construction. |
lag1_predictors |
Optional subset of |
model_types |
Model-ready column families to construct. Can contain one
or more of |
dsm_role_order |
For |
temporal_decomposition |
Temporal decomposition strategy for
|
set_exchangeable_compositions |
Optionally specify dyad compositions
to treat as exchangeable, when their roles would otherwise imply distinguishability.
Requires |
keep_compositions |
Optional observed dyad compositions to keep
before exchangeability overrides and pooling. Requires |
pool_compositions |
Optionally pool exchangeable dyad compositions
into a shared final composition label. Must be a named list where each name
is the final composition label and each value is a character vector of
composition references, for example
|
incomplete_dyads |
How to handle dyads with fewer than two unique
members across all rows in |
missing_role |
How to handle dyads in which at least one member has no
non-missing |
seed |
Optional seed for random |
short_colnames |
Whether to use shorter composition-dependent generated
column names when the final data contain one composition. The default |
include_arbitrary_member_contrast |
Whether to also generate arbitrary
|
add_apim_gmc_predictors |
Whether to add APIM GMC variants for numeric
predictors. |
Data must be in long format. Cross-sectional dyadic data may contain at most
one row per member within dyad. Intensive longitudinal dyadic data may
contain at most one row per member and observed measurement occasion within
dyad. Measured variables may contain missing values. Numeric dyad, member,
time, and selected predictor columns must not contain infinite values.
Structural completeness is assessed across all rows. incomplete_dyads
controls dyads with fewer than two members; dyads with more than two members
always cause an error.
When role is supplied, stable member roles are resolved across repeated
rows before missing_role is applied.
Dyad composition labels are canonical: role labels are sorted alphabetically before being combined, so labels do not depend on row or member order.
The original data as a tibble with class dyadMLM_data,
.composition and .composition_role factor columns,
.is_* numeric indicator columns, and numeric
.member_contrast_* columns coded -1 and 1 for the two members of
each matching composition and 0 otherwise. With one final composition,
their default names omit the composition label. The dyadMLM attribute
contains structural metadata, dyad_compositions, and
predictor metadata such as temporal_decompositions, lag1_predictors,
apim_predictors, and dim_predictors, as well as dsm_predictors and
dsm_role_order when applicable. The generated_columns table records each
package-generated column retained in the returned data. Modifying prepared
data does not automatically regenerate package-generated columns.
data <- data.frame(
dyad_id = c(1, 1, 2, 2, 3, 3),
person_id = c(1, 2, 3, 4, 5, 6),
role = c("female", "male", "female", "female", "male", "male"),
x = c(4, 7, 5, 6, 3, 8)
)
prepared <- prepare_dyad_data(
data,
dyad = dyad_id,
member = person_id,
role = role,
predictors = x,
model_types = "apim"
)
print(prepared)
pooled <- prepare_dyad_data(
data,
dyad = dyad_id,
member = person_id,
role = role,
predictors = x,
model_types = "apim",
set_exchangeable_compositions = "female-male",
pool_compositions = list(
romantic_couples = c("female-female", "male-male", "female-male")
)
)
print(pooled)
ild_data <- data.frame(
dyad_id = rep(c(1, 2), each = 4),
person_id = rep(c(1, 2), times = 4),
time = rep(c(1, 1, 2, 2), times = 2),
x = c(4, 7, 5, 8, 3, 6, 4, 7)
)
ild_prepared <- prepare_dyad_data(
ild_data,
dyad = dyad_id,
member = person_id,
time = time,
predictors = x,
lag1_predictors = x,
model_types = "apim",
seed = 123
)
print(ild_prepared)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.