-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheletemp.r
94 lines (64 loc) · 2.86 KB
/
eletemp.r
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#install.packages('forecast')
library(forecast)
cat("\014")
rm(list = ls())
dev.off(dev.list()["RStudioGD"])
#setwd('Z:/Documents') #RStudiossa taman voi tehda myos valikosta Session->Set working directory
eletemp = read.table(file = "sahko.csv", sep = ";", dec = ",", skip = 1)
ele = ts(eletemp[[1]][1:816], start = 1, frequency = 24)
### ENNUSTE LÄMPÖTILAN KANSSA ###
### ###
#################################
holdout = 100
lag = 14
# Jaetaan aikasarjat testi ja arvointi osiin
d = 0
S = 24
D = 0
x_vakiotermi = 0
temp_estimointi = ts(eletemp[[2]][1:(816-lag-holdout)], start = 1, frequency = 24)
temp_ennuste = eletemp[[2]][(816-lag-holdout+1):(816-lag)]
ele_estimointi = ts(eletemp[[1]][(1+lag+d):(816-holdout)], start = (1+lag), frequency = 24)
temp_estimointi_d = temp_estimointi
if (d > 0) {
temp_estimointi_d = diff(temp_estimointi_d, lag = 1, differences = d)
}
if (D > 0) {
temp_estimointi_d = diff(temp_estimointi, lag = S, differences = D)
}
temp_estimointi_d = temp_estimointi_d + x_vakiotermi
ts.plot(temp_estimointi_d)
mean(temp_estimointi_d)
par(mfrow=c(3,1))
D*S
length(temp_estimointi_d)
length((ele_estimointi))
malli_eletemp = arima(ele_estimointi, order = c(3,1,0), seasonal = list(order = c(1,0,1), period = 24), xreg = temp_estimointi_d)
summary(malli_eletemp)
eletemp_ennuste = predict(malli_eletemp, n.ahead = holdout, newxreg = temp_ennuste)
ts.plot(ele[(816-holdout+1):816], eletemp_ennuste$pred, col = c("red", "blue"), main="Lämpötila ulkoisena muuttujana")
malli_ele = arima(ele_estimointi, order = c(3,1,0), seasonal = list(order = c(1,0,1), period = 24))
summary(malli_ele)
ele_ennuste = predict(malli_ele, n.ahead = holdout)
ts.plot(ele[(816-holdout+1):816], ele_ennuste$pred, col = c("red", "blue"), main = "Ennuste vain oman historian perusteella")
temp_ennuste_ts = ts(temp_ennuste, start = ((816-holdout)/24+1), frequency = 24)
plot(temp_ennuste_ts, main = "lämpötila")
par(mfrow=c(1,1))
lampotilan_vaikutus = malli_eletemp$coef[length(malli_eletemp$coef)]
lampotilan_vaikutus
# Johtopäätös: ennuste parani vähän, mutta silti suuria piikkejä, pitäisikö lämpötilaa käsitellä porrasmuuttujana?
# Kuvaajien perusteella ei nähtäisi että ennuste menisi pieleen säännöllisesti lämpötilasta riippuen
### eletemp mallin testaus
par(mfrow=c(3,1))
ts.plot(malli_eletemp$res, main = "Residuaalit, eletemp")
acf(malli_eletemp$res)
acf(malli_eletemp$res, type = "partial")
par(mfrow=c(1,1))
box = c()
param_maara = 3+1+1+1
for (i in param_maara:50){
box = c(box, Box.test(malli_eletemp$residuals, lag = i, type = "Ljung-Box", fitdf = param_maara)$p.value)
}
box
# Ljung-box testi testaa satunnaisuuttaa annetuilla viiveillä, viiveillä [param+1:param+3] arvot suurempaa kuin 0.1,
# joten mallissa saattaa olla informaatiota mitä ei ole otettu huomioon