Dokumen ini telah diperbaiki untuk menghindari error saat upload ke RPubs. Semua chunk telah dioptimalkan agar output tidak terlalu panjang, dan konfigurasi HTML dibuat self-contained = false sehingga ukuran file lebih kecil.
library(dplyr)
library(ggplot2)
library(readr)
data <- data.frame(
X = 1:10,
Y = c(5,7,6,8,7,9,10,9,11,10)
)
head(data)
## X Y
## 1 1 5
## 2 2 7
## 3 3 6
## 4 4 8
## 5 5 7
## 6 6 9
model <- lm(Y ~ X, data = data)
summary(model)
##
## Call:
## lm(formula = Y ~ X, data = data)
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.90909 -0.72273 -0.03636 0.74091 0.92727
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 5.00000 0.57525 8.692 2.39e-05 ***
## X 0.58182 0.09271 6.276 0.000239 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.8421 on 8 degrees of freedom
## Multiple R-squared: 0.8312, Adjusted R-squared: 0.8101
## F-statistic: 39.38 on 1 and 8 DF, p-value: 0.000239
ggplot(data, aes(X, Y)) +
geom_point() +
geom_smooth(method = "lm", se = FALSE)
predict(model, newdata = data.frame(X = c(2,5,9)))
## 1 2 3
## 6.163636 7.909091 10.236364