Maany Ramanan
Maany Ramanan

Reputation: 53

How to get aov and manova to use categorical variable level means as reference level in R

I am new to modelling using the 'aov' and 'manova' functions in R. My data has three categorical predictor variables of 4, 7, and 8 levels, respectively. I want to be able to understand the effect of each level on collectively on a set of 78 response variables.
Right now, both aov and manova are picking the first level as reference level for each predictor variable. This then gets listed as intercept in the model summary.
How can I get the effects of all my levels, in comparison to their collective mean? In other words, how can I set reference level to be the mean, and get all my levels for var1, var2, and var3 to show up in the model summary?
My code is below and I have attached the link to the example data file. Example data file

#reduced_data is a data frame containing columns 1:3 as predictor variables and 6:83 as
#response variables. Columns 4 and 5 are not used. 
# Assign names to the first 3 columns as predictor variables
predictor_vars <- colnames(reduced_data)[1:3]
        
# Assign names to the response variables (columns 6 to 83)
response_vars <- colnames(reduced_data)[6:83]
        
# Build the formula for the model
formula <- as.formula(paste(paste(response_vars, collapse = " + "), "~", paste(predictor_vars, collapse = " + ")))
        
#run the model
library(agricolae)
model = aov(formula, data= reduced_data)
summary(model)
hsd_model = HSD.test(model, c("var1","var2","var3"),unbalanced=T, alpha= 0.05, group=T)
hsd_model$groups

Upvotes: 0

Views: 74

Answers (0)

Related Questions