1 a) the sires are modelled as random effects because each individual sire could have characteristics unique to itself. They are random smaple of all possible sires.
b)y_ij=u+a_i+e_ij where y_ij is the wiehgt gained from each sire, u is the mean for the popultaion, a_i is the random effect, and e_ij is the random error.
install.packages("lme4", repos= "https://CRAN.R-project.org/package=lme4" )
## Installing package into 'C:/Users/aleks/OneDrive/Documents/R/win-library/3.6'
## (as 'lib' is unspecified)
## Warning: unable to access index for repository https://CRAN.R-project.org/package=lme4/src/contrib:
## cannot open URL 'https://CRAN.R-project.org/package=lme4/src/contrib/PACKAGES'
## Warning: package 'lme4' is not available (for R version 3.6.1)
## Warning: unable to access index for repository https://CRAN.R-project.org/package=lme4/bin/windows/contrib/3.6:
## cannot open URL 'https://CRAN.R-project.org/package=lme4/bin/windows/contrib/3.6/PACKAGES'
library(lme4)
## Loading required package: Matrix
sires=c("A","B","C","D","A","B","C","D","A","B","C","D","A","B","C","D","A","B","C","D","A","B","C","D")
weight=c(1.46,1.17,0.98,0.95,1.23,1.08,1.06,1.10,1.12,1.20,1.15,1.07,1.23,1.08,1.11,1.11,1.02,1.01,0.83,0.89,1.15,0.86,0.86,1.12)
calves=data.frame(sires,weight)
calves
## sires weight
## 1 A 1.46
## 2 B 1.17
## 3 C 0.98
## 4 D 0.95
## 5 A 1.23
## 6 B 1.08
## 7 C 1.06
## 8 D 1.10
## 9 A 1.12
## 10 B 1.20
## 11 C 1.15
## 12 D 1.07
## 13 A 1.23
## 14 B 1.08
## 15 C 1.11
## 16 D 1.11
## 17 A 1.02
## 18 B 1.01
## 19 C 0.83
## 20 D 0.89
## 21 A 1.15
## 22 B 0.86
## 23 C 0.86
## 24 D 1.12
2c)
modC<-lmer(weight~1+(1|sires), data=calves)
2d)
modD<-lm(weight~1, data=calves)
2e)
anova(modC, modD)
## refitting model(s) with ML (instead of REML)
## Data: calves
## Models:
## modD: weight ~ 1
## modC: weight ~ 1 + (1 | sires)
## Df AIC BIC logLik deviance Chisq Chi Df Pr(>Chisq)
## modD 2 -22.898 -20.542 13.449 -26.898
## modC 3 -22.095 -18.561 14.047 -28.095 1.1962 1 0.2741
It seems it was not worth making sires random effect as p vlaue is high at .2.
2f)
summary(modC)
## Linear mixed model fit by REML ['lmerMod']
## Formula: weight ~ 1 + (1 | sires)
## Data: calves
##
## REML criterion at convergence: -23.5
##
## Scaled residuals:
## Min 1Q Median 3Q Max
## -1.6639 -0.5601 0.1081 0.5645 2.3859
##
## Random effects:
## Groups Name Variance Std.Dev.
## sires (Intercept) 0.005078 0.07126
## Residual 0.015945 0.12627
## Number of obs: 24, groups: sires, 4
##
## Fixed effects:
## Estimate Std. Error t value
## (Intercept) 1.07667 0.04397 24.48
The variance is 0.005078 for sires, 0.015945 for residuals
2g)
confint(modC)
## Computing profile confidence intervals ...
## 2.5 % 97.5 %
## .sig01 0.00000000 0.1795777
## .sigma 0.09534633 0.1783855
## (Intercept) 0.97994356 1.1733897