- Time series 時系列?
- Pair of Time & Values 時刻と値のペア
- Fixed interval vs. Varied interval 固定間隔 対 不定間隔
- Make a time series data. 時系列データ
n.t <- 100
my.time <- 1:n.t
phi <- 0.1
x <- cos(phi * my.time)
y <- sin(phi * my.time)
par(mfcol=c(1,2))
plot(x,y)
matplot(cbind(x,y),type="l")
par(mfcol=c(1,1))
- A bit more complicated 少し複雑に
ndate<-100
ncol<-3
tui<-matrix(0,ndate,ncol)
tui[,1]<-1:ndate
tui[,2]<-sort(rnorm(ndate,2,1))
plot(tui[,1],tui[,2],type="l")
tui[,3]<-tui[,2]+rnorm(ndate)*0.5
plot(tui[,1],tui[,3],type="l")
- In time series analysis, you are interested in the increase/decrease. 時系列解析では、増減に興味がある
plot(diff(tui[,3]),type="l")
- difference is following normal distribution?? 増減は正規分布?
hist(diff(tui[,3]),prob=T)
lines(density(diff(tui[,3])))
mu<-mean(diff(tui[,3]))
sigma<-sd(diff(tui[,3]))
x<-seq(min(h$breaks),max(h$breaks),length=100)
lines(x,dnorm(x,mean=mu,sd=sigma),col="blue")
ks.test(diff(tui[,3]),"pnorm",mu,sigma)
shapiro.test(diff(tui[,3]))
plot(tui[,3],type="l")
tui.1<-filter(tui[,3],filter=rep(1/5,5))
tui.2<-filter(tui[,3],filter=rep(1/25,25))
tui.3<-filter(tui[,3],filter=rep(1/50,50))
lines(tui.1,col="red")
lines(tui.2,col="blue")
lines(tui.3,col="green")
- Decompose into periodic component and trend and residual
tt<-ts(tui[,3],freq=12)
plot(stl(tt,s.window="periodic"))
n<-500
x <- seq(from=0,to=10,length=500)
y <- sin(x) + 3*sin(runif(1)*x) + rnorm(n,0,0.5)
fft.out <- fft(y)
z <- fft(fft.out,inverse=TRUE)
plot(x,y)
points(x,Re(z)/length(z),pch=20,col=2,cex=0.6)
- Smoothing with Fourier: Take out "BIG COMPONENT" only
hist(Mod(fft.out))
fft.out2 <- fft.out
fft.out2[which(Mod(fft.out) < 400)] <- 0
z2 <- fft(fft.out2,inverse=TRUE)
plot(x,y)
points(x,Re(z2)/length(z2),pch=20,col=2,cex=0.6)