library(tidyverse)
## Warning: package 'tidyverse' was built under R version 3.6.3
## -- Attaching packages ---------------------------------------------------------------------------- tidyverse 1.3.0 --
## v ggplot2 3.2.1     v purrr   0.3.3
## v tibble  2.1.3     v dplyr   0.8.3
## v tidyr   1.0.0     v stringr 1.4.0
## v readr   1.3.1     v forcats 0.4.0
## -- Conflicts ------------------------------------------------------------------------------- tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
library(faraway)
## Warning: package 'faraway' was built under R version 3.6.3
library(lme4)
## Warning: package 'lme4' was built under R version 3.6.2
## Loading required package: Matrix
## Warning: package 'Matrix' was built under R version 3.6.3
## 
## Attaching package: 'Matrix'
## The following objects are masked from 'package:tidyr':
## 
##     expand, pack, unpack

Example for Discussion_14.

Reading data psid.txt:

psid <- read.delim("./psid.txt", header = TRUE)
attach(psid)
head(psid)
##   age educ sex income year person
## 1  31   12   M   6000   68      1
## 2  31   12   M   5300   69      1
## 3  31   12   M   5200   70      1
## 4  31   12   M   6900   71      1
## 5  31   12   M   7500   72      1
## 6  31   12   M   8000   73      1

ggplot of 20 subjects revealed that some individuals have a slowly increasing income, specially if having steady employment in the same job.

psid20 <- filter(psid, person <= 20)
library(ggplot2)
ggplot(psid20, aes(x=year, y=income))+geom_line()+facet_wrap(~ person)

I found this one specially interesting, because it shows pattern of difference between men’s and women’s incomes.

ggplot(psid20, aes(x=year, y=income+100, group=person)) +geom_line() + facet_wrap(~ sex) + scale_y_log10()