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

Description Usage Arguments Value Examples

View source: R/descriptives.R

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

1

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.

Value

A list of data tables with the means or residuals

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
meanDecompose(mpg ~ vs, data = mtcars)
meanDecompose(mpg ~ vs + cyl, data = mtcars)

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

rm(tmp)

multilevelTools documentation built on March 13, 2020, 2:07 a.m.