Random Coefficients Modeling

Modelos longitudinales

Gonzalo J. Muñoz

2019-07-17

Cuando tenemos datos longitudinales o medidas repetidas podemos usar un modelo multinivel donde la medida repetida está anidada dentro de los individuos.1 Aunque en psicología generalmente la unidad de análisis es el individuo también se puede tomar como unidad, por ejemplo, un país respecto del cual se tienen múltiples observaciones en el tiempo Según distintos autores (Bryk & Raudenbush, 2002; Hox, 2010) hay múltiples ventajas asociadas al uso de modelos multinivel para diseños de medidas repetidas:

La data

Para este ejemplo usaremos la data asociada al libro Multilevel Analysis: Techniques and Applications (2010) de Hox. Un archivo zip que contiene la data de Curran (1997) está disponible aquí. Específicamente usaremos el archivo CurranLong.sav. Como este es un archivo SPSS lo importaremos usando el paquete haven.

library(haven)
d1_long <- read_sav("CurranLong.sav")

Un análisis preliminar de los datos4 Esta análisis lo hice usando la base CurranData.sav que está en formato wide indica que hay un número importante de datos perdidos. Esto es usual en diseños longitudinales donde la muestra inicial se va reduciendo con cada nueva ola de medición, o donde algunos casos tiene mediciones en un momento pero no en otro.

## Loading required package: psych
##         vars   n    mean      sd  median trimmed     mad  min    max
## id         1 405 4171.94 2611.89 3915.00 4110.72 3525.62 22.0 9319.0
## anti1      2 405    1.66    1.66    1.00    1.43    1.48  0.0    9.0
## anti2      3 374    2.03    2.04    1.50    1.72    2.22  0.0   10.0
## anti3      4 297    1.83    1.90    1.00    1.55    1.48  0.0   10.0
## anti4      5 294    2.06    2.15    1.50    1.77    2.22  0.0   10.0
## read1      6 405    2.52    0.92    2.30    2.41    0.74  0.1    7.2
## read2      7 375    4.08    1.08    4.10    4.06    1.19  1.6    8.2
## read3      8 275    5.01    1.16    5.00    5.00    1.19  2.2    8.4
## read4      9 270    5.77    1.25    5.80    5.80    1.33  2.5    8.3
## kidgen    10 405    0.50    0.50    1.00    0.50    0.00  0.0    1.0
## momage    11 405   25.53    1.88   26.00   25.58    1.48 21.0   29.0
## kidage    12 405    6.93    0.64    6.83    6.91    0.86  6.0    8.0
## homecog   13 405    8.89    2.58    9.00    9.03    2.97  1.0   14.0
## homeemo   14 405    9.20    2.31   10.00    9.41    1.48  0.0   13.0
## nmis      15 405    1.35    1.79    0.00    1.10    0.00  0.0    6.0
##          range  skew kurtosis     se
## id      9297.0  0.14    -1.27 129.79
## anti1      9.0  1.10     0.99   0.08
## anti2     10.0  1.22     1.13   0.11
## anti3     10.0  1.31     2.04   0.11
## anti4     10.0  1.13     1.04   0.13
## read1      7.1  1.24     2.40   0.05
## read2      6.6  0.26     0.10   0.06
## read3      6.2  0.10     0.08   0.07
## read4      5.8 -0.24    -0.39   0.08
## kidgen     1.0  0.00    -2.00   0.02
## momage     8.0 -0.18    -0.67   0.09
## kidage     2.0  0.18    -1.30   0.03
## homecog   13.0 -0.45    -0.14   0.13
## homeemo   13.0 -0.78     0.46   0.11
## nmis       6.0  0.97    -0.55   0.09

Ecuaciones básicas

En un modelo longitudinal multinivel, el puntaje para la persona i en el tiempo t se define en el nivel inferior como.

\[Y_{ti}=\pi_{0i}+\pi_{1i}T_{ti}+\pi_{2i}X_{ti} + e_{ti}\]

donde \(T{ti}\) es un indicador para la variable tiempo y \(X_{ti}\) es otra variable predictora que va cambiando en el tiempo. Veremos más adelante un modelo que usa una variable tiempo fija (e.g., tiempo 0, 1, 2, 3) y otro que usa una variable de tiempo variable. La variación entre individuos se especifica añadiendo variables de Nivel 2, que en este caso son variables individuales y efectos cruzados de Nivel 2 con el Nivel 1. Esto es, cada individuo tiene su intercepto pero además se puede incluir una pendiente, una variable predictora de nivel individual y las interacciones entre todos los componentes del modelo.

