SPIDA 2010: Longitudinal Models: Additional material

From MathWiki

Fixed effects regression model

R:
> 
## Fixed model
 
> fits <- lmList(distance ~ age | Subject,dd)
> summary(fits)
Call:
  Model: distance ~ age | Subject 
   Data: dd 
Coefficients:
   (Intercept) 
    Estimate Std. Error   t value     Pr(>|t|)
M16    16.95   3.288173 5.1548379 3.695247e-06
M05    13.65   3.288173 4.1512411 1.181678e-04
M02    14.85   3.288173 4.5161854 3.458934e-05
M11    20.05   3.288173 6.0976106 1.188838e-07
. . .
F02    14.20   3.288173 4.3185072 6.763806e-05
F08    21.45   3.288173 6.5233789 2.443813e-08
F03    14.40   3.288173 4.3793313 5.509579e-05
F04    19.65   3.288173 5.9759625 1.863600e-07
F11    18.95   3.288173 5.7630783 4.078189e-07
   age 
    Estimate Std. Error   t value     Pr(>|t|)
M16    0.550  0.2929338 1.8775576 6.584707e-02
M05    0.850  0.2929338 2.9016799 5.361639e-03
M02    0.775  0.2929338 2.6456493 1.065760e-02
M11    0.325  0.2929338 1.1094659 2.721458e-01
M07    0.800  0.2929338 2.7309929 8.511442e-03
. . .
F02    0.800  0.2929338 2.7309929 8.511442e-03
F08    0.175  0.2929338 0.5974047 5.527342e-01
F03    0.850  0.2929338 2.9016799 5.361639e-03
F04    0.475  0.2929338 1.6215270 1.107298e-01
F11    0.675  0.2929338 2.3042752 2.508117e-02

Residual standard error: 1.310040 on 54 degrees of freedom

> coef(fits)
    (Intercept)   age
M16       16.95 0.550
M05       13.65 0.850
M02       14.85 0.775
M11       20.05 0.325
M07       14.95 0.800
. . .
F02       14.20 0.800
F08       21.45 0.175
F03       14.40 0.850
F04       19.65 0.475
F11       18.95 0.675
 
See wiki for details 
Or using OLS with a interaction between age and Subject

> fit <- lm( distance ~ age * Subject, dd)
> summary(fit)

Call:
lm(formula = distance ~ age * Subject, data = dd)

Residuals:
    Min      1Q  Median      3Q     Max 
-3.6500 -0.4500  0.0500  0.4125  4.9000 

Coefficients:
               Estimate Std. Error t value Pr(>|t|)    
(Intercept)    16.76111    0.63281  26.487  < 2e-16 
age             0.66019    0.05638  11.711  < 2e-16 
Subject.L       5.07509    3.28817   1.543  0.12857    
Subject.Q       0.59068    3.28817   0.180  0.85811    
. . .
Subject^23      7.78686    3.28817   2.368  0.02149 
Subject^24      3.01910    3.28817   0.918  0.36261    
Subject^25     -0.03581    3.28817  -0.011  0.99135    
Subject^26     -6.88594    3.28817  -2.094  0.04095 
age:Subject.L  -0.49787    0.29293  -1.700  0.09496 
age:Subject.Q  -0.19737    0.29293  -0.674  0.50334    
age:Subject.C   0.69724    0.29293   2.380  0.02086 
age:Subject^4   0.18177    0.29293   0.621  0.53752    
. . . . . 
age:Subject^23 -0.58904    0.29293  -2.011  0.04935  
age:Subject^24 -0.10247    0.29293  -0.350  0.72785    
age:Subject^25 -0.21890    0.29293  -0.747  0.45814    
age:Subject^26  0.39963    0.29293   1.364  0.17815    
---

Residual standard error: 1.31 on 54 degrees of freedom
Multiple R-squared: 0.899,      Adjusted R-squared: 0.7999 
F-statistic:  9.07 on 53 and 54 DF,  p-value: 6.568e-14
 
> predict( fit)
    1     2     3     4     5     6     7     8     9    10 
24.90 26.80 28.70 30.60 21.05 22.60 24.15 25.70 22.00 23.50 
   11    12    13    14    15    16    17    18    19    20 
25.00 26.50 26.10 26.45 26.80 27.15 20.45 22.15 23.85 25.55 

. . . .
  101   102   103   104   105   106   107   108 
17.15 18.05 18.95 19.85 24.35 25.70 27.05 28.40 

> dd$distance.ols <- predict( fit )

> some( dd)
Grouped Data: distance ~ age | Subject
    distance age Subject    Sex Sub distance.ols
3       29.0  12     M01   Male M01        28.70
28      26.5  14     M07   Male M07        26.15
45      21.5   8     M12   Male M12        21.25
60      30.0  14     M15   Male M15        29.25
65      21.0   8     F01 Female F01        20.25
78      24.5  10     F04 Female F04        24.40
83      22.5  12     F05 Female F05        22.90
93      23.0   8     F08 Female F08        22.85