これはあなたが望むかもしれないと私が思うものです(箱ひげ図に重ねられた平均IQ値の違いを示すために):
plot(IQ~isAtheist)
lines(x=c(1,2), y=predict( lm(IQ~isAtheist),
newdata=list(isAtheist=c("NO","YES") ) ) ,
col="red", type="b")
plot.formulaのデフォルトのX位置はas.numeric(factor(isAtheist))
、つまり、を使用して想定していた0と1ではなく、1と2ですabline
。これらの値を超えて外挿するのは意味がないので、境界セグメントとしてプロットすることにしました。実例と出力を追加します。
set.seed(123)
isAtheist=factor(c("NO","YES")[1+rep( c(0,1), 50 )])
plot(IQ~isAtheist)
lines(x=c(1,2), y=predict( lm(IQ~isAtheist),
newdata=data.frame(isAtheist=c("NO","YES") ) ) ,
col="red", type="b")
