Reverse elimination in R

I am trying to get the final model using reverse undo with R, but when I run the code I got the following error message. Can someone help me with this?

base<-lm(Eeff~NDF,data=phuong) fullmodel<-lm(Eeff~NDF+ADF+CP+NEL+DMI+FCM,data=phuong) step(full, direction = "backward", trace=FALSE ) > Error in step(full, direction = "backward", trace = FALSE) : number of rows in use has changed: remove missing values? 
+8
r
source share
1 answer

When comparing different submodels, it is necessary that they be tied to one data set - otherwise the results simply do not make sense. (Consider an extreme situation where you have two predictors A and B , each of which is measured only by half of your observations - then the model y~A+B will be installed on all data, but the models y~A and y~B will be is tied to non-overlapping subsets of data.) Thus, step will not allow you to compare submodels that (due to the automatic removal of cases containing NA values) use different subsets of the original data set.

Using na.omit in the source dataset should fix the problem.

 fullmodel <- lm(Eeff ~ NDF + ADF + CP + NEL + DMI + FCM, data = na.omit(phuong)) step(fullmodel, direction = "backward", trace=FALSE ) 

However, if you have many NA values โ€‹โ€‹in different predictors, you can lose a lot of your data set - in extreme cases, you can lose the entire data set. If this happens, you will have to rethink your modeling strategy ...

+10
source share

All Articles