SlideShare a Scribd company logo
1 of 29
A beginner’s view on
mixed modelling
#crapstats
carly.lynsdale@sheffield.ac.uk
CarlyLynsdale
MyanmarElephant
Using R to investigate parasite
infection in Asian Elephants
Photo: Hannah Mumby,
EPG
Are parasite eggs evenly distributed throughout
elephant faeces?
WITHIN BOLUS
119 hosts, 4 samples per host
1 elephant -> 2 samples (C + E) -> 1 repeat of each
C
E
BETWEEN BOLUS
20 hosts, 6 samples per host
1 elephant - > 3 bolus sampled from each ->
centre and edge from each bolus
C
E
C
E
C
E
Variables
Between
• Elephant (ID)
• Bolus (1st, 3rd, Last)
• Sample (C + E)
• EPG
Within
• Elephant (ID)
• Sample (C + E)
• EPG
Continuous
Categorical (Factor)
Why Generalised Linear Mixed Effects Models
(GLMMs)?
The effect of sample location (independent) on EPG
(dependent), with non-parametric data and accounting
for the effect of elephant age, sex and camp.
GLMMs deal with potential pseudoreplication by
including (fixed and) random measures.
The effect of sample location (independent) on EPG
(dependent), with non-parametric data and accounting
for the effect of elephant age, sex and camp.
Why Generalised Linear Mixed Effects Models
(GLMMs)?
GLMMs deal with potential pseudoreplication by
including (fixed and) random measures.
i.e. They account for repeated measures.
The effect of sample location (independent) on EPG
(dependent), with non-parametric data and accounting
for the effect of elephant age, sex and camp.
Why Generalised Linear Mixed Effects Models
(GLMMs)?
library(lme4) = Linear Mixed Effects v4
library(lme4) # Linear Mixed Effects v4
model1 <- glmer(y ~ xf + (1|xr),
family = poisson (link = “log”),
data = dframe1)
Package for GLMMs in R
library(MCMCglmm)= Bayesian Markov chain
Monte Carlo
library(asreml) = ASREML-R
ASREML-R is available on request for research/teaching, for
users with an academic email address. Register online at:
http://www.vsni.co.uk/software/free-to-use/teaching/asreml-teaching/registratio
Others…
library(nlme) = Non-Linear Mixed Effects
So what does my code look like?...
Within:
Between:
modelwithin<- glmer.nb (sqrt(epg) ~ sample1 + ageclass + camp + (1|id),
control=glmerControl(optimizer = "bobyqa"), data = within)
modelbetween <- glmer.nb (sqrt(epg) ~ bolusno1 + sample + ageclass + sex +
mothcol + (1|id1), data = bween, control = glmerControl
(optCtrl=list(optimizer="bobyqa")))
So what does my code look like?...
Within:
Between:
modelwithin<- glmer.nb (sqrt(epg) ~ sample1 + ageclass + camp + (1|id),
control=glmerControl(optimizer = "bobyqa"), data = within)
modelbetween <- glmer.nb (sqrt(epg) ~ bolusno1 + sample + ageclass + sex +
mothcol + (1|id1), data = bween, control = glmerControl
(optCtrl=list(optimizer="bobyqa")))
A typical Negative Binomial
Distribution….
EPG
No.ofHosts
So what does my code look like?...
Within:
Between:
modelwithin<- glmer.nb (sqrt(epg) ~ sample1 + ageclass + camp + (1|id),
control=glmerControl(optimizer = "bobyqa"), data = within)
modelbetween <- glmer.nb (sqrt(epg) ~ bolusno1 + sample + ageclass + sex +
mothcol + (1|id1), data = bween, control = glmerControl
(optCtrl=list(optimizer="bobyqa")))
So what does my code look like?...
Within:
Between:
modelwithin<- glmer.nb (sqrt(epg) ~ sample1 + ageclass + sex + camp + (1|id),
control=glmerControl(optimizer = "bobyqa"), data = within)
modelbetween <- glmer.nb (sqrt(epg) ~ bolusno1 + sample + ageclass + sex +
camp + (1|id1), control = glmerControl (optCtrl=list(optimizer="bobyqa"), data
= bween)
So what does my code look like?...
Within:
Between:
modelwithin<- glmer.nb (sqrt(epg) ~ sample1 + ageclass + sex + camp + (1|id),
control=glmerControl(optimizer = "bobyqa"), data = within)
modelbetween <- glmer.nb (sqrt(epg) ~ bolusno1 + sample + ageclass + sex +
camp + (1|id1), control = glmerControl (optCtrl=list(optimizer="bobyqa"), data
= bween)
http://stackoverflow.com/questions/21344555/convergence-error-
for-development-version-of-lme4
control=glmerControl(optimizer = "bobyqa")
So what does my code look like?...
Within:
Between:
modelwithin<- glmer.nb (sqrt(epg) ~ sample1 + ageclass + sex + camp + (1|id),
control=glmerControl(optimizer = "bobyqa"), data = within)
modelbetween <- glmer.nb (sqrt(epg) ~ bolusno1 + sample + ageclass + sex +
camp + (1|id1), control = glmerControl (optCtrl=list(optimizer="bobyqa"), data
= bween)
model2<-glmer.nb(sqrt(epg) ~ relevel (bolusno1,2) + sample
+ ageclass + sex + mothcol + (1|id1), data = bween, control =
glmerControl(optCtrl=list(optimizer="bobyqa"))
Bolus 1 <- Bolus 3 v Bolus 5
Bolus 3 <- Bolus 1 & Bolus 5
Bolus 5 <- Bolus 1 & Bolus 3
modelwithin <- glmer.nb(sqrt(epg) ~ sample1 + ageclass + sex +
camp + (1|id), control=glmerControl(optimizer = "bobyqa"), data =
within)
anova(modelwithin, modelwithin2)
Within (Centre v Edge)
modelwithin2 <- glmer.nb(sqrt(epg) ~ ageclass + sex + camp + (1|id),
control=glmerControl(optimizer = "bobyqa"), data = within)
Between (1st Bolus v 3rd Bolus
v Last Bolus)
modelbween <- glmer.nb(sqrt(epg) ~
bolusno1+sample+ageclass+sex+camp+(1|id1), data = bween,
control=glmerControl(optCtrl=list(optimizer="bobyqa")))
modelbween2 <- glmer.nb(sqrt(epg) ~
sample+ageclass+sex+camp+(1|id1), data = bween,
control=glmerControl(optCtrl=list(optimizer="bobyqa")))
My Final Tips……
• Sniff out free courses – NERC funded students / Sheffield
APS R course…
• Keep your data simple!
• Triple check everything (on different days), at least in the
beginning…
• Use word / excel / ppt to keep a summary of your
outputs / graphs for when you write up.
• Start naming models, exports, files properly from the
start.
Web Links
• http://www.r-bloggers.com/ - blog site
• Facebook R-space group
• http://www.nerc.ac.uk/skills/postgrad/currentstude
nts/latestopportunities/ - nerc free courses
• https://www.coursera.org/ - free online courses
• http://cran.r-project.org/doc/manuals/r-release/R-
intro.html - R’s own help site
• http://www.statmethods.net/interface/help.html -
nice stats
• https://github.com/ - online stats forum

More Related Content

Similar to Sheffield R Jan 2015 - Using R to investigate parasite infections in Asian elephants, Carly Lynsdale

MEM and SEM in the GME framework: Modelling Perception and Satisfaction - Car...
MEM and SEM in the GME framework: Modelling Perception and Satisfaction - Car...MEM and SEM in the GME framework: Modelling Perception and Satisfaction - Car...
MEM and SEM in the GME framework: Modelling Perception and Satisfaction - Car...SYRTO Project
 
Machine Learning, Data Mining, Genetic Algorithms, Neural ...
Machine Learning, Data Mining, Genetic Algorithms, Neural ...Machine Learning, Data Mining, Genetic Algorithms, Neural ...
Machine Learning, Data Mining, Genetic Algorithms, Neural ...butest
 
ppgardner-lecture06-homologysearch.pdf
ppgardner-lecture06-homologysearch.pdfppgardner-lecture06-homologysearch.pdf
ppgardner-lecture06-homologysearch.pdfPaul Gardner
 
Improving accuracy by using information from relatives—The animal model
Improving accuracy by using information from relatives—The animal modelImproving accuracy by using information from relatives—The animal model
Improving accuracy by using information from relatives—The animal modelILRI
 
Combining co-expression and co-location for gene network inference in porcine...
Combining co-expression and co-location for gene network inference in porcine...Combining co-expression and co-location for gene network inference in porcine...
Combining co-expression and co-location for gene network inference in porcine...tuxette
 
Machine Learning - Genetic Algorithm Fundamental
Machine Learning - Genetic Algorithm FundamentalMachine Learning - Genetic Algorithm Fundamental
Machine Learning - Genetic Algorithm FundamentalAnggi Andriyadi
 
CSC111-Chap_03.pdf
CSC111-Chap_03.pdfCSC111-Chap_03.pdf
CSC111-Chap_03.pdf2b75fd3051
 
Introduction to Julia
Introduction to JuliaIntroduction to Julia
Introduction to Julia岳華 杜
 

Similar to Sheffield R Jan 2015 - Using R to investigate parasite infections in Asian elephants, Carly Lynsdale (9)

MEM and SEM in the GME framework: Modelling Perception and Satisfaction - Car...
MEM and SEM in the GME framework: Modelling Perception and Satisfaction - Car...MEM and SEM in the GME framework: Modelling Perception and Satisfaction - Car...
MEM and SEM in the GME framework: Modelling Perception and Satisfaction - Car...
 
Machine Learning, Data Mining, Genetic Algorithms, Neural ...
Machine Learning, Data Mining, Genetic Algorithms, Neural ...Machine Learning, Data Mining, Genetic Algorithms, Neural ...
Machine Learning, Data Mining, Genetic Algorithms, Neural ...
 
Genetic algorithm
Genetic algorithmGenetic algorithm
Genetic algorithm
 
ppgardner-lecture06-homologysearch.pdf
ppgardner-lecture06-homologysearch.pdfppgardner-lecture06-homologysearch.pdf
ppgardner-lecture06-homologysearch.pdf
 
Improving accuracy by using information from relatives—The animal model
Improving accuracy by using information from relatives—The animal modelImproving accuracy by using information from relatives—The animal model
Improving accuracy by using information from relatives—The animal model
 
Combining co-expression and co-location for gene network inference in porcine...
Combining co-expression and co-location for gene network inference in porcine...Combining co-expression and co-location for gene network inference in porcine...
Combining co-expression and co-location for gene network inference in porcine...
 
Machine Learning - Genetic Algorithm Fundamental
Machine Learning - Genetic Algorithm FundamentalMachine Learning - Genetic Algorithm Fundamental
Machine Learning - Genetic Algorithm Fundamental
 
CSC111-Chap_03.pdf
CSC111-Chap_03.pdfCSC111-Chap_03.pdf
CSC111-Chap_03.pdf
 
Introduction to Julia
Introduction to JuliaIntroduction to Julia
Introduction to Julia
 

More from Paul Richards

SheffieldR July Meeting - Multiple Imputation with Chained Equations (MICE) p...
SheffieldR July Meeting - Multiple Imputation with Chained Equations (MICE) p...SheffieldR July Meeting - Multiple Imputation with Chained Equations (MICE) p...
SheffieldR July Meeting - Multiple Imputation with Chained Equations (MICE) p...Paul Richards
 
Preparing and submitting a package to CRAN - June Sanderson, Sheffield R User...
Preparing and submitting a package to CRAN - June Sanderson, Sheffield R User...Preparing and submitting a package to CRAN - June Sanderson, Sheffield R User...
Preparing and submitting a package to CRAN - June Sanderson, Sheffield R User...Paul Richards
 
Querying open data with R - Talk at April SheffieldR Users Gp
Querying open data with R - Talk at April SheffieldR Users GpQuerying open data with R - Talk at April SheffieldR Users Gp
Querying open data with R - Talk at April SheffieldR Users GpPaul Richards
 
OrienteeRing - using R to optimise mini mountain marathon routes - Pete Dodd ...
OrienteeRing - using R to optimise mini mountain marathon routes - Pete Dodd ...OrienteeRing - using R to optimise mini mountain marathon routes - Pete Dodd ...
OrienteeRing - using R to optimise mini mountain marathon routes - Pete Dodd ...Paul Richards
 
Phylogeny in R - Bianca Santini Sheffield R Users March 2015
Phylogeny in R - Bianca Santini Sheffield R Users March 2015Phylogeny in R - Bianca Santini Sheffield R Users March 2015
Phylogeny in R - Bianca Santini Sheffield R Users March 2015Paul Richards
 
Intro to ggplot2 - Sheffield R Users Group, Feb 2015
Intro to ggplot2 - Sheffield R Users Group, Feb 2015Intro to ggplot2 - Sheffield R Users Group, Feb 2015
Intro to ggplot2 - Sheffield R Users Group, Feb 2015Paul Richards
 
Introduction to Shiny for building web apps in R
Introduction to Shiny for building web apps in RIntroduction to Shiny for building web apps in R
Introduction to Shiny for building web apps in RPaul Richards
 

More from Paul Richards (7)

SheffieldR July Meeting - Multiple Imputation with Chained Equations (MICE) p...
SheffieldR July Meeting - Multiple Imputation with Chained Equations (MICE) p...SheffieldR July Meeting - Multiple Imputation with Chained Equations (MICE) p...
SheffieldR July Meeting - Multiple Imputation with Chained Equations (MICE) p...
 
Preparing and submitting a package to CRAN - June Sanderson, Sheffield R User...
Preparing and submitting a package to CRAN - June Sanderson, Sheffield R User...Preparing and submitting a package to CRAN - June Sanderson, Sheffield R User...
Preparing and submitting a package to CRAN - June Sanderson, Sheffield R User...
 
Querying open data with R - Talk at April SheffieldR Users Gp
Querying open data with R - Talk at April SheffieldR Users GpQuerying open data with R - Talk at April SheffieldR Users Gp
Querying open data with R - Talk at April SheffieldR Users Gp
 
OrienteeRing - using R to optimise mini mountain marathon routes - Pete Dodd ...
OrienteeRing - using R to optimise mini mountain marathon routes - Pete Dodd ...OrienteeRing - using R to optimise mini mountain marathon routes - Pete Dodd ...
OrienteeRing - using R to optimise mini mountain marathon routes - Pete Dodd ...
 
Phylogeny in R - Bianca Santini Sheffield R Users March 2015
Phylogeny in R - Bianca Santini Sheffield R Users March 2015Phylogeny in R - Bianca Santini Sheffield R Users March 2015
Phylogeny in R - Bianca Santini Sheffield R Users March 2015
 
Intro to ggplot2 - Sheffield R Users Group, Feb 2015
Intro to ggplot2 - Sheffield R Users Group, Feb 2015Intro to ggplot2 - Sheffield R Users Group, Feb 2015
Intro to ggplot2 - Sheffield R Users Group, Feb 2015
 
Introduction to Shiny for building web apps in R
Introduction to Shiny for building web apps in RIntroduction to Shiny for building web apps in R
Introduction to Shiny for building web apps in R
 

Recently uploaded

Call Girls In Nihal Vihar Delhi ❤️8860477959 Looking Escorts In 24/7 Delhi NCR
Call Girls In Nihal Vihar Delhi ❤️8860477959 Looking Escorts In 24/7 Delhi NCRCall Girls In Nihal Vihar Delhi ❤️8860477959 Looking Escorts In 24/7 Delhi NCR
Call Girls In Nihal Vihar Delhi ❤️8860477959 Looking Escorts In 24/7 Delhi NCRlizamodels9
 
RESPIRATORY ADAPTATIONS TO HYPOXIA IN HUMNAS.pptx
RESPIRATORY ADAPTATIONS TO HYPOXIA IN HUMNAS.pptxRESPIRATORY ADAPTATIONS TO HYPOXIA IN HUMNAS.pptx
RESPIRATORY ADAPTATIONS TO HYPOXIA IN HUMNAS.pptxFarihaAbdulRasheed
 
LIGHT-PHENOMENA-BY-CABUALDIONALDOPANOGANCADIENTE-CONDEZA (1).pptx
LIGHT-PHENOMENA-BY-CABUALDIONALDOPANOGANCADIENTE-CONDEZA (1).pptxLIGHT-PHENOMENA-BY-CABUALDIONALDOPANOGANCADIENTE-CONDEZA (1).pptx
LIGHT-PHENOMENA-BY-CABUALDIONALDOPANOGANCADIENTE-CONDEZA (1).pptxmalonesandreagweneth
 
Call Us ≽ 9953322196 ≼ Call Girls In Mukherjee Nagar(Delhi) |
Call Us ≽ 9953322196 ≼ Call Girls In Mukherjee Nagar(Delhi) |Call Us ≽ 9953322196 ≼ Call Girls In Mukherjee Nagar(Delhi) |
Call Us ≽ 9953322196 ≼ Call Girls In Mukherjee Nagar(Delhi) |aasikanpl
 
Call Girls in Mayapuri Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
Call Girls in Mayapuri Delhi 💯Call Us 🔝9953322196🔝 💯Escort.Call Girls in Mayapuri Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
Call Girls in Mayapuri Delhi 💯Call Us 🔝9953322196🔝 💯Escort.aasikanpl
 
SOLUBLE PATTERN RECOGNITION RECEPTORS.pptx
SOLUBLE PATTERN RECOGNITION RECEPTORS.pptxSOLUBLE PATTERN RECOGNITION RECEPTORS.pptx
SOLUBLE PATTERN RECOGNITION RECEPTORS.pptxkessiyaTpeter
 
Bentham & Hooker's Classification. along with the merits and demerits of the ...
Bentham & Hooker's Classification. along with the merits and demerits of the ...Bentham & Hooker's Classification. along with the merits and demerits of the ...
Bentham & Hooker's Classification. along with the merits and demerits of the ...Nistarini College, Purulia (W.B) India
 
Spermiogenesis or Spermateleosis or metamorphosis of spermatid
Spermiogenesis or Spermateleosis or metamorphosis of spermatidSpermiogenesis or Spermateleosis or metamorphosis of spermatid
Spermiogenesis or Spermateleosis or metamorphosis of spermatidSarthak Sekhar Mondal
 
Solution chemistry, Moral and Normal solutions
Solution chemistry, Moral and Normal solutionsSolution chemistry, Moral and Normal solutions
Solution chemistry, Moral and Normal solutionsHajira Mahmood
 
Twin's paradox experiment is a meassurement of the extra dimensions.pptx
Twin's paradox experiment is a meassurement of the extra dimensions.pptxTwin's paradox experiment is a meassurement of the extra dimensions.pptx
Twin's paradox experiment is a meassurement of the extra dimensions.pptxEran Akiva Sinbar
 
Call Girls in Aiims Metro Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
Call Girls in Aiims Metro Delhi 💯Call Us 🔝9953322196🔝 💯Escort.Call Girls in Aiims Metro Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
Call Girls in Aiims Metro Delhi 💯Call Us 🔝9953322196🔝 💯Escort.aasikanpl
 
insect anatomy and insect body wall and their physiology
insect anatomy and insect body wall and their  physiologyinsect anatomy and insect body wall and their  physiology
insect anatomy and insect body wall and their physiologyDrAnita Sharma
 
Speech, hearing, noise, intelligibility.pptx
Speech, hearing, noise, intelligibility.pptxSpeech, hearing, noise, intelligibility.pptx
Speech, hearing, noise, intelligibility.pptxpriyankatabhane
 
Artificial Intelligence In Microbiology by Dr. Prince C P
Artificial Intelligence In Microbiology by Dr. Prince C PArtificial Intelligence In Microbiology by Dr. Prince C P
Artificial Intelligence In Microbiology by Dr. Prince C PPRINCE C P
 
Recombinant DNA technology( Transgenic plant and animal)
Recombinant DNA technology( Transgenic plant and animal)Recombinant DNA technology( Transgenic plant and animal)
Recombinant DNA technology( Transgenic plant and animal)DHURKADEVIBASKAR
 
Manassas R - Parkside Middle School 🌎🏫
Manassas R - Parkside Middle School 🌎🏫Manassas R - Parkside Middle School 🌎🏫
Manassas R - Parkside Middle School 🌎🏫qfactory1
 
Call Girls in Hauz Khas Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
Call Girls in Hauz Khas Delhi 💯Call Us 🔝9953322196🔝 💯Escort.Call Girls in Hauz Khas Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
Call Girls in Hauz Khas Delhi 💯Call Us 🔝9953322196🔝 💯Escort.aasikanpl
 
Grafana in space: Monitoring Japan's SLIM moon lander in real time
Grafana in space: Monitoring Japan's SLIM moon lander  in real timeGrafana in space: Monitoring Japan's SLIM moon lander  in real time
Grafana in space: Monitoring Japan's SLIM moon lander in real timeSatoshi NAKAHIRA
 

Recently uploaded (20)

Call Girls In Nihal Vihar Delhi ❤️8860477959 Looking Escorts In 24/7 Delhi NCR
Call Girls In Nihal Vihar Delhi ❤️8860477959 Looking Escorts In 24/7 Delhi NCRCall Girls In Nihal Vihar Delhi ❤️8860477959 Looking Escorts In 24/7 Delhi NCR
Call Girls In Nihal Vihar Delhi ❤️8860477959 Looking Escorts In 24/7 Delhi NCR
 
RESPIRATORY ADAPTATIONS TO HYPOXIA IN HUMNAS.pptx
RESPIRATORY ADAPTATIONS TO HYPOXIA IN HUMNAS.pptxRESPIRATORY ADAPTATIONS TO HYPOXIA IN HUMNAS.pptx
RESPIRATORY ADAPTATIONS TO HYPOXIA IN HUMNAS.pptx
 
LIGHT-PHENOMENA-BY-CABUALDIONALDOPANOGANCADIENTE-CONDEZA (1).pptx
LIGHT-PHENOMENA-BY-CABUALDIONALDOPANOGANCADIENTE-CONDEZA (1).pptxLIGHT-PHENOMENA-BY-CABUALDIONALDOPANOGANCADIENTE-CONDEZA (1).pptx
LIGHT-PHENOMENA-BY-CABUALDIONALDOPANOGANCADIENTE-CONDEZA (1).pptx
 
Call Us ≽ 9953322196 ≼ Call Girls In Mukherjee Nagar(Delhi) |
Call Us ≽ 9953322196 ≼ Call Girls In Mukherjee Nagar(Delhi) |Call Us ≽ 9953322196 ≼ Call Girls In Mukherjee Nagar(Delhi) |
Call Us ≽ 9953322196 ≼ Call Girls In Mukherjee Nagar(Delhi) |
 
Call Girls in Mayapuri Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
Call Girls in Mayapuri Delhi 💯Call Us 🔝9953322196🔝 💯Escort.Call Girls in Mayapuri Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
Call Girls in Mayapuri Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
 
SOLUBLE PATTERN RECOGNITION RECEPTORS.pptx
SOLUBLE PATTERN RECOGNITION RECEPTORS.pptxSOLUBLE PATTERN RECOGNITION RECEPTORS.pptx
SOLUBLE PATTERN RECOGNITION RECEPTORS.pptx
 
Bentham & Hooker's Classification. along with the merits and demerits of the ...
Bentham & Hooker's Classification. along with the merits and demerits of the ...Bentham & Hooker's Classification. along with the merits and demerits of the ...
Bentham & Hooker's Classification. along with the merits and demerits of the ...
 
Spermiogenesis or Spermateleosis or metamorphosis of spermatid
Spermiogenesis or Spermateleosis or metamorphosis of spermatidSpermiogenesis or Spermateleosis or metamorphosis of spermatid
Spermiogenesis or Spermateleosis or metamorphosis of spermatid
 
Solution chemistry, Moral and Normal solutions
Solution chemistry, Moral and Normal solutionsSolution chemistry, Moral and Normal solutions
Solution chemistry, Moral and Normal solutions
 
Twin's paradox experiment is a meassurement of the extra dimensions.pptx
Twin's paradox experiment is a meassurement of the extra dimensions.pptxTwin's paradox experiment is a meassurement of the extra dimensions.pptx
Twin's paradox experiment is a meassurement of the extra dimensions.pptx
 
Call Girls in Aiims Metro Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
Call Girls in Aiims Metro Delhi 💯Call Us 🔝9953322196🔝 💯Escort.Call Girls in Aiims Metro Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
Call Girls in Aiims Metro Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
 
insect anatomy and insect body wall and their physiology
insect anatomy and insect body wall and their  physiologyinsect anatomy and insect body wall and their  physiology
insect anatomy and insect body wall and their physiology
 
Hot Sexy call girls in Moti Nagar,🔝 9953056974 🔝 escort Service
Hot Sexy call girls in  Moti Nagar,🔝 9953056974 🔝 escort ServiceHot Sexy call girls in  Moti Nagar,🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Moti Nagar,🔝 9953056974 🔝 escort Service
 
Speech, hearing, noise, intelligibility.pptx
Speech, hearing, noise, intelligibility.pptxSpeech, hearing, noise, intelligibility.pptx
Speech, hearing, noise, intelligibility.pptx
 
Artificial Intelligence In Microbiology by Dr. Prince C P
Artificial Intelligence In Microbiology by Dr. Prince C PArtificial Intelligence In Microbiology by Dr. Prince C P
Artificial Intelligence In Microbiology by Dr. Prince C P
 
Recombinant DNA technology( Transgenic plant and animal)
Recombinant DNA technology( Transgenic plant and animal)Recombinant DNA technology( Transgenic plant and animal)
Recombinant DNA technology( Transgenic plant and animal)
 
Manassas R - Parkside Middle School 🌎🏫
Manassas R - Parkside Middle School 🌎🏫Manassas R - Parkside Middle School 🌎🏫
Manassas R - Parkside Middle School 🌎🏫
 
Engler and Prantl system of classification in plant taxonomy
Engler and Prantl system of classification in plant taxonomyEngler and Prantl system of classification in plant taxonomy
Engler and Prantl system of classification in plant taxonomy
 
Call Girls in Hauz Khas Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
Call Girls in Hauz Khas Delhi 💯Call Us 🔝9953322196🔝 💯Escort.Call Girls in Hauz Khas Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
Call Girls in Hauz Khas Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
 
Grafana in space: Monitoring Japan's SLIM moon lander in real time
Grafana in space: Monitoring Japan's SLIM moon lander  in real timeGrafana in space: Monitoring Japan's SLIM moon lander  in real time
Grafana in space: Monitoring Japan's SLIM moon lander in real time
 

Sheffield R Jan 2015 - Using R to investigate parasite infections in Asian elephants, Carly Lynsdale

  • 1. A beginner’s view on mixed modelling #crapstats carly.lynsdale@sheffield.ac.uk CarlyLynsdale MyanmarElephant Using R to investigate parasite infection in Asian Elephants
  • 2.
  • 4. EPG
  • 5.
  • 6. Are parasite eggs evenly distributed throughout elephant faeces?
  • 7. WITHIN BOLUS 119 hosts, 4 samples per host 1 elephant -> 2 samples (C + E) -> 1 repeat of each C E
  • 8. BETWEEN BOLUS 20 hosts, 6 samples per host 1 elephant - > 3 bolus sampled from each -> centre and edge from each bolus C E C E C E
  • 9. Variables Between • Elephant (ID) • Bolus (1st, 3rd, Last) • Sample (C + E) • EPG Within • Elephant (ID) • Sample (C + E) • EPG Continuous Categorical (Factor)
  • 10.
  • 11. Why Generalised Linear Mixed Effects Models (GLMMs)? The effect of sample location (independent) on EPG (dependent), with non-parametric data and accounting for the effect of elephant age, sex and camp.
  • 12. GLMMs deal with potential pseudoreplication by including (fixed and) random measures. The effect of sample location (independent) on EPG (dependent), with non-parametric data and accounting for the effect of elephant age, sex and camp. Why Generalised Linear Mixed Effects Models (GLMMs)?
  • 13. GLMMs deal with potential pseudoreplication by including (fixed and) random measures. i.e. They account for repeated measures. The effect of sample location (independent) on EPG (dependent), with non-parametric data and accounting for the effect of elephant age, sex and camp. Why Generalised Linear Mixed Effects Models (GLMMs)?
  • 14. library(lme4) = Linear Mixed Effects v4 library(lme4) # Linear Mixed Effects v4 model1 <- glmer(y ~ xf + (1|xr), family = poisson (link = “log”), data = dframe1) Package for GLMMs in R
  • 15. library(MCMCglmm)= Bayesian Markov chain Monte Carlo library(asreml) = ASREML-R ASREML-R is available on request for research/teaching, for users with an academic email address. Register online at: http://www.vsni.co.uk/software/free-to-use/teaching/asreml-teaching/registratio Others… library(nlme) = Non-Linear Mixed Effects
  • 16. So what does my code look like?... Within: Between: modelwithin<- glmer.nb (sqrt(epg) ~ sample1 + ageclass + camp + (1|id), control=glmerControl(optimizer = "bobyqa"), data = within) modelbetween <- glmer.nb (sqrt(epg) ~ bolusno1 + sample + ageclass + sex + mothcol + (1|id1), data = bween, control = glmerControl (optCtrl=list(optimizer="bobyqa")))
  • 17. So what does my code look like?... Within: Between: modelwithin<- glmer.nb (sqrt(epg) ~ sample1 + ageclass + camp + (1|id), control=glmerControl(optimizer = "bobyqa"), data = within) modelbetween <- glmer.nb (sqrt(epg) ~ bolusno1 + sample + ageclass + sex + mothcol + (1|id1), data = bween, control = glmerControl (optCtrl=list(optimizer="bobyqa")))
  • 18. A typical Negative Binomial Distribution…. EPG No.ofHosts
  • 19. So what does my code look like?... Within: Between: modelwithin<- glmer.nb (sqrt(epg) ~ sample1 + ageclass + camp + (1|id), control=glmerControl(optimizer = "bobyqa"), data = within) modelbetween <- glmer.nb (sqrt(epg) ~ bolusno1 + sample + ageclass + sex + mothcol + (1|id1), data = bween, control = glmerControl (optCtrl=list(optimizer="bobyqa")))
  • 20.
  • 21. So what does my code look like?... Within: Between: modelwithin<- glmer.nb (sqrt(epg) ~ sample1 + ageclass + sex + camp + (1|id), control=glmerControl(optimizer = "bobyqa"), data = within) modelbetween <- glmer.nb (sqrt(epg) ~ bolusno1 + sample + ageclass + sex + camp + (1|id1), control = glmerControl (optCtrl=list(optimizer="bobyqa"), data = bween)
  • 22. So what does my code look like?... Within: Between: modelwithin<- glmer.nb (sqrt(epg) ~ sample1 + ageclass + sex + camp + (1|id), control=glmerControl(optimizer = "bobyqa"), data = within) modelbetween <- glmer.nb (sqrt(epg) ~ bolusno1 + sample + ageclass + sex + camp + (1|id1), control = glmerControl (optCtrl=list(optimizer="bobyqa"), data = bween)
  • 24. So what does my code look like?... Within: Between: modelwithin<- glmer.nb (sqrt(epg) ~ sample1 + ageclass + sex + camp + (1|id), control=glmerControl(optimizer = "bobyqa"), data = within) modelbetween <- glmer.nb (sqrt(epg) ~ bolusno1 + sample + ageclass + sex + camp + (1|id1), control = glmerControl (optCtrl=list(optimizer="bobyqa"), data = bween)
  • 25. model2<-glmer.nb(sqrt(epg) ~ relevel (bolusno1,2) + sample + ageclass + sex + mothcol + (1|id1), data = bween, control = glmerControl(optCtrl=list(optimizer="bobyqa")) Bolus 1 <- Bolus 3 v Bolus 5 Bolus 3 <- Bolus 1 & Bolus 5 Bolus 5 <- Bolus 1 & Bolus 3
  • 26. modelwithin <- glmer.nb(sqrt(epg) ~ sample1 + ageclass + sex + camp + (1|id), control=glmerControl(optimizer = "bobyqa"), data = within) anova(modelwithin, modelwithin2) Within (Centre v Edge) modelwithin2 <- glmer.nb(sqrt(epg) ~ ageclass + sex + camp + (1|id), control=glmerControl(optimizer = "bobyqa"), data = within)
  • 27. Between (1st Bolus v 3rd Bolus v Last Bolus) modelbween <- glmer.nb(sqrt(epg) ~ bolusno1+sample+ageclass+sex+camp+(1|id1), data = bween, control=glmerControl(optCtrl=list(optimizer="bobyqa"))) modelbween2 <- glmer.nb(sqrt(epg) ~ sample+ageclass+sex+camp+(1|id1), data = bween, control=glmerControl(optCtrl=list(optimizer="bobyqa")))
  • 28. My Final Tips…… • Sniff out free courses – NERC funded students / Sheffield APS R course… • Keep your data simple! • Triple check everything (on different days), at least in the beginning… • Use word / excel / ppt to keep a summary of your outputs / graphs for when you write up. • Start naming models, exports, files properly from the start.
  • 29. Web Links • http://www.r-bloggers.com/ - blog site • Facebook R-space group • http://www.nerc.ac.uk/skills/postgrad/currentstude nts/latestopportunities/ - nerc free courses • https://www.coursera.org/ - free online courses • http://cran.r-project.org/doc/manuals/r-release/R- intro.html - R’s own help site • http://www.statmethods.net/interface/help.html - nice stats • https://github.com/ - online stats forum