<?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>Mon, 28 Oct 2013 02:11:53 GMT</pubDate>
    <generator>Blogofile</generator>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <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>
