###Lecture 25 - Code for running an ANOVA in R ### import data datum=read.csv(file.choose()) datum$X=as.factor(datum$X) #Tell R that the x variable is categorical ### replace 'X' with variable name head(datum) ### Run the LM results=lm(Y~X,data=datum) ### Run an ANOVA using the general linear model ### Note: replace 'Y' in above statement with Y variable ### Replace 'X' in above statement with X variable confint(results) ### get the results the usual way ### Plot results plot(Y~X,data=datum) ### Note: replace 'Y' in above statement with Y variable ### Replace 'X' in above statement with X variable ### Change the reference category results4=lm(Y~relevel(X,ref="Cat1"),data=datum) ### replace the x variable you want to change with the 'relevel' function ### Including in relevel function, arguments for category being releveled (X) ### and what category you want to be the reference (ref="whatever category you want")