简体   繁体   中英

Compare two regression models in R

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM