-1- Workshop 93a: Randomized block designs Murray Logan November 23, 16 Table of contents 1 Randomized Block (RCB) designs 1 2 Worked Examples 12 1 Randomized Block (RCB) designs 11 RCB design Simple Randomized block design 12 RCB design y ij = µ + β i + α j + ε ij µ - the mean of the first treatment group
-2- β - the random (Block) effect α - the main within Block effect eg abundance = base + block + treatment 13 Repeated measures designs 0 0 T0 00 00 0 0 T0 00 00 0 0 T0 00 00 0 0 T0 00 00 14 Assumptions Normality, homogeneity of variance No Block by within-block interaction
-3- Q4 Q1 Q4 Q1 Q3 Q3 Q4 Q3 Q2 Q2 Q1 Q2 0 0 0 0 T0 T0 00 00 00 00 Q4 Q3 Q1 Q2 Q3 Q4 Q1 Q2 Q4 Q2 Q1 Q3 0 0 0 0 T0 T0 00 00 00 00 15 Assumptions Normality, homogeneity of variance No Block by within-block interaction Independence (variance-covariance structure) 16 Var-cov structure T1 T2 T3 T4 T1 015 000 000 000 T2 000 015 000 000 T3 000 000 015 000 T4 000 000 000 015 T1 T2 T3 T4 Block B Block A T1 T2 T3 T4 Block D Block C T1 T2 T3 T4 T1 015 005 005 005 T2 005 015 005 005 T3 005 005 015 005 T4 005 005 005 015 Subject C Subject B Subject A T1 T2 T3 T4 T1 015 060 030 010 T2 060 015 060 030 T3 030 060 015 060 T4 010 030 060 015 10 30 40 Time (mins)
-4-17 Assumptions Normality, homogeneity of variance No Block by within-block interaction Independence (variance-covariance structure) RCB - usually met Repeated measures - rarely met 18 Example > datarcb1 <- readcsv('/data/datarcb1csv', stripwhite=true) > head(datarcb1) y A Block 1 3739761 A B1 2 6147033 B B1 3 7807370 C B1 4 3059803 A B2 5 5900035 B B2 6 7672575 C B2 19 Exploratory data analysis Normality and homogeneity of variance > boxplot(y~a, datarcb1) 40 60 80 100 A B C 110 Exploratory data analysis No block by within-block interaction
-5- > library(ggplot2) > ggplot(datarcb1, aes(y=y, x=a, group=block,color=block)) + + geom_line() + + guides(color=guide_legend(ncol=3)) 100 Block B1 B B31 B10 B21 B32 80 B11 B12 B22 B23 B33 B34 B13 B24 B35 y B14 B25 B4 60 B15 B16 B26 B27 B5 B6 B17 B28 B7 B18 B29 B8 40 B19 B2 B3 B30 B9 A B C A 111 Exploratory data analysis No block by within-block interaction > library(car) > residualplots(lm(y~block+a, datarcb1)) Pearson residuals 5 0 5 Pearson residuals 5 0 5 B1 B14 B19 B23 B28 B32 B5 B9 Block A B C A Pearson residuals 5 0 5 40 60 80 100 Fitted values Test stat Pr(> t ) Block NA NA A NA NA Tukey test -0885 0376
-6-112 Sphericity > library(nlme) > datarcb1lme <- lme(y~a, random=~1 Block, + data=datarcb1) > acf(resid(datarcb1lme)) Series resid(datarcb1lme) ACF 04 02 00 02 04 06 08 10 0 5 10 15 Lag 113 Model fitting > #Assuming sphericity > datarcb1lme <- lme(y~a, random=~1 Block, data=datarcb1, + method='reml') > datarcb1lme1 <- lme(y~a, random=~a Block, data=datarcb1, + method='reml') > AIC(datarcb1lme, datarcb1lme1) df AIC datarcb1lme 5 7221087 datarcb1lme1 10 72701 > anova(datarcb1lme, datarcb1lme1) Model df AIC BIC loglik Test LRatio p-value datarcb1lme 1 5 7221087 7352336-3560544 datarcb1lme1 2 10 72701 7534499-3536001 1 vs 2 4908574 04271 114 Model fitting > #Assuming sphericity > datarcb1lmear1 <- lme(y~a, random=~1 Block, data=datarcb1, + correlation=corar1(),method='reml') > datarcb1lme1ar1 <- lme(y~a, random=~a Block, data=datarcb1, + correlation=corar1(),method='reml') > AIC(datarcb1lme, datarcb1lme1,datarcb1lmear1, datarcb1lme1ar1)
-7- df AIC datarcb1lme 5 7221087 datarcb1lme1 10 72701 datarcb1lmear1 6 7233178 datarcb1lme1ar1 11 72901 > anova(datarcb1lme, datarcb1lme1,datarcb1lmear1, datarcb1lme1ar1) Model df AIC BIC loglik Test LRatio p-value datarcb1lme 1 5 7221087 7352336-3560544 datarcb1lme1 2 10 72701 7534499-3536001 1 vs 2 4908574 04271 datarcb1lmear1 3 6 7233178 7390676-3556589 2 vs 3 4117606 03903 datarcb1lme1ar1 4 11 72901 7580748-3536001 3 vs 4 4117606 05326 115 Model validation > plot(datarcb1lme) 2 Standardized residuals 1 0 1 40 60 80 100 Fitted values > plot(resid(datarcb1lme, type='normalized') ~ + datarcb1$a) resid(datarcb1lme, type = "normalized") 1 0 1 2 A B C datarcb1$a 116 Effects plots > library(effects) > plot(effect('a',datarcb1lme))
-8- A effect plot 80 70 y 60 50 40 A B C A 117 Parameter estimates > summary(datarcb1lme) Linear mixed-effects model fit by REML Data: datarcb1 AIC BIC loglik 7221087 7352336-3560544 Random effects: Formula: ~1 Block (Intercept) Residual StdDev: 1151409 4572284 Fixed effects: y ~ A Value StdError DF t-value p-value (Intercept) 4303434 94074 68 55053 0 AB 2845241 1092985 68 2603185 0 AC 4015556 1092985 68 3673936 0 Correlation: (Intr) AB AB -0261 AC -0261 0500 Standardized Within-Group Residuals: Min Q1 Med Q3 Max -178748258-057867597 -007108159 049990644 233727672 Number of Observations: 105 Number of Groups: 35
-9-118 Parameter estimates > intervals(datarcb1lme) Approximate 95% confidence intervals Fixed effects: lower est upper (Intercept) 3885568 4303434 4721300 AB 2627140 2845241 3063343 AC 3797455 4015556 4233658 attr(,"label") [1] "Fixed effects:" Random Effects: Level: Block lower est upper sd((intercept)) 8964236 1151409 1478925 Within-group standard error: lower est upper 3864944 4572284 5409077 119 Parameter estimates > VarCorr(datarcb1lme) Block = pdlogchol(1) Variance StdDev (Intercept) 13257434 11514093 Residual 90578 4572284 1 ANOVA table > anova(datarcb1lme) numdf dendf F-value p-value (Intercept) 1 68 10893799 <0001 A 2 68 7140295 <0001 121 R 2 [1] 06516126 [1] 0300933 [1] 004745443 [1] 09525456
-10-122 What about lmer? > library(lme4) > datarcb1lmer <- lmer(y~a+(1 Block), data=datarcb1, REML=TRUE, + control=lmercontrol(checknobsvsnre="ignore")) > datarcb1lmer1 <- lmer(y~a+(a Block), data=datarcb1, REML=TRUE, + control=lmercontrol(checknobsvsnre="ignore")) > AIC(datarcb1lmer, datarcb1lmer1) df AIC datarcb1lmer 5 7221087 datarcb1lmer1 10 72701 > anova(datarcb1lmer, datarcb1lmer1) Data: datarcb1 Models: datarcb1lmer: y ~ A + (1 Block) datarcb1lmer1: y ~ A + (A Block) Df AIC BIC loglik deviance Chisq Chi Df Pr(>Chisq) datarcb1lmer 5 72903 74230-35951 71903 datarcb1lmer1 10 73398 76052-35699 71398 50529 5 04095 123 What about lmer? > summary(datarcb1lmer) Linear mixed model fit by REML ['lmermod'] Formula: y ~ A + (1 Block) Data: datarcb1 Control: lmercontrol(checknobsvsnre = "ignore") REML criterion at convergence: 7121 Scaled residuals: Min 1Q Median 3Q Max -178748-057868 -007108 049991 233728 Random effects: Groups Name Variance StdDev Block (Intercept) 13257 11514 Residual 91 4572 Number of obs: 105, groups: Block, 35 Fixed effects: Estimate Std Error t value (Intercept) 43034 94 55 AB 28452 1093 2603 AC 40156 1093 3674 Correlation of Fixed Effects: (Intr) AB AB -0261 AC -0261 0500
-11-124 What about lmer? > anova(datarcb1lmer) Analysis of Variance Table Df Sum Sq Mean Sq F value A 2 29855 14927 71403 125 What about lmer? > # Perform SAS-like p-value calculations (requires the lmertest and pbkrtest package) > library(lmertest) > datarcb1lmer <- update(datarcb1lmer) > summary(datarcb1lmer) Linear mixed model fit by REML t-tests use Satterthwaite approximations to degrees of freedom [ lmermod] Formula: y ~ A + (1 Block) Data: datarcb1 Control: lmercontrol(checknobsvsnre = "ignore") REML criterion at convergence: 7121 Scaled residuals: Min 1Q Median 3Q Max -178748-057868 -007108 049991 233728 Random effects: Groups Name Variance StdDev Block (Intercept) 13257 11514 Residual 91 4572 Number of obs: 105, groups: Block, 35 Fixed effects: Estimate Std Error df t value Pr(> t ) (Intercept) 43034 94 40930 55 <2e-16 *** AB 28452 1093 68000 2603 <2e-16 *** AC 40156 1093 68000 3674 <2e-16 *** --- Signif codes: 0 '***' 0001 '**' 001 '*' 005 '' 01 ' ' 1 Correlation of Fixed Effects: (Intr) AB AB -0261 AC -0261 0500 126 What about lmer? > anova(datarcb1lmer) # Satterthwaite denominator df method Analysis of Variance Table of type III with Satterthwaite approximation for degrees of freedom Sum Sq Mean Sq NumDF DenDF Fvalue Pr(>F) A 29855 14927 2 68 71403 < 22e-16 *** --- Signif codes: 0 '***' 0001 '**' 001 '*' 005 '' 01 ' ' 1
-12- > anova(datarcb1lmer,ddf="kenward-roger") # Kenward-Roger denominator df method Analysis of Variance Table Df Sum Sq Mean Sq F value A 2 29855 14927 71403 2 Worked Examples Worked Examples