1. 第1部:入門者講習
2012-05-19 Nagoya.R #8 @ Nagoya Univ.
Saturday, May 19, 12
2. Agenda
1. R 概論
2. 関数と変数が命
3. 外部データの読込
4. あっという間に作図
5. R で検定
Saturday, May 19, 12
3. Agenda
1. R 概論
2. 関数と変数が命
3. 外部データの読込
4. あっという間に作図
5. R で検定
Saturday, May 19, 12
4. とは何か
• 統計処理を目的とするプログラミング言語
• 作者:Ross Ihaka & Robert Gentleman (R & R)
• Ross Ihaka and Robert Gentleman. R: A language for data analysis and graphics.
Journal of Computational and Graphical Statistics, 5(3):299-314, 1996.
• http://biostat.mc.vanderbilt.edu/twiki/pub/Main/JeffreyHorner/JCGSR.pdf
• 無償+オープンソースのソフトウェア
Saturday, May 19, 12
12. のインストール
1. http://www.r-project.org/ にアクセス
2. “download R” をクリック
3. JAPAN の中から、どれか1つを選ぶ
4. 使っている OS のリンクをクリック
Saturday, May 19, 12
13. のインストール
• Windows: : http://cran.md.tsukuba.ac.jp/bin/windows/base/
•「Download R 2.14.0 for Windows」をクリック
• Mac OS X: http://cran.md.tsukuba.ac.jp/bin/macosx/
•「R-2.14.0.pkg (latest version)」をクリック
Saturday, May 19, 12
22. のアンインストール
• Windows
• [ Windows XP] コンパネ→プログラムの追加と削除
• [ Windows 7 ] コンパネ→プログラムのアンインストール
• Mac OS X
• /Applications にある アイコンと /Library の中の
Frameworks にある R. framework を削除(CleanApp 可)
Saturday, May 19, 12
23. の起動
• Windows
• START → Program → R → R 2.14.1
• Mac OS X
• /Applications 内の R アイコンをクリック
R の「コンソール」表示を確認
Saturday, May 19, 12
24. の終了
• Windows も Mac OS X も
1.「q()」と入力
2. 今は作業スペースの保存をしない
3. ウィンドウが消えて、R 終了
Saturday, May 19, 12
25. で困ったら...
• まずは help(sth) を実行
• seekR(http://seekr.jp/)
• R SEEK(http://www.rseek.org/)
• RjpWiki (http://www.okada.jp.org/RWiki/)
• R-Tips
(http://cse.naro.affrc.go.jp/takezawa/r-tips/r.html)
• R による統計処理 (http://aoki2.si.gunma-u.ac.jp/R/)
Saturday, May 19, 12
146. t 検定
• 2つのグループの平均値の差の検定
するのに使う手法
• R では,t.test() であっさりと実行
Saturday, May 19, 12
147. t 検定
• (例)英語の好きな組と嫌いな組が受けたテストの
平均値に差があるかどうか
> like <- c(6,10,6,10,7,8,7,9,10,4)
> dislike <- c(3,5,6,4,4,8,4,5,4,7)
> t.test(like,dislike,var.equal=TRUE)
Saturday, May 19, 12
148. t 検定
> t.test(like,dislike,var.equal=TRUE)
Two Sample t-test
data: like and dislike
t = 3.3041, df = 18, p-value = 0.003946
alternative hypothesis: true difference in
means is not equal to 0 # 両側検定
95 percent confidence interval: # 信頼区間
0.9831754 4.4168246
sample estimates:
mean of x mean of y
7.7 5.0
Saturday, May 19, 12
149. t 検定の前に...
“等分散であるかどうかを確かめてから,普通の
t 検定を使うか,Welch の方法による t 検定にす
るかを決めるというのは,よくない。最初から
Welch の方法による t 検定を使えばよい。”
http://aoki2.si.gunma-u.ac.jp/lecture/Average/bunsan1.html
Saturday, May 19, 12
151. ソース! ソース!
―(等分散の検定はせず)最初から Welch で行け―
• http://oku.edu.mie-u.ac.jp/~okumura/blog/node/2262
• http://aoki2.si.gunma-u.ac.jp/lecture/BF/index.html
• Donald W. Zimmerman, ``Some properties of preliminary tests of equality of variances
in the two-sample location problem'', The Journal of General Psychology, Vol.123, pp.
217-231 (1996)
• The unequal variance t-test is an underused alternative to Student's t-test and the
Mann-Whitney U test -- Ruxton 17 (4): 688 -- Behavioral Ecology
• 馬車馬のように: [統計]Mann-WhitneyのU検定と不等分散(http://qdai.way-
nifty.com/qjes/2005/02/mannwhitneyu.html
Saturday, May 19, 12
152. という訳で...
> t.test(like,dislike,var.equal=FALSE)
Welch Two Sample t-test
data: like and dislike
t = 3.3041, df = 16.795, p-value = 0.004249
alternative hypothesis: true difference in
means is not equal to 0
95 percent confidence interval:
0.9743014 4.4256986
sample estimates:
mean of x mean of y
7.7 5.0
Saturday, May 19, 12
153. ところで t 検定の t は何なのかと...
• t 分布の t なんだけど...
• ゴセットの発表した統計量(Student の t 分布)に,
(論敵の)フィッシャーが t という記号を充てた
• 別に特別な意味は無く,論文中の標本分散s^2に対する
式だったことから,s の次の t を使ったらしい...
• 「ウィリアム・ゴセット」http://ja.wikipedia.org/wiki/%E3%82%A6%E3%82%A3%E3%83%AA
%E3%82%A2%E3%83%A0%E3%83%BB%E3%82%B4%E3%82%BB%E3%83%83%E3%83%88
• 「自由度」http://ja.wikipedia.org/wiki/%E8%87%AA%E7%94%B1%E5%BA%A6
• http://mat.isc.chubu.ac.jp/fpr/fpr1997/0119.html
• http://www.pol.geophys.tohoku.ac.jp/~hanawa/ori/ori/054.html
Saturday, May 19, 12
154. 共分散分析
カイ二乗検定
パワーアナリシス
主成分分析
符号検定
因子分析 t 検定
分散分析
マクマネー検定
クラスカル・ウォリス検定
判別分析
Saturday, May 19, 12
172. 舟尾暢男氏による参考資料
第 22 回日本疫学会総会第19回疫学セミナー 「統計解析ソフトRの活用」
統計解析ソフト R の活用
∼ R 入門& R でデータハンドリング∼
http://www.occn.zaq.ne.jp/cuhxr802/epi_20120126.pdf
Saturday, May 19, 12