Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. # ElecLoad contains hourly loads and other data for 2005 and 2006 (=2*365*24 entries):
  2. # 1. Electricity load in MW
  3. # 2. day of weak: sunday=0, monday=1, etc
  4. # 3. Hour of the day 0 -> 23
  5. # 4. Public Holiday: 1 if Public Holiday, 0 otherwise
  6. # 5. Scool vacation: 1 if no scool
  7. # 6. Temperature in °F
  8.  
  9. # Create the weak matrix = dumy variables for the weakdays
  10. weakmatrix<-model.matrix(~as.factor(ElecLoad[,2]))
  11. #Remove intercept
  12. weakmatrix<-weakmatrix[,-1]
  13.  
  14. #Generate FullTable
  15. FullTable<-cbind(load=ElecLoad[,1], weakmatrix, ElecLoad[,4],
  16. ElecLoad[,3],ElecLoad[,5],ElecLoad[,5]^2, ElecLoad[,6])
  17. colnames(FullTable)<-c("Load","mon","tue","wed","thu","fri","sat",
  18. "ScoolHol","PubHol","Temp","Temp2","Hour")
  19.  
  20. #Create the xreg = substed for a specific hour of the day (column 12 = Hour)
  21. xreg<-subset(FullTable[,2:11], FullTable[,12] == 7)
  22.  
  23. #Create the Load time serie, also a subset of the full table
  24. LoadTs<-ts(subset(FullTable[,1], FullTable[,12] == 7),start=1,frequency=1)
  25.  
  26. #Launch of auto.arima
  27. ArimaLoad<-auto.arima(LoadTs, xreg=xreg, lambda=0)
  28.  
  29. plot(forecast(ArimaLoad,xreg=xreg), include=0)
  30.  
  31. plot(fitted(ArimaLoad))
  32.  
  33. #Create the frame.data
  34. Load<-subset(FullTable[,1], FullTable[,12] == 7)
  35. FullData<-cbind(LogLoad=log(Load), xreg)
  36. FrameData<-data.frame(FullData)
  37.  
  38. # multilinear regression
  39. mlin<-lm(LogLoad ~ mon+tue+wed+thu+fri+sat+ScoolHol+PubHol+Temp+`Temp2`, FrameData)
  40. plot(exp(mlin$model$LogLoad), type="l",col="blue")
  41. lines(exp(fitted(mlin)), col="red")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement