4. Agenda
1. R の基本操作
2. 関数と変数が命
3. 外部データの読込
4. R で作図
5. R で検定
9Sunday, October 6, 13
5. Agenda
1. R の基本操作
2. 関数と変数が命
3. 外部データの読込
4. R で作図
5. R で検定
10Sunday, October 6, 13
6. とは何か
• 統計処理を目的とするプログラミング言語
• 無償+オープンソースのソフトウェア
• 作者: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
12Sunday, October 6, 13
15. のインストール
• Windows: : http://cran.md.tsukuba.ac.jp/bin/windows/base/
•「Download R 3.0.2 for Windows」をクリック
• Mac OS X:http://cran.md.tsukuba.ac.jp/bin/macosx/
•「R-3.0.2.pkg (latest version)」をクリック
22Sunday, October 6, 13
24. のアンインストール
• Windows
• [ Windows XP] コンパネ→プログラムの追加と削除
• [ Windows 7/8 ] コンパネ→プログラムのアンインストール
• Mac OS X
• /Applications にある アイコンと /Library の中の
Frameworks にある R. framework を削除(CleanApp 可)
31Sunday, October 6, 13
25. の起動
• Windows (8は検索→アプリ)
• START → Program → R → R 3.0.2
• Mac OS X
• /Applications 内の をクリック
32Sunday, October 6, 13
168. • (例)あるテストの平均値に男女差があるかどうか
> male <- test2[,2]
> female <- test2[,3]
> t.test(male, female, var.equal=TRUE)
t 検定
182Sunday, October 6, 13
169. > t.test(male, female,var.equal=TRUE)
Two Sample t-test
data: male and female
t = -0.9232, df = 58, p-value = 0.3597
alternative hypothesis: true difference in
means is not equal to 0 # 両側検定
95 percent confidence interval: # 信頼区間
-9.926800 3.660134
sample estimates:
mean of x mean of y
62.06667 65.20000
t 検定
183Sunday, October 6, 13
172. ソース! ソース!
―(等分散の検定はせず)最初から 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
186Sunday, October 6, 13
173. • (例)英語の好きな組と嫌いな組が受けたテストの
平均値に差があるかどうか
> 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=FALSE)
t 検定
187Sunday, October 6, 13
174. > 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
という訳で...
188Sunday, October 6, 13