attach(iris)
library('ggplot2')
q = ggplot(iris, aes(x=Petal.Width, y=Sepal.Length))
q + geom_point() + geom_smooth(method='lm', se=F)
## `geom_smooth()` using formula 'y ~ x'
Xac dinh mo hinh hoi quy tuyen tinh cua Sepal.Length theo Petal.Width
m = lm(Sepal.Length~Petal.Width)
summary(m)
##
## Call:
## lm(formula = Sepal.Length ~ Petal.Width)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1.38822 -0.29358 -0.04393 0.26429 1.34521
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 4.77763 0.07293 65.51 <2e-16 ***
## Petal.Width 0.88858 0.05137 17.30 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.478 on 148 degrees of freedom
## Multiple R-squared: 0.669, Adjusted R-squared: 0.6668
## F-statistic: 299.2 on 1 and 148 DF, p-value: < 2.2e-16
Theo mo hinh tren, ta thay:
Petal.Width co Pr<0.05 nen no co y nghia thong ke doi voi Sepal.Length
Mo hinh co phuong trinh: Sepal.Length = 4.77 + 0.88*Petal.Width
Khi Petal.Width tang 1 don vi, thi Sepal.Length tang 0.88 don vi.
R binh phuong = 67%
Nghia la mo hinh co the du bao 67% do dao dong cua Sepal.Length
Petal.Width=1 thi Sepal.Length = 5.65
Petal.Width=2 thi Sepal.Length = 6.53