Nested mixed model in R

reference

# load package
library(nlme)
# read in data
setwd("C:\\Users\\hed2\\OneDrive - National Institutes of Health\\Mixed model by SAS and R")
DF <- read.csv("Oxide.csv")
# specific the reference group
DF$Source=as.factor(DF$Source) 
DF <- within(DF, Source<- relevel(Source, ref = 2))
# nested
# using lme package
model2 = lme(Thickness ~ Source  , 
           random = (~ 1   |Lot/Wafer), data = DF, method= "REML")  #wafer nested into lot
summary(model2)
## Linear mixed-effects model fit by REML
##   Data: DF 
##        AIC      BIC    logLik
##   456.4779 467.7203 -223.2389
## 
## Random effects:
##  Formula: ~1 | Lot
##         (Intercept)
## StdDev:    10.94954
## 
##  Formula: ~1 | Wafer %in% Lot
##         (Intercept) Residual
## StdDev:      5.9888 3.545341
## 
## Fixed effects:  Thickness ~ Source 
##                 Value Std.Error DF  t-value p-value
## (Intercept) 2005.1944  5.771575 48 347.4259  0.0000
## Source1      -10.0833  8.162240  6  -1.2354  0.2629
##  Correlation: 
##         (Intr)
## Source1 -0.707
## 
## Standardized Within-Group Residuals:
##        Min         Q1        Med         Q3        Max 
## -1.8864255 -0.5139735  0.1177649  0.5346573  1.7803582 
## 
## Number of Observations: 72
## Number of Groups: 
##            Lot Wafer %in% Lot 
##              8             24
# using lme4 package
library("lme4")
## Loading required package: Matrix
## 
## Attaching package: 'lme4'
## The following object is masked from 'package:nlme':
## 
##     lmList
model3 = lmer(Thickness ~ Source+(1   | Lot/Wafer), data=DF) #wafer nested into lot
summary(model3)
## Linear mixed model fit by REML ['lmerMod']
## Formula: Thickness ~ Source + (1 | Lot/Wafer)
##    Data: DF
## 
## REML criterion at convergence: 446.5
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -1.8864 -0.5140  0.1178  0.5347  1.7804 
## 
## Random effects:
##  Groups    Name        Variance Std.Dev.
##  Wafer:Lot (Intercept)  35.87    5.989  
##  Lot       (Intercept) 119.89   10.950  
##  Residual               12.57    3.545  
## Number of obs: 72, groups:  Wafer:Lot, 24; Lot, 8
## 
## Fixed effects:
##             Estimate Std. Error t value
## (Intercept) 2005.194      5.772 347.426
## Source1      -10.083      8.162  -1.235
## 
## Correlation of Fixed Effects:
##         (Intr)
## Source1 -0.707
# nested
# using lme package
model2 = lme(Thickness ~ Source  , 
           random = (~ 1 +Source  |Lot/Wafer), data = DF, method= "REML")  #wafer nested into lot
summary(model2)
## Linear mixed-effects model fit by REML
##   Data: DF 
##        AIC      BIC    logLik
##   461.7463 481.9828 -221.8732
## 
## Random effects:
##  Formula: ~1 + Source | Lot
##  Structure: General positive-definite, Log-Cholesky parametrization
##             StdDev   Corr  
## (Intercept) 14.90295 (Intr)
## Source1     12.23376 -0.971
## 
##  Formula: ~1 + Source | Wafer %in% Lot
##  Structure: General positive-definite, Log-Cholesky parametrization
##             StdDev   Corr  
## (Intercept) 6.139956 (Intr)
## Source1     6.006845 -0.539
## Residual    3.545341       
## 
## Fixed effects:  Thickness ~ Source 
##                 Value Std.Error DF   t-value p-value
## (Intercept) 2005.1944  7.682136 48 261.02044  0.0000
## Source1      -10.0833  8.162243  6  -1.23536  0.2629
##  Correlation: 
##         (Intr)
## Source1 -0.941
## 
## Standardized Within-Group Residuals:
##         Min          Q1         Med          Q3         Max 
## -1.90163456 -0.52516955  0.08334173  0.55620990  1.76514940 
## 
## Number of Observations: 72
## Number of Groups: 
##            Lot Wafer %in% Lot 
##              8             24
# using lme4 package
model3 = lmer(Thickness ~ Source+(1 +Source  | Lot/Wafer), data=DF) #wafer nested into lot
summary(model3)
## Linear mixed model fit by REML ['lmerMod']
## Formula: Thickness ~ Source + (1 + Source | Lot/Wafer)
##    Data: DF
## 
## REML criterion at convergence: 443.7
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -1.90163 -0.52517  0.08334  0.55621  1.76515 
## 
## Random effects:
##  Groups    Name        Variance  Std.Dev. Corr 
##  Wafer:Lot (Intercept)  37.69812  6.1399       
##            Source1       0.09436  0.3072  -1.00
##  Lot       (Intercept) 222.08656 14.9026       
##            Source1     195.45615 13.9806  -0.96
##  Residual               12.56948  3.5453       
## Number of obs: 72, groups:  Wafer:Lot, 24; Lot, 8
## 
## Fixed effects:
##             Estimate Std. Error t value
## (Intercept) 2005.194      7.682 261.027
## Source1      -10.083      8.162  -1.235
## 
## Correlation of Fixed Effects:
##         (Intr)
## Source1 -0.941

Nested mixed model in SAS

# /*nested*/
# PROC MIXED DATA=Oxide METHOD=REML;
# CLASS Lot    Wafer    Source  ;
# MODEL Thickness  = Source   /solution;
# RANDOM   int  /subject=Lot;
# RANDOM   int  / subject= Wafer(Lot)    type=un ;  /*wafer nested into lot*/
# RUN; QUIT; 

output

# Solution for Fixed Effects 
# Effect Source Estimate Standard
# Error DF t Value Pr > |t| 
# Intercept   2005.19 5.7716 6 347.43 <.0001 
# Source 1 -10.0833 8.1622 48 -1.24 0.2227 
# Source 2 0 . . . .
# /*nested*/
# PROC MIXED DATA=Oxide METHOD=REML;
# CLASS Lot    Wafer    Source  ;
# MODEL Thickness  = Source   /solution;
# RANDOM   int Source/subject=Lot;
# RANDOM   int Source/ subject= Wafer(Lot)    type=un ;  /*wafer nested into lot*/
# RUN; QUIT; 

output

# Solution for Fixed Effects 
# Effect Source Estimate Standard
# Error DF t Value Pr > |t| 
# Intercept   2005.19 5.7596 0 348.15 . 
# Source 1 -10.0833 8.1143 0 -1.24 . 
# Source 2 0 . . . .

Summary: