r-statistics-fanの日記

統計好きの現場の臨床医の覚書のようなもの

Fisher's exact testが"正確”かどうか

f:id:r-statistics-fan:20171031163411j:plainf:id:r-statistics-fan:20171031163416j:plainf:id:r-statistics-fan:20171031163421j:plainf:id:r-statistics-fan:20171031163425j:plain

https://oku.edu.mie-u.ac.jp/~okumura/stat/fisher-chisq.html
https://twitter.com/genkuroki/status/910360137256325121

このあたりのFisher's exact testが"正確”かどうかという議論が勉強になる

それぞれの立場でそれぞれ一理ある

前提として周辺度数の固定という条件を許容するかどうか
P値について、理想の値に近いことを正確と表現するか、アルファエラーが保たれることを正確とするか
で混乱しているように思う

自分の認識は、
”サンプルサイズが少ないときはカイ二乗検定ではアルファエラーが保たれないので
Fisher's exact testを使用するべき”
です。
なぜなら、研究時に少ないNのデータで有意差を証明したとしても、もしアルファエラーが
保たれない可能性がある手法を使っていたら誰も納得しないからです。

一方、全体の状況を眺めるとき(個々の有意差が主目的ではない)などは、より理想値に近い
カイ二乗が良いと考えます。


というものの、理想の値に近く、かつ、アルファ水準が保たれる手法がベストです。
Fisher's exact testは、周辺度数が固定されない一般の状況下において、
あまりに保守的すぎるのも事実です。


結局、個別にモンテカルロシミュレーションをしてカイ二乗の分布を個別に出して
P値を計算するのが現状でのベストかなと思います。
全体を眺める際には多数の表を計算するので時間がかかりますがそっちは通常のカイ二乗で良いわけで
メインアウトカムの評価時だけなら時間がかかっても問題なし。

同じことを考えた人は恐らく多いと思うが、検索する気力はなしー。

ということで、Rで実際にやってみる。
ろくに検証しておらず載せるかどうか悩んだが、好き放題書いて批評されて
自分の勉強になることも目的の一つに敢えて匿名blogにしているのでGOサイン~。

奥村先生のコードを流用します
https://oku.edu.mie-u.ac.jp/~okumura/stat/fisher-chisq.html

素人なんで間違っていたらごめんなさい。
叩かれまくったら今度はじめて伺うJapanRで端っこの方で恥ずかしくて縮こまってますわー。

###########
prob = c(0.12,0.18,0.28,0.42)
ni = 100000
chi = pfis = pchi = pchic = numeric(ni)
for (i in 1:ni) {
      k = sample(1:4, 50, replace=TRUE, prob=prob)
      na = sum(k == 1)
      nb = sum(k == 2)
      nc = sum(k == 3)
      nd = sum(k == 4)
      a = matrix(c(na, nb, nc, nd), nrow=2)
      pfis[i] = fisher.test(a)$p.value
      pchi[i] = chisq.test(a, correct=FALSE)$p.value
      chi[i] = chisq.test(a, correct=FALSE)$statistic
      pchic[i] = chisq.test(a, correct=TRUE)$p.value
}
ecdf_chi <- ecdf(-chi)
monte_chi_p <- ecdf_chi(-chi)
ecdf_monte_chi <- ecdf(monte_chi_p)

lim <- 0.06
ecdf_monte_pchi <- ecdf(monte_chi_p)
ecdf_pfis <- ecdf(pfis)
ecdf_pchi <- ecdf(pchi)

f0 <- function(lim){
      x1 <- seq(0, lim, length.out = length(monte_chi_p))
      plot(0, type = "n", asp=1, xlab="", ylab="", xlim=c(0,lim), ylim=c(0,lim),
   main="ECDF of Fisher, chisq, monte_chisq")
lines(x1, ecdf_pfis(x1), asp=1, xlab="", ylab="", xlim=c(0,lim), ylim=c(0,lim), type = "l",
     main="ECDF of Fisher, chisq, monte_chisq")
lines(x1, ecdf_pchi(x1), xlab="", ylab="", xlim=c(0,lim), ylim=c(0,lim),
     col = "RED")
lines(x1, ecdf_monte_pchi(x1), xlab="", ylab="", xlim=c(0,lim), ylim=c(0,lim),
     col = "GREEN")
abline(0,1, col = "blue")

legend("bottomright", legend=c("Fisher", "chisq", "montecaro"), lty =1, col = c("black", "red", "green"))
}

f0(0.06)
f0(1)



f <- function(lim, y_lim){
x1 <- seq(0, lim, length.out = length(monte_chi_p))
plot(0,0, type ="n", xlim=c(0, lim), ylim= y_lim, main = "ERROR prob(Pvalue < x) - x")
lines(x1, ecdf_monte_pchi(x1) - x1, type ="l", col = "green")
lines(x1, ecdf_pfis(x1) - x1, type ="l", col = "black")
lines(x1, ecdf_pchi(x1) - x1, type ="l", col = "red")
abline(h=0, col = "blue")

legend("bottomleft", legend=c("Fisher", "chisq", "montecaro"), lty =1, col = c("black", "red", "green"))
}

f(0.06,c(-0.025, 0.01))
f(1, c(-0.3, 0.05))



うまく、理想のP値に近く、かつ、アルファエラーを保てるP値になりました。

なお、それぞれ個別のP値を出すにはシミュレーションで計算されたecdf_chiを使って
ecdf_chi(マイナス カイ二乗値)
で出せば良い。

追記。今回のecdf_chi()を使用して、別のシミュレーションで検証。
ecdf_chi()を作ったデータに適合するのは当たり前だからね。
別データなので少しずれるが、なかなかよろしい。
f:id:r-statistics-fan:20171031185340j:plainf:id:r-statistics-fan:20171031185345j:plainf:id:r-statistics-fan:20171031185349j:plainf:id:r-statistics-fan:20171031185354j:plain

ライコウのレイド時のCPの表~ポケモンGO

ヨーロッパ出張で希少な自由時間にエンテイをゲット。1/1ゲットなので運が良かった。 ついでに運良くバリヤードもゲットした。 ということで、ライコウエンテイのレイド用の表も作成しておく。

次にライコウ

