科学の箱

科学・IT・登山の話題

R

Rによるやさしい統計学/5-統計的検定-2

投稿日:

練習問題-2

勉強時間と定期試験の点数についてデータを作成する。

study_time <- c(1, 3, 10, 12, 6, 3, 8, 4, 1, 5)
point <- c(20, 40, 100, 80, 50, 50, 70, 50, 10, 60)

ピアソンの無相関検定を実行する。Rではcor.test()を利用する。この際にmethods=”pearson”を指定する。

> cor.test(study_time, point, method="pearson")

        Pearson's product-moment correlation

data:  study_time and point 
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

帰無仮説は相関係数=0であり、2つの変数に相関はないとする。対立仮説は相関係数は0と等しくないとします。

計算されたt値は6.1802となり、自由度=8からp値は0.0002651です。有意水準を5%とすると帰無仮説は棄却されます。

サンプルから計算された相関係数は0.9092974となり、95%の信頼区間は0.654~0.979となります。

練習問題-4

データはランダムで作成する。

> food<-sample(c("洋食", "和食"), 20, replace=TRUE)
> food
 [1] "洋食" "洋食" "洋食" "洋食" "洋食" "洋食" "和食" "和食" "洋食" "和食"
[11] "和食" "和食" "和食" "和食" "和食" "洋食" "洋食" "洋食" "和食" "洋食"
> taste<-sample(c("甘党", "辛党"), 20, replace=TRUE)
> taste
 [1] "辛党" "辛党" "甘党" "甘党" "甘党" "甘党" "辛党" "辛党" "甘党" "辛党"
[11] "甘党" "辛党" "辛党" "辛党" "辛党" "甘党" "辛党" "甘党" "甘党" "辛党"

クロス集計表を作成する

> tasting_table <-  table(food, taste)
> tasting_table
      taste
food   甘党 辛党
  洋食    7    4
  和食    2    7

Χ検定を実施する

> chisq.test(tasting_table, correct=FALSE)

        Pearson's Chi-squared test

data:  tasting_table 
X-squared = 3.4303, df = 1, p-value = 0.06401

 警告メッセージ: 
In chisq.test(tasting_table, correct = FALSE) :
   カイ自乗近似は不正確かもしれません 

帰無仮説では食事の好みとお酒の好みは独立である。

Χ^2値は3.4303となる。自由度1からp値は0.064と求められた。p値は有意水準5%より大きいので帰無仮説は棄却できない。よって、食事の好みとお酒の好みが独立ではないとはいえない。

サンプルサイズの影響

下記のデータを利用して無相関検定に対するサンプルサイズの影響を検証する。

study_time <- c(1, 3, 10, 12, 6, 3, 8, 4, 1, 5)
point <- c(20, 40, 100, 80, 50, 50, 70, 50, 10, 60)

この時

p-value = 0.0002651

次にサンプルサイズを2倍にする。

> study_time_2 <- rep(study_time, 2)
> study_time_2
 [1]  1  3 10 12  6  3  8  4  1  5  1  3 10 12  6  3  8  4  1  5
> point_2 <- rep(point, 2)
> point_2
 [1]  20  40 100  80  50  50  70  50  10  60  20  40 100  80  50  50  70  50
[19]  10  60
> cor.test(study_time_2, point_2, method="pearson")

        Pearson's product-moment correlation

data:  study_time_2 and point_2 
t = 9.2703, df = 18, p-value = 2.829e-08
alternative hypothesis: true correlation is not equal to 0 
95 percent confidence interval:
 0.7810631 0.9639436 
sample estimates:
      cor 
0.9092974

p値は2.829e-08となっていて、サンプルサイズが大きくなると有意になりやすいことがわかる。

メタ情報

inarticle



メタ情報

inarticle



-R
-

執筆者:


comment

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

関連記事

no image

Rで%>%を利用する。

rvestでスクレイピングをしようとしたら、%>%という記述が大量頻出。これ何かということで調べてみた。 https://stackoverflow.com/questions/24536154 …

no image

R Dataset – bone

データの説明 261人の子供たちから得られた年齢別骨密度。 フォーマット idnum: 識別コード age: 測定時の年齢 gender: 性別 spnbmd: 骨密度 チェック テーブル全体について …

no image

ジニ係数(再掲)

ジニ係数について修正した。とりあえずコード。 revenue<-read.csv(file=”data.csv”, head=TRUE) revenue$TotalRevenues_n < …

no image

findFn{sos}

findFn{sos} findFn(string, maxPages = 20, sortby = NULL, verbose = 1, …) 文字列から関数を探すことができる。パッケー …

no image

Rによるやさしい統計学/4-母集団と標本

言葉の定義 推測統計、推定、点推定、区間推定、検定 標本、標本統計量、推定量、標本抽出、確率変数、確率分布、標本誤差 標本分布、標本統計量、平均、標準偏差、標準誤差 4.5 標本分布 標本平均の標本分 …

2014年5月
« 4月   6月 »
 1234
567891011
12131415161718
19202122232425
262728293031  

side bar top



アーカイブ

カテゴリー