##### Code for running a nonlinear model and comparing to #a linear model using the marginal Sum of Squares test #(This is a true lack of fit test) #### Note this code assumes you have already imported data and created # a regression object and an ANOVA object ###Importing data #datum=read.csv(file.choose()) #head(datum) ### Run a regression - treat Protein as continuous #results2=lm(Mass~Protein) #Protein is continuous #summary(results) ###Run a nonlinear model results3=lm(Mass~Protein+I(Protein^2),data=datum) summary(results3) #The 'I' function tells R to do whatever the math is # inside the parantheses ### Conduct the f-drop test anova(results3,result2) ### the two models you want to compare are included as arguments ### order doesn't usually matter, but it's best to put the more complicated ### model first for those few cases where it does ### Note that the two models can't have the same number of parameters ### A significant p-value means the more complex model is a ### significant improvement in fit ### A non-significant p-value means the simpler model is adequate ### Note that RSS (which is the same thing as SSE) is always lower ### in the more complex model ######## Not run as part of class ### Run a cubic or higher order polynomial # results4=lm(Mass~Protein+I(Protein^2)+I(Protein^3),data=datum) # summary(results4) # anova(results4,results3) ### Alternative parameterization that uses polynomial contrasts ### eliminates collinearity among terms # results5=lm(Mass~poly(Protein,5),data=datum) # summary(results5) # anova(results5,results4)