ddsc_ml {multid} | R Documentation |
Deconstructing difference score correlation with multi-level modeling
Description
Deconstructs a bivariate association between x and a difference score y1-y2 with multi-level modeling approach. Within each upper-level unit (lvl2_unit) there can be multiple observations of y1 and y2. Can be used for either pre-fitted lmer-models or to long format data. A difference score correlation is indicative that slopes for y1 as function of x and y2 as function of x are non-parallel. Deconstructing the bivariate association to these slopes allows for understanding the pattern and magnitude of this non-parallelism.
Usage
ddsc_ml(
model = NULL,
data = NULL,
predictor,
moderator,
moderator_values,
DV = NULL,
lvl2_unit = NULL,
re_cov_test = FALSE,
var_boot_test = FALSE,
boot_slopes = FALSE,
nsim = NULL,
level = 0.95,
seed = NULL,
covariates = NULL,
scaling_sd = "observed"
)
Arguments
model |
Multilevel model fitted with lmerTest. |
data |
Data frame. |
predictor |
Character string. Variable name of independent variable predicting difference score (i.e., x). |
moderator |
Character string. Variable name indicative of difference score components (w). |
moderator_values |
Vector. Values of the component score groups in moderator (i.e., y1 and y2). |
DV |
Character string. Name of the dependent variable (if model is not supplied as input). |
lvl2_unit |
Character string. Name of the level-2 clustering variable (if model is not supplied as input). |
re_cov_test |
Logical. Significance test for random effect covariation? (Default FALSE) |
var_boot_test |
Logical. Compare variance by lower-level groups at the upper-level in a reduced model with bootstrap? (Default FALSE) |
boot_slopes |
Logical. Are bootstrap estimates and percentile confidence intervals obtained for the estimates presented in results? (Default FALSE) |
nsim |
Numeric. Number of bootstrap simulations. |
level |
Numeric. The confidence level required for the var_boot_test output (Default .95) |
seed |
Numeric. Seed number for bootstrap simulations. |
covariates |
Character string or vector. Variable names of covariates (Default NULL). |
scaling_sd |
Character string (either default "observed" or "model"). Are the simple slopes scaled with observed or model-based SDs? |
Value
results |
Summary of key results. |
descriptives |
Means, standard deviations, and intercorrelations at level 2. |
vpc_at_moderator_values |
Variance partition coefficients for moderator values in the model without the predictor and interactions. |
model |
Fitted lmer object. |
reduced_model |
Fitted lmer object without the predictor. |
lvl2_data |
Data summarized at level 2. |
ddsc_sem_fit |
ddsc_sem object fitted to level 2 data. |
re_cov_test |
Likelihood ratio significance test for random effect covariation. |
boot_var_diffs |
List of different variance bootstrap tests. |
Examples
## Not run:
set.seed(95332)
n1 <- 10 # groups
n2 <- 10 # observations per group
dat <- data.frame(
group = rep(c(LETTERS[1:n1]), each = n2),
w = sample(c(-0.5, 0.5), n1 * n2, replace = TRUE),
x = rep(sample(1:5, n1, replace = TRUE), each = n2),
y = sample(1:5, n1 * n2, replace = TRUE)
)
library(lmerTest)
fit <- lmerTest::lmer(y ~ x * w + (w | group),
data = dat
)
round(ddsc_ml(model=fit,
predictor="x",
moderator="w",
moderator_values=c(0.5,-0.5))$results,3)
round(ddsc_ml(data=dat,
DV="y",
lvl2_unit="group",
predictor="x",
moderator="w",
moderator_values=c(0.5,-0.5))$results,3)
## End(Not run)