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.
meanDecompose(formula, data)
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.
Returns
A list of data tables with the means or residuals
Examples
meanDecompose(mpg ~ vs, data = mtcars)meanDecompose(mpg ~ vs + cyl, data = mtcars)## Example plotting the resultstmp <- 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)