37 lines
1.4 KiB
R
37 lines
1.4 KiB
R
|
rok <- 1995:2002
|
||
|
liczba_przypadkow <- c(39.7, 38.2, 34.7, 33.1, 30.1, 28.4, 26.3, 24.7)
|
||
|
data_set <- data.frame(rok = rok, liczba_przypadkow = liczba_przypadkow)
|
||
|
plot(data_set, main = "Wykres rozrzutu", pch = 16)
|
||
|
|
||
|
model <- lm(liczba_przypadkow ~ rok, data = data_set)
|
||
|
model$coefficients
|
||
|
plot(data_set, main = "Wykres rozrzutu", pch = 16)
|
||
|
abline(model, col = "red", lwd = 2)
|
||
|
coef(model)
|
||
|
confint(model)
|
||
|
|
||
|
summary(model)
|
||
|
|
||
|
fitted(model)
|
||
|
residuals(model)
|
||
|
|
||
|
temp_rok <- data.frame(rok = seq(min(data_set$rok) - 10,
|
||
|
max(data_set$rok) + 10,
|
||
|
length = 100))
|
||
|
pred <- stats::predict(model, temp_rok, interval = "prediction")
|
||
|
plot(data_set, main = "Wykres rozrzutu", pch = 16)
|
||
|
abline(model, col = "red", lwd = 2)
|
||
|
lines(temp_rok$rok, pred[, 2], lty = 2, col = "red")
|
||
|
lines(temp_rok$rok, pred[, 3], lty = 2, col = "red")
|
||
|
|
||
|
|
||
|
new_rok <- data.frame(rok = 2003:2007)
|
||
|
(pred_2003_2007 <- stats::predict(model, new_rok, interval = 'prediction'))
|
||
|
plot(data_set, main = "Wykres rozrzutu z predykcją na lata 2003-2007", pch = 16,
|
||
|
xlim = c(1995, 2007), ylim = c(10, 40))
|
||
|
abline(model, col = "red", lwd = 2)
|
||
|
points(2003:2007, pred_2003_2007[, 1], col = "blue", pch = 16)
|
||
|
temp_rok <- data.frame(rok = seq(1994, 2008, length = 100))
|
||
|
pred <- stats::predict(model, temp_rok, interval = "prediction")
|
||
|
lines(temp_rok$rok, pred[, 2], lty = 2, col = "red")
|
||
|
lines(temp_rok$rok, pred[, 3], lty = 2, col = "red")
|