0
age25=subset(juul,juul[,"age"]>25.00)## create a subset of age greater than 25
modelgf=lm(age25[,"igf1"]~age25[,"age"])
age20=subset(juul,juul[,"age"]<20.00)
modelgf2=lm(age20[,"igf1"]~age20[,"age"])

I tried to compare the modelgf and modelgf2 models using anova(m1,m2). However, I get a warning message:

In anova.lmlist(object, ...) :
  models with response ‘"age20[, \"igf1\"]"’ removed because response differs from model 1

Are there any other ways to compare these two models?

camille
  • 16,432
  • 18
  • 38
  • 60
  • 2
    This is just wrong. You should instead create a factor variable for age categories and run on regression. – IRTFM Mar 13 '19 at 01:53
  • It's difficult to help without a sample of your data to make this [reproducible](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – camille Mar 13 '19 at 03:15
  • Why discretize a continuous variable at all? This is almost always a bad idea... https://stats.stackexchange.com/a/230756/176202 – Frans Rodenburg Mar 13 '19 at 04:30

1 Answers1

-1

Here you go:

# Dummy for Age>25
juul[,"ageCat25"] <- juul[,"ageCat"] > 25.00
# Collinear dummy for Age<20
juul[,"ageCat20"] <- ifelse(!juul[,"ageCat25"] & juul[,"age"]<20.00, TRUE, juul[,"ageCat25"])
m1 <- lm(foo ~ ageCat25, juul)
m2 <- lm(foo ~ ageCat20, juul)
anova(m1,m2)

Interpretation left to the OP.

NWPope
  • 9
  • 2
  • 1
    If you are comparing two different models with `anova` they need to be built on the same data. – IRTFM Mar 13 '19 at 03:47