AT DF HP 固体値% レイド時CP レイド時HP 最大強化CP 最大CP順位 レイド上位% 80%以上の確率で入手するの必要な数 同90%以上
15 15 15 100.0 1913 116 3301 1 0.5 322 460
15 14 15 97.8 1909 116 3293 2 0.9 179 255
15 15 14 97.8 1908 115 3292 3 1.4 115 164
14 15 15 97.8 1906 116 3288 4 1.9 84 121
15 13 15 95.6 1905 116 3286 5 2.3 70 99
15 14 14 95.6 1904 115 3285 6 2.8 57 82
15 15 13 95.6 1903 115 3284 7 3.2 50 71
14 14 15 95.6 1902 116 3281 8 3.7 43 62
14 15 14 95.6 1901 115 3279 9 4.6 35 49
15 12 15 93.3 1900 116 3279 9 4.6 35 49
15 13 14 93.3 1900 115 3278 11 5.1 31 44
15 14 13 93.3 1899 115 3277 12 5.6 28 40
15 15 12 93.3 1898 114 3275 13 6.5 24 35
13 15 15 95.6 1898 116 3275 13 6.5 24 35
14 13 15 93.3 1897 116 3273 15 6.9 23 33
14 14 14 93.3 1897 115 3272 16 7.4 21 30
14 15 13 93.3 1896 115 3271 17 8.3 19 27
15 11 15 91.1 1896 116 3271 17 8.3 19 27
15 12 14 91.1 1896 115 3270 19 8.8 18 25
15 13 13 91.1 1895 115 3269 20 9.3 17 24
15 14 12 91.1 1894 114 3268 21 10.2 15 22
13 14 15 93.3 1894 116 3268 21 10.2 15 22
15 15 11 91.1 1893 114 3267 23 11.1 14 20
13 15 14 93.3 1893 115 3267 23 11.1 14 20
14 12 15 91.1 1893 116 3266 25 11.6 14 19
14 13 14 91.1 1892 115 3265 26 12.0 13 19
14 14 13 91.1 1892 115 3264 27 13.0 12 17
15 10 15 88.9 1892 116 3264 27 13.0 12 17
14 15 12 91.1 1891 114 3263 29 13.9 11 16
15 11 14 88.9 1891 115 3263 29 13.9 11 16
15 12 13 88.9 1891 115 3262 31 14.8 11 15
12 15 15 93.3 1891 116 3262 31 14.8 11 15
15 13 12 88.9 1890 114 3261 33 15.3 10 14
13 13 15 91.1 1890 116 3260 34 16.2 10 14
15 14 11 88.9 1889 114 3260 34 16.2 10 14
13 14 14 91.1 1889 115 3259 36 17.1 9 13
14 11 15 88.9 1889 116 3259 36 17.1 9 13
15 15 10 88.9 1889 113 3258 38 18.5 8 12
13 15 13 91.1 1889 115 3258 38 18.5 8 12
14 12 14 88.9 1888 115 3258 38 18.5 8 12
14 13 13 88.9 1887 115 3256 41 19.4 8 11
15 10 14 86.7 1887 115 3256 41 19.4 8 11
14 14 12 88.9 1887 114 3255 43 20.8 7 10
12 14 15 91.1 1887 116 3255 43 20.8 7 10
15 11 13 86.7 1886 115 3255 43 20.8 7 10
14 15 11 88.9 1886 114 3254 46 21.8 7 10
12 15 14 91.1 1886 115 3254 46 21.8 7 10
15 12 12 86.7 1886 114 3253 48 22.7 7 9
13 12 15 88.9 1886 116 3253 48 22.7 7 9
15 13 11 86.7 1885 114 3252 50 23.6 6 9
13 13 14 88.9 1885 115 3252 50 23.6 6 9
15 14 10 86.7 1884 113 3251 52 25.0 6 9
13 14 13 88.9 1884 115 3251 52 25.0 6 9
14 10 15 86.7 1884 116 3251 52 25.0 6 9
13 15 12 88.9 1884 114 3250 55 25.9 6 8
14 11 14 86.7 1884 115 3250 55 25.9 6 8
14 12 13 86.7 1883 115 3249 57 26.9 6 8
11 15 15 91.1 1883 116 3249 57 26.9 6 8
14 13 12 86.7 1883 114 3248 59 27.8 5 8
12 13 15 88.9 1882 116 3248 59 27.8 5 8
14 14 11 86.7 1882 114 3247 61 29.2 5 7
15 10 13 84.4 1882 115 3247 61 29.2 5 7
12 14 14 88.9 1882 115 3247 61 29.2 5 7
15 11 12 84.4 1881 114 3246 64 30.1 5 7
13 11 15 86.7 1881 116 3246 64 30.1 5 7
14 15 10 86.7 1881 113 3245 66 31.9 5 6
15 12 11 84.4 1881 114 3245 66 31.9 5 6
12 15 13 88.9 1881 115 3245 66 31.9 5 6
13 12 14 86.7 1881 115 3245 66 31.9 5 6
15 13 10 84.4 1880 113 3244 70 32.9 5 6
13 13 13 86.7 1880 115 3244 70 32.9 5 6
14 10 14 84.4 1880 115 3243 72 33.3 4 6
13 14 12 86.7 1879 114 3242 73 34.7 4 6
14 11 13 84.4 1879 115 3242 73 34.7 4 6
11 14 15 88.9 1879 116 3242 73 34.7 4 6
13 15 11 86.7 1879 114 3241 76 36.1 4 6
14 12 12 84.4 1878 114 3241 76 36.1 4 6
11 15 14 88.9 1878 115 3241 76 36.1 4 6
14 13 11 84.4 1878 114 3240 79 37.0 4 5
12 12 15 86.7 1878 116 3240 79 37.0 4 5
12 13 14 86.7 1878 115 3239 81 38.0 4 5
15 10 12 82.2 1877 114 3239 81 38.0 4 5
14 14 10 84.4 1877 113 3238 83 39.8 4 5
15 11 11 82.2 1877 114 3238 83 39.8 4 5
12 14 13 86.7 1877 115 3238 83 39.8 4 5
13 10 15 84.4 1877 116 3238 83 39.8 4 5
12 15 12 86.7 1876 114 3237 87 40.7 4 5
13 11 14 84.4 1876 115 3237 87 40.7 4 5
15 12 10 82.2 1876 113 3236 89 42.1 3 5
13 12 13 84.4 1876 115 3236 89 42.1 3 5
10 15 15 88.9 1876 116 3236 89 42.1 3 5
13 13 12 84.4 1875 114 3235 92 43.1 3 5
11 13 15 86.7 1875 116 3235 92 43.1 3 5
13 14 11 84.4 1875 114 3234 94 44.4 3 4
14 10 13 82.2 1875 115 3234 94 44.4 3 4
11 14 14 86.7 1874 115 3234 94 44.4 3 4
13 15 10 84.4 1874 113 3233 97 46.3 3 4
14 11 12 82.2 1874 114 3233 97 46.3 3 4
11 15 13 86.7 1874 115 3233 97 46.3 3 4
12 11 15 84.4 1874 116 3233 97 46.3 3 4
14 12 11 82.2 1873 114 3232 101 47.2 3 4
12 12 14 84.4 1873 115 3232 101 47.2 3 4
14 13 10 82.2 1873 113 3231 103 48.1 3 4
12 13 13 84.4 1873 115 3231 103 48.1 3 4
15 10 11 80.0 1872 114 3230 105 49.5 3 4
12 14 12 84.4 1872 114 3230 105 49.5 3 4
13 10 14 82.2 1872 115 3230 105 49.5 3 4
15 11 10 80.0 1872 113 3229 108 50.9 3 4
13 11 13 82.2 1872 115 3229 108 50.9 3 4
10 14 15 86.7 1872 116 3229 108 50.9 3 4
12 15 11 84.4 1871 114 3228 111 52.3 3 4
13 12 12 82.2 1871 114 3228 111 52.3 3 4
10 15 14 86.7 1871 115 3228 111 52.3 3 4
11 12 15 84.4 1871 116 3227 114 53.2 3 4
13 13 11 82.2 1870 114 3227 114 53.2 3 4
13 14 10 82.2 1870 113 3226 116 55.1 3 3
14 10 12 80.0 1870 114 3226 116 55.1 3 3
11 13 14 84.4 1870 115 3226 116 55.1 3 3
12 10 15 82.2 1870 116 3226 116 55.1 3 3
14 11 11 80.0 1869 114 3225 120 56.5 2 3
11 14 13 84.4 1869 115 3225 120 56.5 2 3
12 11 14 82.2 1869 115 3225 120 56.5 2 3
14 12 10 80.0 1869 113 3224 123 57.9 2 3
11 15 12 84.4 1869 114 3224 123 57.9 2 3
12 12 13 82.2 1868 115 3224 123 57.9 2 3
12 13 12 82.2 1868 114 3223 126 58.3 2 3
15 10 10 77.8 1867 113 3222 127 59.7 2 3
13 10 13 80.0 1867 115 3222 127 59.7 2 3
10 13 15 84.4 1867 116 3222 127 59.7 2 3
12 14 11 82.2 1867 114 3221 130 61.1 2 3
13 11 12 80.0 1867 114 3221 130 61.1 2 3
10 14 14 84.4 1867 115 3221 130 61.1 2 3
11 11 15 82.2 1867 116 3220 133 63.0 2 3
12 15 10 82.2 1866 113 3220 133 63.0 2 3
13 12 11 80.0 1866 114 3220 133 63.0 2 3
10 15 13 84.4 1866 115 3220 133 63.0 2 3
11 12 14 82.2 1866 115 3219 137 63.4 2 3
13 13 10 80.0 1865 113 3218 138 64.8 2 3
14 10 11 77.8 1865 114 3218 138 64.8 2 3
11 13 13 82.2 1865 115 3218 138 64.8 2 3
11 14 12 82.2 1865 114 3217 141 65.7 2 3
12 10 14 80.0 1865 115 3217 141 65.7 2 3
14 11 10 77.8 1864 113 3216 143 67.1 2 3
11 15 11 82.2 1864 114 3216 143 67.1 2 3
12 11 13 80.0 1864 115 3216 143 67.1 2 3
12 12 12 80.0 1864 114 3215 146 68.1 2 3
10 12 15 82.2 1863 116 3215 146 68.1 2 3
12 13 11 80.0 1863 114 3214 148 69.0 2 2
10 13 14 82.2 1863 115 3214 148 69.0 2 2
13 10 12 77.8 1863 114 3213 150 70.8 2 2
12 14 10 80.0 1862 113 3213 150 70.8 2 2
10 14 13 82.2 1862 115 3213 150 70.8 2 2
11 10 15 80.0 1862 116 3213 150 70.8 2 2
13 11 11 77.8 1862 114 3212 154 71.8 2 2
11 11 14 80.0 1862 115 3212 154 71.8 2 2
13 12 10 77.8 1861 113 3211 156 73.1 2 2
10 15 12 82.2 1861 114 3211 156 73.1 2 2
11 12 13 80.0 1861 115 3211 156 73.1 2 2
11 13 12 80.0 1860 114 3210 159 73.6 2 2
14 10 10 75.6 1860 113 3209 160 75.0 2 2
11 14 11 80.0 1860 114 3209 160 75.0 2 2
12 10 13 77.8 1860 115 3209 160 75.0 2 2
12 11 12 77.8 1859 114 3208 163 75.5 2 2
11 15 10 80.0 1859 113 3207 164 76.9 2 2
12 12 11 77.8 1859 114 3207 164 76.9 2 2
10 11 15 80.0 1859 116 3207 164 76.9 2 2
10 12 14 80.0 1859 115 3206 167 77.8 2 2
12 13 10 77.8 1858 113 3206 167 77.8 2 2
13 10 11 75.6 1858 114 3205 169 79.2 2 2
10 13 13 80.0 1858 115 3205 169 79.2 2 2
11 10 14 77.8 1857 115 3205 169 79.2 2 2
13 11 10 75.6 1857 113 3204 172 80.6 1 2
10 14 12 80.0 1857 114 3204 172 80.6 1 2
11 11 13 77.8 1857 115 3204 172 80.6 1 2
10 15 11 80.0 1857 114 3203 175 81.5 1 2
11 12 12 77.8 1856 114 3203 175 81.5 1 2
11 13 11 77.8 1856 114 3201 177 82.4 1 2
12 10 12 75.6 1855 114 3201 177 82.4 1 2
11 14 10 77.8 1855 113 3200 179 83.8 1 2
12 11 11 75.6 1855 114 3200 179 83.8 1 2
10 10 15 77.8 1855 116 3200 179 83.8 1 2
10 11 14 77.8 1854 115 3199 182 84.3 1 2
12 12 10 75.6 1854 113 3198 183 85.2 1 2
10 12 13 77.8 1854 115 3198 183 85.2 1 2
13 10 10 73.3 1853 113 3197 185 86.1 1 2
10 13 12 77.8 1853 114 3197 185 86.1 1 2
11 10 13 75.6 1853 115 3196 187 87.0 1 2
10 14 11 77.8 1852 114 3196 187 87.0 1 2
10 15 10 77.8 1852 113 3195 189 88.0 1 2
11 11 12 75.6 1852 114 3195 189 88.0 1 2
11 12 11 75.6 1851 114 3194 191 88.4 1 2
11 13 10 75.6 1851 113 3193 192 88.9 1 2
12 10 11 73.3 1850 114 3192 193 89.8 1 2
10 10 14 75.6 1850 115 3192 193 89.8 1 2
12 11 10 73.3 1850 113 3191 195 90.7 1 1
10 11 13 75.6 1850 115 3191 195 90.7 1 1
10 12 12 75.6 1849 114 3190 197 91.2 1 1
10 13 11 75.6 1848 114 3189 198 91.7 1 1
11 10 12 73.3 1848 114 3188 199 92.1 1 1
10 14 10 75.6 1848 113 3187 200 93.1 1 1
11 11 11 73.3 1847 114 3187 200 93.1 1 1
11 12 10 73.3 1847 113 3186 202 93.5 1 1
12 10 10 71.1 1846 113 3184 203 94.4 1 1
10 10 13 73.3 1845 115 3184 203 94.4 1 1
10 11 12 73.3 1845 114 3183 205 94.9 1 1
10 12 11 73.3 1844 114 3182 206 95.4 1 1
10 13 10 73.3 1843 113 3180 207 96.3 1 1
11 10 11 71.1 1843 114 3180 207 96.3 1 1
11 11 10 71.1 1842 113 3179 209 96.8 1 1
10 10 12 71.1 1841 114 3175 210 97.2 1 1
10 11 11 71.1 1840 114 3174 211 97.7 1 1
10 12 10 71.1 1839 113 3173 212 98.1 1 1
11 10 10 68.9 1838 113 3171 213 98.6 1 1
10 10 11 68.9 1836 114 3167 214 99.1 1 1
10 11 10 68.9 1835 113 3166 215 99.5 1 1
10 10 10 66.7 1831 113 3159 216 100.0 1 1

エンテイのレイド時のCPの表~ポケモンGO

ヨーロッパ出張で希少な自由時間にエンテイをゲット。1/1ゲットなので運が良かった。 ついでに運良くバリヤードもゲットした。 ということで、ライコウエンテイのレイド用の表も作成しておく。

f:id:r-statistics-fan:20170918200945j:plain

まずはエンテイ

AT DF HP 固体値% レイド時CP レイド時HP 最大強化CP 最大CP順位 レイド上位% 80%以上の確率で入手するの必要な数 同90%以上
15 15 15 100.0 1930 146 3329 1 0.5 322 460
15 15 14 97.8 1926 145 3322 2 0.9 179 255
15 14 15 97.8 1924 146 3320 3 1.4 115 164
14 15 15 97.8 1922 146 3316 4 1.9 84 121
15 15 13 95.6 1922 145 3315 5 2.3 70 99
15 14 14 95.6 1921 145 3313 6 2.8 57 82
15 13 15 95.6 1919 146 3312 7 3.2 50 71
15 15 12 93.3 1918 144 3309 8 4.2 38 54
14 15 14 95.6 1918 145 3309 8 4.2 38 54
15 14 13 93.3 1917 145 3307 10 5.1 31 44
14 14 15 95.6 1917 146 3307 10 5.1 31 44
15 13 14 93.3 1916 145 3305 12 5.6 28 40
15 12 15 93.3 1914 146 3303 13 6.0 27 38
15 15 11 91.1 1914 143 3302 14 7.4 21 30
14 15 13 93.3 1914 145 3302 14 7.4 21 30
13 15 15 95.6 1914 146 3302 14 7.4 21 30
15 14 12 91.1 1913 144 3300 17 8.3 19 27
14 14 14 93.3 1913 145 3300 17 8.3 19 27
15 13 13 91.1 1912 145 3298 19 9.3 17 24
14 13 15 93.3 1912 146 3298 19 9.3 17 24
15 12 14 91.1 1910 145 3296 21 10.2 15 22
13 15 14 93.3 1910 145 3296 21 10.2 15 22
15 15 10 88.9 1910 143 3295 23 11.1 14 20
14 15 12 91.1 1910 144 3295 23 11.1 14 20
15 11 15 91.1 1909 146 3294 25 12.0 13 19
13 14 15 93.3 1909 146 3294 25 12.0 13 19
15 14 11 88.9 1909 143 3293 27 13.0 12 17
14 14 13 91.1 1909 145 3293 27 13.0 12 17
14 13 14 91.1 1908 145 3292 29 13.4 12 17
15 13 12 88.9 1908 144 3291 30 13.9 11 16
14 12 15 91.1 1907 146 3290 31 14.4 11 15
15 12 13 88.9 1907 145 3289 32 15.7 10 14
13 15 13 91.1 1906 145 3289 32 15.7 10 14
12 15 15 93.3 1906 146 3289 32 15.7 10 14
14 15 11 88.9 1906 143 3288 35 16.2 10 14
14 14 12 88.9 1905 144 3287 36 17.6 9 12
15 11 14 88.9 1905 145 3287 36 17.6 9 12
13 14 14 91.1 1905 145 3287 36 17.6 9 12
15 14 10 86.7 1905 143 3286 39 18.1 9 12
14 13 13 88.9 1904 145 3285 40 19.4 8 11
15 10 15 88.9 1904 146 3285 40 19.4 8 11
13 13 15 91.1 1904 146 3285 40 19.4 8 11
15 13 11 86.7 1904 143 3284 43 19.9 8 11
14 12 14 88.9 1903 145 3283 44 20.4 8 11
15 12 12 86.7 1903 144 3282 45 22.2 7 10
12 15 14 91.1 1903 145 3282 45 22.2 7 10
14 15 10 86.7 1902 143 3282 45 22.2 7 10
13 15 12 88.9 1902 144 3282 45 22.2 7 10
14 11 15 88.9 1902 146 3281 49 22.7 7 9
14 14 11 86.7 1901 143 3280 50 24.5 6 9
15 11 13 86.7 1901 145 3280 50 24.5 6 9
13 14 13 88.9 1901 145 3280 50 24.5 6 9
12 14 15 91.1 1901 146 3280 50 24.5 6 9
15 13 10 84.4 1900 143 3278 54 26.4 6 8
14 13 12 86.7 1900 144 3278 54 26.4 6 8
15 10 14 86.7 1900 145 3278 54 26.4 6 8
13 13 14 88.9 1900 145 3278 54 26.4 6 8
15 12 11 84.4 1899 143 3276 58 28.7 5 7
14 12 13 86.7 1899 145 3276 58 28.7 5 7
12 15 13 88.9 1899 145 3276 58 28.7 5 7
13 12 15 88.9 1899 146 3276 58 28.7 5 7
11 15 15 91.1 1899 146 3276 58 28.7 5 7
13 15 11 86.7 1898 143 3275 63 29.2 5 7
15 11 12 84.4 1898 144 3274 64 30.6 5 7
14 11 14 86.7 1898 145 3274 64 30.6 5 7
12 14 14 88.9 1898 145 3274 64 30.6 5 7
14 14 10 84.4 1897 143 3273 67 31.5 5 7
13 14 12 86.7 1897 144 3273 67 31.5 5 7
14 10 15 86.7 1897 146 3272 69 33.3 4 6
15 10 13 84.4 1896 145 3272 69 33.3 4 6
13 13 13 86.7 1896 145 3272 69 33.3 4 6
12 13 15 88.9 1896 146 3272 69 33.3 4 6
14 13 11 84.4 1896 143 3271 73 33.8 4 6
13 12 14 86.7 1895 145 3270 74 34.3 4 6
15 12 10 82.2 1895 143 3269 75 36.1 4 6
14 12 12 84.4 1895 144 3269 75 36.1 4 6
12 15 12 86.7 1895 144 3269 75 36.1 4 6
11 15 14 88.9 1895 145 3269 75 36.1 4 6
13 15 10 84.4 1894 143 3268 79 37.0 4 5
13 11 15 86.7 1894 146 3268 79 37.0 4 5
15 11 11 82.2 1894 143 3267 81 39.4 4 5
14 11 13 84.4 1894 145 3267 81 39.4 4 5
12 14 13 86.7 1894 145 3267 81 39.4 4 5
11 14 15 88.9 1894 146 3267 81 39.4 4 5
13 14 11 84.4 1893 143 3267 81 39.4 4 5
14 10 14 84.4 1893 145 3265 86 41.2 4 5
12 13 14 86.7 1893 145 3265 86 41.2 4 5
15 10 12 82.2 1892 144 3265 86 41.2 4 5
13 13 12 84.4 1892 144 3265 86 41.2 4 5
14 13 10 82.2 1892 143 3264 90 41.7 3 5
14 12 11 82.2 1891 143 3263 91 43.1 3 5
13 12 13 84.4 1891 145 3263 91 43.1 3 5
12 12 15 86.7 1891 146 3263 91 43.1 3 5
12 15 11 84.4 1891 143 3262 94 44.4 3 4
11 15 13 86.7 1891 145 3262 94 44.4 3 4
10 15 15 88.9 1891 146 3262 94 44.4 3 4
14 11 12 82.2 1890 144 3261 97 45.4 3 4
13 11 14 84.4 1890 145 3261 97 45.4 3 4
15 11 10 80.0 1890 143 3260 99 47.2 3 4
13 14 10 82.2 1890 143 3260 99 47.2 3 4
12 14 12 84.4 1890 144 3260 99 47.2 3 4
11 14 14 86.7 1890 145 3260 99 47.2 3 4
14 10 13 82.2 1889 145 3259 103 48.6 3 4
13 10 15 84.4 1889 146 3259 103 48.6 3 4
11 13 15 86.7 1889 146 3259 103 48.6 3 4
15 10 11 80.0 1889 143 3258 106 50.0 3 4
12 13 13 84.4 1889 145 3258 106 50.0 3 4
13 13 11 82.2 1888 143 3258 106 50.0 3 4
14 12 10 80.0 1887 143 3256 109 52.3 3 4
13 12 12 82.2 1887 144 3256 109 52.3 3 4
11 15 12 84.4 1887 144 3256 109 52.3 3 4
12 12 14 84.4 1887 145 3256 109 52.3 3 4
10 15 14 86.7 1887 145 3256 109 52.3 3 4
12 15 10 82.2 1887 143 3255 114 52.8 3 4
14 11 11 80.0 1886 143 3254 115 55.6 2 3
12 14 11 82.2 1886 143 3254 115 55.6 2 3
13 11 13 82.2 1886 145 3254 115 55.6 2 3
11 14 13 84.4 1886 145 3254 115 55.6 2 3
12 11 15 84.4 1886 146 3254 115 55.6 2 3
10 14 15 86.7 1886 146 3254 115 55.6 2 3
14 10 12 80.0 1885 144 3252 121 57.4 2 3
12 13 12 82.2 1885 144 3252 121 57.4 2 3
13 10 14 82.2 1885 145 3252 121 57.4 2 3
11 13 14 84.4 1885 145 3252 121 57.4 2 3
15 10 10 77.8 1885 143 3251 125 58.3 2 3
13 13 10 80.0 1885 143 3251 125 58.3 2 3
12 12 13 82.2 1884 145 3250 127 59.3 2 3
11 12 15 84.4 1884 146 3250 127 59.3 2 3
13 12 11 80.0 1883 143 3249 129 60.6 2 3
11 15 11 82.2 1883 143 3249 129 60.6 2 3
10 15 13 84.4 1883 145 3249 129 60.6 2 3
13 11 12 80.0 1882 144 3248 132 61.6 2 3
12 11 14 82.2 1882 145 3248 132 61.6 2 3
14 11 10 77.8 1882 143 3247 134 63.4 2 3
12 14 10 80.0 1882 143 3247 134 63.4 2 3
11 14 12 82.2 1882 144 3247 134 63.4 2 3
10 14 14 84.4 1882 145 3247 134 63.4 2 3
13 10 13 80.0 1881 145 3246 138 64.4 2 3
12 10 15 82.2 1881 146 3246 138 64.4 2 3
14 10 11 77.8 1881 143 3245 140 66.2 2 3
12 13 11 80.0 1881 143 3245 140 66.2 2 3
11 13 13 82.2 1881 145 3245 140 66.2 2 3
10 13 15 84.4 1881 146 3245 140 66.2 2 3
13 12 10 77.8 1880 143 3243 144 67.6 2 3
12 12 12 80.0 1880 144 3243 144 67.6 2 3
11 12 14 82.2 1880 145 3243 144 67.6 2 3
11 15 10 80.0 1879 143 3242 147 68.5 2 2
10 15 12 82.2 1879 144 3242 147 68.5 2 2
12 11 13 80.0 1879 145 3241 149 70.4 2 2
11 11 15 82.2 1879 146 3241 149 70.4 2 2
13 11 11 77.8 1878 143 3241 149 70.4 2 2
10 14 13 82.2 1878 145 3241 149 70.4 2 2
11 14 11 80.0 1878 143 3240 153 70.8 2 2
13 10 12 77.8 1877 144 3239 154 72.7 2 2
11 13 12 80.0 1877 144 3239 154 72.7 2 2
12 10 14 80.0 1877 145 3239 154 72.7 2 2
10 13 14 82.2 1877 145 3239 154 72.7 2 2
14 10 10 75.6 1877 143 3238 158 73.6 2 2
12 13 10 77.8 1877 143 3238 158 73.6 2 2
11 12 13 80.0 1876 145 3237 160 74.5 2 2
10 12 15 82.2 1876 146 3237 160 74.5 2 2
12 12 11 77.8 1876 143 3236 162 75.5 2 2
10 15 11 80.0 1875 143 3236 162 75.5 2 2
11 11 14 80.0 1875 145 3235 164 75.9 2 2
13 11 10 75.6 1875 143 3234 165 77.8 2 2
12 11 12 77.8 1875 144 3234 165 77.8 2 2
11 14 10 77.8 1874 143 3234 165 77.8 2 2
10 14 12 80.0 1874 144 3234 165 77.8 2 2
11 10 15 80.0 1874 146 3233 169 78.2 2 2
12 10 13 77.8 1874 145 3232 170 80.1 1 2
13 10 11 75.6 1873 143 3232 170 80.1 1 2
11 13 11 77.8 1873 143 3232 170 80.1 1 2
10 13 13 80.0 1873 145 3232 170 80.1 1 2
12 12 10 75.6 1872 143 3230 174 81.5 1 2
11 12 12 77.8 1872 144 3230 174 81.5 1 2
10 12 14 80.0 1872 145 3230 174 81.5 1 2
10 15 10 77.8 1872 143 3229 177 81.9 1 2
12 11 11 75.6 1871 143 3228 178 83.3 1 2
11 11 13 77.8 1871 145 3228 178 83.3 1 2
10 11 15 80.0 1871 146 3228 178 83.3 1 2
10 14 11 77.8 1871 143 3227 181 83.8 1 2
12 10 12 75.6 1870 144 3226 182 84.7 1 2
11 10 14 77.8 1870 145 3226 182 84.7 1 2
13 10 10 73.3 1870 143 3225 184 86.1 1 2
11 13 10 75.6 1869 143 3225 184 86.1 1 2
10 13 12 77.8 1869 144 3225 184 86.1 1 2
11 12 11 75.6 1868 143 3223 187 87.0 1 2
10 12 13 77.8 1868 145 3223 187 87.0 1 2
12 11 10 73.3 1867 143 3221 189 88.4 1 2
11 11 12 75.6 1867 144 3221 189 88.4 1 2
10 11 14 77.8 1867 145 3221 189 88.4 1 2
10 14 10 75.6 1867 143 3220 192 88.9 1 2
12 10 11 73.3 1866 143 3219 193 90.7 1 1
10 13 11 75.6 1866 143 3219 193 90.7 1 1
11 10 13 75.6 1866 145 3219 193 90.7 1 1
10 10 15 77.8 1866 146 3219 193 90.7 1 1
10 12 12 75.6 1865 144 3217 197 91.7 1 1
11 12 10 73.3 1864 143 3217 197 91.7 1 1
11 11 11 73.3 1863 143 3215 199 92.6 1 1
10 11 13 75.6 1863 145 3215 199 92.6 1 1
11 10 12 73.3 1862 144 3213 201 93.5 1 1
10 10 14 75.6 1862 145 3213 201 93.5 1 1
12 10 10 71.1 1862 143 3212 203 94.4 1 1
10 13 10 73.3 1862 143 3212 203 94.4 1 1
10 12 11 73.3 1861 143 3210 205 94.9 1 1
10 11 12 73.3 1860 144 3208 206 95.8 1 1
11 11 10 71.1 1859 143 3208 206 95.8 1 1
11 10 11 71.1 1858 143 3206 208 96.8 1 1
10 10 13 73.3 1858 145 3206 208 96.8 1 1
10 12 10 71.1 1857 143 3203 210 97.2 1 1
10 11 11 71.1 1856 143 3202 211 97.7 1 1
10 10 12 71.1 1855 144 3200 212 98.1 1 1
11 10 10 68.9 1854 143 3199 213 98.6 1 1
10 11 10 68.9 1852 143 3195 214 99.1 1 1
10 10 11 68.9 1851 143 3193 215 99.5 1 1
10 10 10 66.7 1847 143 3186 216 100.0 1 1

