1 In class Exercise1

1.2 see it

## 'data.frame':    12 obs. of  2 variables:
##  $ family    : int  1 1 1 2 2 2 2 3 3 4 ...
##  $ liberalism: int  25 29 34 18 21 21 26 31 35 30 ...
##   family liberalism
## 1      1         25
## 2      1         29
## 3      1         34
## 4      2         18
## 5      2         21
## 6      2         21

1.4 fixed and random effects

##             Df Sum Sq Mean Sq F value  Pr(>F)   
## family       3 244.33   81.44   7.726 0.00951 **
## Residuals    8  84.33   10.54                   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Error: family
##           Df Sum Sq Mean Sq F value Pr(>F)
## Residuals  3  244.3   81.44               
## 
## Error: Within
##           Df Sum Sq Mean Sq F value Pr(>F)
## Residuals  8  84.33   10.54

1.5 regression and anova

## 
## Call:
## lm(formula = liberalism ~ family - 1, data = dta)
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
## -4.333 -1.000 -0.500  1.500  4.667 
## 
## Coefficients:
##         Estimate Std. Error t value Pr(>|t|)    
## family1   29.333      1.875   15.65 2.77e-07 ***
## family2   21.500      1.623   13.24 1.01e-06 ***
## family3   33.000      2.296   14.37 5.36e-07 ***
## family4   30.667      1.875   16.36 1.96e-07 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 3.247 on 8 degrees of freedom
## Multiple R-squared:  0.9911, Adjusted R-squared:  0.9867 
## F-statistic: 223.6 on 4 and 8 DF,  p-value: 3.065e-08
## Analysis of Variance Table
## 
## Response: liberalism
##           Df Sum Sq Mean Sq F value    Pr(>F)    
## family     4 9429.7 2357.42  223.63 3.065e-08 ***
## Residuals  8   84.3   10.54                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## Linear mixed model fit by REML ['lmerMod']
## Formula: liberalism ~ 1 + (1 | family)
##    Data: dta
## 
## REML criterion at convergence: 65.4
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -1.3116 -0.3850 -0.1135  0.5998  1.4772 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  family   (Intercept) 21.92    4.682   
##  Residual             10.48    3.238   
## Number of obs: 12, groups:  family, 4
## 
## Fixed effects:
##             Estimate Std. Error t value
## (Intercept)    28.49       2.53   11.26
## $family
##   (Intercept)
## 1   0.7271474
## 2  -6.2437983
## 3   3.6394896
## 4   1.8771613
## 
## with conditional variances for "family"
##    ID       fe         re     pred
## 1 S11 28.49027  0.7271474 29.21742
## 2 S12 28.49027  0.7271474 29.21742
## 3 S13 28.49027  0.7271474 29.21742
## 4 S14 28.49027 -6.2437983 22.24648
## 5 S15 28.49027 -6.2437983 22.24648
## 6 S16 28.49027 -6.2437983 22.24648
##     ID family liberalism    g_ave  grp_ave grp_ave_uw       fe         re
## 1  S11      1         25 27.66667 29.33333     28.625 28.49027  0.7271474
## 2  S12      1         29 27.66667 29.33333     28.625 28.49027  0.7271474
## 3  S13      1         34 27.66667 29.33333     28.625 28.49027  0.7271474
## 4  S14      2         18 27.66667 21.50000     28.625 28.49027 -6.2437983
## 5  S15      2         21 27.66667 21.50000     28.625 28.49027 -6.2437983
## 6  S16      2         21 27.66667 21.50000     28.625 28.49027 -6.2437983
## 7  S17      2         26 27.66667 21.50000     28.625 28.49027 -6.2437983
## 8  S18      3         31 27.66667 33.00000     28.625 28.49027  3.6394896
## 9  S19      3         35 27.66667 33.00000     28.625 28.49027  3.6394896
## 10 S20      4         30 27.66667 30.66667     28.625 28.49027  1.8771613
## 11 S21      4         30 27.66667 30.66667     28.625 28.49027  1.8771613
## 12 S22      4         32 27.66667 30.66667     28.625 28.49027  1.8771613
##        pred
## 1  29.21742
## 2  29.21742
## 3  29.21742
## 4  22.24648
## 5  22.24648
## 6  22.24648
## 7  22.24648
## 8  32.12976
## 9  32.12976
## 10 30.36744
## 11 30.36744
## 12 30.36744

1.6 The end

The correlation between any two liberalism ratings from the same family is 21.919/(21.919+10.482) = 0.677

The best linear unbiased prediction of the random effect for family 4 is (30.667 - 28.49)*(21.919/(21.919+(10.482/3))) = 1.877

The predicted mean for family 4 is 28.49 + 1.877 = 30.368 < 30.667