Advertisement
Guest User

workshop 2

a guest
Feb 10th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.82 KB | None | 0 0
  1. install.packages("nlme")
  2. library
  3. ##individual variablility known as random factor/effect/subject
  4. ##using a nested design (hieraarchial) to incoroporate individual variability (see the variability in nature)
  5. ##fixed factor = temp (cold,tepid,warm)
  6. ##random = nest
  7. ##response = mass. mass~temp+nest
  8. ##under data, as it's numbers, nest is shown as interger, not recognised as factor
  9. eggs$nest<-as.factor(eggs$nest)
  10. ##now factor
  11. ##fully nested design, eg frog maud nested in cold, not tepid or warm. Jean is nested (exists) in warm and nowhere else
  12. ##use 1|frog|temp
  13. install.packages("lme4")
  14. library(lme4)
  15. install.packages("lmerTest")
  16. library(lmerTest)
  17. install.packages("nlme")~
  18. library(nlme)
  19. install.packages("multcomp")
  20. library(multcomp)
  21. model<-lmer(mass~temp+(1|nest),data=eggs,REML=T) ##REML=T component means restricted maximum likelihood or nested factor included
  22. ##(1|nest tells it nest is random componenent
  23. ## (response~fixed+(1|random))
  24. ##residuals
  25. ###x causing change in y. y=mx+c < doesn't inc error, or how accurate it predicts
  26. ##residuals (points around line (regression)) residual error = points not explained well
  27. ##test residuals are normally distributed, unbiased
  28. ##unable to use levene
  29. ##test for normal distribution and that residuals are unbiased and homoscedastic
  30. ##use hist() to plot histogram
  31. hist(residuals(model)
  32. plot(fitted(model),residuals(model))
  33. ## can see line of best fit, teset for bias/normal/homoscedastic
  34. ##can do on fixed/categorical data, model predicts means for each group. residuals are errors around the mean
  35. plot(model)
  36. anova(model)
  37. ##finding out about the random factor
  38. rand(model)
  39. ##test for differences between the random factor (egg masses between females)
  40. ##nested design over orthogonal, evaluate patterns
  41. difflsmeans(model,testeffs="temp")
  42. ##difflsmeans(model name,testeffs="fixed factor") (test effect of fixed factors, calc means, difference of means and comparing them (similar to tukey))
  43. with(eggs, boxplot(mass~temp))
  44. ##produces box plot with errors
  45. posthoc<-glht(model,linfct=mcp(temp="Tukey"))
  46. ## glht(model name, multiple comparison, fixed factor
  47. ## asked to use ageneralised linear hypothesis test (GLHT)
  48. ## asked to use multiple comparison, (MCP) grouped by the fixed factor
  49. mcs=summary(posthoc)
  50. cld(mcs,level=0.05, decreasing=T)
  51. ##produces compact letter display, if letters match up then not significant
  52. mean.mass<-with(eggs, tapply(mass, list (temp),mean)) ## make mean
  53. sd.mass<-with(eggs, tapply(mass,list(temp),sd)) ## make sd
  54. mids<-barplot(mean.mass, ylim=c(0,200), xlab = "Female", ## barplot means with error bar using sd/mean + labels
  55. ylab = "egg mass")
  56. arrows(mids, mean.mass+sd.mass,mids,mean.mass-sd.mass,code=3,angle=90,length=0.1),
  57. text(mids, mean.mass+30, labels=c("a","b","a")) ## 2 a's not sig
  58. install.packages("vegan")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement