Keo Corak
Read and format data
eel<-read.table("eel.txt", header=TRUE,
colClasses = c(rep("factor", 4),
rep("numeric",2)))
str(eel)
## 'data.frame': 48 obs. of 6 variables:
## $ Rep : Factor w/ 4 levels "1","2","3","4": 1 1 1 1 1 1 1 1 1 1 ...
## $ Trt : Factor w/ 12 levels "1","10","11",..: 1 5 6 7 8 9 10 11 12 2 ...
## $ Rate : Factor w/ 3 levels "0","1","2": 1 1 1 1 2 2 2 2 3 3 ...
## $ Chem : Factor w/ 4 levels "K","M","N","S": 1 2 3 4 1 2 3 4 1 2 ...
## $ Before: num 296 100 197 216 230 212 282 138 283 238 ...
## $ After : num 466 219 421 808 256 386 398 194 280 379 ...
options(contrasts=c("contr.sum", "contr.poly"))
Check assumptions
lmAfter<-lm(After~Rep+Rate:Chem, data=eel)
plot(residuals(lmAfter)) #heterogeneous variance of resids*
hist(residuals(lmAfter)) #roughly normal
Note that there is one extreme value in resid plot.
residsAfter<-residuals(lmAfter)
lmBefore<-lm(Before~Rep+Rate:Chem, data=eel)
residsBefore<-residuals(lmBefore)
plot(residsAfter, residsBefore)
Positive relationship between Before and After resids
**ANCOVA
Without covariate
lmAfter<-lm(After~Rep+Rate*Chem, data=eel)
drop1(lmAfter, scope= ~., test="F")
## Single term deletions
##
## Model:
## After ~ Rep + Rate * Chem
## Df Sum of Sq RSS AIC F value Pr(>F)
## <none> 533343 477.15
## Rep 3 282220 815563 491.54 5.8207 0.002623 **
## Rate 2 159894 693237 485.74 4.9466 0.013215 *
## Chem 3 17980 551323 472.75 0.3708 0.774550
## Rate:Chem 6 127180 660523 475.42 1.3115 0.279594
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Blk captures some of the variation in response. Rate effect is significant
With covariate
AfterMod<-lm(After~Before+Rep+Rate*Chem, data=eel)
drop1(AfterMod, ~., test="F")
## Single term deletions
##
## Model:
## After ~ Before + Rep + Rate * Chem
## Df Sum of Sq RSS AIC F value Pr(>F)
## <none> 240505 440.93
## Before 1 292838 533343 477.15 38.9631 5.396e-07 ***
## Rep 3 126770 367275 455.25 5.6224 0.0032670 **
## Rate 2 173156 413661 462.96 11.5195 0.0001705 ***
## Chem 3 44097 284602 443.01 1.9558 0.1404956
## Rate:Chem 6 144258 384763 451.48 3.1990 0.0141844 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Covariate captures some of variation in response. Now both rate effect and effect of interaction of chem and rate appear significant
With covariate and interaction beteween covariate and treatments
AfterMod2<-lm(After~Before+Rep+Rate*Chem+Before:Rate+Before:Chem+Before:Chem:Rate, data=eel)
drop1(AfterMod2, ~., test="F")
## Single term deletions
##
## Model:
## After ~ Before + Rep + Rate * Chem + Before:Rate + Before:Chem +
## Before:Chem:Rate
## Df Sum of Sq RSS AIC F value Pr(>F)
## <none> 86147 413.65
## Before 1 255598 341745 477.79 62.3072 1.02e-07 ***
## Rep 3 119378 205525 449.38 9.7003 0.0003222 ***
## Rate 2 18887 105034 419.16 2.3021 0.1247509
## Chem 3 16512 102659 416.06 1.3417 0.2877186
## Rate:Chem 6 47924 134071 422.88 1.9471 0.1198911
## Before:Rate 2 5112 91259 412.41 0.6230 0.5459391
## Before:Chem 3 39404 125551 425.72 3.2018 0.0442156 *
## Before:Rate:Chem 6 85324 171471 434.69 3.4666 0.0153752 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Here, we can see evidence for heterogenity in slopes. The interaction between the covariate and treatment variables is significant for Chem and Chem:Rate. Rate, Chem and Rep still explain significant amounts of variation. Interestingly, the covariate on its own no longer appears significant.
AfterMod3<-lm(After~Before+Rep+Rate*Chem+Before:Chem+Before:Chem:Rate, data=eel)
drop1(AfterMod3, ~., test="F")
## Single term deletions
##
## Model:
## After ~ Before + Rep + Rate * Chem + Before:Chem + Before:Chem:Rate
## Df Sum of Sq RSS AIC F value Pr(>F)
## <none> 86147 413.65
## Before 1 255598 341745 477.79 62.3072 1.02e-07 ***
## Rep 3 119378 205525 449.38 9.7003 0.0003222 ***
## Rate 2 18887 105034 419.16 2.3021 0.1247509
## Chem 3 16512 102659 416.06 1.3417 0.2877186
## Rate:Chem 6 47924 134071 422.88 1.9471 0.1198911
## Before:Chem 3 39404 125551 425.72 3.2018 0.0442156 *
## Before:Rate:Chem 8 112872 199019 437.84 3.4394 0.0109786 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Nothing changes from AfterMod2. AIC are the same
I would select either AfterMod2 or AfterMod3. These models suggest that the effects of different chemicals/dose treatments on nematode counts depends heavily on inital field conditions, which I imagine has pretty signficant implications for practitoners.
library(lsmeans)
## Warning: package 'lsmeans' was built under R version 3.2.5
## Loading required package: estimability
## Warning: package 'estimability' was built under R version 3.2.5
lsmeans(lmAfter, specs="Rate"); lsmeans(AfterMod3, specs="Rate")
## NOTE: Results may be misleading due to involvement in interactions
## Rate lsmean SE df lower.CL upper.CL
## 0 397.3750 31.78238 33 332.7133 462.0367
## 1 269.2500 31.78238 33 204.5883 333.9117
## 2 281.5625 31.78238 33 216.9008 346.2242
##
## Results are averaged over the levels of: Rep, Chem
## Confidence level used: 0.95
## NOTE: Results may be misleading due to involvement in interactions
## Rate lsmean SE df lower.CL upper.CL
## 0 438.1822 18.10815 21 400.5242 475.8402
## 1 285.1264 16.56408 21 250.6795 319.5733
## 2 268.4891 18.03952 21 230.9739 306.0044
##
## Results are averaged over the levels of: Rep, Chem
## Confidence level used: 0.95
a<-as.table(rbind(cbind(397.3750,269.2500,281.5625), cbind(438.1822,285.1264,268.4891))); colnames(a)<-c("0","1", "2"); rownames(a)<-c("naive","final")
lsmeans(lmAfter, specs="Chem"); lsmeans(AfterMod3, specs="Chem")
## NOTE: Results may be misleading due to involvement in interactions
## Chem lsmean SE df lower.CL upper.CL
## K 335.5833 36.69914 33 260.9184 410.2483
## M 328.7500 36.69914 33 254.0850 403.4150
## N 314.7500 36.69914 33 240.0850 389.4150
## S 285.1667 36.69914 33 210.5017 359.8316
##
## Results are averaged over the levels of: Rep, Rate
## Confidence level used: 0.95
## NOTE: Results may be misleading due to involvement in interactions
## Chem lsmean SE df lower.CL upper.CL
## K 286.4906 24.37162 21 235.8070 337.1742
## M 333.8905 19.00444 21 294.3686 373.4124
## N 353.2400 19.62526 21 312.4271 394.0530
## S 348.7758 20.34713 21 306.4617 391.0900
##
## Results are averaged over the levels of: Rep, Rate
## Confidence level used: 0.95
b<-as.table(rbind(cbind(335.5833, 328.750,314.7500,285.1667), cbind(286.4906,333.8905,353.2400,348.7758))); colnames(b)<-c("K","M","N","S"); rownames(b)<-c("naive","final")
a
## 0 1 2
## naive 397.3750 269.2500 281.5625
## final 438.1822 285.1264 268.4891
b
## K M N S
## naive 335.5833 328.7500 314.7500 285.1667
## final 286.4906 333.8905 353.2400 348.7758
Mean counts at 0 dosage are shifted up compared to naive model. Mean counts are shifted slighly down for other dosages Mean counts are shifted down for K and up for S and N.