packagea loading
library(panelr)
library(tidyverse)
library(DataExplorer)
Prepare the dataset
data("teen_poverty")
teen_poverty
## # A tibble: 1,151 x 28
## id pov1 mother1 spouse1 inschool1 hours1 pov2 mother2 spouse2
## <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 22 1 0 0 1 21 0 0 0
## 2 75 0 0 0 1 8 0 0 0
## 3 92 0 0 0 1 30 0 0 0
## 4 96 0 0 0 0 19 1 1 0
## 5 141 0 0 0 1 0 0 0 0
## 6 161 0 0 0 1 0 0 0 0
## 7 220 0 0 0 1 6 0 0 0
## 8 229 0 0 0 1 0 1 0 0
## 9 236 0 0 0 1 0 0 0 0
## 10 240 0 0 0 1 18 1 0 0
## # ... with 1,141 more rows, and 19 more variables: inschool2 <dbl>,
## # hours2 <dbl>, pov3 <dbl>, mother3 <dbl>, spouse3 <dbl>,
## # inschool3 <dbl>, hours3 <dbl>, pov4 <dbl>, mother4 <dbl>,
## # spouse4 <dbl>, inschool4 <dbl>, hours4 <dbl>, age <dbl>, black <dbl>,
## # pov5 <dbl>, mother5 <dbl>, spouse5 <dbl>, inschool5 <dbl>,
## # hours5 <dbl>
mumming
long_panel(teen_poverty, label_location = "end", periods = 1:5)
## # Panel data: 5,755 x 9
## # entities: id [1151]
## # wave variable: wave [1, 2, 3, ... (5 waves)]
## id wave age black pov mother spouse inschool hours
## <fct> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 22 1 16 0 1 0 0 1 21
## 2 22 2 16 0 0 0 0 1 15
## 3 22 3 16 0 0 0 0 1 3
## 4 22 4 16 0 0 0 0 1 0
## 5 22 5 16 0 0 0 0 1 0
## 6 75 1 17 0 0 0 0 1 8
## 7 75 2 17 0 0 0 0 1 0
## 8 75 3 17 0 0 0 0 1 0
## 9 75 4 17 0 0 0 0 1 4
## 10 75 5 17 0 1 0 0 1 0
## # ... with 5,745 more rows
teen <- long_panel(teen_poverty, label_location = "end", periods = 1:5)
teen
## # Panel data: 5,755 x 9
## # entities: id [1151]
## # wave variable: wave [1, 2, 3, ... (5 waves)]
## id wave age black pov mother spouse inschool hours
## <fct> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 22 1 16 0 1 0 0 1 21
## 2 22 2 16 0 0 0 0 1 15
## 3 22 3 16 0 0 0 0 1 3
## 4 22 4 16 0 0 0 0 1 0
## 5 22 5 16 0 0 0 0 1 0
## 6 75 1 17 0 0 0 0 1 8
## 7 75 2 17 0 0 0 0 1 0
## 8 75 3 17 0 0 0 0 1 0
## 9 75 4 17 0 0 0 0 1 4
## 10 75 5 17 0 1 0 0 1 0
## # ... with 5,745 more rows
Analysis
model <- wbm(hours ~ spouse + mother + inschool, data = teen)
summary(model)
## MODEL INFO:
## Entities: 1151
## Time periods: 1-5
## Dependent variable: hours
## Model type: Linear mixed effects
## Specification: within-between
##
## MODEL FIT:
## AIC = 45755.31, BIC = 45815.23
## Pseudo-R² (fixed effects) = 0.15
## Pseudo-R² (total) = 0.35
## Entity ICC = 0.23
##
## WITHIN EFFECTS:
## --------------------------------------------------------
## Est. S.E. t val. d.f. p
## -------------- -------- ------ -------- --------- ------
## spouse -1.22 0.83 -1.47 4601.00 0.14
## mother -6.52 0.74 -8.76 4601.00 0.00
## inschool -11.09 0.47 -23.65 4601.00 0.00
## --------------------------------------------------------
##
## BETWEEN EFFECTS:
## ---------------------------------------------------------------
## Est. S.E. t val. d.f. p
## --------------------- -------- ------ -------- --------- ------
## (Intercept) 20.38 0.76 26.87 1147.00 0.00
## imean(spouse) -1.53 1.29 -1.18 1147.00 0.24
## imean(mother) -9.83 0.90 -10.95 1147.00 0.00
## imean(inschool) -15.23 0.94 -16.27 1147.00 0.00
## ---------------------------------------------------------------
##
## p values calculated using Satterthwaite d.f.
##
## RANDOM EFFECTS:
## ------------------------------------
## Group Parameter Std. Dev.
## ---------- ------------- -----------
## id (Intercept) 6.504
## Residual 11.74
## ------------------------------------
Analysis
model <- wbm(hours ~ spouse + mother + inschool | black, data = teen)
summary(model)
## MODEL INFO:
## Entities: 1151
## Time periods: 1-5
## Dependent variable: hours
## Model type: Linear mixed effects
## Specification: within-between
##
## MODEL FIT:
## AIC = 45755.79, BIC = 45822.37
## Pseudo-R² (fixed effects) = 0.15
## Pseudo-R² (total) = 0.35
## Entity ICC = 0.23
##
## WITHIN EFFECTS:
## --------------------------------------------------------
## Est. S.E. t val. d.f. p
## -------------- -------- ------ -------- --------- ------
## spouse -1.22 0.83 -1.47 4601.00 0.14
## mother -6.52 0.74 -8.76 4601.00 0.00
## inschool -11.09 0.47 -23.65 4601.00 0.00
## --------------------------------------------------------
##
## BETWEEN EFFECTS:
## ---------------------------------------------------------------
## Est. S.E. t val. d.f. p
## --------------------- -------- ------ -------- --------- ------
## (Intercept) 20.60 0.79 26.07 1146.00 0.00
## imean(spouse) -1.67 1.30 -1.29 1146.00 0.20
## imean(mother) -9.65 0.92 -10.54 1146.00 0.00
## imean(inschool) -15.15 0.94 -16.13 1146.00 0.00
## black -0.52 0.51 -1.01 1146.00 0.31
## ---------------------------------------------------------------
##
## p values calculated using Satterthwaite d.f.
##
## RANDOM EFFECTS:
## ------------------------------------
## Group Parameter Std. Dev.
## ---------- ------------- -----------
## id (Intercept) 6.504
## Residual 11.74
## ------------------------------------
Analysis
model <- wbm(hours ~ spouse + mother + inschool | black | black * mother, data = teen)
summary(model)
## MODEL INFO:
## Entities: 1151
## Time periods: 1-5
## Dependent variable: hours
## Model type: Linear mixed effects
## Specification: within-between
##
## MODEL FIT:
## AIC = 45735.34, BIC = 45808.58
## Pseudo-R² (fixed effects) = 0.15
## Pseudo-R² (total) = 0.35
## Entity ICC = 0.24
##
## WITHIN EFFECTS:
## --------------------------------------------------------
## Est. S.E. t val. d.f. p
## -------------- -------- ------ -------- --------- ------
## spouse -0.87 0.83 -1.05 4600.00 0.30
## mother -10.78 1.21 -8.92 4600.00 0.00
## inschool -11.01 0.47 -23.51 4600.00 0.00
## --------------------------------------------------------
##
## BETWEEN EFFECTS:
## ---------------------------------------------------------------
## Est. S.E. t val. d.f. p
## --------------------- -------- ------ -------- --------- ------
## (Intercept) 20.60 0.79 26.07 1146.00 0.00
## imean(spouse) -1.67 1.30 -1.29 1146.00 0.20
## imean(mother) -9.65 0.92 -10.54 1146.00 0.00
## imean(inschool) -15.15 0.94 -16.13 1146.00 0.00
## black -0.52 0.51 -1.01 1146.00 0.31
## ---------------------------------------------------------------
##
## CROSS-LEVEL INTERACTIONS:
## ----------------------------------------------------------
## Est. S.E. t val. d.f. p
## ------------------ ------ ------ -------- --------- ------
## mother:black 6.34 1.42 4.47 4600.00 0.00
## ----------------------------------------------------------
##
## p values calculated using Satterthwaite d.f.
##
## RANDOM EFFECTS:
## ------------------------------------
## Group Parameter Std. Dev.
## ---------- ------------- -----------
## id (Intercept) 6.512
## Residual 11.72
## ------------------------------------