Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- install.packages("nlme")
- library
- ##individual variablility known as random factor/effect/subject
- ##using a nested design (hieraarchial) to incoroporate individual variability (see the variability in nature)
- ##fixed factor = temp (cold,tepid,warm)
- ##random = nest
- ##response = mass. mass~temp+nest
- ##under data, as it's numbers, nest is shown as interger, not recognised as factor
- eggs$nest<-as.factor(eggs$nest)
- ##now factor
- ##fully nested design, eg frog maud nested in cold, not tepid or warm. Jean is nested (exists) in warm and nowhere else
- ##use 1|frog|temp
- install.packages("lme4")
- library(lme4)
- install.packages("lmerTest")
- library(lmerTest)
- install.packages("nlme")~
- library(nlme)
- install.packages("multcomp")
- library(multcomp)
- model<-lmer(mass~temp+(1|nest),data=eggs,REML=T) ##REML=T component means restricted maximum likelihood or nested factor included
- ##(1|nest tells it nest is random componenent
- ## (response~fixed+(1|random))
- ##residuals
- ###x causing change in y. y=mx+c < doesn't inc error, or how accurate it predicts
- ##residuals (points around line (regression)) residual error = points not explained well
- ##test residuals are normally distributed, unbiased
- ##unable to use levene
- ##test for normal distribution and that residuals are unbiased and homoscedastic
- ##use hist() to plot histogram
- hist(residuals(model)
- plot(fitted(model),residuals(model))
- ## can see line of best fit, teset for bias/normal/homoscedastic
- ##can do on fixed/categorical data, model predicts means for each group. residuals are errors around the mean
- plot(model)
- anova(model)
- ##finding out about the random factor
- rand(model)
- ##test for differences between the random factor (egg masses between females)
- ##nested design over orthogonal, evaluate patterns
- difflsmeans(model,testeffs="temp")
- ##difflsmeans(model name,testeffs="fixed factor") (test effect of fixed factors, calc means, difference of means and comparing them (similar to tukey))
- with(eggs, boxplot(mass~temp))
- ##produces box plot with errors
- posthoc<-glht(model,linfct=mcp(temp="Tukey"))
- ## glht(model name, multiple comparison, fixed factor
- ## asked to use ageneralised linear hypothesis test (GLHT)
- ## asked to use multiple comparison, (MCP) grouped by the fixed factor
- mcs=summary(posthoc)
- cld(mcs,level=0.05, decreasing=T)
- ##produces compact letter display, if letters match up then not significant
- mean.mass<-with(eggs, tapply(mass, list (temp),mean)) ## make mean
- sd.mass<-with(eggs, tapply(mass,list(temp),sd)) ## make sd
- mids<-barplot(mean.mass, ylim=c(0,200), xlab = "Female", ## barplot means with error bar using sd/mean + labels
- ylab = "egg mass")
- arrows(mids, mean.mass+sd.mass,mids,mean.mass-sd.mass,code=3,angle=90,length=0.1),
- text(mids, mean.mass+30, labels=c("a","b","a")) ## 2 a's not sig
- install.packages("vegan")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement