2020年5月29日金曜日

Global PMI manufacturing



> pmi_global <- as.xts(c(50.3,50.1,50.4, 47.1,47.3,39.8),seq(as.Date("2019-11-01"),as.Date("2020-04-01"),by='months'))
> pmi_global
           [,1]
2019-11-01 50.3
2019-12-01 50.1
2020-01-01 50.4
2020-02-01 47.1
2020-03-01 47.3
2020-04-01 39.8


> pmi_global <- append(pmi_global,as.xts(c(47.9,50.3,51.8,52.3),seq(as.Date("2020-06-01"),as.Date("2020-09-01"),by='months')))

> pmi_global
           [,1]
2019-11-01 50.3
2019-12-01 50.1
2020-01-01 50.4
2020-02-01 47.1
2020-03-01 47.3
2020-04-01 39.6
2020-05-01 42.4
2020-06-01 47.9
2020-07-01 50.3
2020-08-01 51.8
2020-09-01 52.3

2020年5月23日土曜日

Tokyo Newly Infection and R + 7 days moving average


  • データはhttps://catalog.data.metro.tokyo.lg.jp/dataset/t000010d0000000068/resource/c2d997db-1450-43fa-8037-ebb11ec28d4c から取得した「リソース」ボタンを押すこと。
  • データは公表年月日データが記録されれているだけなので、これをapply.daily()を使用して日毎に集計する必要がある。結果は日々差分データとなる。
  • nod は平滑化のための期間パラメータ(日数)である。ここでは 7 とする。
  • Kは、(十進LOG(過去nod日間の新規感染確認者数計)ー 十進LOG(さらにその前のnod日間の新規感染確認者数計))/ nod
  • L = 平均潜伏期間 = 4.76 (7 in china) 出典= https://www.fukuishimbun.co.jp/articles/-/1071227
  • 福井県内で新型コロナウイルスの感染が確認された人のうち、ほかの感染者と接触し発症するまでの潜伏期間が推定できるケースの平均値は「4.76日」だった。
  • D = 平均潜伏感染期間 = 9 あるいはL+2。2は中国での実測値。
  • R = K^2*(L*D)+K*(L+D)+1

l <- 4.76
d <- l+2
nod <- 7


w <- c()
# w <- read.csv("~/R/R2/covid/summary.csv")
# https://stopcovid19.metro.tokyo.lg.jp/data/130001_tokyo_covid19_patients.csv
curl <- "https://stopcovid19.metro.tokyo.lg.jp/data/130001_tokyo_covid19_patients.csv"
cdestfile <- "~/R/R2/covid/tokyo.csv"
download.file(curl,cdestfile)
w <- read.csv("~/R/R2/covid/tokyo.csv")

w <- apply.daily(as.xts(rep(1,length(w[,1])),as.Date(w[,5])),sum)
last(w)


len <- length(w[,1])
k <- c()
for(i in seq(2*nod+1,len,1)) {
 k <- append(k,((log10(sum(w[,1][(i-nod+1):i]))) - log10(sum(w[,1][(i-2*nod+1):(i-nod)])))/nod)
}
r <- round(k**2*(l*d) + k*(l+d) +1,2)
w <- merge(w,as.xts(r,last(index(w),length(r))))
w


colnames(w)[2] <- "effective_repro"
last(w,len-11)
# plot(last(w[,2],60))

# R と新規感染者数を混在させるためスケール調整のために係数を計算する。
multi <- (max(na.omit(last(w[,1],length_graph))) / max(na.omit(last(w[,2],length_graph))))
length_graph <- 60 # グラフは過去45日間が対象
# merge(w,)

# as.xts(as.vector(round(last((na.omit(filter(w[,1],rep(1,7))/7)),length_graph),2)),as.Date(last(index(w),length_graph)))
w <- merge(w,as.xts(as.vector(round(last((na.omit(filter(w[,1],rep(1,7))/7)),length_graph),2)),as.Date(last(index(w),length_graph))))
w[,2] <- w[,2]*multi
positive <- as.vector(last(w[,1],length_graph))
repro <- as.vector(round(last(w[,2],length_graph),2))
moving_a <- as.vector(last(w[,3],length_graph))
date <- as.Date(last(index(w),length_graph))


df <- data.frame(
                p=positive,
                r=repro,
                m=moving_a,
                # s=seq(1,45,1))
                t=date)


p <- ggplot(df,aes(x=t))

p <- p + geom_bar(aes(y=p),stat="identity", colour="limegreen",fill="limegreen")
# p <- p + scale_x_date(date_breaks = "1 month", date_labels = "%M")
p <- p + geom_path(aes(y=r),colour='red')
p <- p + geom_path(aes(y=m),colour='blue')
# p <- p + scale_x_date(date_breaks = "1 month", date_labels = "%M")


p <- p + theme(axis.title.x=element_blank(),axis.title.y=element_blank())
p <- p+annotate("text",label=as.character("1.0"),x=as.Date(df$t[length_graph]), y=5+1*multi,colour='black')
p <- p + geom_hline(yintercept = 1*multi,size=0.5,linetype=2,colour="red",alpha=1)
p <- p+annotate("text",label=as.character("2.0"),x=as.Date(df$t[length_graph]), y=5+2*multi,,colour='black')
p <- p + geom_hline(yintercept = 2*multi,size=0.5,linetype=2,colour="red",alpha=1)
png("03tokyo.png", width = 800, height = 600)
plot(p)
dev.off()



2020年5月21日木曜日

All Region Daily New Infection stack histgram curl(),matrix(), cbind(),transform(),png(),melt()




  • データは"https://raw.githubusercontent.com/kazogiwara/covid19/master/data/prefectures.csv"から取得
  • データは各県のデータが日付と県名をキーにシーケンシャルに格納されている。必要なデータだけを抽出、ソートの上使用する。 
  • nod は平滑化のための期間パラメータ(日数)である。ここでは 7 とする。
  • Kは、(十進LOG(過去nod日間の新規感染確認者数計)ー 十進LOG(さらにその前のnod日間の新規感染確認者数計))/ nod
  • L = 平均潜伏期間 = 4.76 (7 in china)
  • from https://www.fukuishimbun.co.jp/articles/-/1071227
  • 福井県内で新型コロナウイルスの感染が確認された人のうち、ほかの感染者と接触し発症するまでの潜伏期間が推定できるケースの平均値は「4.76日」だった。
  • D = 平均潜伏感染期間 = 9 あるいはL+2。2は中国での実測値。
  • R = K^2*(L*D)+K*(L+D)+1
  • library(reshape2) を事前に実行しておくこと。melt()に必要。

library(reshape2)
length_graph <- 60 # グラフは過去length_graph日間が対象
l <- 4.76
d <- l+2
nod <- 7

w <- c()
curl <- "https://raw.githubusercontent.com/kaz-ogiwara/covid19/master/data/prefectures.csv"
# curl <- "https://github.com/kaz-ogiwara/covid19/blob/master/data/summary.csv"
cdestfile <- "~/R/R2/covid/pref.csv"
download.file(curl,cdestfile)
w <- read.csv("~/R/R2/covid/pref.csv")
# w <- as.xts(w[,c(5,6)],as.Date(paste(w[,1],w[,2],w[,3],sep='-')))
# とりあえずdata.frameを作って必要なデータを抜きす。
df <- c()
df <- data.frame(t=as.Date(paste(w[,1],w[,2],w[,3],sep='-')),
                r=w[,5],
                p=w[,6])

# データフレームから県名を抜き出し、unique(w[,5])で県名一覧を作る。
# 行列を作成し、各県のデータを抜き出し、順次行列にbindしていく。
i <- 1
mtx <- matrix(diff(df$p[df$r == unique(w[,5])[i]]))
for( i in seq(2,length(unique(w[,5])),1)){
  mtx <- cbind(mtx,diff(df$p[df$r == unique(w[,5])[i]]))
}
# 行列をデータフレームに変換し、そののち日付データを先のデータフレームから抜き出し付加する。
mdf <-as.data.frame(mtx)
mdf <-transform(mdf,t=unique(df$t)[-1])
# データフレームの列名を県名一覧で変更する。
colnames(mdf)[1:length(unique(w[,5]))] <- as.character(unique(w[,5]))

df.melt <- melt(data=mdf, id.vars="t", measure.vars=as.character(unique(w[,5])))
head(df.melt)
df <- df.melt
g <- ggplot(df, aes(x = t, y = value, fill = variable))
g <- g + geom_bar(stat = "identity")


png("04em.png", width = 1400, height = 600)
plot(g)
dev.off()


2020年5月19日火曜日

EPS 2020MAY19


EPS2020MAY13 has a serious problem. where data length should be 12, it has only 11 entries.


~$ tac eps.txt 
3/31/2019 2834.40 $37.99 $35.02 18.52 21.09 $153.05 $134.39
6/30/2019 2941.76 $40.14 $34.93 19.04 21.75 $154.54 $135.27
9/30/2019  2976.74 $39.81 $33.99 19.46 22.40 $152.97 $132.90
12/31/2019 3230.78 $39.18 $35.53 20.56 23.16 $157.12 $139.47
3/31/2020 (90.3%) 2584.59 $20.00 $12.56 20.50 24.38 $139.13 $117.01
6/30/2020 $23.66 $21.18 23.26 27.62 $122.65 $103.26
9/30/2020 $31.60 $28.27 24.93 29.24 $114.44 $97.55
12/31/2020 $36.41 $33.57 25.54 29.84 $111.67 $95.59
3/31/2021 $37.29 $33.26 22.12 24.53 $128.96 $116.28
6/30/2021 $38.53 $34.73 19.83 21.97 $143.83 $129.84
9/30/2021 $42.52 $38.61 18.43 20.35 $154.75 $140.17
12/31/2021 $44.80 $40.82 17.49 19.35 $163.14 $147.42

~$ tac eps.txt | awk '{gsub("\\$","",$NF);print "eps_year_xts[\"2019::\"]["NR"] <- "$NF}'
eps_year_xts["2019::"][1] <- 134.39
eps_year_xts["2019::"][2] <- 135.27
eps_year_xts["2019::"][3] <- 132.90
eps_year_xts["2019::"][4] <- 139.47
eps_year_xts["2019::"][5] <- 117.01
eps_year_xts["2019::"][6] <- 103.26
eps_year_xts["2019::"][7] <- 97.55
eps_year_xts["2019::"][8] <- 95.59
eps_year_xts["2019::"][9] <- 116.28
eps_year_xts["2019::"][10] <- 129.84
eps_year_xts["2019::"][11] <- 140.17
eps_year_xts["2019::"][12] <- 147.42

2020年5月18日月曜日

Is Jigger & Pony in Singapore

Asia’s Best Bar for 2020 Is Jigger & Pony in Singapore



  1. Jigger & Pony (Singapore)
  2. The Old Man (Hong Kong)
  3. Coa (Hong Kong)
  4. Indulge Experimental Bistro (Taipei)
  5. Atlas (Singapore)
  6. Native (Singapore)
  7. The Bamboo Bar at Mandarin Oriental (Bangkok)
  8. Manhattan (Singapore)
  9. The SG Club (Tokyo)
  10. Aha Saloon (Taipei)
  11. Vesper (Bangkok)
  12. Sober Company (Shanghai)
  13. Bar Mood (Taipei)
  14. Bar Trigona (Kuala Lumpur)
  15. Ben Benfiddich (Tokyo)
  16. Quinary (Hong Kong)
  17. Tippling Club (Singapore)
  18. The Wise King (Hong Kong)
  19. Speak Low (Shanghai)
  20. High Five (Tokyo)
  21. Bee’s Knees (Kyoto)
  22. The Old Man (Singapore)
  23. D.Bespoke (Singapore)
  24. Tropic City (Bangkok)
  25. Gibson (Singapore)
  26. Draft Land (Taipei)
  27. Room by Le Kief (Taipei)
  28. 8 ½ Otto e Mezzo Bombano (Hong Kong)
  29. Charles H (Seoul)
  30. 28 HongKong Street (Singapore)
  31. Rabbit Hole (Bangkok)
  32. Nutmeg & Clove (Singapore)
  33. Backstage Cocktail Bar (Bangkok)
  34. Caprice Bar (Hong Kong)
  35. The Pontiac (Hong Kong)
  36. Hope & Sesame (Guangzhou)
  37. Junglebird (Kuala Lumpur)
  38. The Odd Couple (Shanghai)
  39. Bar Trench (Tokyo)
  40. Sidecar (New Delhi)
  41. Bar Orchard Ginza (Tokyo)
  42. The Curator (Manila)
  43. Union Brasserie, Bakery & Bar (Jakarta)
  44. Lobster Bar & Grill  (Hong Kong)
  45. The Back Room (Manila)
  46. MO Bar (Singapore)
  47. Alice (Seoul)
  48. Coley (Kuala Lumpur)
  49. Le Chamber (Seoul)
  50. Bar Cham (Seoul)



2020年5月13日水曜日

EPS 2020MAY13


> eps_year_xts["2020::"]
             [,1]
2020-01-01 125.55
2020-04-01 112.16
2020-07-01 107.75
2020-10-01 106.97
2021-01-01 119.15
2021-04-01 133.29
2021-07-01 143.24
2021-10-01 150.31

~$ cat eps.txt 
12/31/2021 $45.05 $41.12 17.84 19.84 $164.19 $147.68
9/30/2021 $42.79 $38.61 18.79 20.86 $155.89 $140.44
6/30/2021 $38.88 $34.70 20.21 22.50 $144.98 $130.19
3/31/2021 $37.47 $33.25 22.52 25.31 $130.07 $115.77
12/31/2020 $36.75 $33.89 25.92 30.79 $113.03 $95.16
9/30/2020 $31.88 $28.35 25.38 30.27 $115.46 $96.80
6/30/2020 $23.97 $20.28 23.74 28.60 $123.39 $102.44
3/31/2020 (88.1%) 2584.59 $20.43 $12.64 20.99 25.02 $139.56 $117.09
12/31/2019 3230.78 $39.18 $35.53 20.56 23.16 $157.12 $139.47
9/30/2019  2976.74 $39.81 $33.99 19.46 22.40 $152.97 $132.90
6/30/2019 2941.76 $40.14 $34.93 19.04 21.75 $154.54 $135.27

~$ tac eps.txt | awk '{gsub("\\$","",$NF);print "eps_year_xts[\"2019::\"]["NR"] <- "$NF}'
eps_year_xts["2019::"][1] <- 135.27
eps_year_xts["2019::"][2] <- 132.90
eps_year_xts["2019::"][3] <- 139.47
eps_year_xts["2019::"][4] <- 117.09
eps_year_xts["2019::"][5] <- 102.44
eps_year_xts["2019::"][6] <- 96.80
eps_year_xts["2019::"][7] <- 95.16
eps_year_xts["2019::"][8] <- 115.77
eps_year_xts["2019::"][9] <- 130.19
eps_year_xts["2019::"][10] <- 140.44
eps_year_xts["2019::"][11] <- 147.68

2020年5月9日土曜日

EPS 2020MAY09



> eps_year_xts["2020::"]
             [,1]
2020-01-01 129.39
2020-04-01 117.62
2020-07-01 113.96
2020-10-01 113.05
2021-01-01 121.56
2021-04-01 133.87
2021-07-01 142.67
2021-10-01 149.17

~$ tac eps.txt 
3/31/2019 2834.40 $37.99 $35.02 18.52 21.09 $153.05 $134.39
6/30/2019 2941.76 $40.14 $34.93 19.04 21.75 $154.54 $135.27
9/30/2019  2976.74 $39.81 $33.99 19.46 22.40 $152.97 $132.90
12/31/2019 3230.78 $39.18 $35.53 20.56 23.16 $157.12 $139.47
3/31/2020 (71.8%) 2584.59 $27.89 $21.10 19.25 22.55 $147.02 $125.55
6/30/2020 $24.57 $21.54 21.53 25.24 $131.45 $112.16
9/30/2020 $32.39 $29.58 22.82 26.27 $124.03 $107.75
12/31/2020 $37.09 $34.75 23.21 26.46 $121.94 $106.97
3/31/2021 $37.61 $33.28 21.50 23.76 $131.66 $119.15
6/30/2021 $39.19 $35.68 19.35 21.24 $146.28 $133.29
9/30/2021 $43.07 $39.53 18.03 19.76 $156.96 $143.24
12/31/2021 $45.25 $41.82 17.14 18.83 $165.12 $150.31
~$ tac eps.txt | awk '{gsub("\\$","",$NF);print "eps_year_xts[\"2019::\"]["NR"] <- "$NF}'
eps_year_xts["2019::"][1] <- 134.39
eps_year_xts["2019::"][2] <- 135.27
eps_year_xts["2019::"][3] <- 132.90
eps_year_xts["2019::"][4] <- 139.47
eps_year_xts["2019::"][5] <- 125.55
eps_year_xts["2019::"][6] <- 112.16
eps_year_xts["2019::"][7] <- 107.75
eps_year_xts["2019::"][8] <- 106.97
eps_year_xts["2019::"][9] <- 119.15
eps_year_xts["2019::"][10] <- 133.29
eps_year_xts["2019::"][11] <- 143.24
eps_year_xts["2019::"][12] <- 150.31