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"))

Introduction to ALASCA

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

Installation

if (!requireNamespace("devtools", quietly = TRUE))
    install.packages("devtools")

devtools::install_github(“andjar/ALASCA”, ref = “main”)

Citation

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}
}

Creating an ASCA model

Generating a data set

We will start by creating an artificial data set with 100 participants, 5 time points, and 20 variables. The variables follow four patterns

wzxhzdk:3

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)

Data format

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.

Initialize an ALASCA model

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:

To see the resulting model:

plot(res, component = c(1,2), type = 'effect')

See the vignette on plotting the model for more visualizations.



andjar/ALASCA documentation built on March 2, 2024, 12:55 p.m.