\[\pi_{0i}=\beta_{00}+\beta_{01}Z{i}+u_{0i}\]

\[\pi_{1i}=\beta_{10}+\beta_{11}Z{i}+u_{1i}\] \[\pi_{2i}=\beta_{20}+\beta_{21}Z{i}+u_{2i}\]

Sustituyendo, el modelo para \(Y_{ti}\) sería:

\[Y_{ti}=\beta_{00}+\beta_{10}T_{ti}+\beta_{20}X_{ti}+\beta_{01}Z_i+ \beta_{11}T_{ti}Z_i+\beta_{21}X_{ti}Z_i+u_{1i}T{ti}+u_{2i}X{ti}+u_{0i}+e_{ti}\]

Intercept-only model

A continuación intentaremos reproducir los resultados de la Tabla 14.2 de Hox. El modelo inicial sólo tiene un intercepto y una variable de agrupación que es el id del individuo. Para todos los modelos usaremos maximum likelihood ya que se deduce, dado los resultados obtenidos, que ese es el método de estimación utilizado para construir la Tabla 14.2.

Es importante consignar que este modelo NO es el más indicado para evaluar el efecto de los predictores sustantivos del análisis. Más adelante usaremos como benchmark el modelo que incorpora la variable tiempo.

require(lme4)
## Loading required package: lme4
## Loading required package: Matrix
model.0<-lmer(read~1+(1|id), REML=FALSE, data=d1_long)
summary(model.0)
## Linear mixed model fit by maximum likelihood  ['lmerMod']
## Formula: read ~ 1 + (1 | id)
##    Data: d1_long
## 
##      AIC      BIC   logLik deviance df.resid 
##   5057.8   5073.4  -2525.9   5051.8     1322 
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -2.21973 -0.79677  0.02322  0.72395  2.34508 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  id       (Intercept) 0.2978   0.5458  
##  Residual             2.3903   1.5461  
## Number of obs: 1325, groups:  id, 405
## 
## Fixed effects:
##             Estimate Std. Error t value
## (Intercept)  4.11298    0.05087   80.86

Means-as-outcomes adding occasion as predictor

En el segundo modelo incluimos la variable occasion como la variable predictora, que en este caso es el tiempo en que se tomó la medición y que va de 0 (primera medición) a 3 (cuarta medición). Es crítico consignar que el valor del intercepto corresponde a la media de read en la primera medición (occasion = 0). Esta codificación es recomendable para interpretar el valor del intercepto con facilidad.

table(d1_long$occasion)
## 
##   0   1   2   3 
## 405 387 301 300
model.1<-lmer(read~occasion+(1|id), REML=FALSE, data=d1_long)
summary(model.1)
## Linear mixed model fit by maximum likelihood  ['lmerMod']
## Formula: read ~ occasion + (1 | id)
##    Data: d1_long
## 
##      AIC      BIC   logLik deviance df.resid 
##   3485.1   3505.8  -1738.5   3477.1     1321 
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.6191 -0.5208  0.0376  0.5211  3.7454 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  id       (Intercept) 0.7775   0.8817  
##  Residual             0.4604   0.6785  
## Number of obs: 1325, groups:  id, 405
## 
## Fixed effects:
##             Estimate Std. Error t value
## (Intercept)  2.70375    0.05251   51.49
## occasion     1.10134    0.01758   62.66
## 
## Correlation of Fixed Effects:
##          (Intr)
## occasion -0.406

Means- and Slopes-as-outcomes

Mismo modelo que el anterior pero ahora liberando los valores para la pendiente.

model.2<-lmer(read~occasion+(occasion|id), REML=FALSE, data=d1_long)
## Warning in checkConv(attr(opt, "derivs"), opt$par, ctrl =
## control$checkConv, : Model failed to converge with max|grad| = 0.00211389
## (tol = 0.002, component 1)
summary(model.2)
## Linear mixed model fit by maximum likelihood  ['lmerMod']
## Formula: read ~ occasion + (occasion | id)
##    Data: d1_long
## 
##      AIC      BIC   logLik deviance df.resid 
##   3383.8   3414.9  -1685.9   3371.8     1319 
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.7183 -0.5209 -0.0229  0.4803  4.1920 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev. Corr
##  id       (Intercept) 0.57102  0.7557       
##           occasion    0.07406  0.2721   0.29
##  Residual             0.34590  0.5881       
## Number of obs: 1325, groups:  id, 405
## 
## Fixed effects:
##             Estimate Std. Error t value
## (Intercept)  2.69613    0.04524   59.59
## occasion     1.11907    0.02165   51.69
## 
## Correlation of Fixed Effects:
##          (Intr)
## occasion -0.155
## convergence code: 0
## Model failed to converge with max|grad| = 0.00211389 (tol = 0.002, component 1)

