天気情報
矢島町(秋田県)のデータ
その1:矢島 1988-2008年の気温の推移(作成中)
- 使用データ
- 期間:1988年1月~2008月12月
- 月次データ
- データの種類
- 気温(平均、最低・最高)
- このページにファイル名"yashima88-08.csv"でアップ済
#ファイル名
"yashima88-08.csv"
Y8808 <- read.table("yashima88-08.csv",sep=",",skip=1)
AT <- Y8808[,1]
HT <- Y8808[,2]
LT <- Y8808[,3]
DF <- HT-LT
AT2 <- ts(AT, start=c(1988,1),frequency=12)
HT2 <- ts(HT, start=c(1988,1),frequency=12)
LT2 <- ts(LT, start=c(1988,1),frequency=12)
DF2 <- ts(DF, start=c(1988,1),frequency=12)
par(mfrow=c(2,2))#4グラフを1画面に導出
ts.plot(AT2,xlab='1988-2008',ylab='deg C',main="平均気温@yashima")
ts.plot(HT2,xlab='1988-2008',ylab='deg C',main="最高気温@yashima")
ts.plot(LT2,xlab='1988-2008',ylab='deg C',main="最低気温@yashima")
ts.plot(DF2,xlab='1988-2008',ylab='deg C',main="最高気温と最低気温の差異")
#ACFを確認
par(mfrow=c(2,2))
acf(AT2)
acf(HT2)
acf(LT2)
acf(DF2)
#ついでPACF
par(mfrow=c(2,2))
pacf(AT2)
pacf(HT2)
pacf(LT2)
pacf(DF2)
- 移動平均を求める
- 方法1:手入力で作成
- 方法2:移動平均をもとめる関数を作成
- "MA.R"というファイルを読み込み実行(未確認)
- あるいは"MA.R.tst"をPCに保存。ファイルの拡張子を".R"に変更。R上で"source("MA.R")"と入力し読み込ませる。参考:ttp://www.f.waseda.jp/tamaki/ja/R/npv-irr.html
- あるいは"MA.R.tst"をR上にコピペする。
#先ず
#移動平均
の比較
MAT13 <- MA(AT2,13)
MHT13 <- MA(HT2,13)
MLT13 <- MA(LT2,13)
MDF13 <- MA(DF2,13)
par(mfrow=c(2,2))
ts.plot(MAT13)
ts.plot(MHT13)
ts.plot(MLT13)
ts.plot(MDF13)
#移動平均
の比較
MAT60 <- MA(AT2,60)
MHT60 <- MA(HT2,60)
MLT60 <- MA(LT2,60)
MDF60 <- MA(DF2,60)
par(mfrow=c(2,2))
ts.plot(MAT60)
ts.plot(MHT60)
ts.plot(MLT60)
ts.plot(MDF60)
#移動平均
の比較
MAT120 <- MA(AT2,120)
MHT120 <- MA(HT2,120)
MLT120 <- MA(LT2,120)
MDF120 <- MA(DF2,120)
par(mfrow=c(2,2))
ts.plot(MAT120)
ts.plot(MHT120)
ts.plot(MLT120)
ts.plot(MDF120)
#平均と移動平均の比較
#平均気温
ts.plot(AT2,MAT13,MAT60,MAT120,gpars=list(xlab="year", ylab="deg C", lwd=c(1:4), col=c(1:4)),main="平均気温と移動平均(13,60,120月)の比較")
#マウスで凡例の場所を選べる
。
legend(locator(1),c("平均気温","前年同月比","5年前同月比","13か月移動平均","60ヶ月移動平均","12ヶ月移動平均"),lty=c(1:6),col=c(1:6))
#参考
:最高気温の場合
ts.plot(HT2,MHT13,MHT60,MHT120,gpars=list(xlab="year", ylab="deg C", lwd=c(1:4), col=c(1:4)))
#参考
:最低気温の場合
ts.plot(AT2,MAT13,MAT60,MAT120,gpars=list(xlab="year", ylab="deg C", lwd=c(1:4), col=c(1:4)))
#前年比
AT3 <- diff(AT2,12)
HT3 <- diff(HT2,12)
LT3 <- diff(LT2,12)
DF3 <- diff(DF2,12)
par(mfrow=c(2,2))#4グラフを1画面に導出
ts.plot(AT3,xlab='1988-2008',ylab='deg C',main="平均気温の前年比@yashima")
ts.plot(HT3,xlab='1988-2008',ylab='deg C',main="最高気温の前年比@yashima")
ts.plot(LT3,xlab='1988-2008',ylab='deg C',main="最低気温の前年比@yashima")
ts.plot(DF3,xlab='1988-2008',ylab='deg C',main="最高気温と最低気温の差の前年比")
#同じデータの異なるMAの比較
MAT6 <- MA(AT,6)
MAT12 <- MA(AT,12)
MAT13 <- MA(AT,13)
MAT25 <- MA(AT,25)
par(mfrow=c(2,2))
ts.plot(MAT6)
ts.plot(MAT12)
ts.plot(MAT13)
ts.plot(MAT25)
#AT2
decompose(AT2, type = c("additive", "multiplicative"), filter = NULL)
filter(AT2, filter, method = c("convolution", "recursive"),
sides = 2, circular = FALSE, init)
par(mfrow=c(1,1))
plot(decompose(AT2))
#HT2
decompose(HT2, type = c("additive", "multiplicative"), filter = NULL)
filter(HT2, filter, method = c("convolution", "recursive"),
sides = 2, circular = FALSE, init)
par(mfrow=c(1,1))
plot(decompose(HT2))
#LT2
decompose(LT2, type = c("additive", "multiplicative"), filter = NULL)
filter(LT2, filter, method = c("convolution", "recursive"),
sides = 2, circular = FALSE, init)
par(mfrow=c(1,1))
plot(decompose(LT2))
- 季節成分のプロット(引用:Rの基本パッケージ中の時系列オブジェクト一覧 )
- 「時系列の季節成分(または、他の副系列)をプロットする。」
- 「各季節(もしくは他のカテゴリ)毎に時系列がプロットされる。現在の作図デバイスにプロットが行われるが、返り値は無い。」
par(mfrow=c(2,2))#4グラフを1画面に導出
monthplot(AT2)
monthplot(HT2)
monthplot(LT2)
monthplot(DF2)
以下未整理のもの
1.日照時間(作成中・未整理)
- 使用データ
- 期間:2009年1月~3月
- 日次データ
- データの種類
- 積雪量
- 日照時間
- 気温(平均、最低・最高)
Rのコード
(1)ファイルの読み込み、データの確認
YSM09 <- read.table("YASHIMA2009.csv",sep=",",skip=1)
colnames(YSM09) <- c("sunshine", "ATem", "HTem","LTem","snow") #列ごとに名前を付ける
YSM09
summary(YSM09)
plot(YSM09)#相関
sunshine ATem HTem LTem
Min. :0.000 Min. :-4.100 Min. :-2.300 Min. :-9.300
1st Qu.:0.225 1st Qu.:-0.175 1st Qu.: 2.525 1st Qu.:-4.275
Median :1.400 Median : 0.850 Median : 4.700 Median :-2.500
Mean :2.441 Mean : 1.249 Mean : 5.189 Mean :-2.591
3rd Qu.:3.975 3rd Qu.: 2.500 3rd Qu.: 7.050 3rd Qu.:-0.925
Max. :9.600 Max. :14.600 Max. :19.500 Max. : 8.200
snow
Min. : 0.000
1st Qu.: 0.000
Median : 2.000
Mean : 4.578
3rd Qu.: 5.750
Max. :33.000
(2)データ分析
#「N degrees centigrade」は「N deg C」と表記するらしい・・・。
par(mfrow=c(2,2))
ts.plot(YSM09$sunshine,xlab=',Jan-Mar,09',ylab='hours',main="actual sunshine duration" )
ts.plot(YSM09$HTem,xlab='Jan-Mar,09',ylab='deg C',main="High Tem")
ts.plot(YSM09$LTem,xlab='Jan-Mar,09',ylab='deg C',main="Low Tem")
ts.plot(YSM09$snow,xlab=',Jan-Mar,09',ylab='cm',main="Snow accumulation")
#調べなおすと降雪量だったのでSnow
accumulationよりSnowfallのほうが適切と思われる。
(1)、別のアプローチ
SS <- YSM09[,1]
AT <- YSM09[,2]
HT <- YSM09[,3]
LT <- YSM09[,4]
SN <- YSM09[,5]
TSS <- ts(SS)
TAT <- ts(AT)
THT <- ts(HT)
TLT <- ts(LT)
TSN <- ts(SN)
par(mfrow=c(2,2))
ts.plot(TSS,xlab='Jan-Mar,09',ylab='hours',main="actual sunshine duration" )
ts.plot(THT,xlab='Jan-Mar,09',ylab='deg C',main="High Tem")
ts.plot(TLT,xlab='Jan-Mar,09',ylab='deg C',main="Low Tem")
ts.plot(TSN,xlab='Jan-Mar,09',ylab='cm',main="Snowfall")
(3)差分
d.SS <- diff(log(TSS))
d.AT <- diff(log(TAT))
d.HT <- diff(log(THT))
d.LT <- diff(log(TLT))
d.SN <- diff(log(TSN))
d.SS2 <- diff(TSS)
d.AT2 <- diff(TAT)
d.HT2 <- diff(THT)
d.LT2 <- diff(TLT)
d.SN2 <- diff(TSN)
#全データのとき
d.YSM1 <- ts.union(d.SS2,d.AT2,d.HT2,d.LT2,d.SN2)
ar(d.YSM1, order.max=12)$aic #最大12
#SS
、ATM、SNのとき
d.YSM2 <- ts.union(d.SS2,d.AT2,d.SN2)
ar(d.YSM2, order.max=12)$aic #最大12
#2変数の組み合わせ
#ccf
全データの時
0 1 2 3 4 5 6
128.02100 54.48593 34.89174 0.00000 20.76393 25.46176 37.40009
7 8 9 10 11 12
41.92036 55.61239 79.94372 61.82282 81.54054 98.74195
3データの時
0 1 2 3 4 5 6
49.066649 27.633105 7.196761 0.000000 7.900328 6.271213 21.269245
7 8 9 10 11 12
23.584943 25.885291 34.382546 11.762741 20.115169 33.984821
(4)影響を調べる
library(vars) #念のため読み込ませる。
v2 <- data.frame(SS,AT,SN)
var2 <- VAR(v2,p=3,type="const")
#インパルス応答関数の設定
、プロット
impulse21 <-irf(var2,impulse="SS",response=c("SS","AT","SN"))
plot(impulse21,main="SS→他")
impulse22 <-irf(var2,impulse="AT",response=c("SS","AT","SN"))
plot(impulse22,main="AT→他")
impulse23 <-irf(var2,impulse="SN",response=c("SS","AT","SN"))
plot(impulse23,main="SN→他")
"var2"の中身
VAR Estimation Results:
=======================
Estimated coefficients for equation SS:
=======================================
Call:
SS = SS.l1 + AT.l1 + SN.l1 + SS.l2 + AT.l2 + SN.l2 + SS.l3 + AT.l3 + SN.l3 + const
SS.l1 AT.l1 SN.l1 SS.l2 AT.l2 SN.l2 SS.l3 AT.l3 SN.l3 const
0.11613158 -0.33429867 -0.07123071 -0.17250042 0.34202598 -0.00782936 -0.16166771 -0.12141726 -0.03739378 3.66364149
Estimated coefficients for equation AT:
=======================================
Call:
AT = SS.l1 + AT.l1 + SN.l1 + SS.l2 + AT.l2 + SN.l2 + SS.l3 + AT.l3 + SN.l3 + const
SS.l1 AT.l1 SN.l1 SS.l2 AT.l2 SN.l2 SS.l3 AT.l3 SN.l3 const
0.147749090 0.512310938 -0.044991174 -0.046607111 -0.119111172 -0.012354123 0.053713185 0.216879178 -0.004970423 0.404915884
Estimated coefficients for equation SN:
=======================================
Call:
SN = SS.l1 + AT.l1 + SN.l1 + SS.l2 + AT.l2 + SN.l2 + SS.l3 + AT.l3 + SN.l3 + const
SS.l1 AT.l1 SN.l1 SS.l2 AT.l2 SN.l2 SS.l3 AT.l3 SN.l3 const
- 0.02224250 -0.14336840 0.69759293 0.10028917 0.40833359 -0.28246075 -0.24348971 -0.23207981 0.12737774 2.31196019
2.気温(作成中・未整理)
- 使用データ
- 期間:2009年1月~12月
- 日次データ
- データの種類
- 気温(平均、最低・最高)
- このページにファイル名"yashima_dy2009.csv"でアップ済
Rのコード
#ファイル名
:yashima_dy2009.csv
YSM09D <- read.table("yashima_dy2009.csv",sep=",",skip=1)
#一応データの確認
YSM09D#原データには「」が入っていたりするので修正済
summary(YSM09)
AT <- YSM09D[,1]
HT <- YSM09D[,2]
LT <- YSM09D[,3]
DF <- HT-LT
AT2 <- ts(AT, start=c(2009,1,1),frequency=365)
HT2 <- ts(HT, start=c(2009,1,1),frequency=365)
LT2 <- ts(LT, start=c(2009,1,1),frequency=365)
DF2 <- ts(DF, start=c(2009,1,1),frequency=365)
par(mfrow=c(2,2))#4グラフを1画面に導出
ts.plot(AT2,xlab='2009',ylab='deg C',main="平均気温@yashima")
ts.plot(HT2,xlab='2009',ylab='deg C',main="最高気温@yashima")
ts.plot(LT2,xlab='2009',ylab='deg C',main="最低気温@yashima")
ts.plot(DF2,xlab='2009',ylab='deg C',main="最高気温と最低気温の差異")
#cf
.他の方法
#ts
.plot(YSM09D[,1])
#ts
.plot(YSM09D[,2])
#ts
.plot(YSM09D[,3])
#8つだとみにくいので4つずつ表示させる
。
#ACFから
par(mfrow=c(2,2))
acf(AT2)
acf(HT2)
acf(LT2)
acf(DF2)
#ついでPACF
par(mfrow=c(2,2))
pacf(AT2)
pacf(HT2)
pacf(LT2)
pacf(DF2)
#cf
.8つ同時の時
par(mfrow=c(4,2))
acf(AT2)
acf(HT2)
acf(LT2)
acf(DF2)
pacf(AT2)
pacf(HT2)
pacf(LT2)
pacf(DF2)
最終更新:2010年07月11日 19:38