Data wrangling: In-Class Exercise 4

2020-Spring [Data Management] Instructor: SHEU, Ching-Fan

CHIU, Ming-Tzu

2020-04-13

The data set Vocab{car} gives observations on gender, education and vocabulary, from respondents to U.S. General Social Surveys, 1972-2004. Summarize the relationship between education and vocabulary over the years by gender.

讀資料

library(car)
#> Loading required package: carData
dta <- Vocab
str(dta)
#> 'data.frame':    30351 obs. of  4 variables:
#>  $ year      : num  1974 1974 1974 1974 1974 ...
#>  $ sex       : Factor w/ 2 levels "Female","Male": 2 2 1 1 1 2 2 2 1 1 ...
#>  $ education : num  14 16 10 10 12 16 17 10 12 11 ...
#>  $ vocabulary: num  9 9 9 5 8 8 9 5 3 5 ...
#>  - attr(*, "na.action")= 'omit' Named int  1 2 3 4 5 6 7 8 9 10 ...
#>   ..- attr(*, "names")= chr  "19720001" "19720002" "19720003" "19720004" ...

使用 Lattice 畫圖

library(lattice)
xyplot(vocabulary ~ education | sex, 
       group = year, 
       data = dta, 
       type = "r", 
       xlab = "Education",
       ylab = "Vocabulary", 
       main = "Education vs Vocabulary over Years in Gender", 
       auto.key = list(column=10))

由結果可之,女性的教育與字彙量迴歸關係在 1974 – 2016 間的動盪較男性劇烈。