<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
     xmlns:content="http://purl.org/rss/1.0/modules/content/"
     xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
     xmlns:atom="http://www.w3.org/2005/Atom"
     xmlns:dc="http://purl.org/dc/elements/1.1/"
     xmlns:wfw="http://wellformedweb.org/CommentAPI/"
     >
  <channel>
    <title>mojavy.com</title>
    <link>http://mojavy.com/blog</link>
    <description></description>
    <pubDate>Tue, 12 Nov 2013 03:01:16 GMT</pubDate>
    <generator>Blogofile</generator>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>ベイズの定理から見るガン検査</title>
      <link>http://mojavy.com/blog/2013/11/12/bayes-theorem-and-detecting-cancer/</link>
      <pubDate>Tue, 12 Nov 2013 03:01:16 JST</pubDate>
      <category><![CDATA[statistics]]></category>
      <guid isPermaLink="true">http://mojavy.com/blog/2013/11/12/bayes-theorem-and-detecting-cancer/</guid>
      <description>ベイズの定理から見るガン検査</description>
      <content:encoded><![CDATA[<p><a href="http://www.huffingtonpost.jp/2013/11/10/cancer-test_n_4252707.html">http://www.huffingtonpost.jp/2013/11/10/cancer-test_n_4252707.html</a> </p>
<p>高校生がすい臓がん発見の画期的方法を開発したという記事が話題になってます。</p>
<p>この検査法の改善が統計的にどういう意味をもつのか実際にベイズの定理をつかって計算してみます。</p>
<p>ここでは以下のような問題を考えることとします。</p>
<blockquote>
<p>あるガン検査法は、被験者ががんの場合はp1の確率で陽性になり、被験者ががんでなければp2の確率で陰性になります。被験者ががん患者である確率がp3のとき、がん患者が検査の結果実際に陽性だと判定される確率を求めなさい。</p>
</blockquote>
<p>Xを被検査者はガンであるという事象、Yを検査の結果が被検査者はガンであると示す事象として、それぞれ以下のように置き換えることができます。</p>
<p><img src="/images/874a5aeecf9b35cdbf1134ce65609eb8.png">
</p>

<p>
ただし、<img src="/images/33690e97dbeaa68d615e68dba167db2a.png"> はBが起こったときにAが起こる確率(条件付き確率)、<img src="/images/f679168b61f35c21700eef5eb88dc82d.png"> はAが起こらないという事象(補事象)を表します。
</p>

<p>求めたい確率は<img src="/images/7082016653a57c45dae6f7d57ceea8ba.png"> なので、ベイズの定理より
<p><img src="/images/227eb2fa21aa259a48119a03e888a78c.png">
</p></p>
<p>ここで<img src="/images/0c3d72395d7576ab13b9e9389f865960.png"> は検査結果が真陽性となる確率と偽陰性となる確率を足したものなので、
<p><img src="/images/e2fb081253f2ada10b84e8c39da103d6.png">
</p></p>
<p>また、
<p><img src="/images/18b3d7224708203cb4000f3539856aab.png"> 
</p>
なので、</p>
<p><img src="/images/298c37b1f601ada40fbe0808816d66a3.png"> 
</p>

<p>となります。</p>
<p>以上の結果に実際に値をあてはめてみます。</p>
<p>2008年のすい臓がん推定患者数は29584 <sup id="fnref:1"><a href="#fn:1" rel="footnote">1</a></sup>、同年の人口は127692000 <sup id="fnref:2"><a href="#fn:2" rel="footnote">2</a></sup>なので、<code>p3=0.23168 * 10^-3</code>。
また、簡単のためにp1, p2をひとまとめに誤検出の確率と仮定して<code>p1=p2=q</code>おくと、P(Y|X)が70%となるようなqは、<strong>q=0.99990</strong>となります。</p>
<p>このことから、99.99%の精度をもつ検出方法でも実際には30%も見逃してしまうということがわかります。</p>
<p>さらに、「400倍の精度で検査できる」という部分を誤検出の確率が400分の1になったという意味だと解釈して、
<code>q'=1-(1-q)/400</code>とおいてがん患者が検査の結果実際に陽性だと判定される確率を再度計算すると<strong>P(Y|X)=0.99892</strong>となります。</p>
<p>つまり30%見逃していたのが1%程度まで減ったということです。
これはすばらしい成果といえるのではないでしょうか。</p>
<p>最初は30%も見逃すとかどんなひどい検査だったんだ、などと思ってしまうかもしれませんが、上記の計算で実際はそれほど単純な話ではないことがわかると思います。</p>
<p><a href="http://www.amazon.co.jp/gp/product/4130420658/ref=as_li_ss_il?ie=UTF8&camp=247&creative=7399&creativeXSIN=4130420658&linkCode=as2&tag=armyofpigs-22"><img border="0" src="http://ws-fe.amazon-adsystem.com/widgets/q?_encoding=UTF8&ASIN=4130420658&Format=_SL160_&ID=AsinImage&MarketPlace=JP&ServiceVersion=20070822&WS=1&tag=armyofpigs-22" ></a><img src="http://ir-jp.amazon-adsystem.com/e/ir?t=armyofpigs-22&l=as2&o=9&a=4130420658" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /> <sup id="fnref:3"><a href="#fn:3" rel="footnote">3</a></sup> </p>
<div class="footnote">
<hr />
<ol>
<li id="fn:1">
<p><a href="http://ganjoho.jp/professional/statistics/statistics.html">国立がん研究センターがん対策情報センター - http://ganjoho.jp/professional/statistics/statistics.html</a> &#160;<a href="#fnref:1" rev="footnote" title="Jump back to footnote 1 in the text">&#8617;</a></p>
</li>
<li id="fn:2">
<p><a href="http://www.e-stat.go.jp/SG1/estat/List.do?lid=000001054002">http://www.e-stat.go.jp/SG1/estat/List.do?lid=000001054002</a> &#160;<a href="#fnref:2" rev="footnote" title="Jump back to footnote 2 in the text">&#8617;</a></p>
</li>
<li id="fn:3">
<p>この問題は統計学入門の練習問題4.7を参考にしています。&#160;<a href="#fnref:3" rev="footnote" title="Jump back to footnote 3 in the text">&#8617;</a></p>
</li>
</ol>
</div>]]></content:encoded>
    </item>
    <item>
      <title>R Tutorial Part2 Chapter08 (Numerical Measures)</title>
      <link>http://mojavy.com/blog/2013/10/28/r-tutor-chap08/</link>
      <pubDate>Mon, 28 Oct 2013 02:11:53 JST</pubDate>
      <category><![CDATA[note]]></category>
      <category><![CDATA[statistics]]></category>
      <category><![CDATA[R]]></category>
      <guid isPermaLink="true">http://mojavy.com/blog/2013/10/28/r-tutor-chap08/</guid>
      <description>R Tutorial Part2 Chapter08 (Numerical Measures)</description>
      <content:encoded><![CDATA[<p>これは<a href="http://www.r-tutor.com/elementary-statistics/numerical-measures">R Tutorial Part2 Chapter08 (Numerical Measures)</a> のノートです。
<a href="/slide/2013/10/26/r-tutor-chap08/">slideはこちら</a> 。</p>
<h3 id="mean-median">mean, median</h3>
<ul>
<li>mean: 平均</li>
<li>median: 中央値、中間値。データ数が偶数個の場合は前後の2つの数の平均。</li>
</ul>
<div class="pygments_borland"><pre>&gt; library(MASS)
&gt; mean(faithful$eruption)
[1] 3.487783
&gt; median(faithful$eruption)
[1] 4
</pre></div>

<h3 id="quartile-quantile-percentile">quartile, quantile, percentile</h3>
<ul>
<li>first quartile, lower quartile: ソートされたデータの数を１：３に分ける位置の値。 第１四分位</li>
<li>second quartile, median: 中間値</li>
<li>third quartile, upper quartile: 第３四分位</li>
<li>quantile: 変位値</li>
<li>percentile: 百分位数</li>
</ul>
<div class="pygments_borland"><pre>&gt; quantile(faithful$eruption)
     0%     25%     50%     75%    100% 
1.60000 2.16275 4.00000 4.45425 5.10000 
&gt; x = sort(faithful$eruption)
&gt; x[1+floor((length(x) - 1)/4)] + (x[1+ceiling((length(x) - 1)/4)] - x[1+floor((length(x) - 1)/4)]) * 3 / 4
[1] 2.16275
&gt; quantile(faithful$eruption, c(.32, .57, .98))
    32%     57%     98% 
2.39524 4.13300 4.93300 
</pre></div>

<h3 id="max-min-range">max, min, range</h3>
<div class="pygments_borland"><pre>&gt; max(faithful$eruption)
[1] 5.1
&gt; min(faithful$eruption)
[1] 1.6
&gt; max(faithful$eruption) - min(faithful$eruption)
[1] 3.5
</pre></div>

<h3 id="interquartile-range">interquartile range</h3>
<ul>
<li>interquartile range: 四分位範囲, upper quartile - lower quartile</li>
</ul>
<div class="pygments_borland"><pre>&gt; IQR(faithful$eruption)
[1] 2.2915
&gt; x = quantile(faithful$eruption)
&gt; x[4] - x[2]
   75% 
2.2915 
</pre></div>

<h3 id="box-plot">box plot</h3>
<ul>
<li>boxplot: 箱ひげ図</li>
</ul>
<div class="pygments_borland"><pre>&gt; boxplot(faithful$eruption, horizontal=TRUE)
</pre></div>

<p><img alt="boxplot" src="/images/numerical-measures4x.png" /> </p>
<p>※ 箱のなかの線はmedian</p>
<h3 id="variance-standard-deviation">variance, standard deviation</h3>
<ul>
<li>variance: 分散。Rのvar関数は<a href="http://www.sist.ac.jp/~kanakubo/research/statistic/fuhenbunsan.html">不偏分散</a> </li>
<li>standard deviation: 標準偏差</li>
</ul>
<div class="pygments_borland"><pre>&gt; var(faithful$eruption)
[1] 1.302728
&gt; sd(faithful$eruption)
[1] 1.141371

&gt; var2 &lt;- function(x) { sum((x - mean(x)) ^ 2) / length(x) }   # 普通の分散
&gt; var2(faithful$eruption)
[1] 1.297939
</pre></div>

<h3 id="covariance-correlation-coefficient">covariance, correlation coefficient</h3>
<ul>
<li>covariance: 共分散。2 組の対応するデータ間での、平均からの偏差の積の平均値。</li>
<li>correlation coefficient: 相関係数。共分散をそれぞれのデータの標準偏差の積で割ったもの。</li>
</ul>
<div class="pygments_borland"><pre>&gt; cov(faithful$eruption, faithful$waiting)
[1] 13.97781
&gt; cor(faithful$eruption, faithful$waiting)
[1] 0.9008112
</pre></div>

<p>correlation coefficientが1に近いほど正の相関があるといえる</p>
<h3 id="e1071">e1071</h3>
<blockquote>
<p>Functions for latent class analysis, short time Fourier transform, fuzzy clustering, support vector machines, shortest path computation, bagged clustering, naive Bayes classifier</p>
</blockquote>
<div class="pygments_borland"><pre>&gt; install.packages(&#39;e1071&#39;)
</pre></div>

<p><a href="http://cran.r-project.org/web/packages/e1071/index.html">http://cran.r-project.org/web/packages/e1071/index.html</a> </p>
<h3 id="central-moment">central moment</h3>
<ul>
<li>central moment： 中心積率。標本分散は2次のcentral moment</li>
</ul>
<div class="pygments_borland"><pre>&gt; library(e1071)
&gt; moment(faithful$eruption, order=3, center=TRUE)
[1] -0.6149059
</pre></div>

<h3 id="skewness-kurtosis">skewness, kurtosis</h3>
<ul>
<li>skewness: 歪度。対象性の度合いの指標。一般に、skewness &lt; 0 ならばmean &lt; median でそのデータの分散はleft skewed という。skewness &gt; 0 ならばmean &gt; median でright skewed という。</li>
<li>kurtosis: 尖度。分布の尖り具合の指標。kurtosis &lt; 0 ならフラットな分布になりplatykurtic(緩尖な)という。kurtosis &gt; 0ならとがった分布になりleptokurticという。正規分布の場合は0になりmesokurticという。</li>
</ul>
<div class="pygments_borland"><pre>&gt; skewness(faithful$eruption)
[1] -0.4135498
&gt; kurtosis(faithful$eruption)
[1] -1.511605
</pre></div>

<h3 id="misc">misc</h3>
<ul>
<li>この項は統計でよくつかう関数のまとめになってます</li>
<li>各関数の詳細はhelpを参照</li>
</ul>]]></content:encoded>
    </item>
  </channel>
</rss>