Cross-level effects (time constant variable)

En el modelo 4 de la Tabla 14.2 Hox incluye la edad del niño kidage, la presencia de estimulación cognitiva homecog y su interacción respectiva con la variable tiempo occasion. Existe una pequeña discrepancia entre los resultados obtenidos aquí y los resultados reportados por Hox en relación al efecto de occasion que trasunta en una diferencia en Deviance.

model.3<-lmer(read~occasion+kidage+homecog+occasion*kidage+occasion*homecog+(occasion|id), REML=FALSE, data=d1_long)
summary(model.3)
## Linear mixed model fit by maximum likelihood  ['lmerMod']
## Formula: 
## read ~ occasion + kidage + homecog + occasion * kidage + occasion *  
##     homecog + (occasion | id)
##    Data: d1_long
## 
##      AIC      BIC   logLik deviance df.resid 
##   3199.0   3250.9  -1589.5   3179.0     1315 
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.5239 -0.5650 -0.0451  0.5122  4.8315 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev. Corr
##  id       (Intercept) 0.29757  0.5455       
##           occasion    0.05978  0.2445   0.82
##  Residual             0.34312  0.5858       
## Number of obs: 1325, groups:  id, 405
## 
## Fixed effects:
##                   Estimate Std. Error t value
## (Intercept)      -3.277579   0.422198  -7.763
## occasion          2.188649   0.236459   9.256
## kidage            0.803137   0.058288  13.779
## homecog           0.046472   0.014399   3.227
## occasion:kidage  -0.185407   0.032758  -5.660
## occasion:homecog  0.023225   0.008033   2.891
## 
## Correlation of Fixed Effects:
##             (Intr) occasn kidage homecg occsn:k
## occasion    -0.033                             
## kidage      -0.949  0.033                      
## homecog     -0.280  0.006 -0.025               
## occasin:kdg  0.033 -0.949 -0.036  0.004        
## occasn:hmcg  0.007 -0.282  0.004 -0.033 -0.023

Time constant variable vs time-varying variable

En los modelo 4 de la Tabla 14.3 Hox compara los resultados de occasion con kidage6. La variable kidage6 resulta de dos transformaciones que no están explicitadas en el capítulo pero que Hox describe en su libro. La trasformación consiste en sumarle 2, 4, y 8 años a la edad inicial del niño para que refleje la diferencia de tiempo entre administraciones de la prueba (hubiese sido mejor tener la edad exacta). En la data, el resultado de esta transformación aparece como kidagetv. La segunda transformación consiste en restarle 6 a la edad resultante para que la edad mínima sea 0; así obtenemos kidage6.

