在回归模型中使用二次项时如何寻找最小影响?

3

二次项在回归中非常常见。以下是来自John Fox的一个例子(http://www.jstatsoft.org/v08/i15/paper

library(car) # For data
library(splines)  # For bs()
library(effects) # For plotting

data(Prestige)

prestige.mod <- lm(prestige ~ log(income) + bs(education, df=3) + poly(women, 2), data=Prestige)
summary(prestige.mod)

test <- plot(all.effects(prestige.mod, default.levels=50))

输入图像描述

是否有R命令可以立即获取二次效应的最小/最大值,而无需手动推导/绘制它?


我不确定你所说的“二次效应的最小值/最大值”是什么意思。 - Roland
1个回答

1
如果我理解正确,我将会近似计算出“女性”价值,在该价值处将找到“最小效应”:
idx <-  which.min( predict(prestige.mod, newdata= data.frame(
       women=seq(min(Prestige$women), max(Prestige$women), length=100), 
       income=mean(Prestige$income, na.rm=TRUE), 
       education=mean(Prestige$education, na.rm=TRUE) ) ) )
idx
#37 
#37 
# Just copy the argument to the newdata argument in predict call above
# and get the value that produced the minimum
 seq(min(Prestige$women), max(Prestige$women), length=100)[idx]
#[1] 35.45818

使用predict函数对包含在“newdata”数据框中的值序列进行操作,无疑是出现在这些“效果”绘图的“幕后”。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接