《R語(yǔ)言入門(mén)經(jīng)典》第16章R模型和面向?qū)ο?/h2>

這一章看得云里霧里,統(tǒng)計(jì)沒(méi)有學(xué)好,感覺(jué)啥也不會(huì)

補(bǔ)充練習(xí)

#用airquality數(shù)據(jù)庫(kù),擬合一個(gè)Ozone和Wind的線性模型
model1 <- lm(Ozone~Wind, data = airquality)
#創(chuàng)建詳細(xì)的文本和診斷圖
summary(model1)
par(mfrow = c(2,2))
plot(model1)

#雙變量
model2 <- update(model1,. ~ . +Temp) 
anova(model2)

#添加交互項(xiàng)并評(píng)估模型
model3 <- update(model2,. ~ . +Wind:Temp)
summary(model13)
res1 <- resid(model1)
fit1 <- fitted(model1)
res2 <- resid(model2)
fit2 <- fitted(model2)
res3 <- resid(model3)
fit3 <- fitted(model3)
resRange <- c(-1,1)*max((max(abs(res1),abs(res2))),abs(res3))
fitRange <- range((range(fit1,fit2)),fit3)
plot(fit1,res1, xlim = fitRange, ylim = resRange,col = "red", pch = 16,)
lines(loess.smooth(fit3,res3),col = "black")
points(fit2, res2,col = "blue", pch = 16)
points(fit3, res3,col = "black", pch = 16)
lines(loess.smooth(fit1,res1),col = "red")
lines(loess.smooth(fit2,res2),col = "blue")
lines(loess.smooth(fit3,res3),col = "black")
refFun <- function(res,col) abline(h = quantile(res,c(.05,.95),col = col ,lty =3))
refFun(res3,"black")
refFun(res2,"blue")
refFun(res1,"red")
anova(model1,model2,model3)

#在模型中添加Month作為分類(lèi)自變量
model4 <- update(model3,. ~ . +factor(Month))
summary(model13)
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容