複数人(同窓会対応)の生存曲線の描画とN年後に全員生存している確率を計算するwebアプリ

f:id:r-statistics-fan:20170901121521j:plain

shinyアプリへのリンク

 ##追記:無料サービスを利用しているので接続が月25時間を超えると翌月まで使えなくなってしまうようです。自腹で課金する気はないので、つながらない場合はごめんなさい。

前回の記事 

 

をshinyでwebアプリ化(ここをクリックするとブラウザ上で計算と描画が出来ます)してみた。

本当は数値表で入力させたかったけど、いちいち入力ウィジェットを配置する方法しか分からないので下に長い感じになってしまった。他に良い方法は有るのだろうか。

スイクンのレイド時のCPの表

スイクンは実際にゲットしていないので、正しいかどうかわからないが、 https://pokemongo-get.com/pokego01148/ を参考に、種族値HP200/AT180/DF235を採用し、レイド用の表を作っておく。 実際の種族値と違っていたら申し訳ない。

AT DF HP 固体値% レイド時CP レイド時HP 最大強化CP 最大CP順位 レイド上位% 80%以上の確率で入手するの必要な数 同90%以上
15 15 15 100.0 1613 128 2783 1 0.5 322 460
15 14 15 97.8 1610 128 2777 2 0.9 179 255
15 15 14 97.8 1609 127 2776 3 1.4 115 164
15 13 15 95.6 1606 128 2772 4 1.9 84 121
15 14 14 95.6 1606 127 2771 5 2.3 70 99
15 15 13 95.6 1605 127 2770 6 2.8 57 82
14 15 15 97.8 1605 128 2769 7 3.2 50 71
15 12 15 93.3 1603 128 2766 8 3.7 43 62
15 13 14 93.3 1603 127 2765 9 4.2 38 54
15 14 13 93.3 1602 127 2764 10 4.6 35 49
15 15 12 93.3 1602 126 2763 11 5.6 28 40
14 14 15 95.6 1601 128 2763 11 5.6 28 40
14 15 14 95.6 1601 127 2762 13 6.0 27 38
15 12 14 91.1 1600 127 2760 14 6.9 23 33
15 11 15 91.1 1600 128 2760 14 6.9 23 33
15 13 13 91.1 1599 127 2759 16 7.4 21 30
15 14 12 91.1 1598 126 2758 17 7.9 20 28
15 15 11 91.1 1598 126 2757 18 9.3 17 24
14 14 14 93.3 1598 127 2757 18 9.3 17 24
14 13 15 93.3 1598 128 2757 18 9.3 17 24
14 15 13 93.3 1597 127 2756 21 9.7 16 23
15 10 15 88.9 1597 128 2755 22 10.2 15 22
15 11 14 88.9 1596 127 2754 23 11.1 14 20
13 15 15 95.6 1596 128 2754 23 11.1 14 20
15 12 13 88.9 1596 127 2753 25 11.6 14 19
15 13 12 88.9 1595 126 2752 26 12.5 13 18
14 12 15 91.1 1595 128 2752 26 12.5 13 18
15 14 11 88.9 1595 126 2751 28 13.4 12 17
14 13 14 91.1 1595 127 2751 28 13.4 12 17
15 15 10 88.9 1594 125 2750 30 14.4 11 15
14 14 13 91.1 1594 127 2750 30 14.4 11 15
14 15 12 91.1 1593 126 2749 32 15.3 10 14
13 14 15 93.3 1593 128 2749 32 15.3 10 14
15 11 13 86.7 1593 127 2748 34 16.7 9 13
15 10 14 86.7 1593 127 2748 34 16.7 9 13
13 15 14 93.3 1593 127 2748 34 16.7 9 13
15 12 12 86.7 1592 126 2747 37 17.1 9 13
14 11 15 88.9 1592 128 2746 38 18.1 9 12
15 13 11 86.7 1591 126 2746 38 18.1 9 12
15 14 10 86.7 1591 125 2745 40 19.4 8 11
14 13 13 88.9 1591 127 2745 40 19.4 8 11
14 12 14 88.9 1591 127 2745 40 19.4 8 11
14 14 12 88.9 1590 126 2744 43 19.9 8 11
14 15 11 88.9 1590 126 2743 44 20.8 7 10
13 13 15 91.1 1590 128 2743 44 20.8 7 10
15 10 13 84.4 1589 127 2742 46 21.8 7 10
13 14 14 91.1 1589 127 2742 46 21.8 7 10
15 11 12 84.4 1589 126 2741 48 23.1 7 9
13 15 13 91.1 1589 127 2741 48 23.1 7 9
14 10 15 86.7 1589 128 2741 48 23.1 7 9
15 12 11 84.4 1588 126 2740 51 24.5 6 9
14 11 14 86.7 1588 127 2740 51 24.5 6 9
12 15 15 93.3 1588 128 2740 51 24.5 6 9
15 13 10 84.4 1588 125 2739 54 25.5 6 8
14 12 13 86.7 1588 127 2739 54 25.5 6 8
14 13 12 86.7 1587 126 2738 56 26.4 6 8
13 12 15 88.9 1587 128 2738 56 26.4 6 8
14 14 11 86.7 1586 126 2737 58 27.3 6 8
13 13 14 88.9 1586 127 2737 58 27.3 6 8
14 15 10 86.7 1586 125 2736 60 28.7 5 7
15 10 12 82.2 1586 126 2736 60 28.7 5 7
13 14 13 88.9 1586 127 2736 60 28.7 5 7
15 11 11 82.2 1585 126 2735 63 30.1 5 7
13 15 12 88.9 1585 126 2735 63 30.1 5 7
12 14 15 91.1 1585 128 2735 63 30.1 5 7
14 10 14 84.4 1585 127 2734 66 31.5 5 7
15 12 10 82.2 1584 125 2734 66 31.5 5 7
12 15 14 91.1 1584 127 2734 66 31.5 5 7
14 12 12 84.4 1584 126 2733 69 32.4 5 6
14 11 13 84.4 1584 127 2733 69 32.4 5 6
13 11 15 86.7 1584 128 2732 71 33.3 4 6
14 13 11 84.4 1583 126 2732 71 33.3 4 6
14 14 10 84.4 1583 125 2731 73 34.3 4 6
13 12 14 86.7 1583 127 2731 73 34.3 4 6
13 13 13 86.7 1583 127 2730 75 34.7 4 6
15 10 11 80.0 1582 126 2729 76 36.6 4 6
13 14 12 86.7 1582 126 2729 76 36.6 4 6
12 13 15 88.9 1582 128 2729 76 36.6 4 6
13 15 11 86.7 1581 126 2729 76 36.6 4 6
15 11 10 80.0 1581 125 2728 80 38.0 4 5
14 10 13 82.2 1581 127 2728 80 38.0 4 5
12 14 14 88.9 1581 127 2728 80 38.0 4 5
14 11 12 82.2 1581 126 2727 83 39.4 4 5
12 15 13 88.9 1581 127 2727 83 39.4 4 5
13 10 15 84.4 1580 128 2727 83 39.4 4 5
14 12 11 82.2 1580 126 2726 86 40.7 4 5
13 11 14 84.4 1580 127 2726 86 40.7 4 5
11 15 15 91.1 1580 128 2726 86 40.7 4 5
14 13 10 82.2 1580 125 2725 89 41.7 3 5
13 12 13 84.4 1579 127 2725 89 41.7 3 5
13 13 12 84.4 1579 126 2724 91 42.1 3 5
12 12 15 86.7 1579 128 2723 92 44.0 3 4
15 10 10 77.8 1578 125 2723 92 44.0 3 4
13 14 11 84.4 1578 126 2723 92 44.0 3 4
12 13 14 86.7 1578 127 2723 92 44.0 3 4
13 15 10 84.4 1578 125 2722 96 45.4 3 4
12 14 13 86.7 1578 127 2722 96 45.4 3 4
14 10 12 80.0 1577 126 2722 96 45.4 3 4
14 11 11 80.0 1577 126 2721 99 46.3 3 4
12 15 12 86.7 1577 126 2721 99 46.3 3 4
13 10 14 82.2 1577 127 2720 101 47.7 3 4
11 14 15 88.9 1577 128 2720 101 47.7 3 4
14 12 10 80.0 1576 125 2720 101 47.7 3 4
13 12 12 82.2 1576 126 2719 104 49.1 3 4
13 11 13 82.2 1576 127 2719 104 49.1 3 4
11 15 14 88.9 1576 127 2719 104 49.1 3 4
13 13 11 82.2 1575 126 2718 107 50.0 3 4
12 11 15 84.4 1575 128 2718 107 50.0 3 4
13 14 10 82.2 1575 125 2717 109 50.9 3 4
12 12 14 84.4 1575 127 2717 109 50.9 3 4
12 13 13 84.4 1574 127 2716 111 51.4 3 4
14 10 11 77.8 1574 126 2715 112 52.8 3 4
12 14 12 84.4 1574 126 2715 112 52.8 3 4
11 13 15 86.7 1574 128 2715 112 52.8 3 4
14 11 10 77.8 1573 125 2714 115 54.6 3 3
12 15 11 84.4 1573 126 2714 115 54.6 3 3
13 10 13 80.0 1573 127 2714 115 54.6 3 3
11 14 14 86.7 1573 127 2714 115 54.6 3 3
13 11 12 80.0 1572 126 2713 119 55.6 2 3
11 15 13 86.7 1572 127 2713 119 55.6 2 3
13 12 11 80.0 1572 126 2712 121 56.9 2 3
12 11 14 82.2 1572 127 2712 121 56.9 2 3
12 10 15 82.2 1572 128 2712 121 56.9 2 3
10 15 15 88.9 1572 128 2711 124 58.3 2 3
13 13 10 80.0 1571 125 2711 124 58.3 2 3
12 12 13 82.2 1571 127 2711 124 58.3 2 3
12 13 12 82.2 1571 126 2710 127 58.8 2 3
14 10 10 75.6 1570 125 2709 128 60.2 2 3
12 14 11 82.2 1570 126 2709 128 60.2 2 3
11 12 15 84.4 1570 128 2709 128 60.2 2 3
12 15 10 82.2 1570 125 2708 131 61.6 2 3
11 13 14 84.4 1570 127 2708 131 61.6 2 3
11 14 13 84.4 1569 127 2708 131 61.6 2 3
13 11 11 77.8 1569 126 2707 134 63.0 2 3
13 10 12 77.8 1569 126 2707 134 63.0 2 3
11 15 12 84.4 1569 126 2707 134 63.0 2 3
13 12 10 77.8 1568 125 2706 137 64.4 2 3
12 10 14 80.0 1568 127 2706 137 64.4 2 3
10 14 15 86.7 1568 128 2706 137 64.4 2 3
12 11 13 80.0 1568 127 2705 140 65.3 2 3
10 15 14 86.7 1568 127 2705 140 65.3 2 3
12 12 12 80.0 1568 126 2704 142 66.2 2 3
11 11 15 82.2 1567 128 2704 142 66.2 2 3
12 13 11 80.0 1567 126 2703 144 67.6 2 3
11 12 14 82.2 1567 127 2703 144 67.6 2 3
12 14 10 80.0 1566 125 2703 144 67.6 2 3
11 13 13 82.2 1566 127 2702 147 68.1 2 3
13 10 11 75.6 1566 126 2701 148 69.4 2 2
11 14 12 82.2 1566 126 2701 148 69.4 2 2
10 13 15 84.4 1565 128 2701 148 69.4 2 2
13 11 10 75.6 1565 125 2700 151 71.3 2 2
11 15 11 82.2 1565 126 2700 151 71.3 2 2
12 10 13 77.8 1565 127 2700 151 71.3 2 2
10 14 14 84.4 1565 127 2700 151 71.3 2 2
12 11 12 77.8 1564 126 2699 155 72.2 2 2
10 15 13 84.4 1564 127 2699 155 72.2 2 2
12 12 11 77.8 1564 126 2698 157 73.6 2 2
11 11 14 80.0 1564 127 2698 157 73.6 2 2
11 10 15 80.0 1564 128 2698 157 73.6 2 2
12 13 10 77.8 1563 125 2697 160 74.5 2 2
11 12 13 80.0 1563 127 2697 160 74.5 2 2
11 13 12 80.0 1562 126 2696 162 75.0 2 2
13 10 10 73.3 1562 125 2695 163 76.4 2 2
11 14 11 80.0 1562 126 2695 163 76.4 2 2
10 12 15 82.2 1562 128 2695 163 76.4 2 2
10 13 14 82.2 1562 127 2694 166 77.3 2 2
11 15 10 80.0 1561 125 2694 166 77.3 2 2
12 11 11 75.6 1561 126 2693 168 78.7 2 2
12 10 12 75.6 1561 126 2693 168 78.7 2 2
10 14 13 82.2 1561 127 2693 168 78.7 2 2
10 15 12 82.2 1561 126 2692 171 80.1 1 2
12 12 10 75.6 1560 125 2692 171 80.1 1 2
11 10 14 77.8 1560 127 2692 171 80.1 1 2
11 11 13 77.8 1560 127 2691 174 80.6 1 2
11 12 12 77.8 1559 126 2690 175 81.5 1 2
10 11 15 80.0 1559 128 2690 175 81.5 1 2
11 13 11 77.8 1559 126 2689 177 82.4 1 2
10 12 14 80.0 1558 127 2689 177 82.4 1 2
11 14 10 77.8 1558 125 2688 179 83.3 1 2
10 13 13 80.0 1558 127 2688 179 83.3 1 2
12 10 11 73.3 1557 126 2687 181 84.3 1 2
10 14 12 80.0 1557 126 2687 181 84.3 1 2
12 11 10 73.3 1557 125 2686 183 85.6 1 2
10 15 11 80.0 1557 126 2686 183 85.6 1 2
11 10 13 75.6 1557 127 2686 183 85.6 1 2
11 11 12 75.6 1556 126 2685 186 86.1 1 2
11 12 11 75.6 1556 126 2684 187 87.0 1 2
10 10 15 77.8 1556 128 2684 187 87.0 1 2
11 13 10 75.6 1555 125 2683 189 88.4 1 2
10 12 13 77.8 1555 127 2683 189 88.4 1 2
10 11 14 77.8 1555 127 2683 189 88.4 1 2
10 13 12 77.8 1554 126 2682 192 88.9 1 2
12 10 10 71.1 1554 125 2681 193 89.8 1 2
10 14 11 77.8 1554 126 2681 193 89.8 1 2
10 15 10 77.8 1553 125 2680 195 90.3 1 1
11 11 11 73.3 1553 126 2679 196 91.2 1 1
11 10 12 73.3 1553 126 2679 196 91.2 1 1
11 12 10 73.3 1552 125 2678 198 92.1 1 1
10 10 14 75.6 1552 127 2678 198 92.1 1 1
10 11 13 75.6 1552 127 2677 200 92.6 1 1
10 12 12 75.6 1551 126 2676 201 93.1 1 1
10 13 11 75.6 1551 126 2675 202 93.5 1 1
10 14 10 75.6 1550 125 2674 203 94.0 1 1
11 10 11 71.1 1549 126 2673 204 94.4 1 1
11 11 10 71.1 1549 125 2672 205 95.4 1 1
10 10 13 73.3 1549 127 2672 205 95.4 1 1
10 11 12 73.3 1548 126 2671 207 95.8 1 1
10 12 11 73.3 1548 126 2670 208 96.3 1 1
10 13 10 73.3 1547 125 2669 209 96.8 1 1
11 10 10 68.9 1546 125 2667 210 97.2 1 1
10 10 12 71.1 1545 126 2665 211 98.1 1 1
10 11 11 71.1 1544 126 2665 211 98.1 1 1
10 12 10 71.1 1544 125 2664 213 98.6 1 1
10 10 11 68.9 1541 126 2659 214 99.1 1 1
10 11 10 68.9 1541 125 2658 215 99.5 1 1
10 10 10 66.7 1538 125 2653 216 100.0 1 1

