簡單回歸分析
MTCARS <- as.data.frame(mtcars) //將內建資料庫讀出,重新名為MTCARS
ggplot(mtcars,aes(x=mtcars$hp,y=wt))+geom_point()+geom_smooth(method=lm,se=FALSE) //繪製散佈圖
modle <- lm(wt~hp,data=mtcars) //建立簡單的回歸方程式
modle$coefficients //估計迴歸係數 a b
summary(modle) //產出回歸報表
ggplot(mtcars,aes(x=mtcars$qsec,y=wt))+geom_point()+geom_smooth(method=lm,se=FALSE)
modle <- lm(wt~qsec,data=mtcars)
modle$coefficients
summary(modle)