## 1) # 帰無仮説 : 平均170cmの正規分布に従うサンプルである height <- c(165, 150, 170, 168, 159, 167, 178, 155, 161, 162, 166, 171, 160, 172, 167)< span> t.test(height, mu=170) # One Sample t-test # # data: height # t = -3.8503, df = 19, p-value = 0.001079 # alternative hypothesis: true mean is not equal to 170 # 95 percent confidence interval: # 160.584 167.216 # sample estimates: # mean of x # 163.9 #=> p = 0.00107で 0.05より小さいので帰無仮説は棄却
## 2) ## 帰無仮説 : 勉強時間とテスト結果には相関性がない hour <- c(1,3,10,12,6,3,8,4,1,5)< span> score <- c(20,40,100,80,50,50,70,50,10,60)< span> cor.test(hour, score) # Pearson's product-moment correlation # # data: hour and score # t = 6.1802, df = 8, p-value = 0.0002651 # alternative hypothesis: true correlation is not equal to 0 # 95 percent confidence interval: # 0.6542283 0.9786369 # sample estimates: # cor # 0.9092974
## 3) ## スピアマンの順位相関係数 ## http://goo.gl/sFitJ
cor.test(hour, score, method="spearman") # Spearman's rank correlation rho # # data: hour and score # S = 10.1822, p-value = 5.887e-05 # alternative hypothesis: true rho is not equal to 0 # sample estimates: # rho # 0.9382895
## ケンドールの順位相関係数 ## http://goo.gl/2HRaa
cor.test(hour, score, method="kendall") # Kendall's rank correlation tau # # data: hour and score # z = 3.2937, p-value = 0.0009889 # alternative hypothesis: true tau is not equal to 0 # sample estimates: # tau # 0.8471174
## 4) χ2乗検定 youwa <- c('洋食', '和食', '洋食', '和食')< span> amakara <- c('甘党', '辛党', '甘党', '辛党')< span> chisq.test(youwa, amakara) # Pearson's Chi-squared test with Yates' continuity correction # # data: youwa and amakara # X-squared = 0.8081, df = 1, p-value = 0.3687
## 5-1) 無相関検定 lang <- c(60, 40, 30, 70, 55)< span> soci <- c(80, 25, 35, 70, 50)< span> cor.test(lang, soci) # Pearson's product-moment correlation # # data: lang and soci # t = 2.6952, df = 3, p-value = 0.07408 # alternative hypothesis: true correlation is not equal to 0 # 95 percent confidence interval: # -0.1590624 0.9892731 # sample estimates: # cor # 0.841263 #=> p値が有意水準(0.05)より高いので2つの結果に相関はない
## 5-2) 無相関検定 : 同じサンプルを2回使う lang2 <- rep(lang, 2)< span> soci2 <- rep(soci, 2)< span> cor.test(lang2, soci2) # Pearson's product-moment correlation # # data: lang2 and soci2 # t = 4.4013, df = 8, p-value = 0.002283 # alternative hypothesis: true correlation is not equal to 0 # 95 percent confidence interval: # 0.4499858 0.9615658 # sample estimates: # cor # 0.841263 #=> p値が有意水準(0.05)より低いので2つの結果に相関はある
#=> (5-1)と(5-2)は相関係数(cor)は一致するがp値が大きく異る ->->->->->->->->-> |