require(lme4) require(dplyr) require(ggplot2) require(lattice) # read in data fucoidan <- read.csv('fucoidan.csv', stringsAsFactors = F) # prepare data: # * replace zeros with small number (but not too small as it deteriorates model fit) # * anemones are discarted after each time point (due to relaxing solution), # * so need to re-label as unique anemone-time combination fucoidan_test <- fucoidan %>% filter(!Time==0) %>% mutate(Infection = infection+0.01, anemone = paste(anemone,Time)) # run mixed effects model fucoidan_model <- lmer(formula = log(Infection)~as.factor(Time)*Treatment+ (1|anemone), data=fucoidan_test) # summaries summary(fucoidan_model) anova(fucoidan_model) confint(fucoidan_model) qqmath(fucoidan_model) # summaries suggest estimate for 96h time point at 100mg not significantly different, all others are # generate plot summu <- fucoidan %>% group_by(Treatment,Time) %>% summarise(ns = n(), means = mean(infection), stdev = sd(infection)/(n())) summu$stdev[is.na(summu$stdev)] <- 0 my.labs <- list('Filtered seawater control',bquote(paste('200 ',mu,"g/ml Fucoidan washed control")),bquote(paste('100 ',mu,"g/ml Fucoidan")),bquote(paste('200 ',mu,"g/ml Fucoidan")),bquote(paste('400 ',mu,"g/ml Fucoidan"))) ggplot(summu,aes(x=Time,y=means,linetype=Treatment)) + geom_line() + geom_pointrange(aes(ymax = means+stdev, ymin = means-stdev),linetype=1) + geom_text(aes(x=Time, y=means+stdev+0.05,label=c(rep(NA,6),c(NA,'*',NA),rep(c(NA,'*','*'),2))),data=summu)+ theme_bw() + scale_x_continuous('Time (h)',breaks=c(0,48,96),limits=c(0,100)) + scale_linetype_discrete('Treatment',labels = my.labs) + ylab('Percent colonisation')+ theme(legend.key = element_blank()) ggsave('Fucoidan_exp.pdf', width = 8, height = 4) # Fit linear model to Fucoidan fluorescance data. # A saturating function would likely be more appropriate, # but the results are fairly obvious and not model dependant. fucoidan <- read.csv('fucoidan_fluo.csv') fucoidan_fluo <- tidyr::gather(fucoidan,key = replicate, value = DAF, read1, read2, read3, -X) inform <- lmer(formula = DAF~Fucoidan+(1|Anemone)+(1|Tentacle),data=fucoidan_fluo) summary(inform) confint(inform) qqmath(inform)