同窓会で5年後に全員生存している確率は~H27の日本人完全生命表で計算する

#追記
ここをクリックでブラウザで各自計算できます


昔の記事で日本人の生存曲線を扱ったが、H27の国勢調査のデータによる完全生命表が出ているのでアップデートすることにした。

http://www.mhlw.go.jp/toukei/saikin/hw/life/22th/
ここのデータを引っ張ってくる。
pdfを読む関数を使ってみたが、マルチバイト文字のエラーとか色々で余計時間かかるわってなって断念。
pdf-excel変換ソフトを使ったらあっさり行けた。

というか、pdfでの公開はやめて欲しい。csvがベスト、せめてエクセルでお願いしたいものだ。

せっかくデーターを得たので何か計算しよう。

先日母校の同窓会にでたりしたが、自分たちも恩師も明らかに年をとってきており、次回5年後に全員生きている可能性はどんなものか気になった。

アップデートされたデータで計算してみる。

とりあえずフィクションの例を提示する
生徒は40才で男女35人ずつ、先生が75男性、70男性、65女性とする。
この合計73人が全員5,10,15,20年後に生存している率を日本人の生命表を元に計算する。

その他たとえば、家族全員のデータを入れても興味深いだろう。
生命保険に入るかどうかとか、起業した場合のリスクとか、相続の可能性とか色々参考に出来るだろう。

calc_all_alive(
      target_age = c(40, 40, 75, 70, 65),  #対象の年齢
      target_sex = c(0, 1, 1, 1, 0),       #対象の性男1女0
      target_N = c(35, 35, 1, 1, 1),     #対象の人数
      target_year = c(5, 10, 15, 20),      #計算する年数
      plot_year = 30                      #plotする年数
)

f:id:r-statistics-fan:20170830223844j:plain

           平均余命 余命中央値 5年後の生存率 10年後の生存率 15年後の生存率 20年後の生存率
40才女性       47.7       49.9     0.9962918      0.9905526     0.98178217    0.969697582
40才男性       41.8       44.0     0.9937605      0.9837753     0.96786605    0.943009822
75才男性       12.0       11.9     0.8392625      0.6055661     0.33302515    0.115608795
70才男性       15.6       15.9     0.8994071      0.7548386     0.54465039    0.299525175
65才女性       24.2       25.4     0.9727091      0.9300539     0.85822970    0.729128645
全員生存率       NA         NA     0.5178770      0.1720260     0.02607728    0.001102978

このばあい、5年後に全員生きている可能性は五分五分の51.7%
10年後だと17%しかない。基本誰かが死んでしまうということ。
リアルな結果に戦慄した。

以下計算するプログラム。

