I have a model with 13 independent variables (2 of them are categorical variables) and 678 observations. All of the variables are significant.I'm planning to check the coefficients stability. My approach is to start from a model with one variable and find that coefficients. Then I’ll add another variable; however, I'm keeping the previous variable also. I’ll continue until that all variables are in the final model. I'm using the following R code:

add.APV<-lm(HPV~log(APV),data=Mydata)
add1(add.APV,scope =~ AWD + Variety.bodyandchassis + Flexibility + Model.types + Year + log(CAC)+ Outsourcing + Platformstrategy + Hourly.total + Newownership + Vehicle.Launch + Segment.MD., test="F", k=2, trace=TRUE)

And I'm getting the following error:

Error in factor.scope(attr(terms1, "factors"), list(add = attr(terms2,  : 
  upper scope has term ‘NA’ not included in model

I was wondering what the problem is. Any feedback would be appreciated.

  • You can start by looking for NA's in your data, via. "is.na(add.APV$scope)" etc. – Alex R. May 10 '16 at 19:57
  • Thanks Alex, as far as I know there isn't any missing value; however, I checked your advice also and got "logical(0)". – Amir May 11 '16 at 21:11

I had the same problem, and my data is all numeric and free from NAs. The fix is really trivial: instead of scope = ~ var1 + var2 + ..., you should use scope = ~ . + var1 + var2 + .... . Seems like this ought to be covered in the add1 examples on its help page.

Your data file read some numerical variables as factors with many categories.

numeric <- apply(Mydata,2,is.factor)

glm.model_step_1 <- glm(scope ~ AWD + Variety.bodyandchassis + Flexibility + Model.types + Year + log(CAC)+ Outsourcing + Platformstrategy + Hourly.total + Newownership + Vehicle.Launch + Segment.MD., data = na.omit(Mydata), 
                    family = binomial(link = 'logit'))

add1(glm.model_step_1, scope=~.)

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.