mixed_model_analysis {scdtb} | R Documentation |
Mixed Model Analysis
Description
Performs a mixed model analysis on a dataset, allowing for the specification of a dependent variable, time variable, phase variable, participant identification, and covariates. It supports reverse timing within phases, custom phase levels and labels, and adds covariates to the fixed effects model. The function fits a model using generalized least squares and returns a list containing the modified dataset, the fitted model, and a plot of predicted values with phase annotations.
Usage
mixed_model_analysis(
.df,
.dv,
.time,
.phase,
.participant = NULL,
rev_time_in_phase = FALSE,
phase_levels = NULL,
phase_labels = NULL,
covs = NULL,
...
)
Arguments
.df |
A data frame containing the dataset to be analyzed. |
.dv |
The name of the dependent variable in the dataset. |
.time |
The name of the time variable in the dataset. |
.phase |
The name of the phase variable in the dataset. |
.participant |
(optional) The name of the participant identifier variable in the dataset. If not provided, a default factor will be used. |
rev_time_in_phase |
(optional) A boolean indicating whether to reverse the timing within each phase. Defaults to FALSE. |
phase_levels |
(optional) A vector of phase levels to be used for the phase variable. If NULL, the unique values in the phase variable will be used. |
phase_labels |
(optional) A vector of labels corresponding to the phase_levels. If NULL, phase_levels will be used as labels. |
covs |
(optional) A vector of names of covariates to be added to the fixed effect model. |
... |
Additional arguments passed to the |
Value
A list containing three elements:
- data
: The modified dataset with added time variables and predicted
values.
- fitted_mod
: The fitted model object from nlme::gls
.
- plot
: A ggplot object showing the predicted values and phase
annotations.
References
Maric, M., & van der Werff, V. (2020). Single-Case Experimental Designs in Clinical Intervention Research. In R. van de Schoot & M. Miocevic (Eds.), Small Sample Size Solutions: A Guide for Applied Researchers and Practitioners (1st ed., pp. 10). Routledge. doi:10.4324/9780429273872-9
Examples
res <- mixed_model_analysis(efficacy_of_CBT, .dv = "Anxious", .time = "time",
.phase = "phase",rev_time_in_phase = TRUE,
phase_levels = c(0, 1),
phase_labels = c("Exposure", "Exposure + CT"))
summary(res$fitted_mod)