dat<-structure(list(x=c(0,1,2,3,4,5,6,7,8,9,10,11,12,
13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,
29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,
45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,
61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,
77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,
93,94,95,96,97,98,99,100,101,102,103,104,105,106,
107,108,109,110,111,112,113,114,115,0,1,2,3,4,5,
6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,
23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,
39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,
55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,
71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,
87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,
102,103,104,105,106,107,108,109,110,111,112),lx=c(1e+05,
99822,99790,99770,99758,99749,99742,99734,99726,99718,
99712,99705,99698,99691,99684,99676,99666,99654,99641,
99626,99610,99593,99575,99554,99533,99510,99486,99461,
99434,99405,99375,99345,99313,99279,99243,99204,99163,
99121,99075,99025,98969,98907,98839,98766,98687,98602,
98509,98405,98291,98167,98034,97889,97730,97557,97368,
97166,96951,96726,96489,96239,95970,95679,95361,95015,
94643,94244,93811,93340,92829,92275,91672,91010,90281,
89480,88606,87652,86599,85419,84087,82582,80883,78974,
76831,74422,71720,68716,65407,61784,57847,53594,49063,
44306,39389,34364,29340,24464,19866,15734,12140,9115,
6652,4711,3234,2149,1380,855,510,293,162,85,43,21,
10,4,2,1,1e+05,99798,99765,99741,99725,99714,99704,
99694,99684,99676,99668,99661,99653,99645,99635,99621,
99604,99583,99557,99524,99486,99441,99392,99341,99288,
99234,99179,99124,99070,99016,98961,98903,98844,98783,
98718,98649,98576,98501,98423,98338,98245,98142,98029,
97907,97776,97632,97473,97297,97102,96887,96651,96394,
96111,95801,95461,95088,94677,94227,93739,93214,92646,
92026,91338,90573,89734,88825,87830,86749,85582,84326,
82978,81528,79966,78291,76515,74631,72610,70426,68048,
65454,62635,59589,56311,52807,49094,45194,41150,37034,
32907,28827,24854,21044,17465,14163,11195,8628,6506,
4788,3435,2401,1633,1080,693,431,260,151,85,46,24,
12,6,3,1),ndx=c(178,32,20,12,8,8,8,8,7,7,7,7,
7,7,8,10,12,13,15,16,17,19,20,22,23,24,25,27,
28,30,31,32,34,36,39,41,42,45,50,56,62,68,73,79,
85,94,104,114,124,134,145,159,174,189,202,215,226,
237,250,268,291,318,346,372,399,433,471,511,554,603,
662,729,802,874,954,1053,1180,1332,1505,1699,1909,
2143,2409,2701,3004,3310,3622,3938,4253,4531,4757,4918,
5025,5024,4876,4598,4132,3594,3025,2464,1941,1477,1085,
769,525,345,217,132,76,42,22,11,5,2,1,0,202,34,
24,16,11,10,10,10,9,8,7,7,8,11,13,17,21,26,32,
39,45,49,51,53,55,55,54,54,54,56,57,59,61,65,69,
73,75,78,84,93,103,113,122,131,144,159,176,195,215,
236,257,283,310,340,373,411,450,488,525,568,620,688,
764,839,910,994,1081,1166,1256,1349,1450,1561,1675,
1776,1885,2021,2185,2377,2594,2819,3046,3279,3504,3714,
3900,4043,4116,4127,4080,3973,3810,3580,3302,2967,2567,
2123,1718,1352,1034,768,554,387,262,171,108,66,39,
22,12,6,3,2,1),npx=c(0.99822,0.99968,0.9998,0.99988,
0.99992,0.99992,0.99992,0.99992,0.99993,0.99993,0.99993,
0.99993,0.99993,0.99993,0.99992,0.9999,0.99988,0.99987,
0.99985,0.99984,0.99983,0.99981,0.9998,0.99978,0.99977,
0.99976,0.99975,0.99973,0.99971,0.9997,0.99969,0.99968,
0.99966,0.99963,0.99961,0.99959,0.99957,0.99954,0.9995,
0.99943,0.99937,0.99931,0.99926,0.9992,0.99913,0.99905,
0.99895,0.99884,0.99874,0.99864,0.99852,0.99838,0.99822,
0.99807,0.99792,0.99779,0.99767,0.99755,0.99741,0.99721,
0.99696,0.99667,0.99638,0.99609,0.99578,0.9954,0.99498,
0.99453,0.99403,0.99346,0.99278,0.992,0.99112,0.99023,
0.98923,0.98798,0.98637,0.98441,0.98211,0.97943,0.97639,
0.97286,0.96864,0.9637,0.95812,0.95184,0.94462,0.93627,
0.92648,0.91546,0.90305,0.889,0.87243,0.85381,0.8338,0.81204,
0.79202,0.77161,0.75083,0.7297,0.70825,0.68649,0.66446,
0.64217,0.61967,0.59699,0.57415,0.55121,0.52821,0.50518,
0.48217,0.45924,0.43642,0.41378,0.39136,0.36921,0.99798,
0.99966,0.99976,0.99984,0.99988,0.9999,0.9999,0.9999,0.99991,
0.99992,0.99993,0.99993,0.99992,0.99989,0.99987,0.99983,
0.99979,0.99974,0.99968,0.99961,0.99955,0.99951,0.99949,
0.99946,0.99945,0.99945,0.99945,0.99946,0.99945,0.99944,
0.99942,0.9994,0.99938,0.99934,0.9993,0.99926,0.99924,
0.9992,0.99915,0.99905,0.99895,0.99885,0.99876,0.99866,
0.99853,0.99837,0.99819,0.998,0.99778,0.99757,0.99734,
0.99707,0.99677,0.99645,0.99609,0.99568,0.99525,0.99482,
0.9944,0.99391,0.99331,0.99252,0.99163,0.99074,0.98986,
0.98881,0.98769,0.98655,0.98532,0.98401,0.98253,0.98085,
0.97905,0.97732,0.97537,0.97293,0.96991,0.96624,0.96188,
0.95693,0.95138,0.94498,0.93778,0.92968,0.92055,0.91053,
0.89998,0.88856,0.87601,0.86217,0.84671,0.8299,0.81095,
0.79047,0.77068,0.75399,0.73592,0.71757,0.69896,0.68011,
0.66104,0.64176,0.62229,0.60267,0.58291,0.56303,0.54307,
0.52305,0.50301,0.48296,0.46295,0.44302,0.42318),nqx=c(0.00178,
0.00032,2e-04,0.00012,8e-05,8e-05,8e-05,8e-05,7e-05,7e-05,
7e-05,7e-05,7e-05,7e-05,8e-05,1e-04,0.00012,0.00013,0.00015,
0.00016,0.00017,0.00019,2e-04,0.00022,0.00023,0.00024,
0.00025,0.00027,0.00029,3e-04,0.00031,0.00032,0.00034,
0.00037,0.00039,0.00041,0.00043,0.00046,5e-04,0.00057,
0.00063,0.00069,0.00074,8e-04,0.00087,0.00095,0.00105,
0.00116,0.00126,0.00136,0.00148,0.00162,0.00178,0.00193,
0.00208,0.00221,0.00233,0.00245,0.00259,0.00279,0.00304,
0.00333,0.00362,0.00391,0.00422,0.0046,0.00502,0.00547,
0.00597,0.00654,0.00722,0.008,0.00888,0.00977,0.01077,
0.01202,0.01363,0.01559,0.01789,0.02057,0.02361,0.02714,
0.03136,0.0363,0.04188,0.04816,0.05538,0.06373,0.07352,
0.08454,0.09695,0.111,0.12757,0.14619,0.1662,0.18796,0.20798,
0.22839,0.24917,0.2703,0.29175,0.31351,0.33554,0.35783,
0.38033,0.40301,0.42585,0.44879,0.47179,0.49482,0.51783,
0.54076,0.56358,0.58622,0.60864,0.63079,0.00202,0.00034,
0.00024,0.00016,0.00012,1e-04,1e-04,1e-04,9e-05,8e-05,
7e-05,7e-05,8e-05,0.00011,0.00013,0.00017,0.00021,0.00026,
0.00032,0.00039,0.00045,0.00049,0.00051,0.00054,0.00055,
0.00055,0.00055,0.00054,0.00055,0.00056,0.00058,6e-04,
0.00062,0.00066,7e-04,0.00074,0.00076,8e-04,0.00085,0.00095,
0.00105,0.00115,0.00124,0.00134,0.00147,0.00163,0.00181,
0.002,0.00222,0.00243,0.00266,0.00293,0.00323,0.00355,
0.00391,0.00432,0.00475,0.00518,0.0056,0.00609,0.00669,
0.00748,0.00837,0.00926,0.01014,0.01119,0.01231,0.01345,
0.01468,0.01599,0.01747,0.01915,0.02095,0.02268,0.02463,
0.02707,0.03009,0.03376,0.03812,0.04307,0.04862,0.05502,
0.06222,0.07032,0.07945,0.08947,0.10002,0.11144,0.12399,
0.13783,0.15329,0.1701,0.18905,0.20953,0.22932,0.24601,
0.26408,0.28243,0.30104,0.31989,0.33896,0.35824,0.37771,
0.39733,0.41709,0.43697,0.45693,0.47695,0.49699,0.51704,
0.53705,0.55698,0.57682),mux=c(0.05782,4e-04,0.00023,
0.00016,1e-04,8e-05,8e-05,8e-05,8e-05,7e-05,7e-05,7e-05,
7e-05,7e-05,8e-05,9e-05,0.00011,0.00013,0.00014,0.00015,
0.00016,0.00018,2e-04,0.00021,0.00023,0.00024,0.00025,
0.00026,0.00028,0.00029,0.00031,0.00032,0.00033,0.00035,
0.00038,4e-04,0.00042,0.00044,0.00048,0.00053,6e-04,0.00066,
0.00071,0.00077,0.00083,9e-04,0.001,0.00111,0.00121,0.00131,
0.00142,0.00155,0.0017,0.00186,0.00201,0.00215,0.00227,
0.00239,0.00252,0.00269,0.00291,0.00318,0.00348,0.00378,
0.00406,0.00441,0.00482,0.00526,0.00573,0.00626,0.00688,
0.00762,0.00847,0.00936,0.01029,0.0114,0.01284,0.01466,
0.01682,0.01936,0.02227,0.0256,0.02956,0.03429,0.03976,
0.04593,0.05298,0.06118,0.07085,0.08208,0.09485,0.1094,
0.12656,0.14682,0.16949,0.19609,0.22051,0.24603,0.27272,
0.30063,0.32981,0.36033,0.39223,0.42559,0.46047,0.49694,
0.53507,0.57494,0.61663,0.66022,0.7058,0.75346,0.80329,
0.85539,0.90987,0.96683,0.06764,0.00038,0.00024,0.00019,
0.00013,1e-04,1e-04,1e-04,9e-05,8e-05,7e-05,7e-05,8e-05,
9e-05,0.00012,0.00015,0.00019,0.00024,0.00029,0.00036,
0.00042,0.00047,5e-04,0.00053,0.00054,0.00055,0.00055,
0.00055,0.00054,0.00055,0.00057,0.00059,0.00061,0.00064,
0.00068,0.00072,0.00075,0.00078,0.00082,9e-04,0.001,0.0011,
0.0012,0.00129,0.0014,0.00155,0.00171,0.0019,0.00211,0.00233,
0.00255,0.0028,0.00308,0.00339,0.00373,0.00412,0.00454,
0.00498,0.0054,0.00585,0.00639,0.00709,0.00795,0.00886,
0.00973,0.0107,0.01182,0.01295,0.01415,0.01543,0.01684,
0.01846,0.02025,0.02205,0.02388,0.0261,0.02889,0.03233,
0.03649,0.04134,0.0468,0.05307,0.06025,0.06839,0.07766,
0.0881,0.09941,0.11156,0.125,0.14002,0.15698,0.17602,0.19751,
0.22205,0.24801,0.27055,0.29434,0.3191,0.34485,0.37165,
0.39954,0.42855,0.45874,0.49015,0.52284,0.55684,0.59223,
0.62905,0.66736,0.70722,0.74869,0.79185,0.83675),nLx=c(99861,
99806,99780,99763,99753,99746,99738,99730,99722,99715,
99708,99701,99695,99688,99680,99671,99660,99647,99633,
99618,99602,99584,99565,99544,99521,99498,99473,99447,
99420,99391,99360,99329,99296,99261,99223,99184,99142,
99098,99051,98998,98939,98873,98803,98727,98645,98556,
98458,98349,98230,98101,97962,97811,97645,97463,97268,
97060,96839,96608,96365,96106,95827,95522,95190,94832,
94446,94031,93579,93088,92556,91978,91346,90651,89887,
89049,88136,87135,86020,84766,83350,81750,79947,77923,
75649,73096,70244,67087,63622,59842,55745,51350,46701,
41859,36881,31846,26884,22135,17756,13890,10580,7838,
5640,3937,2662,1741,1100,670,393,222,120,62,31,15,
7,3,1,0,99843,99783,99753,99732,99719,99709,99699,
99689,99680,99672,99664,99657,99649,99640,99628,99613,
99594,99570,99541,99506,99464,99417,99367,99315,99261,
99206,99151,99097,99043,98989,98932,98874,98814,98751,
98684,98613,98539,98462,98381,98293,98195,98086,97969,
97842,97705,97554,97386,97201,96996,96771,96524,96255,
95958,95634,95277,94886,94455,93986,93480,92934,92341,
91688,90962,90160,89286,88335,87297,86173,84962,83660,
82262,80757,79138,77411,75583,73633,71533,69254,66770,
64063,61131,57970,54577,50967,47158,43181,39096,34969,
30861,26829,22933,19233,15788,12649,9876,7530,5614,4083,
2894,1997,1340,874,553,339,201,116,64,34,18,9,4,
2,1),Tx=c(8698726,8598865,8499059,8399279,8299516,8199762,
8100017,8000279,7900550,7800828,7701113,7601405,7501703,
7402008,7302321,7202641,7102970,7003311,6903663,6804030,
6704411,6604809,6505225,6405661,6306117,6206596,6107098,
6007625,5908177,5808758,5709367,5610007,5510678,5411383,
5312122,5212898,5113715,5014573,4915474,4816424,4717426,
4618487,4519614,4420811,4322084,4223438,4124882,4026425,
3928076,3829846,3731745,3633783,3535972,3438327,3340864,
3243596,3146536,3049697,2953088,2856723,2760617,2664790,
2569268,2474078,2379246,2284800,2190769,2097190,2004102,
1911547,1819569,1728223,1637572,1547685,1458636,1370500,
1283365,1197345,1112579,1029229,947479,867532,789609,713959,
640864,570620,503533,439911,380069,324323,272974,226273,
184414,147533,115686,88802,66667,48911,35021,24441,16603,
10963,7026,4364,2623,1523,853,460,238,118,56,26,11,
5,2,1,8075244,7975401,7875618,7775866,7676133,7576414,
7476706,7377007,7277318,7177638,7077966,6978302,6878645,
6778995,6679355,6579727,6480114,6380520,6280950,6181409,
6081903,5982440,5883023,5783656,5684341,5585080,5485874,
5386722,5287625,5188582,5089593,4990661,4891787,4792973,
4694222,4595538,4496925,4398387,4299925,4201543,4103251,
4005056,3906970,3809001,3711159,3613454,3515900,3418514,
3321313,3224317,3127546,3031022,2934767,2838809,2743175,
2647898,2553012,2458557,2364571,2271091,2178157,2085816,
1994129,1903167,1813007,1723721,1635386,1548089,1461916,
1376954,1293294,1211033,1130276,1051138,973727,898144,
824511,752979,683725,616955,552891,491760,433791,379213,
328246,281088,237907,198811,163842,132982,106153,83220,
63987,48199,35550,25674,18144,12529,8447,5553,3556,2215,
1341,788,449,247,132,68,34,16,7,3,1),ex=c(86.99,
86.14,85.17,84.19,83.2,82.2,81.21,80.22,79.22,78.23,
77.23,76.24,75.24,74.25,73.25,72.26,71.27,70.28,69.29,
68.3,67.31,66.32,65.33,64.34,63.36,62.37,61.39,60.4,
59.42,58.44,57.45,56.47,55.49,54.51,53.53,52.55,51.57,
50.59,49.61,48.64,47.67,46.7,45.73,44.76,43.8,42.83,
41.87,40.92,39.96,39.01,38.07,37.12,36.18,35.24,34.31,
33.38,32.45,31.53,30.61,29.68,28.77,27.85,26.94,26.04,
25.14,24.24,23.35,22.47,21.59,20.72,19.85,18.99,18.14,
17.3,16.46,15.64,14.82,14.02,13.23,12.46,11.71,10.99,
10.28,9.59,8.94,8.3,7.7,7.12,6.57,6.05,5.56,5.11,4.68,
4.29,3.94,3.63,3.36,3.11,2.88,2.68,2.5,2.33,2.17,2.03,
1.9,1.78,1.67,1.57,1.48,1.39,1.31,1.23,1.16,1.1,1.04,
0.98,80.75,79.92,78.94,77.96,76.97,75.98,74.99,74,73,
72.01,71.02,70.02,69.03,68.03,67.04,66.05,65.06,64.07,
63.09,62.11,61.13,60.16,59.19,58.22,57.25,56.28,55.31,
54.34,53.37,52.4,51.43,50.46,49.49,48.52,47.55,46.58,
45.62,44.65,43.69,42.73,41.77,40.81,39.86,38.9,37.96,
37.01,36.07,35.13,34.2,33.28,32.36,31.44,30.54,29.63,
28.74,27.85,26.97,26.09,25.23,24.36,23.51,22.67,21.83,
21.01,20.2,19.41,18.62,17.85,17.08,16.33,15.59,14.85,
14.13,13.43,12.73,12.03,11.36,10.69,10.05,9.43,8.83,
8.25,7.7,7.18,6.69,6.22,5.78,5.37,4.98,4.61,4.27,3.95,
3.66,3.4,3.18,2.98,2.79,2.62,2.46,2.31,2.18,2.05,1.94,
1.83,1.73,1.63,1.55,1.46,1.39,1.32,1.25,1.19,1.13),
sexM1=c(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1)),.Names=c("x","lx","ndx","npx","nqx",
"mux","nLx","Tx","ex","sexM1"),class="data.frame",row.names=c(NA,
-229L))

