www.crosshyou.info

政府統計の総合窓口のデータや、OECDやUCIやのデータを使って、Rの練習をしています。ときどき、読書記録も載せています。

社会生活基本調査データの分析4 - R言語のcoplot関数で男女別の年齢と行動者率の散布図を描く。

 

www.crosshyou.info

 の続きです。

今回は年齢による行動の違いを見てみようと思います。

まずは、年齢がどういう区分で分かれているかを確認しましょう。R言語のstr関数とtable関数で確認します。

f:id:cross_hyou:20190323100341j:plain

14のファクタに分かれています。1014yというのは10歳から14歳という意味です。

ファクタのままでもいいのですが、せっかくなので数値データの変数も作りましょう。

substr関数ではじめの2文字、1014yなら10だけを抽出します。

f:id:cross_hyou:20190323100756j:plain

 

次に、as.numeric関数で文字列型を数値型に変換します。

f:id:cross_hyou:20190323100952j:plain

1014yの中心は12歳ですから、それぞれに2歳を加えて完成です。

f:id:cross_hyou:20190323101216j:plain

これで完成です。

この数値型の年齢と各行動の相関を見ていきましょう。

まずは、Sample_size, 調査人数です。

f:id:cross_hyou:20190323101611j:plain

f:id:cross_hyou:20190323101625j:plain

年齢が高いほど、調査人数は多いようです。

次は、Population, 人口です。

f:id:cross_hyou:20190323101922j:plain

f:id:cross_hyou:20190323101943j:plain

10代の人口が少ないですね。同じ年齢に2つずつプロット点があります。男女を表しています。年齢が上がるほど、差が開いています。女性のほうが長生きですからね。

次は、Totalです。行動者率の合計です。

f:id:cross_hyou:20190323102424j:plain

f:id:cross_hyou:20190323102436j:plain

年齢とともに行動者率は低下しています。

次は、Foreign_languagesです。外国語学習です。

f:id:cross_hyou:20190323102729j:plain

f:id:cross_hyou:20190323102807j:plain

外国語学習も年齢とともに行動者率は低下します。

次は、English_language, 英語学習です。

f:id:cross_hyou:20190323103101j:plain

f:id:cross_hyou:20190323103114j:plain

英語学習も年齢とともに行動者率は低下します。

次は、Other_foreign_languagesです。その他の外国語です。

f:id:cross_hyou:20190323103458j:plain

f:id:cross_hyou:20190323103510j:plain

年齢とともに低下するのは英語学習と同じですが、ピークは17歳、22歳のところにあります。また40歳ぐらいのところで低下して50台のところで少し上昇しています。

次は、Commerce_and_business_total, 商業実務・ビジネス関係(総数)です。

f:id:cross_hyou:20190323104305j:plain

f:id:cross_hyou:20190323104318j:plain

年齢とともに低下するのは外国語学習と同じですが、男女の差がかなり開いているように推測されます。coplot関数で確認してみましょう。

f:id:cross_hyou:20190323105338j:plain

f:id:cross_hyou:20190323105359j:plain

思ったとおり、男性のほうが行動者比率が高いですね。

続いて、Computing_etc, パソコンなどの情報処理です。

f:id:cross_hyou:20190323105806j:plain

f:id:cross_hyou:20190323105819j:plain

年齢とともに低下していますが、男女でパターンに大きな違いがありそうです。

これもcoplot関数で確認してみます。

f:id:cross_hyou:20190323110113j:plain

f:id:cross_hyou:20190323110127j:plain

女性の50歳以降の落ち込みが激しいですね。男性はそれほど落ち込んでいません。

次は、Commerce_and_business, 商業実務・ビジネス関係です。

f:id:cross_hyou:20190323110543j:plain

f:id:cross_hyou:20190323110555j:plain

これも男女でパターンにおおきな違いがありそうですね。coplot関数で確認します。

f:id:cross_hyou:20190323110854j:plain

f:id:cross_hyou:20190323110909j:plain

男性では、20代、30代が高い行動者率ですが、女性は22歳から年齢とともに低下しています。

次は、Caring, 介護です。これも男女で違いがあるでしょう。はじめからcoplot関数を使いましょう。

f:id:cross_hyou:20190323111348j:plain

f:id:cross_hyou:20190323111441j:plain

女性の50代が一番高い行動者率です。

次は、Home_economics_and_housework, 家政・家事(料理・裁縫・家庭経営)です。

f:id:cross_hyou:20190323112026j:plain

