グループ間の比較

データをグループごとに比較してみることは、データの特徴をつかむ上で重要な作業です。ここでは、bigclass2.csvを使って、男女間の身長の分布について調べてみます。

まず、bigclass2.csvをRで読み込みます。

class <- read.csv("bigclass2.csv")

男子と女子のデータをclassから抽出し、それぞれclass_male, class_femaleに代入します。

class_male <- subset(class,性別=="M")

class_female <- subset(class,性別=="F")

class_maleの内容を表示してみます。

class_male

名前 年齢 性別 身長 体重

6 TIM 12 M 60 84

7 JAMES 12 M 61 128

8 ROBERT 12 M 51 79

12 JOHN 13 M 65 98

13 JOE 13 M 63 105

14 MICHAEL 13 M 58 95

男子の身長のヒストグラムと箱ひげ図を表示します。

par(mfrow=c(2,1))

boxplot(class_male$身長,horizontal=T,main="男子身長の箱ひげ図",xlab="身長")

hist(class_male$身長,main="男子身長のヒストグラム",xlab="身長")

clip_image002

同様に女子についても表示してみます。

par(mfrow=c(2,1))

boxplot(class_female$身長,horizontal=T,main="女子身長の箱ひげ図",xlab="身長")

hist(class_female$身長,main="女子身長のヒストグラム",xlab="身長")

clip_image004

基本統計量も見てみましょう。

mean(class_male$身長)

[1] 63.90909

mean(class_female$身長)

[1] 60.88889

sd(class_male$身長)

[1] 4.308453

sd(class_female$身長)

[1] 3.61189

これより男性の身長の方が女性の身長に比べ平均身長が高く、ばらつきも大きいことが分かります。

トラックバック(0)

このブログ記事を参照しているブログ一覧: グループ間の比較

このブログ記事に対するトラックバックURL: http://www.moriyasu.org/cgi/mt/mt-tb.cgi/150

プロフィール

講義

About This Post

This page contains a single entry by moriyasu posted on 2008年6月 3日 12:50.

データの基準化 was the previous post in this blog.

計量経済学(夜間主):第1回レポート課題 is the next post in this blog.

Find recent content on the main index or look in the archives to find all content.

Powered by Movable Type 4.0