Learn R Programming

multilevelTools (version 0.2.0)

meanDecompose: Mean decomposition of a variable by group(s)

Description

This function decomposes a variable in a long data set by grouping factors, such as by ID. If multiple grouping factors are listed, the decomposition is in order from left to right. Residuals from the lowest level are returned.

Usage

meanDecompose(formula, data)

Value

A list of data tables with the means or residuals

Arguments

formula

A formula of the variables to be used in the analysis. Should have the form: variable ~ groupingfactors.

data

A data table or data frame containing the variables used in the formula. This is a required argument.

Examples

Run this code
meanDecompose(mpg ~ vs, data = mtcars)
meanDecompose(mpg ~ vs + cyl, data = mtcars)

## Example plotting the results
tmp <- meanDecompose(Sepal.Length ~ Species, data = iris)
do.call(ggpubr::ggarrange, c(lapply(names(tmp), function(x) {
  plot(JWileymisc::testDistribution(tmp[[x]]$X), plot = FALSE, varlab = x)$Density
}), ncol = 1))

rm(tmp)

Run the code above in your browser using DataLab