#Table 14.3
model.1b<-lmer(read~occasion+(1|id), REML=FALSE, data=d1_long)
summary(model.1b)
## Linear mixed model fit by maximum likelihood  ['lmerMod']
## Formula: read ~ occasion + (1 | id)
##    Data: d1_long
## 
##      AIC      BIC   logLik deviance df.resid 
##   3485.1   3505.8  -1738.5   3477.1     1321 
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.6191 -0.5208  0.0376  0.5211  3.7454 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  id       (Intercept) 0.7775   0.8817  
##  Residual             0.4604   0.6785  
## Number of obs: 1325, groups:  id, 405
## 
## Fixed effects:
##             Estimate Std. Error t value
## (Intercept)  2.70375    0.05251   51.49
## occasion     1.10134    0.01758   62.66
## 
## Correlation of Fixed Effects:
##          (Intr)
## occasion -0.406
model.2b<-lmer(read~occasion+(occasion|id), REML=FALSE, data=d1_long)
## Warning in checkConv(attr(opt, "derivs"), opt$par, ctrl =
## control$checkConv, : Model failed to converge with max|grad| = 0.00211389
## (tol = 0.002, component 1)
summary(model.2b)
## Linear mixed model fit by maximum likelihood  ['lmerMod']
## Formula: read ~ occasion + (occasion | id)
##    Data: d1_long
## 
##      AIC      BIC   logLik deviance df.resid 
##   3383.8   3414.9  -1685.9   3371.8     1319 
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.7183 -0.5209 -0.0229  0.4803  4.1920 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev. Corr
##  id       (Intercept) 0.57102  0.7557       
##           occasion    0.07406  0.2721   0.29
##  Residual             0.34590  0.5881       
## Number of obs: 1325, groups:  id, 405
## 
## Fixed effects:
##             Estimate Std. Error t value
## (Intercept)  2.69613    0.04524   59.59
## occasion     1.11907    0.02165   51.69
## 
## Correlation of Fixed Effects:
##          (Intr)
## occasion -0.155
## convergence code: 0
## Model failed to converge with max|grad| = 0.00211389 (tol = 0.002, component 1)
model.3a<-lmer(read~kidage6+(1|id), REML=FALSE, data=d1_long)
summary(model.3a)
## Linear mixed model fit by maximum likelihood  ['lmerMod']
## Formula: read ~ kidage6 + (1 | id)
##    Data: d1_long
## 
##      AIC      BIC   logLik deviance df.resid 
##   3421.9   3442.7  -1707.0   3413.9     1321 
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.6422 -0.5256  0.0064  0.5252  3.7158 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  id       (Intercept) 0.6482   0.8051  
##  Residual             0.4592   0.6776  
## Number of obs: 1325, groups:  id, 405
## 
## Fixed effects:
##             Estimate Std. Error t value
## (Intercept) 2.190242   0.053262   41.12
## kidage6     0.551809   0.008708   63.37
## 
## Correlation of Fixed Effects:
##         (Intr)
## kidage6 -0.549
model.4a<-lmer(read~kidage6+(kidage6|id), REML=FALSE, data=d1_long)
## Warning in checkConv(attr(opt, "derivs"), opt$par, ctrl =
## control$checkConv, : Model failed to converge with max|grad| = 0.0193925
## (tol = 0.002, component 1)
summary(model.4a)
## Linear mixed model fit by maximum likelihood  ['lmerMod']
## Formula: read ~ kidage6 + (kidage6 | id)
##    Data: d1_long
## 
##      AIC      BIC   logLik deviance df.resid 
##   3238.8   3269.9  -1613.4   3226.8     1319 
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.5910 -0.5586 -0.0356  0.5002  5.2980 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev. Corr
##  id       (Intercept) 0.16659  0.4081       
##           kidage6     0.01761  0.1327   0.87
##  Residual             0.35948  0.5996       
## Number of obs: 1325, groups:  id, 405
## 
## Fixed effects:
##             Estimate Std. Error t value
## (Intercept)  2.16429    0.03724   58.12
## kidage6      0.56432    0.01067   52.88
## 
## Correlation of Fixed Effects:
##         (Intr)
## kidage6 -0.240
## convergence code: 0
## Model failed to converge with max|grad| = 0.0193925 (tol = 0.002, component 1)

Por último, podemos comparar el ajuste de todos los modelos en un sólo paso mediante la función anova. Como señala Hox, sólo podemos usar la desviación para comparar modelos cuando uno de los modelos se obtiene añadiendo (o extrayendo) predictores del modelo de comparación. Cuando este no es el caso (como aquí) podemos usar el Akaike Information Criterion (AIC) que es la desviación más dos veces el número de parámetros estimados de un modelo. Por ejemplo, el modelo 2b tiene 8 parámetros (1 intercepto, 1 efecto de occasion, 1 residuo, 1 efecto de individuo, y 4 medidas repetidas) por lo que AIC = 3477.1 + 8 = 3485.1. Valore menores de AIC reflejan un mejor ajuste.

anova(model.1b,model.2b,model.3a,model.4a)
## Data: d1_long
## Models:
## model.1b: read ~ occasion + (1 | id)
## model.3a: read ~ kidage6 + (1 | id)
## model.2b: read ~ occasion + (occasion | id)
## model.4a: read ~ kidage6 + (kidage6 | id)
##          Df    AIC    BIC  logLik deviance   Chisq Chi Df Pr(>Chisq)    
## model.1b  4 3485.1 3505.8 -1738.5   3477.1                              
## model.3a  4 3421.9 3442.7 -1707.0   3413.9  63.163      0  < 2.2e-16 ***
## model.2b  6 3383.8 3414.9 -1685.9   3371.8  42.122      2  7.134e-10 ***
## model.4a  6 3238.8 3269.9 -1613.4   3226.8 145.045      0  < 2.2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Una ilustración con tendencias no-lineales

