Jesse001 - 9 months ago 97

R Question

I'm trying to run a simple backwards stepwise multiple linear regression in R using the stepAIC function from the MASS package. The model runs fine, but I can't seem to get the results. When I run "step$anova" I get

`Error in step$anova : object of type 'closure' is not subsettable`

I've used this exact code many times and never gotten this error before, but I also see no issues in my data matrix or any difference between this and what I usually do. Any tips on this error would be greatly appreciated.

My code is:

`PCBiomass<-lm(y1~x1+x2+x3,data=abioY1)`

PCBstep<- stepAIC(PCBiomass, direction="backward")

step$anova

the data are attached and useable (earlier in the code they're used in an RDA)

Answer

Oops, It should be `PCBstep$anova`

in the final line. You can not subset `step`

, because that is an R's built-in function. *(You know the stats::step function, right?)* A function is a closure; that is what the error is complaining about.