njtierney / brolgar

BRowse Over Longitudinal Data Graphically and Analytically in R
http://brolgar.njtierney.com/
Other
109 stars 10 forks source link

Explore two models with brolgar #69

Open njtierney opened 5 years ago

njtierney commented 5 years ago

Explore fitting a model and exploring the individual observations.

For example, imagine fitting two models:

  1. Linear mixed effects model predicting ln_wages - fitting a slope and intercept for each individual.
  2. As for 1., but with a fixed effect for education.

When comparing models, the instinct might be to do something like:

But what about comparing and exploring what the model predictions mean at the individual level?

njtierney commented 4 years ago

Here is some content from the mixed models vignette that is getting moved here for the time being.

wages_fit_int <- lmer(ln_wages ~ xp + ged + (xp |id), data = wages)

We can use the tools from modelr to add predictions and residuals to the data

wages_aug <- wages %>%
  add_predictions(wages_fit_int, var = "pred_int") %>%
  add_residuals(wages_fit_int, var = "res_int")
# Exploring changes across models

We can also explore how the data match the model when we change the model

```{r}
wages_fit_int_slope <- lmer(ln_wages ~ xp + ged + (1 + xp |id), 
                            data = wages)

wages_aug_int_slope <- wages_aug %>%
  add_predictions(wages_fit_int_slope, var = "pred_int_slope") %>%
  add_residuals(wages_fit_int_slope, var = "res_int_slope")