Advertisement
Guest User

Untitled

a guest
Feb 6th, 2016
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. Lines <- "Hour,PF
  2. 0,14/01/2015 00:00,0.305
  3. 1,14/01/2015 01:00,0.306
  4. 2,14/01/2015 02:00,0.307
  5. 3,14/01/2015 03:00,0.3081
  6. 4,14/01/2015 04:00,0.3091
  7. 5,14/01/2015 05:00,0.3101
  8. 6,14/01/2015 06:00,0.3111
  9. 7,14/01/2015 07:00,0.3122
  10. 8,14/01/2015 08:00,0.455
  11. 9,14/01/2015 09:00,0.7103
  12. 10,14/01/2015 10:00,0.9656
  13. 11,14/01/2015 11:00,1
  14. 12,14/01/2015 12:00,0.9738
  15. 13,14/01/2015 13:00,0.9476
  16. 14,14/01/2015 14:00,0.9213
  17. 15,14/01/2015 15:00,0.8951
  18. 16,14/01/2015 16:00,0.8689
  19. 17,14/01/2015 17:00,0.8427
  20. 18,14/01/2015 18:00,0.6956
  21. 19,14/01/2015 19:00,0.6006
  22. 20,14/01/2015 20:00,0.5056
  23. 21,14/01/2015 21:00,0.4106
  24. 22,14/01/2015 22:00,0.3157
  25. 23,14/01/2015 23:00,0.3157"
  26.  
  27. library (zoo)
  28. library (strucchange)
  29.  
  30. z <- read.zoo(text = Lines, tz = "", format = "%d/%m/%Y %H:%M", sep = ",")
  31.  
  32. bp <- breakpoints(z ~ 1, h = 2)
  33.  
  34. plot(z)
  35. abline(v = time(z)[bp$breakpoints])
  36. fit <- zoo(fitted(bp), time(z))
  37. lines(fit, col = "blue", lty = 2, lwd = 2)
  38.  
  39. fits <- lapply(seq_len(nrow(breaks)), function(x) {
  40. idx <- index(z)>=breaks[x, 1] & index(z)<=breaks[x, 2]
  41. fit <- lm(z[idx]~index(z[idx]))
  42. })
  43. sapply(fits, coefficients)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement