時系列解析

  • メモ
blog <- read.table("blog.txt",col.names=c("統計遺伝学","応用数学"))

ryamada.two <- ts(blog, start=c(2005,1), end=c(2016, 11), frequency=12)

plot(ryamada.two,plot.type="single",col=1:2)


ryamada22 <- ts(blog$統計遺伝学, start=c(2005,1), end=c(2016, 11), frequency=12)
ryamada <- ts(blog$応用数学, start=c(2005,1), end=c(2016, 11), frequency=12)

ryamadaall <- ts(blog$統計遺伝学+blog$応用数学, start=c(2005,1), end=c(2016, 12), frequency=12)

# Seasonal decomposition
fit <- stl(ryamada, s.window="period")
fit22 <- stl(ryamada22, s.window="period")
fitall <- stl(ryamadaall,s.window="period")

ts.data<- ryamada.two
ts.seasonal <- ts(cbind(fit22[[1]][,1],fit[[1]][,1]), start=c(2005,1), end=c(2016, 11), frequency=12)

ts.trend <- ts(cbind(fit22[[1]][,2],fit[[1]][,2]), start=c(2005,1), end=c(2016, 11), frequency=12)

ts.residual <- ts(cbind(fit22[[1]][,3],fit[[1]][,3]), start=c(2005,1), end=c(2016, 11), frequency=12)
op <- par(mfcol = c(2,2))
op <- par(mar = c(0, 4, 0, 3), oma = c(5, 0, 4, 0), mfcol = c(4,1))
plot(ts.data,plot.type="single",col=1:2)
plot(ts.seasonal,plot.type="single",col=1:2)
plot(ts.trend,plot.type="single",col=1:2)
plot(ts.residual,plot.type="single",col=1:2)

plot(fit,main="応用数学",set.pars = NULL)
plot(fit22,main="遺伝統計学",set.pars = NULL)
#plot(fitall)

matplot(cbind("応用数学"=fit[[1]][,1],"統計遺伝学"=fit22[[1]][,1]),type="l",)




# additional plots
monthplot(fit)
monthplot(fit22)
monthplot(fitall)

library(forecast)
seasonplot(fit)
seasonplot(fit22)
seasonplot(fitall)


plot(blog$V1,blog$V2,type="l")

ryamada22.year <- ryamada.year <- rep(0,12)
for(i in 1:12){
	tmp <- (1:12) + (i-1) * 12
	points(blog$V1[tmp],blog$V2[tmp],col=i,pch=20)
	ryamada22.year[i] <- sum(blog$V1[tmp])
	ryamada.year[i] <- sum(blog$V2[tmp])
}

plot(ryamada22.year,ryamada.year)

0	0
0	0
0	0
0	0
0	0
0	0
0	0
0	0
0	0
0	0
1761	50
2401	374
4070	339
3420	345
3314	340
3438	308
5042	501
5004	355
5114	226
4662	0
5283	0
5875	0
6439	0
5908	0
6275	0
5015	0
5198	0
5185	0
5901	0
6045	0
6412	0
5060	0
5391	0
7388	0
9132	0
7705	0
9763	0
7296	0
6216	0
8217	0
9015	0
9604	0
10856	0
8005	0
9175	0
11059	0
10367	0
9370	0
9982	0
7466	0
6063	0
6870	0
7899	0
9560	0
9687	0
6561	0
6446	0
8314	0
7633	0
7185	0
7479	0
6986	0
5830	0
5144	0
6066	0
7262	0
6792	325
6097	1316
6105	1532
8522	2220
8761	3164
7282	2681
8289	3037
7310	2158
5847	1671
7167	1983
8290	2433
8524	2318
8787	2848
5989	2107
6618	2320
7160	2704
7390	2619
7112	2660
8509	3765
8023	3955
6112	3305
7235	3934
9040	4607
9649	4899
9411	5259
7081	4317
6240	4151
8142	5290
8362	5597
8265	5325
8868	5697
7081	4825
5975	4229
7051	5033
8364	5241
7610	5211
7910	6200
6354	4987
6454	4311
8531	5482
9522	6159
9011	5973
9542	6004
7537	4683
6996	4115
7947	5342
8684	5765
9141	5876
9083	6301
7450	5280
7228	5351
8937	5741
8903	6008
8801	6118
9855	7017
7858	5800
6683	5480
9688	5817
8047	5366
8715	5896
8633	5970
6310	4790
7115	4451
7641	5696
7584	5942
7775	6165
8636	5955
7176	6729
7578	5613
7862	5941
9263	6302
9457	6374
10824	7664
8887	6036
8469	5445
7060	5679
9027	6805