calc_all_alive <- function(
target_age = c(45, 45, 75, 70, 65),  #対象の年齢
target_sex = c(0, 1, 1, 1, 1),       #対象の性男1女0
target_N = c(100, 100, 1, 1, 1),     #対象の人数
target_year = c(5, 10, 15, 20),      #計算する年数
plot_year = 30                      #plotする年数
){      
if(length(target_age) != length(target_sex) | length(target_age) != length(target_N)){
      cat("入力データエラー。データの長さが異なります")
      return(NA)
}else{
      plot(NULL, type = "n", xlim = c(0, plot_year), ylim = c(0,1), labels = NULL, ylab = "survival rate", xlab = "years", lab = NULL)
      
      col_1 <- rainbow(length(target_age))
      
      for(i in 1:length(target_age)){      
      temp2 <- subset(dat, sexM1 == target_sex[i]) 
      lines(seq_len(length(temp2$lx[temp2$x >= target_age[i]])) - 1, 
            temp2$lx[temp2$x >= target_age[i]]/temp2$lx[temp2$x == target_age[i]], 
            ann=F, type = "l", col = col_1[i], lty = i) #年齢別生存確率
      }
      tsex_temp <- chartr(c("01"), c("女男"), target_sex)
      legend_1 <- paste0(target_age, "才", tsex_temp, "性")
      
      legend("bottomleft", legend = legend_1, col = col_1, lty = 1:length(target_age),
             text.col = col_1, bty = "n")
 
      abline(v = c(0, target_year), lty = 3)     
      abline(h = c(0, 0.2, 0.4, 0.6, 0.8, 1), lty = 3)    
      
      result <- matrix(0, nrow = length(target_age), ncol = 2 + length(target_year))
      row.names(result) <- legend_1
      colnames(result) <- c("平均余命", "余命中央値", paste0(target_year, "年後の生存率"))

      ave.yomei <- function(age = 80, M1F0 = 1){
            temp <- subset(dat, sexM1 == M1F0)
            temp$ex[temp$x == age]
      }
      
      cal.median <- function(y, b){  #age = y #sex=b(F0M1) 以降でのmedian生存期間
            ssp <- smooth.spline(dat$lx[dat$sexM1 == b]/100000, dat$x[dat$sexM1 ==b])
            temp <- dat$lx[dat$sexM1 == b & dat$x == y]/100000
            return(predict(ssp, x = temp / 2)$y - y)      
      }
      
      result[,1] <- round(Vectorize(ave.yomei)(age = target_age, M1F0 = target_sex), digits = 1)
      result[,2] <- round(Vectorize(cal.median)(y = target_age, b = target_sex), digits = 1)

      for(i in 1:length(target_age)){    
      temp2 <- subset(dat, sexM1 == target_sex[i]) 
      for(j in 1:length(target_year)){
      result[i, 2 + j] <- temp2$lx[temp2$x == (target_age[i] + target_year[j])]/temp2$lx[temp2$x == target_age[i]] #年齢別生存確率
      
      }
      }
      temp_alive <- result[,3:(2+length(target_year))] ^ target_N
      alive_all <- c(NA, NA, apply(temp_alive, 2, function(x){Reduce("*", x)}))
result <- rbind(result, alive_all)
row.names(result) <- c(legend_1, "全員生存率")
return(result)

}      
}

カビゴンのレイド時のCPの表

ミュウツーのEXレイドに備えてレイド時のCPの表を作っておく。 ついでに、バンギラスファイヤーフリーザーサンダールギアカイリキーラプラスカビゴンもたまに戦うかもしれないので表を作っておく。間違っていても責任は持ちませぬ。

8.カビゴン