f:id:cross_hyou:20190323112042j:plain

女性は40代が落ち込んでいます。男性は22歳のところが一番高いですが、それでも女性の47歳の行動者率よりも低いです。

次は、Humanities_social_and_natural_science, 人文・社会・自然科学(歴史・経済・数学・生物など)です。

f:id:cross_hyou:20190323112816j:plain

f:id:cross_hyou:20190323112828j:plain

女性は17歳のところ、つまり15歳から19歳がピークで、男性は22歳のところ、つまり20歳から24歳のところがピークです。

次は、Arts_and_culture, 芸術文化です。

f:id:cross_hyou:20190323113344j:plain

f:id:cross_hyou:20190323113403j:plain

女性の10代が突出して高いですね。

最後はOther, その他です。

f:id:cross_hyou:20190323113901j:plain

f:id:cross_hyou:20190323113916j:plain

男女ともに若者の行動者率が高いですね。

今回はcoplot関数を使って、男女別の年齢と行動者率の散布図を描きました。

今回は以上です。

 次回は

 

www.crosshyou.info

 

です。

以下に今回のコードを記載しておきます。

# 年齢の区分の確認
str(dfnew$Age)
table(dfnew$Age)

# 数値型の年齢の作成 始めの2文字を抽出
dfnew$Age_n <- substr(dfnew$Age, 1, 2)
str(dfnew$Age_n)

# 数値型年齢の作成 数値型に変換
dfnew$Age_n <- as.numeric(dfnew$Age_n)
str(dfnew$Age_n)

# 数値型年齢の作成 それぞれの要素に2歳を加える
dfnew$Age_n <- dfnew$Age_n +2
str(dfnew$Age_n)

# 年齢とSanple_size
plot(dfnew$Age_n, dfnew$Sample_size)
cor(dfnew$Age_n, dfnew$Sample_size)

# 年齢とPopulation
plot(dfnew$Age_n, dfnew$Population)
cor(dfnew$Age_n, dfnew$Population)

# 年齢とTotal
plot(dfnew$Age_n, dfnew$Total)
cor(dfnew$Age_n, dfnew$Total)

# 年齢とForeign_languages
plot(dfnew$Age_n, dfnew$Foreign_languages)
cor(dfnew$Age_n, dfnew$Foreign_languages)

# 年齢とEnglish_language
plot(dfnew$Age_n, dfnew$English_language)
cor(dfnew$Age_n, dfnew$English_language)

# 年齢とOther_foreign_languages
plot(dfnew$Age_n, dfnew$Other_foreign_languages)
cor(dfnew$Age_n, dfnew$Other_foreign_languages)

# 年齢とCommerce_and_business_total
plot(dfnew$Age_n, dfnew$Commerce_and_business_total)
cor(dfnew$Age_n, dfnew$Commerce_and_business_total)

# coplot関数で男女の違いを確認
coplot(Commerce_and_business_total ~ Age_n | Sex, data = dfnew)

# 年齢とComputing_etc
plot(dfnew$Age_n, dfnew$Computing_etc)
cor(dfnew$Age_n, dfnew$Computing_etc)

# coplot関数で男女の違いを確認
coplot(Computing_etc ~ Age_n | Sex, data = dfnew)

# 年齢とCommerce_and_business
plot(Commerce_and_business ~ Age_n, data = dfnew)
cor(dfnew$Age_n, dfnew$Commerce_and_business)

# coplot関数で男女の違いを確認
coplot(Commerce_and_business ~ Age_n | Sex, data = dfnew)

# 年齢とCaring, coplot関数で
coplot(Caring ~ Age_n | Sex, data = dfnew)
cor(dfnew$Age_n, dfnew$Caring)

# 年齢とHome_economics_and_housework
coplot(Home_economics_and_housework ~ Age_n | Sex, data = dfnew)
cor(dfnew$Age_n, dfnew$Home_economics_and_housework)

# 年齢とHumanities_social_and_natural_science
coplot(Humanities_social_and_natural_science ~ Age_n | Sex, data = dfnew)
cor(dfnew$Age_n, dfnew$Humanities_social_and_natural_science)

# 年齢とArts_and_culture
coplot(Arts_and_culture ~ Age_n | Sex, data = dfnew)
cor(dfnew$Age_n, dfnew$Arts_and_culture)

# 年齢とOther
coplot(Other ~ Age_n | Sex, data = dfnew)
cor(dfnew$Age_n, dfnew$Other)