knitr::opts_chunk$set( collapse = TRUE, comment = "#>", out.width = "100%", fig.asp = 0.7, fig.width = 12, fig.align = "center", cache = FALSE, external = FALSE ) library("ALASCA") library("data.table") library("ggplot2") theme_set(theme_bw() + theme(legend.position = "bottom"))
The ALASCA package is described in the paper ALASCA: An R package for longitudinal and cross-sectional analysis of multivariate data by ASCA-based methods.. The paper contains several examples of how the package can be used.
This vignette will only show how to quickly get started with the ALASCA package. For more examples, see
if (!requireNamespace("devtools", quietly = TRUE)) install.packages("devtools") devtools::install_github(“andjar/ALASCA”, ref = “main”)
If you have utilized the ALASCA package, please consider citing:
Jarmund AH, Madssen TS and Giskeødegård GF (2022) ALASCA: An R package for longitudinal and cross-sectional analysis of multivariate data by ASCA-based methods. Front. Mol. Biosci. 9:962431. doi: 10.3389/fmolb.2022.962431
@ARTICLE{10.3389/fmolb.2022.962431, AUTHOR={Jarmund, Anders Hagen and Madssen, Torfinn Støve and Giskeødegård, Guro F.}, TITLE={ALASCA: An R package for longitudinal and cross-sectional analysis of multivariate data by ASCA-based methods}, JOURNAL={Frontiers in Molecular Biosciences}, VOLUME={9}, YEAR={2022}, URL={https://www.frontiersin.org/articles/10.3389/fmolb.2022.962431}, DOI={10.3389/fmolb.2022.962431}, ISSN={2296-889X} }
We will start by creating an artificial data set with 100 participants, 5 time points, and 20 variables. The variables follow four patterns
Overall (ignoring the random effects), the four patterns look like this:
ggplot(df[variable %in% c("variable_1", "variable_2", "variable_3", "variable_4"),], aes(time, value)) + geom_smooth() + facet_wrap(~variable, scales = "free_y") + scale_color_viridis_d(end = 0.8)
We want time to be a categorical variable:
df[, time := paste0("t_", time)]
Your data can either be provided in long or wide format. In long format, there is one column with variable names and one column with the variable values. For example:
head(df)
In wide format, each variable has a separate column:
head(dcast(data = df, ... ~ variable))
ALASCA supports both formats but defaults to long format. To use wide format, you have to set wide = TRUE
.
In this example, we are only looking at the common time development. For examples involving group differences, see the vignette on regression models.
To assess the time development in this data set, we will use the regression formula value ~ time + (1|id)
. Here, value
is the measured variable value, time
the predictor, and (1|id)
a random intercept per participant-id. ALASCA will implicitly run the regression for each variable separately.
res <- ALASCA( df, value ~ time + (1|id) )
The ALASCA function will provide output with important information:
Guessing effects: 'time'
When effects are not explicitly provided to ALASCA, the package will try to guess the effects you are interested in. See the vignette on regression models for details.Will use linear mixed models!
ALASCA will use linear mixed models when you provide a random effect in the regression formula (i.e., (1|id)
)Will use Rfast!
Linear mixed model regression can be performed by one out of two different R packages: the lme4 package or the Rfast packageThe 'time' column is used for stratification
This is only important for model validation. For details, see the vignette on model validationConverting 'character' columns to factors
We provided time as a character variable and ALASCA converts it to a factor variable. If the levels of your variable matters and they are not in alphabetical order, you may want to convert the variable to a factor by yourself.Scaling data with sdall ...
ALASCA supports various scalings, and sdall
is the default. For details, see our paper ALASCA: An R package for longitudinal and cross-sectional analysis of multivariate data by ASCA-based methods.Calculating LMM coefficients
Simply informs you that the regression is ongoing as this may take some timeTo see the resulting model:
plot(res, component = c(1,2), type = 'effect')
See the vignette on plotting the model for more visualizations.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.