library(dplyr)
library(ggplot2)
library(broom)
# employed only
acs12_emp <- acs12 %>%
filter(
age >= 30, age <= 60,
employment == "employed",
income > 0
)
# linear model
ggplot(acs12_emp, mapping = aes(x = age, y = income)) +
geom_point() +
geom_smooth(method = "lm")
lm(income ~ age, data = acs12_emp) %>%
tidy()
# log-transormed model
ggplot(acs12_emp, mapping = aes(x = age, y = log(income))) +
geom_point() +
geom_smooth(method = "lm")
lm(log(income) ~ age, data = acs12_emp) %>%
tidy()
Run the code above in your browser using DataLab