Load the data and take a look at it
eo <- read.csv("~/Desktop/data.csv")
eo
## essential.oil concentration survival
## 1 Cinnamon 1 44.44
## 2 Cinnamon 2 50.00
## 3 Cinnamon 3 33.33
## 4 Cinnamon 4 22.22
## 5 Cinnamon 5 25.00
## 6 Rosemary 1 81.81
## 7 Rosemary 2 41.67
## 8 Rosemary 3 8.33
## 9 Rosemary 4 30.77
## 10 Rosemary 5 13.33
## 11 Clove 1 53.85
## 12 Clove 2 44.44
## 13 Clove 3 57.14
## 14 Clove 4 0.00
## 15 Clove 5 15.38
## 16 Eucalyptus 1 45.45
## 17 Eucalyptus 2 76.92
## 18 Eucalyptus 3 60.00
## 19 Eucalyptus 4 53.85
## 20 Eucalyptus 5 12.50
## 21 Lemon 1 14.29
## 22 Lemon 2 33.33
## 23 Lemon 3 15.38
## 24 Lemon 4 0.00
## 25 Lemon 5 0.00
## 26 Control 0 90.00
Tweak to add control to each treatment
oils<-levels(eo$essential.oil)[-3]
controls<-data.frame(oils,rep(0,5),rep(90,5))
names(controls)<-names(eo)
eo<-rbind(eo,controls)
eo<-eo[-26,]
Load the plotting package and plot
require(ggplot2)
## Loading required package: ggplot2
#simple plot
eop <- ggplot(data=eo, aes(x=concentration, y=survival))
eop + geom_point()
#plot with all the works
eop+
geom_point()+
geom_smooth(method=lm,formula=y~log(x+0.001))+ #adds a fitted log curve
facet_grid(essential.oil~.)+ #breaks out oils
theme_bw() #take out the grey background
Those plots are fine, but are difficult to compare treatments visually. Let’s take off the standard error zones and use colors instead of facets. We’ll also clean up the axis labels.
eop+
geom_point(aes(colour=essential.oil))+
geom_smooth(aes(colour=essential.oil),method=lm,formula=y~log(x+0.001),se=F)+
theme_bw()+
scale_y_continuous("survival (%)")+ #change the y-axis label
scale_x_continuous("concentration (µL)")+ #change the x-axis label
scale_colour_discrete(name = "Essential Oil") #change the legend title
And let’s get a statistic to see if each treatment fits a logarithmic curve, and if they differ from one another. First, let’s drop the control from the model.
eo.measured<-eo[1:25,]
eop.measured <- ggplot(data=eo.measured, aes(x=concentration, y=survival))
eop.measured+
geom_point(aes(colour=essential.oil))+
geom_smooth(aes(colour=essential.oil),method=lm,formula=y~log(x+0.001),se=F)+
theme_bw()+
scale_y_continuous("survival (%)")+ #change the y-axis label
scale_x_continuous("concentration (µL)")+ #change the x-axis label
scale_colour_discrete(name = "Essential Oil") #change the legend title
Next we build the models and compare them
require(nlme)
## Loading required package: nlme
B1<-gls(survival ~ log(concentration+0.001),method="REML",data=eo.measured) #one model with shared intercept
B2<-lme(survival ~ log(concentration+0.001),random=~1|essential.oil,method="REML",data=eo.measured) #same model, different intercepts for different oils
summary(B1)
## Generalized least squares fit by REML
## Model: survival ~ log(concentration + 0.001)
## Data: eo.measured
## AIC BIC logLik
## 213.9881 217.3946 -103.994
##
## Coefficients:
## Value Std.Error t-value p-value
## (Intercept) 54.84053 7.774675 7.053739 0.0000
## log(concentration + 0.001) -22.44712 6.980588 -3.215650 0.0038
##
## Correlation:
## (Intr)
## log(concentration + 0.001) -0.86
##
## Standardized residuals:
## Min Q1 Med Q3 Max
## -2.0438242 -0.5233654 -0.0754732 0.3557017 1.8986748
##
## Residual standard error: 19.82954
## Degrees of freedom: 25 total; 23 residual
summary(B2)
## Linear mixed-effects model fit by REML
## Data: eo.measured
## AIC BIC logLik
## 213.4495 217.9915 -102.7248
##
## Random effects:
## Formula: ~1 | essential.oil
## (Intercept) Residual
## StdDev: 10.88469 17.03489
##
## Fixed effects: survival ~ log(concentration + 0.001)
## Value Std.Error DF t-value p-value
## (Intercept) 54.84053 8.264615 19 6.635582 0.0000
## log(concentration + 0.001) -22.44712 5.996789 19 -3.743191 0.0014
## Correlation:
## (Intr)
## log(concentration + 0.001) -0.695
##
## Standardized Within-Group Residuals:
## Min Q1 Med Q3 Max
## -1.56204387 -0.57515788 -0.05127819 0.46837366 1.56370665
##
## Number of Observations: 25
## Number of Groups: 5
anova(B1,B2)
## Model df AIC BIC logLik Test L.Ratio p-value
## B1 1 3 213.9881 217.3946 -103.9940
## B2 2 4 213.4495 217.9915 -102.7248 1 vs 2 2.53857 0.1111
So, while all essential oils show the logarithmic curve, there’s not really clear evidence that they are different in intercept from one another. Note that AIC, BIC, and likelihood are fairly similar between the models.
It looks similar if we look analyse it as a linear model with categorical additive term:
summary(lm(survival~log(concentration+0.001)+essential.oil,data=eo.measured))
##
## Call:
## lm(formula = survival ~ log(concentration + 0.001) + essential.oil,
## data = eo.measured)
##
## Residuals:
## Min 1Q Median 3Q Max
## -25.775 -7.224 1.497 9.069 26.143
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 56.501 9.541 5.922 1.06e-05 ***
## log(concentration + 0.001) -22.447 5.997 -3.743 0.00138 **
## essential.oilClove -0.836 10.774 -0.078 0.93896
## essential.oilEucalyptus 14.746 10.774 1.369 0.18706
## essential.oilLemon -22.398 10.774 -2.079 0.05141 .
## essential.oilRosemary 0.184 10.774 0.017 0.98655
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 17.03 on 19 degrees of freedom
## Multiple R-squared: 0.5794, Adjusted R-squared: 0.4688
## F-statistic: 5.235 on 5 and 19 DF, p-value: 0.003453
Although we can see here that lemon is close to being significantly different (lower in intercept) than the other oils (as is clear from the plots)