AT DF HP 固体値% レイド時CP レイド時HP 最大強化CP 最大CP順位 レイド上位% 80%以上の確率で入手するの必要な数 同90%以上
15 15 15 100.0 1917 200 3307 1 0.5 322 460
15 15 14 97.8 1914 199 3302 2 0.9 179 255
15 14 15 97.8 1912 200 3299 3 1.4 115 164
15 15 13 95.6 1911 198 3297 4 1.9 84 121
15 14 14 95.6 1909 199 3294 5 2.3 70 99
15 15 12 93.3 1908 198 3292 6 2.8 57 82
15 13 15 95.6 1907 200 3291 7 3.7 43 62
14 15 15 97.8 1907 200 3291 7 3.7 43 62
15 14 13 93.3 1906 198 3289 9 4.2 38 54
15 15 11 91.1 1905 197 3287 10 4.6 35 49
15 13 14 93.3 1905 199 3286 11 5.6 28 40
14 15 14 95.6 1905 199 3286 11 5.6 28 40
15 14 12 91.1 1904 198 3284 13 6.0 27 38
15 12 15 93.3 1903 200 3283 14 6.9 23 33
14 14 15 95.6 1903 200 3283 14 6.9 23 33
15 15 10 88.9 1902 197 3282 16 7.4 21 30
15 13 13 91.1 1902 198 3281 17 8.3 19 27
14 15 13 93.3 1902 198 3281 17 8.3 19 27
15 14 11 88.9 1901 197 3279 19 8.8 18 25
15 12 14 91.1 1900 199 3278 20 9.7 16 23
14 14 14 93.3 1900 199 3278 20 9.7 16 23
15 13 12 88.9 1899 198 3276 22 10.6 15 21
14 15 12 91.1 1899 198 3276 22 10.6 15 21
15 11 15 91.1 1898 200 3275 24 12.0 13 19
14 13 15 93.3 1898 200 3275 24 12.0 13 19
13 15 15 95.6 1898 200 3275 24 12.0 13 19
15 14 10 86.7 1898 197 3274 27 12.5 13 18
15 12 13 88.9 1897 198 3273 28 13.4 12 17
14 14 13 91.1 1897 198 3273 28 13.4 12 17
15 13 11 86.7 1896 197 3271 30 14.4 11 15
14 15 11 88.9 1896 197 3271 30 14.4 11 15
15 11 14 88.9 1895 199 3270 32 15.7 10 14
14 13 14 91.1 1895 199 3270 32 15.7 10 14
13 15 14 93.3 1895 199 3270 32 15.7 10 14
15 12 12 86.7 1894 198 3268 35 16.7 9 13
14 14 12 88.9 1894 198 3268 35 16.7 9 13
14 12 15 91.1 1893 200 3267 37 17.6 9 12
13 14 15 93.3 1893 200 3267 37 17.6 9 12
15 13 10 84.4 1893 197 3266 39 19.0 8 11
14 15 10 86.7 1893 197 3266 39 19.0 8 11
15 10 15 88.9 1893 200 3266 39 19.0 8 11
15 11 13 86.7 1892 198 3265 42 20.4 8 11
14 13 13 88.9 1892 198 3265 42 20.4 8 11
13 15 13 91.1 1892 198 3265 42 20.4 8 11
15 12 11 84.4 1891 197 3263 45 21.3 7 10
14 14 11 86.7 1891 197 3263 45 21.3 7 10
14 12 14 88.9 1891 199 3262 47 22.2 7 10
13 14 14 91.1 1891 199 3262 47 22.2 7 10
15 10 14 86.7 1890 199 3261 49 22.7 7 9
14 13 12 86.7 1890 198 3260 50 24.1 6 9
13 15 12 88.9 1890 198 3260 50 24.1 6 9
15 11 12 84.4 1889 198 3260 50 24.1 6 9
14 11 15 88.9 1889 200 3259 53 25.5 6 8
13 13 15 91.1 1889 200 3259 53 25.5 6 8
12 15 15 93.3 1889 200 3259 53 25.5 6 8
14 14 10 84.4 1889 197 3258 56 26.4 6 8
15 12 10 82.2 1888 197 3258 56 26.4 6 8
15 10 13 84.4 1888 198 3257 58 27.8 5 8
14 12 13 86.7 1888 198 3257 58 27.8 5 8
13 14 13 88.9 1888 198 3257 58 27.8 5 8
15 11 11 82.2 1887 197 3255 61 29.2 5 7
14 13 11 84.4 1887 197 3255 61 29.2 5 7
13 15 11 86.7 1887 197 3255 61 29.2 5 7
14 11 14 86.7 1886 199 3254 64 30.6 5 7
13 13 14 88.9 1886 199 3254 64 30.6 5 7
12 15 14 91.1 1886 199 3254 64 30.6 5 7
15 10 12 82.2 1885 198 3252 67 31.9 5 6
14 12 12 84.4 1885 198 3252 67 31.9 5 6
13 14 12 86.7 1885 198 3252 67 31.9 5 6
13 12 15 88.9 1884 200 3251 70 32.9 5 6
12 14 15 91.1 1884 200 3251 70 32.9 5 6
15 11 10 80.0 1884 197 3250 72 34.7 4 6
14 13 10 82.2 1884 197 3250 72 34.7 4 6
13 15 10 84.4 1884 197 3250 72 34.7 4 6
14 10 15 86.7 1884 200 3250 72 34.7 4 6
14 11 13 84.4 1883 198 3249 76 36.1 4 6
13 13 13 86.7 1883 198 3249 76 36.1 4 6
12 15 13 88.9 1883 198 3249 76 36.1 4 6
15 10 11 80.0 1882 197 3247 79 37.5 4 5
14 12 11 82.2 1882 197 3247 79 37.5 4 5
13 14 11 84.4 1882 197 3247 79 37.5 4 5
14 10 14 84.4 1881 199 3246 82 38.9 4 5
13 12 14 86.7 1881 199 3246 82 38.9 4 5
12 14 14 88.9 1881 199 3246 82 38.9 4 5
14 11 12 82.2 1880 198 3244 85 40.3 4 5
13 13 12 84.4 1880 198 3244 85 40.3 4 5
12 15 12 86.7 1880 198 3244 85 40.3 4 5
13 11 15 86.7 1879 200 3243 88 41.2 4 5
12 13 15 88.9 1879 200 3243 88 41.2 4 5
15 10 10 77.8 1879 197 3242 90 43.1 3 5
14 12 10 80.0 1879 197 3242 90 43.1 3 5
13 14 10 82.2 1879 197 3242 90 43.1 3 5
11 15 15 91.1 1879 200 3242 90 43.1 3 5
14 10 13 82.2 1878 198 3241 94 44.4 3 4
13 12 13 84.4 1878 198 3241 94 44.4 3 4
12 14 13 86.7 1878 198 3241 94 44.4 3 4
14 11 11 80.0 1877 197 3239 97 45.8 3 4
13 13 11 82.2 1877 197 3239 97 45.8 3 4
12 15 11 84.4 1877 197 3239 97 45.8 3 4
13 11 14 84.4 1877 199 3238 100 47.2 3 4
12 13 14 86.7 1877 199 3238 100 47.2 3 4
11 15 14 88.9 1877 199 3238 100 47.2 3 4
14 10 12 80.0 1876 198 3236 103 48.6 3 4
13 12 12 82.2 1876 198 3236 103 48.6 3 4
12 14 12 84.4 1876 198 3236 103 48.6 3 4
12 12 15 86.7 1875 200 3235 106 49.1 3 4
14 11 10 77.8 1875 197 3234 107 51.4 3 4
13 13 10 80.0 1875 197 3234 107 51.4 3 4
12 15 10 82.2 1875 197 3234 107 51.4 3 4
13 10 15 84.4 1875 200 3234 107 51.4 3 4
11 14 15 88.9 1875 200 3234 107 51.4 3 4
13 11 13 82.2 1874 198 3233 112 52.8 3 4
12 13 13 84.4 1874 198 3233 112 52.8 3 4
11 15 13 86.7 1874 198 3233 112 52.8 3 4
14 10 11 77.8 1873 197 3231 115 54.2 3 3
13 12 11 80.0 1873 197 3231 115 54.2 3 3
12 14 11 82.2 1873 197 3231 115 54.2 3 3
13 10 14 82.2 1872 199 3230 118 55.6 2 3
12 12 14 84.4 1872 199 3230 118 55.6 2 3
11 14 14 86.7 1872 199 3230 118 55.6 2 3
13 11 12 80.0 1871 198 3228 121 56.9 2 3
12 13 12 82.2 1871 198 3228 121 56.9 2 3
11 15 12 84.4 1871 198 3228 121 56.9 2 3
12 11 15 84.4 1870 200 3227 124 57.9 2 3
11 13 15 86.7 1870 200 3227 124 57.9 2 3
14 10 10 75.6 1870 197 3226 126 59.7 2 3
13 12 10 77.8 1870 197 3226 126 59.7 2 3
12 14 10 80.0 1870 197 3226 126 59.7 2 3
10 15 15 88.9 1870 200 3226 126 59.7 2 3
13 10 13 80.0 1869 198 3225 130 61.1 2 3
12 12 13 82.2 1869 198 3225 130 61.1 2 3
11 14 13 84.4 1869 198 3225 130 61.1 2 3
13 11 11 77.8 1868 197 3223 133 62.5 2 3
12 13 11 80.0 1868 197 3223 133 62.5 2 3
11 15 11 82.2 1868 197 3223 133 62.5 2 3
12 11 14 82.2 1867 199 3222 136 63.4 2 3
11 13 14 84.4 1867 199 3222 136 63.4 2 3
10 15 14 86.7 1867 199 3221 138 63.9 2 3
13 10 12 77.8 1866 198 3220 139 65.3 2 3
12 12 12 80.0 1866 198 3220 139 65.3 2 3
11 14 12 82.2 1866 198 3220 139 65.3 2 3
12 10 15 82.2 1866 200 3219 142 66.2 2 3
11 12 15 84.4 1866 200 3219 142 66.2 2 3
13 11 10 75.6 1865 197 3218 144 68.1 2 3
12 13 10 77.8 1865 197 3218 144 68.1 2 3
11 15 10 80.0 1865 197 3218 144 68.1 2 3
10 14 15 86.7 1865 200 3218 144 68.1 2 3
12 11 13 80.0 1865 198 3217 148 69.4 2 2
11 13 13 82.2 1865 198 3217 148 69.4 2 2
10 15 13 84.4 1864 198 3217 148 69.4 2 2
13 10 11 75.6 1864 197 3215 151 70.8 2 2
12 12 11 77.8 1864 197 3215 151 70.8 2 2
11 14 11 80.0 1864 197 3215 151 70.8 2 2
12 10 14 80.0 1863 199 3214 154 72.2 2 2
11 12 14 82.2 1863 199 3214 154 72.2 2 2
10 14 14 84.4 1863 199 3214 154 72.2 2 2
12 11 12 77.8 1862 198 3212 157 73.6 2 2
11 13 12 80.0 1862 198 3212 157 73.6 2 2
10 15 12 82.2 1862 198 3212 157 73.6 2 2
11 11 15 82.2 1861 200 3211 160 74.1 2 2
13 10 10 73.3 1861 197 3210 161 75.9 2 2
12 12 10 75.6 1861 197 3210 161 75.9 2 2
11 14 10 77.8 1861 197 3210 161 75.9 2 2
10 13 15 84.4 1861 200 3210 161 75.9 2 2
12 10 13 77.8 1860 198 3209 165 77.3 2 2
11 12 13 80.0 1860 198 3209 165 77.3 2 2
10 14 13 82.2 1860 198 3209 165 77.3 2 2
12 11 11 75.6 1859 197 3207 168 78.7 2 2
11 13 11 77.8 1859 197 3207 168 78.7 2 2
10 15 11 80.0 1859 197 3207 168 78.7 2 2
11 11 14 80.0 1858 199 3206 171 79.6 2 2
10 13 14 82.2 1858 199 3206 171 79.6 2 2
12 10 12 75.6 1857 198 3204 173 81.0 1 2
11 12 12 77.8 1857 198 3204 173 81.0 1 2
10 14 12 80.0 1857 198 3204 173 81.0 1 2
11 10 15 80.0 1856 200 3203 176 81.9 1 2
10 12 15 82.2 1856 200 3203 176 81.9 1 2
12 11 10 73.3 1856 197 3202 178 83.3 1 2
11 13 10 75.6 1856 197 3202 178 83.3 1 2
10 15 10 77.8 1856 197 3202 178 83.3 1 2
11 11 13 77.8 1855 198 3201 181 84.3 1 2
10 13 13 80.0 1855 198 3201 181 84.3 1 2
12 10 11 73.3 1854 197 3199 183 85.6 1 2
11 12 11 75.6 1854 197 3199 183 85.6 1 2
10 14 11 77.8 1854 197 3199 183 85.6 1 2
11 10 14 77.8 1854 199 3198 186 86.6 1 2
10 12 14 80.0 1853 199 3198 186 86.6 1 2
11 11 12 75.6 1853 198 3196 188 87.5 1 2
10 13 12 77.8 1853 198 3196 188 87.5 1 2
10 11 15 80.0 1852 200 3195 190 88.0 1 2
12 10 10 71.1 1852 197 3194 191 89.4 1 2
11 12 10 73.3 1852 197 3194 191 89.4 1 2
10 14 10 75.6 1851 197 3194 191 89.4 1 2
11 10 13 75.6 1851 198 3193 194 90.3 1 1
10 12 13 77.8 1851 198 3193 194 90.3 1 1
11 11 11 73.3 1850 197 3191 196 91.2 1 1
10 13 11 75.6 1850 197 3191 196 91.2 1 1
10 11 14 77.8 1849 199 3190 198 91.7 1 1
11 10 12 73.3 1848 198 3188 199 92.6 1 1
10 12 12 75.6 1848 198 3188 199 92.6 1 1
11 11 10 71.1 1847 197 3187 201 93.5 1 1
10 10 15 77.8 1847 200 3187 201 93.5 1 1
10 13 10 73.3 1847 197 3186 203 94.0 1 1
10 11 13 75.6 1846 198 3185 204 94.4 1 1
11 10 11 71.1 1845 197 3183 205 95.4 1 1
10 12 11 73.3 1845 197 3183 205 95.4 1 1
10 10 14 75.6 1844 199 3182 207 95.8 1 1
10 11 12 73.3 1843 198 3180 208 96.3 1 1
11 10 10 68.9 1842 197 3179 209 97.2 1 1
10 12 10 71.1 1842 197 3179 209 97.2 1 1
10 10 13 73.3 1842 198 3177 211 97.7 1 1
10 11 11 71.1 1841 197 3175 212 98.1 1 1
10 10 12 71.1 1839 198 3172 213 98.6 1 1
10 11 10 68.9 1838 197 3171 214 99.1 1 1
10 10 11 68.9 1836 197 3168 215 99.5 1 1
10 10 10 66.7 1833 197 3163 216 100.0 1 1