hist(d1_wide$kidage, breaks=35)

Se aprecia una relación cuadrática entre la edad y read

plot(d1_long$kidagetv,d1_long$read)

Agregamos el efecto cuadrático

d1_long$kidage6sq<-d1_long$kidage6*d1_long$kidage6
model.1<-lmer(read~kidage6 + kidage6sq+(1|id), REML=FALSE, data=d1_long, na.action = na.exclude)
summary(model.1)
## Linear mixed model fit by maximum likelihood  ['lmerMod']
## Formula: read ~ kidage6 + kidage6sq + (1 | id)
##    Data: d1_long
## 
##      AIC      BIC   logLik deviance df.resid 
##   3255.0   3281.0  -1622.5   3245.0     1320 
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.7977 -0.5571 -0.0472  0.5079  3.8241 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  id       (Intercept) 0.6569   0.8105  
##  Residual             0.3856   0.6210  
## Number of obs: 1325, groups:  id, 405
## 
## Fixed effects:
##              Estimate Std. Error t value
## (Intercept)  1.741647   0.061270   28.43
## kidage6      0.926830   0.028777   32.21
## kidage6sq   -0.049391   0.003642  -13.56
## 
## Correlation of Fixed Effects:
##           (Intr) kidag6
## kidage6   -0.640       
## kidage6sq  0.539 -0.961

Podemos visualizar el model.1 usado ggplot2

require(dplyr)
## Loading required package: dplyr
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
require(ggplot2)
## Loading required package: ggplot2
## Registered S3 methods overwritten by 'ggplot2':
##   method         from 
##   [.quosures     rlang
##   c.quosures     rlang
##   print.quosures rlang
## 
## Attaching package: 'ggplot2'
## The following objects are masked from 'package:psych':
## 
##     %+%, alpha
d1_long %>% 
  # save predicted values
  mutate(pred_dist = fitted(model.1)) %>% 
  # graph
  ggplot(aes(x=kidage6, y=pred_dist,group=id)) + theme_classic() +
  geom_line(size=1) 

En comparación con el model.1 el modelo model.2 incluye la edad de la madre, la estimulación cognitiva y el soporte emocional. Para obtener los mismos resultados de Hox es imprescindible centrar estas variables.

#Estoy usando el promedio de la data wide porque si no las medias estarían influidas por la presencia de medidas repetidas perdidas en la data long
mean(d1_wide$momage)
## [1] 25.53086
d1_long$momagec<-d1_long$momage-mean(d1_wide$momage)

mean(d1_wide$homecog)
## [1] 8.893827
d1_long$homecogc<-d1_long$homecog-mean(d1_wide$homecog)

mean(d1_wide$homeemo)
## [1] 9.204938
d1_long$homeemoc<-d1_long$homeemo-mean(d1_wide$homeemo)
model.2<-lmer(read~ kidage6 + kidage6sq + momagec + homecogc + homeemoc + (1|id), REML=FALSE, data=d1_long, na.action = na.exclude)
summary(model.2)
## Linear mixed model fit by maximum likelihood  ['lmerMod']
## Formula: read ~ kidage6 + kidage6sq + momagec + homecogc + homeemoc +  
##     (1 | id)
##    Data: d1_long
## 
##      AIC      BIC   logLik deviance df.resid 
##   3232.2   3273.7  -1608.1   3216.2     1317 
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.8173 -0.5510 -0.0589  0.4919  3.8358 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  id       (Intercept) 0.6016   0.7756  
##  Residual             0.3858   0.6212  
## Number of obs: 1325, groups:  id, 405
## 
## Fixed effects:
##              Estimate Std. Error t value
## (Intercept)  1.744493   0.060144  29.005
## kidage6      0.924936   0.028773  32.146
## kidage6sq   -0.049201   0.003642 -13.510
## momagec      0.053691   0.023635   2.272
## homecogc     0.050708   0.018031   2.812
## homeemoc     0.039233   0.019960   1.966
## 
## Correlation of Fixed Effects:
##           (Intr) kidag6 kdg6sq momagc homcgc
## kidage6   -0.652                            
## kidage6sq  0.549 -0.961                     
## momagec    0.013 -0.017  0.015              
## homecogc   0.001 -0.002  0.000 -0.176       
## homeemoc  -0.001 -0.001  0.003 -0.150 -0.324

