데이터분석/Machine Learning
R을 이용한 시계열분석 함수 이용 예
늘근이
2016. 1. 10. 11:28
> kings<-c(60,43,67,50,56,42,50,65,68,43,65,34,47,34,49,41,13,35,
53,56,16,43,69,59,48,59,86,55,68,51,33,49,67,77,81,67,71,81,68,70,77,56)
> kingsts <- ts(kings)
> kingsts
Time Series:
Start = 1
End = 42
Frequency = 1
[1] 60 43 67 50 56 42 50 65 68 43 65 34 47 34 49 41 13 35 53 56 16 43 69 59 48 59 86 55 68 51 33 49 67 77 81 67 71 81 68 70
[41] 77 56
> births <- scan("http://robjhyndman.com/tsdldata/data/nybirths.dat")
Read 168 items
> birthts <- ts(births, frequency=12, start=c(1946,1))
> souvenir <- scan('http://robjhyndman.com/tsdldata/data/fancy.dat')
시계열 데이터 plot
> plot.ts(kingsts)
lot() 함수를 취해서 plot할수도 있다.
평탄화 (TTR패키지 SMA 함수)
> SMA(kingsts, n=3)
시계열 요소 죄다 decompose
> result <- decompose(birthts)
> result
plot()을 그리면 예쁘다.
![](https://img1.daumcdn.net/thumb/R720x0.q80/?scode=mtistory2&fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F232DAE495691C20215)