Search code examples
ranova

How to do an ANOVA test of multiple parameters in R


I have a data structure organized as in next image (two populations and some parameters). I'm getting confused with coding. Which is the way to make an ANOVA test that drops the suitability (F, p value) of each parameter, please?

enter image description here


Solution

  • You could try something like this, but probably need to account for multiple comparisons:

    library(data.table)
    
    DT <- data.table("GROUP" = c("GR1", "GR1", "GR1", "GR2", "GR2")
                   , "Weight" = c(78, 85, 84.3, 70, 67)
                   , "BloodPres" = c(11, 14, 13, 12, 12)
                   , "Heart" = c(140, 130, 142, 135, 120)
                   , "Glucose" = c(80, 110, 95, 97, 105))
    
    Outcomes <- c("Weight", "BloodPres", "Heart", "Glucose")
    
    sapply(Outcomes, function(my) {
           f <- as.formula(paste(my, "~GROUP", sep=""))
           summary(aov(f, data=DT))
    })
    

    This works for one-way, but you'll need to adjust it for two-way (see Correct use of sapply with Anova on multiple subsets in R).