En el modelo 3 se permite que la relación entre edad y read varíe por sujeto.5 Nótese que no incluyo en este modelo el término cuadrático como efecto aleatorio ya que su variabilidad es muy pequeña 0.0009338

model.3<-lmer(read~ kidage6 + kidage6sq + momagec + homecogc + homeemoc + (1+kidage6|id), REML=FALSE, data=d1_long, na.action = na.exclude)
summary(model.3)
## Linear mixed model fit by maximum likelihood  ['lmerMod']
## Formula: read ~ kidage6 + kidage6sq + momagec + homecogc + homeemoc +  
##     (1 + kidage6 | id)
##    Data: d1_long
## 
##      AIC      BIC   logLik deviance df.resid 
##   3035.4   3087.3  -1507.7   3015.4     1315 
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.1340 -0.5312 -0.0466  0.4488  5.3381 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev. Corr
##  id       (Intercept) 0.21245  0.4609       
##           kidage6     0.01859  0.1363   0.57
##  Residual             0.27807  0.5273       
## Number of obs: 1325, groups:  id, 405
## 
## Fixed effects:
##              Estimate Std. Error t value
## (Intercept)  1.748517   0.045791  38.185
## kidage6      0.920582   0.026082  35.295
## kidage6sq   -0.048115   0.003252 -14.796
## momagec      0.026514   0.019333   1.371
## homecogc     0.037024   0.014866   2.490
## homeemoc     0.003082   0.016599   0.186
## 
## Correlation of Fixed Effects:
##           (Intr) kidag6 kdg6sq momagc homcgc
## kidage6   -0.638                            
## kidage6sq  0.619 -0.921                     
## momagec    0.042 -0.046  0.043              
## homecogc   0.009 -0.015  0.017 -0.175       
## homeemoc  -0.022  0.025 -0.025 -0.145 -0.333

Por último incluimos la interacción entre la edad de la madre y el soporte emocional recibido en casa con la edad del niño para predecir read6 Al parecer hay un error en el libro de Hox ya que los valores fijos no coinciden con los resultados obtenidos en este paso

model.4<-lmer(read~ kidage6 + kidage6sq + homecogc+ kidage6*momagec + kidage6*homeemoc + (1+kidage6|id), REML=FALSE, data=d1_long, na.action = na.exclude)
summary(model.4)
## Linear mixed model fit by maximum likelihood  ['lmerMod']
## Formula: 
## read ~ kidage6 + kidage6sq + homecogc + kidage6 * momagec + kidage6 *  
##     homeemoc + (1 + kidage6 | id)
##    Data: d1_long
## 
##      AIC      BIC   logLik deviance df.resid 
##   3019.3   3081.6  -1497.6   2995.3     1313 
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.1373 -0.5436 -0.0321  0.4790  5.4759 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev. Corr
##  id       (Intercept) 0.21055  0.4589       
##           kidage6     0.01614  0.1270   0.64
##  Residual             0.27975  0.5289       
## Number of obs: 1325, groups:  id, 405
## 
## Fixed effects:
##                   Estimate Std. Error t value
## (Intercept)       1.748018   0.045734  38.221
## kidage6           0.920501   0.025936  35.491
## kidage6sq        -0.048126   0.003243 -14.839
## homecogc          0.037640   0.014857   2.534
## momagec           0.017351   0.019744   0.879
## homeemoc         -0.009362   0.016973  -0.552
## kidage6:momagec   0.011844   0.005389   2.198
## kidage6:homeemoc  0.014925   0.004356   3.426
## 
## Correlation of Fixed Effects:
##             (Intr) kidag6 kdg6sq homcgc momagc homemc kdg6:m
## kidage6     -0.638                                          
## kidage6sq    0.619 -0.926                                   
## homecogc     0.010 -0.015  0.017                            
## momagec      0.049 -0.054  0.051 -0.172                     
## homeemoc    -0.027  0.031 -0.031 -0.327 -0.146              
## kidag6:mmgc -0.042  0.045 -0.045  0.001 -0.206  0.040       
## kidag6:hmmc  0.026 -0.032  0.033  0.008  0.042 -0.211 -0.222