SlideShare a Scribd company logo
1 of 34
Download to read offline
Lab 8 – Nested ANOVA
October 8 & 9, 2017
FANR 6750
Richard Chandler and Bob Cooper
Outline
1 Overview
2 Using aov
3 Using lme
Overview Using aov Using lme 2 / 16
Scenario
We subsample each experimental unit
Overview Using aov Using lme 3 / 16
Scenario
We subsample each experimental unit
For example
• We count larvae at multiple subplots within a plot
• We weigh multiple chicks in a brood
Overview Using aov Using lme 3 / 16
Scenario
We subsample each experimental unit
For example
• We count larvae at multiple subplots within a plot
• We weigh multiple chicks in a brood
We’re interested in treatment effects at the experimental
(whole) unit level, not the subunit level
Overview Using aov Using lme 3 / 16
The additive model
yijk = µ + αi + βij + εijk
Overview Using aov Using lme 4 / 16
The additive model
yijk = µ + αi + βij + εijk
Because we want our inferences to apply to all experimental
units, not just the ones in our sample, βij is random.
Overview Using aov Using lme 4 / 16
The additive model
yijk = µ + αi + βij + εijk
Because we want our inferences to apply to all experimental
units, not just the ones in our sample, βij is random.
Specifically:
βij ∼ Normal(0, σ2
B)
Overview Using aov Using lme 4 / 16
The additive model
yijk = µ + αi + βij + εijk
Because we want our inferences to apply to all experimental
units, not just the ones in our sample, βij is random.
Specifically:
βij ∼ Normal(0, σ2
B)
And as always,
εijk ∼ Normal(0, σ2
)
Overview Using aov Using lme 4 / 16
Hypotheses
Treatment effects
H0 : α1 = · · · = αa = 0
Ha : at least one inequality
Overview Using aov Using lme 5 / 16
Hypotheses
Treatment effects
H0 : α1 = · · · = αa = 0
Ha : at least one inequality
Random variation among experimental units
H0 : σ2
B = 0
Ha : σ2
B > 0
Overview Using aov Using lme 5 / 16
Example data
Import data
gypsyData <- read.csv("gypsyData.csv")
str(gypsyData)
## 'data.frame': 36 obs. of 3 variables:
## $ larvae : num 16 16 15.8 14.2 13.9 14.2 13.5 13.4 14 13.
## $ Treatment: Factor w/ 3 levels "Bt","Control",..: 1 1 1 1 1
## $ Plot : int 1 1 1 1 2 2 2 2 3 3 ...
Overview Using aov Using lme 6 / 16
Example data
Import data
gypsyData <- read.csv("gypsyData.csv")
str(gypsyData)
## 'data.frame': 36 obs. of 3 variables:
## $ larvae : num 16 16 15.8 14.2 13.9 14.2 13.5 13.4 14 13.
## $ Treatment: Factor w/ 3 levels "Bt","Control",..: 1 1 1 1 1
## $ Plot : int 1 1 1 1 2 2 2 2 3 3 ...
Convert Plot to a factor and then cross-tabulate
gypsyData$Plot <- factor(gypsyData$Plot)
table(gypsyData$Treatment, gypsyData$Plot)
##
## 1 2 3 4 5 6 7 8 9
## Bt 4 4 4 0 0 0 0 0 0
## Control 0 0 0 4 4 4 0 0 0
## Dimilin 0 0 0 0 0 0 4 4 4
Overview Using aov Using lme 6 / 16
Incorrect analysis
aov.wrong <- aov(larvae ~ Treatment + Plot,
data=gypsyData)
Overview Using aov Using lme 7 / 16
Incorrect analysis
aov.wrong <- aov(larvae ~ Treatment + Plot,
data=gypsyData)
summary(aov.wrong)
## Df Sum Sq Mean Sq F value Pr(>F)
## Treatment 2 215.39 107.69 208.89 <2e-16 ***
## Plot 6 11.17 1.86 3.61 0.0093 **
## Residuals 27 13.92 0.52
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' '
Overview Using aov Using lme 7 / 16
Incorrect analysis
aov.wrong <- aov(larvae ~ Treatment + Plot,
data=gypsyData)
summary(aov.wrong)
## Df Sum Sq Mean Sq F value Pr(>F)
## Treatment 2 215.39 107.69 208.89 <2e-16 ***
## Plot 6 11.17 1.86 3.61 0.0093 **
## Residuals 27 13.92 0.52
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' '
The denominator degrees-of-freedom are wrong
Overview Using aov Using lme 7 / 16
Correct analysis
aov.correct <- aov(larvae ~ Treatment + Error(Plot),
data=gypsyData)
Overview Using aov Using lme 8 / 16
Correct analysis
aov.correct <- aov(larvae ~ Treatment + Error(Plot),
data=gypsyData)
summary(aov.correct)
##
## Error: Plot
## Df Sum Sq Mean Sq F value Pr(>F)
## Treatment 2 215.39 107.69 57.87 0.00012 ***
## Residuals 6 11.17 1.86
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' '
##
## Error: Within
## Df Sum Sq Mean Sq F value Pr(>F)
## Residuals 27 13.92 0.5156
Overview Using aov Using lme 8 / 16
What happens if we analyze plot-level means?
The aggregate function is similar to tapply but it works on
entire data.frames. Here we get averages for each whole plot.
plotData <- aggregate(formula=larvae ~ Treatment + Plot,
data=gypsyData, FUN=mean)
Overview Using aov Using lme 9 / 16
What happens if we analyze plot-level means?
The aggregate function is similar to tapply but it works on
entire data.frames. Here we get averages for each whole plot.
plotData <- aggregate(formula=larvae ~ Treatment + Plot,
data=gypsyData, FUN=mean)
plotData
## Treatment Plot larvae
## 1 Bt 1 15.50
## 2 Bt 2 13.75
## 3 Bt 3 14.00
## 4 Control 4 18.25
## 5 Control 5 18.75
## 6 Control 6 19.25
## 7 Dimilin 7 12.50
## 8 Dimilin 8 13.50
## 9 Dimilin 9 13.00
Overview Using aov Using lme 9 / 16
F and p values are the same as before
aov.plot <- aov(larvae ~ Treatment, data=plotData)
summary(aov.plot)
## Df Sum Sq Mean Sq F value Pr(>F)
## Treatment 2 53.85 26.924 57.87 0.00012 ***
## Residuals 6 2.79 0.465
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Overview Using aov Using lme 10 / 16
F and p values are the same as before
aov.plot <- aov(larvae ~ Treatment, data=plotData)
summary(aov.plot)
## Df Sum Sq Mean Sq F value Pr(>F)
## Treatment 2 53.85 26.924 57.87 0.00012 ***
## Residuals 6 2.79 0.465
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
summary(aov.correct)
##
## Error: Plot
## Df Sum Sq Mean Sq F value Pr(>F)
## Treatment 2 215.39 107.69 57.87 0.00012 ***
## Residuals 6 11.17 1.86
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Error: Within
## Df Sum Sq Mean Sq F value Pr(>F)
## Residuals 27 13.92 0.5156
Overview Using aov Using lme 10 / 16
Issues
When using using aov with Error term:
• You can’t use TukeyHSD
• You don’t get a direct estimate of σ2
B
• Doesn’t handle unbalanced designs well
• But, you can use model.tables and se.contrast
Overview Using aov Using lme 11 / 16
Issues
When using using aov with Error term:
• You can’t use TukeyHSD
• You don’t get a direct estimate of σ2
B
• Doesn’t handle unbalanced designs well
• But, you can use model.tables and se.contrast
An alternative is to use lme function in nlme package
Overview Using aov Using lme 11 / 16
Issues
When using using aov with Error term:
• You can’t use TukeyHSD
• You don’t get a direct estimate of σ2
B
• Doesn’t handle unbalanced designs well
• But, you can use model.tables and se.contrast
An alternative is to use lme function in nlme package
• Possible to get direct estimates of σ2
B and other variance
parameters
• Handles very complex models and unbalanced designs
• Possible to do multiple comparisons and contrasts using the
the glht function in the multcomp package.
Overview Using aov Using lme 11 / 16
Issues
When using using aov with Error term:
• You can’t use TukeyHSD
• You don’t get a direct estimate of σ2
B
• Doesn’t handle unbalanced designs well
• But, you can use model.tables and se.contrast
An alternative is to use lme function in nlme package
• Possible to get direct estimates of σ2
B and other variance
parameters
• Handles very complex models and unbalanced designs
• Possible to do multiple comparisons and contrasts using the
the glht function in the multcomp package.
• But. . .
• Only works if there random effects
• ANOVA tables aren’t as complete as aov
Overview Using aov Using lme 11 / 16
Using the lme function
library(nlme)
library(multcomp)
lme1 <- lme(larvae ~ Treatment, random=~1|Plot,
data=gypsyData)
Overview Using aov Using lme 12 / 16
Using the lme function
library(nlme)
library(multcomp)
lme1 <- lme(larvae ~ Treatment, random=~1|Plot,
data=gypsyData)
anova(lme1, Terms="Treatment")
## F-test for: Treatment
## numDF denDF F-value p-value
## 1 2 6 57.86567 1e-04
Overview Using aov Using lme 12 / 16
Variance parameter estimates
The first row shows the estimates of σ2
B and σB. The second row shows
the estimates of σ2
and σ
VarCorr(lme1)
## Plot = pdLogChol(1)
## Variance StdDev
## (Intercept) 0.3363889 0.5799904
## Residual 0.5155556 0.7180220
Overview Using aov Using lme 13 / 16
Variance parameter estimates
The first row shows the estimates of σ2
B and σB. The second row shows
the estimates of σ2
and σ
VarCorr(lme1)
## Plot = pdLogChol(1)
## Variance StdDev
## (Intercept) 0.3363889 0.5799904
## Residual 0.5155556 0.7180220
There is more random variation within whole units than among
whole units (after accounting for treatment effects)
Overview Using aov Using lme 13 / 16
Extract the plot-level random effects
These are the βij’s
round(ranef(lme1), 2)
## (Intercept)
## 1 0.78
## 2 -0.48
## 3 -0.30
## 4 -0.36
## 5 0.00
## 6 0.36
## 7 -0.36
## 8 0.36
## 9 0.00
Overview Using aov Using lme 14 / 16
Multiple comparisons
tuk <- glht(lme1, linfct=mcp(Treatment="Tukey"))
Overview Using aov Using lme 15 / 16
Multiple comparisons
tuk <- glht(lme1, linfct=mcp(Treatment="Tukey"))
summary(tuk)
##
## Simultaneous Tests for General Linear Hypotheses
##
## Multiple Comparisons of Means: Tukey Contrasts
##
##
## Fit: lme.formula(fixed = larvae ~ Treatment, data = gypsyData, random = ~1 |
## Plot)
##
## Linear Hypotheses:
## Estimate Std. Error z value Pr(>|z|)
## Control - Bt == 0 4.3333 0.5569 7.781 <0.001 ***
## Dimilin - Bt == 0 -1.4167 0.5569 -2.544 0.0295 *
## Dimilin - Control == 0 -5.7500 0.5569 -10.324 <0.001 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## (Adjusted p values reported -- single-step method)
Overview Using aov Using lme 15 / 16
Assignment
To determine if salinity affects adult fish reproductive performance, a
researcher places one pregnant female in a tank with one of three salinity
levels: low, medium, and high, or a control tank. A week after birth, two
offspring (fry) are measured.
Run a nested ANOVA using aov and lme on the fishData.csv
dataset. Answer the following questions:
(1) What are the null and alternative hypotheses?
(2) Does salinity affect fry growth?
(3) If so, which salinity levels differ?
(4) Is there more random variation among or within experimental units?
Upload your self-contained R script to ELC at least one day before
your next lab
Overview Using aov Using lme 16 / 16

More Related Content

Similar to Nested ANOVA of Fish Reproductive Data

Scilab as a calculator
Scilab as a calculatorScilab as a calculator
Scilab as a calculatorScilab
 
Instrumentation and measurements
Instrumentation and measurementsInstrumentation and measurements
Instrumentation and measurementsTuba Tanveer
 
PVS-Studio team is about to produce a technical breakthrough, but for now let...
PVS-Studio team is about to produce a technical breakthrough, but for now let...PVS-Studio team is about to produce a technical breakthrough, but for now let...
PVS-Studio team is about to produce a technical breakthrough, but for now let...PVS-Studio
 
Numerical analysis using Scilab: Error analysis and propagation
Numerical analysis using Scilab: Error analysis and propagationNumerical analysis using Scilab: Error analysis and propagation
Numerical analysis using Scilab: Error analysis and propagationScilab
 
White Box testing by Pankaj Thakur, NITTTR Chandigarh
White Box testing by Pankaj Thakur, NITTTR ChandigarhWhite Box testing by Pankaj Thakur, NITTTR Chandigarh
White Box testing by Pankaj Thakur, NITTTR ChandigarhPankaj Thakur
 
RxJava 2 Reactive extensions for the JVM
RxJava 2  Reactive extensions for the JVMRxJava 2  Reactive extensions for the JVM
RxJava 2 Reactive extensions for the JVMNetesh Kumar
 
Verilog Lecture2 thhts
Verilog Lecture2 thhtsVerilog Lecture2 thhts
Verilog Lecture2 thhtsBéo Tú
 
Verilog Lecture3 hust 2014
Verilog Lecture3 hust 2014Verilog Lecture3 hust 2014
Verilog Lecture3 hust 2014Béo Tú
 
MATLAB Basics-Part1
MATLAB Basics-Part1MATLAB Basics-Part1
MATLAB Basics-Part1Elaf A.Saeed
 
Numerical analysis using Scilab: Numerical stability and conditioning
Numerical analysis using Scilab: Numerical stability and conditioningNumerical analysis using Scilab: Numerical stability and conditioning
Numerical analysis using Scilab: Numerical stability and conditioningScilab
 
CMIS 102 Hands-On Lab Week 4OverviewThis hands-on lab all.docx
CMIS 102 Hands-On Lab Week 4OverviewThis hands-on lab all.docxCMIS 102 Hands-On Lab Week 4OverviewThis hands-on lab all.docx
CMIS 102 Hands-On Lab Week 4OverviewThis hands-on lab all.docxmonicafrancis71118
 
Introduction to flowchart
Introduction to flowchartIntroduction to flowchart
Introduction to flowchartJordan Delacruz
 
T11_effects_of_peripheral_stim
T11_effects_of_peripheral_stimT11_effects_of_peripheral_stim
T11_effects_of_peripheral_stimtutorialsruby
 
T11_effects_of_peripheral_stim
T11_effects_of_peripheral_stimT11_effects_of_peripheral_stim
T11_effects_of_peripheral_stimtutorialsruby
 
Design ofexperimentstutorial
Design ofexperimentstutorialDesign ofexperimentstutorial
Design ofexperimentstutorialIngrid McKenzie
 

Similar to Nested ANOVA of Fish Reproductive Data (20)

Scilab as a calculator
Scilab as a calculatorScilab as a calculator
Scilab as a calculator
 
Instrumentation and measurements
Instrumentation and measurementsInstrumentation and measurements
Instrumentation and measurements
 
PVS-Studio team is about to produce a technical breakthrough, but for now let...
PVS-Studio team is about to produce a technical breakthrough, but for now let...PVS-Studio team is about to produce a technical breakthrough, but for now let...
PVS-Studio team is about to produce a technical breakthrough, but for now let...
 
Numerical analysis using Scilab: Error analysis and propagation
Numerical analysis using Scilab: Error analysis and propagationNumerical analysis using Scilab: Error analysis and propagation
Numerical analysis using Scilab: Error analysis and propagation
 
White Box testing by Pankaj Thakur, NITTTR Chandigarh
White Box testing by Pankaj Thakur, NITTTR ChandigarhWhite Box testing by Pankaj Thakur, NITTTR Chandigarh
White Box testing by Pankaj Thakur, NITTTR Chandigarh
 
Ch05
Ch05Ch05
Ch05
 
RxJava 2 Reactive extensions for the JVM
RxJava 2  Reactive extensions for the JVMRxJava 2  Reactive extensions for the JVM
RxJava 2 Reactive extensions for the JVM
 
Verilog Lecture2 thhts
Verilog Lecture2 thhtsVerilog Lecture2 thhts
Verilog Lecture2 thhts
 
Verilog Lecture3 hust 2014
Verilog Lecture3 hust 2014Verilog Lecture3 hust 2014
Verilog Lecture3 hust 2014
 
MATLAB Basics-Part1
MATLAB Basics-Part1MATLAB Basics-Part1
MATLAB Basics-Part1
 
Numerical analysis using Scilab: Numerical stability and conditioning
Numerical analysis using Scilab: Numerical stability and conditioningNumerical analysis using Scilab: Numerical stability and conditioning
Numerical analysis using Scilab: Numerical stability and conditioning
 
CMIS 102 Hands-On Lab Week 4OverviewThis hands-on lab all.docx
CMIS 102 Hands-On Lab Week 4OverviewThis hands-on lab all.docxCMIS 102 Hands-On Lab Week 4OverviewThis hands-on lab all.docx
CMIS 102 Hands-On Lab Week 4OverviewThis hands-on lab all.docx
 
Perl_Part2
Perl_Part2Perl_Part2
Perl_Part2
 
Chapter 18,19
Chapter 18,19Chapter 18,19
Chapter 18,19
 
Blocking lab
Blocking labBlocking lab
Blocking lab
 
Introduction to flowchart
Introduction to flowchartIntroduction to flowchart
Introduction to flowchart
 
T11_effects_of_peripheral_stim
T11_effects_of_peripheral_stimT11_effects_of_peripheral_stim
T11_effects_of_peripheral_stim
 
T11_effects_of_peripheral_stim
T11_effects_of_peripheral_stimT11_effects_of_peripheral_stim
T11_effects_of_peripheral_stim
 
P spice tutorialhkn
P spice tutorialhknP spice tutorialhkn
P spice tutorialhkn
 
Design ofexperimentstutorial
Design ofexperimentstutorialDesign ofexperimentstutorial
Design ofexperimentstutorial
 

More from richardchandler

Introduction to Generalized Linear Models
Introduction to Generalized Linear ModelsIntroduction to Generalized Linear Models
Introduction to Generalized Linear Modelsrichardchandler
 
Introduction to statistical modeling in R
Introduction to statistical modeling in RIntroduction to statistical modeling in R
Introduction to statistical modeling in Rrichardchandler
 
Lab on contrasts, estimation, and power
Lab on contrasts, estimation, and powerLab on contrasts, estimation, and power
Lab on contrasts, estimation, and powerrichardchandler
 
t-tests in R - Lab slides for UGA course FANR 6750
t-tests in R - Lab slides for UGA course FANR 6750t-tests in R - Lab slides for UGA course FANR 6750
t-tests in R - Lab slides for UGA course FANR 6750richardchandler
 
Introduction to R - Lab slides for UGA course FANR 6750
Introduction to R - Lab slides for UGA course FANR 6750Introduction to R - Lab slides for UGA course FANR 6750
Introduction to R - Lab slides for UGA course FANR 6750richardchandler
 
Hierarchichal species distributions model and Maxent
Hierarchichal species distributions model and MaxentHierarchichal species distributions model and Maxent
Hierarchichal species distributions model and Maxentrichardchandler
 
The role of spatial models in applied ecological research
The role of spatial models in applied ecological researchThe role of spatial models in applied ecological research
The role of spatial models in applied ecological researchrichardchandler
 

More from richardchandler (12)

Introduction to Generalized Linear Models
Introduction to Generalized Linear ModelsIntroduction to Generalized Linear Models
Introduction to Generalized Linear Models
 
Introduction to statistical modeling in R
Introduction to statistical modeling in RIntroduction to statistical modeling in R
Introduction to statistical modeling in R
 
ANCOVA in R
ANCOVA in RANCOVA in R
ANCOVA in R
 
Assumptions of ANOVA
Assumptions of ANOVAAssumptions of ANOVA
Assumptions of ANOVA
 
Lab on contrasts, estimation, and power
Lab on contrasts, estimation, and powerLab on contrasts, estimation, and power
Lab on contrasts, estimation, and power
 
One-way ANOVA
One-way ANOVAOne-way ANOVA
One-way ANOVA
 
t-tests in R - Lab slides for UGA course FANR 6750
t-tests in R - Lab slides for UGA course FANR 6750t-tests in R - Lab slides for UGA course FANR 6750
t-tests in R - Lab slides for UGA course FANR 6750
 
Introduction to R - Lab slides for UGA course FANR 6750
Introduction to R - Lab slides for UGA course FANR 6750Introduction to R - Lab slides for UGA course FANR 6750
Introduction to R - Lab slides for UGA course FANR 6750
 
Hierarchichal species distributions model and Maxent
Hierarchichal species distributions model and MaxentHierarchichal species distributions model and Maxent
Hierarchichal species distributions model and Maxent
 
Slides from ESA 2015
Slides from ESA 2015Slides from ESA 2015
Slides from ESA 2015
 
The role of spatial models in applied ecological research
The role of spatial models in applied ecological researchThe role of spatial models in applied ecological research
The role of spatial models in applied ecological research
 
2014 ISEC slides
2014 ISEC slides2014 ISEC slides
2014 ISEC slides
 

Recently uploaded

Neurodevelopmental disorders according to the dsm 5 tr
Neurodevelopmental disorders according to the dsm 5 trNeurodevelopmental disorders according to the dsm 5 tr
Neurodevelopmental disorders according to the dsm 5 trssuser06f238
 
Analytical Profile of Coleus Forskohlii | Forskolin .pptx
Analytical Profile of Coleus Forskohlii | Forskolin .pptxAnalytical Profile of Coleus Forskohlii | Forskolin .pptx
Analytical Profile of Coleus Forskohlii | Forskolin .pptxSwapnil Therkar
 
Call Girls in Munirka Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Munirka Delhi 💯Call Us 🔝8264348440🔝Call Girls in Munirka Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Munirka Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
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
 
Call Girls in Munirka Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
Call Girls in Munirka Delhi 💯Call Us 🔝9953322196🔝 💯Escort.Call Girls in Munirka Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
Call Girls in Munirka Delhi 💯Call Us 🔝9953322196🔝 💯Escort.aasikanpl
 
Physiochemical properties of nanomaterials and its nanotoxicity.pptx
Physiochemical properties of nanomaterials and its nanotoxicity.pptxPhysiochemical properties of nanomaterials and its nanotoxicity.pptx
Physiochemical properties of nanomaterials and its nanotoxicity.pptxAArockiyaNisha
 
Behavioral Disorder: Schizophrenia & it's Case Study.pdf
Behavioral Disorder: Schizophrenia & it's Case Study.pdfBehavioral Disorder: Schizophrenia & it's Case Study.pdf
Behavioral Disorder: Schizophrenia & it's Case Study.pdfSELF-EXPLANATORY
 
TOPIC 8 Temperature and Heat.pdf physics
TOPIC 8 Temperature and Heat.pdf physicsTOPIC 8 Temperature and Heat.pdf physics
TOPIC 8 Temperature and Heat.pdf physicsssuserddc89b
 
Natural Polymer Based Nanomaterials
Natural Polymer Based NanomaterialsNatural Polymer Based Nanomaterials
Natural Polymer Based NanomaterialsAArockiyaNisha
 
STERILITY TESTING OF PHARMACEUTICALS ppt by DR.C.P.PRINCE
STERILITY TESTING OF PHARMACEUTICALS ppt by DR.C.P.PRINCESTERILITY TESTING OF PHARMACEUTICALS ppt by DR.C.P.PRINCE
STERILITY TESTING OF PHARMACEUTICALS ppt by DR.C.P.PRINCEPRINCE C P
 
All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...
All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...
All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...Sérgio Sacani
 
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
 
Animal Communication- Auditory and Visual.pptx
Animal Communication- Auditory and Visual.pptxAnimal Communication- Auditory and Visual.pptx
Animal Communication- Auditory and Visual.pptxUmerFayaz5
 
Orientation, design and principles of polyhouse
Orientation, design and principles of polyhouseOrientation, design and principles of polyhouse
Orientation, design and principles of polyhousejana861314
 
Luciferase in rDNA technology (biotechnology).pptx
Luciferase in rDNA technology (biotechnology).pptxLuciferase in rDNA technology (biotechnology).pptx
Luciferase in rDNA technology (biotechnology).pptxAleenaTreesaSaji
 
Isotopic evidence of long-lived volcanism on Io
Isotopic evidence of long-lived volcanism on IoIsotopic evidence of long-lived volcanism on Io
Isotopic evidence of long-lived volcanism on IoSérgio Sacani
 
CALL ON ➥8923113531 🔝Call Girls Kesar Bagh Lucknow best Night Fun service 🪡
CALL ON ➥8923113531 🔝Call Girls Kesar Bagh Lucknow best Night Fun service  🪡CALL ON ➥8923113531 🔝Call Girls Kesar Bagh Lucknow best Night Fun service  🪡
CALL ON ➥8923113531 🔝Call Girls Kesar Bagh Lucknow best Night Fun service 🪡anilsa9823
 
Recombination DNA Technology (Nucleic Acid Hybridization )
Recombination DNA Technology (Nucleic Acid Hybridization )Recombination DNA Technology (Nucleic Acid Hybridization )
Recombination DNA Technology (Nucleic Acid Hybridization )aarthirajkumar25
 
Disentangling the origin of chemical differences using GHOST
Disentangling the origin of chemical differences using GHOSTDisentangling the origin of chemical differences using GHOST
Disentangling the origin of chemical differences using GHOSTSérgio Sacani
 

Recently uploaded (20)

Neurodevelopmental disorders according to the dsm 5 tr
Neurodevelopmental disorders according to the dsm 5 trNeurodevelopmental disorders according to the dsm 5 tr
Neurodevelopmental disorders according to the dsm 5 tr
 
Analytical Profile of Coleus Forskohlii | Forskolin .pptx
Analytical Profile of Coleus Forskohlii | Forskolin .pptxAnalytical Profile of Coleus Forskohlii | Forskolin .pptx
Analytical Profile of Coleus Forskohlii | Forskolin .pptx
 
Call Girls in Munirka Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Munirka Delhi 💯Call Us 🔝8264348440🔝Call Girls in Munirka Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Munirka Delhi 💯Call Us 🔝8264348440🔝
 
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 ...
 
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 Munirka Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
Call Girls in Munirka Delhi 💯Call Us 🔝9953322196🔝 💯Escort.Call Girls in Munirka Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
Call Girls in Munirka Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
 
Physiochemical properties of nanomaterials and its nanotoxicity.pptx
Physiochemical properties of nanomaterials and its nanotoxicity.pptxPhysiochemical properties of nanomaterials and its nanotoxicity.pptx
Physiochemical properties of nanomaterials and its nanotoxicity.pptx
 
Behavioral Disorder: Schizophrenia & it's Case Study.pdf
Behavioral Disorder: Schizophrenia & it's Case Study.pdfBehavioral Disorder: Schizophrenia & it's Case Study.pdf
Behavioral Disorder: Schizophrenia & it's Case Study.pdf
 
TOPIC 8 Temperature and Heat.pdf physics
TOPIC 8 Temperature and Heat.pdf physicsTOPIC 8 Temperature and Heat.pdf physics
TOPIC 8 Temperature and Heat.pdf physics
 
Natural Polymer Based Nanomaterials
Natural Polymer Based NanomaterialsNatural Polymer Based Nanomaterials
Natural Polymer Based Nanomaterials
 
STERILITY TESTING OF PHARMACEUTICALS ppt by DR.C.P.PRINCE
STERILITY TESTING OF PHARMACEUTICALS ppt by DR.C.P.PRINCESTERILITY TESTING OF PHARMACEUTICALS ppt by DR.C.P.PRINCE
STERILITY TESTING OF PHARMACEUTICALS ppt by DR.C.P.PRINCE
 
All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...
All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...
All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...
 
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) |
 
Animal Communication- Auditory and Visual.pptx
Animal Communication- Auditory and Visual.pptxAnimal Communication- Auditory and Visual.pptx
Animal Communication- Auditory and Visual.pptx
 
Orientation, design and principles of polyhouse
Orientation, design and principles of polyhouseOrientation, design and principles of polyhouse
Orientation, design and principles of polyhouse
 
Luciferase in rDNA technology (biotechnology).pptx
Luciferase in rDNA technology (biotechnology).pptxLuciferase in rDNA technology (biotechnology).pptx
Luciferase in rDNA technology (biotechnology).pptx
 
Isotopic evidence of long-lived volcanism on Io
Isotopic evidence of long-lived volcanism on IoIsotopic evidence of long-lived volcanism on Io
Isotopic evidence of long-lived volcanism on Io
 
CALL ON ➥8923113531 🔝Call Girls Kesar Bagh Lucknow best Night Fun service 🪡
CALL ON ➥8923113531 🔝Call Girls Kesar Bagh Lucknow best Night Fun service  🪡CALL ON ➥8923113531 🔝Call Girls Kesar Bagh Lucknow best Night Fun service  🪡
CALL ON ➥8923113531 🔝Call Girls Kesar Bagh Lucknow best Night Fun service 🪡
 
Recombination DNA Technology (Nucleic Acid Hybridization )
Recombination DNA Technology (Nucleic Acid Hybridization )Recombination DNA Technology (Nucleic Acid Hybridization )
Recombination DNA Technology (Nucleic Acid Hybridization )
 
Disentangling the origin of chemical differences using GHOST
Disentangling the origin of chemical differences using GHOSTDisentangling the origin of chemical differences using GHOST
Disentangling the origin of chemical differences using GHOST
 

Nested ANOVA of Fish Reproductive Data

  • 1. Lab 8 – Nested ANOVA October 8 & 9, 2017 FANR 6750 Richard Chandler and Bob Cooper
  • 2. Outline 1 Overview 2 Using aov 3 Using lme Overview Using aov Using lme 2 / 16
  • 3. Scenario We subsample each experimental unit Overview Using aov Using lme 3 / 16
  • 4. Scenario We subsample each experimental unit For example • We count larvae at multiple subplots within a plot • We weigh multiple chicks in a brood Overview Using aov Using lme 3 / 16
  • 5. Scenario We subsample each experimental unit For example • We count larvae at multiple subplots within a plot • We weigh multiple chicks in a brood We’re interested in treatment effects at the experimental (whole) unit level, not the subunit level Overview Using aov Using lme 3 / 16
  • 6. The additive model yijk = µ + αi + βij + εijk Overview Using aov Using lme 4 / 16
  • 7. The additive model yijk = µ + αi + βij + εijk Because we want our inferences to apply to all experimental units, not just the ones in our sample, βij is random. Overview Using aov Using lme 4 / 16
  • 8. The additive model yijk = µ + αi + βij + εijk Because we want our inferences to apply to all experimental units, not just the ones in our sample, βij is random. Specifically: βij ∼ Normal(0, σ2 B) Overview Using aov Using lme 4 / 16
  • 9. The additive model yijk = µ + αi + βij + εijk Because we want our inferences to apply to all experimental units, not just the ones in our sample, βij is random. Specifically: βij ∼ Normal(0, σ2 B) And as always, εijk ∼ Normal(0, σ2 ) Overview Using aov Using lme 4 / 16
  • 10. Hypotheses Treatment effects H0 : α1 = · · · = αa = 0 Ha : at least one inequality Overview Using aov Using lme 5 / 16
  • 11. Hypotheses Treatment effects H0 : α1 = · · · = αa = 0 Ha : at least one inequality Random variation among experimental units H0 : σ2 B = 0 Ha : σ2 B > 0 Overview Using aov Using lme 5 / 16
  • 12. Example data Import data gypsyData <- read.csv("gypsyData.csv") str(gypsyData) ## 'data.frame': 36 obs. of 3 variables: ## $ larvae : num 16 16 15.8 14.2 13.9 14.2 13.5 13.4 14 13. ## $ Treatment: Factor w/ 3 levels "Bt","Control",..: 1 1 1 1 1 ## $ Plot : int 1 1 1 1 2 2 2 2 3 3 ... Overview Using aov Using lme 6 / 16
  • 13. Example data Import data gypsyData <- read.csv("gypsyData.csv") str(gypsyData) ## 'data.frame': 36 obs. of 3 variables: ## $ larvae : num 16 16 15.8 14.2 13.9 14.2 13.5 13.4 14 13. ## $ Treatment: Factor w/ 3 levels "Bt","Control",..: 1 1 1 1 1 ## $ Plot : int 1 1 1 1 2 2 2 2 3 3 ... Convert Plot to a factor and then cross-tabulate gypsyData$Plot <- factor(gypsyData$Plot) table(gypsyData$Treatment, gypsyData$Plot) ## ## 1 2 3 4 5 6 7 8 9 ## Bt 4 4 4 0 0 0 0 0 0 ## Control 0 0 0 4 4 4 0 0 0 ## Dimilin 0 0 0 0 0 0 4 4 4 Overview Using aov Using lme 6 / 16
  • 14. Incorrect analysis aov.wrong <- aov(larvae ~ Treatment + Plot, data=gypsyData) Overview Using aov Using lme 7 / 16
  • 15. Incorrect analysis aov.wrong <- aov(larvae ~ Treatment + Plot, data=gypsyData) summary(aov.wrong) ## Df Sum Sq Mean Sq F value Pr(>F) ## Treatment 2 215.39 107.69 208.89 <2e-16 *** ## Plot 6 11.17 1.86 3.61 0.0093 ** ## Residuals 27 13.92 0.52 ## --- ## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' Overview Using aov Using lme 7 / 16
  • 16. Incorrect analysis aov.wrong <- aov(larvae ~ Treatment + Plot, data=gypsyData) summary(aov.wrong) ## Df Sum Sq Mean Sq F value Pr(>F) ## Treatment 2 215.39 107.69 208.89 <2e-16 *** ## Plot 6 11.17 1.86 3.61 0.0093 ** ## Residuals 27 13.92 0.52 ## --- ## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' The denominator degrees-of-freedom are wrong Overview Using aov Using lme 7 / 16
  • 17. Correct analysis aov.correct <- aov(larvae ~ Treatment + Error(Plot), data=gypsyData) Overview Using aov Using lme 8 / 16
  • 18. Correct analysis aov.correct <- aov(larvae ~ Treatment + Error(Plot), data=gypsyData) summary(aov.correct) ## ## Error: Plot ## Df Sum Sq Mean Sq F value Pr(>F) ## Treatment 2 215.39 107.69 57.87 0.00012 *** ## Residuals 6 11.17 1.86 ## --- ## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' ## ## Error: Within ## Df Sum Sq Mean Sq F value Pr(>F) ## Residuals 27 13.92 0.5156 Overview Using aov Using lme 8 / 16
  • 19. What happens if we analyze plot-level means? The aggregate function is similar to tapply but it works on entire data.frames. Here we get averages for each whole plot. plotData <- aggregate(formula=larvae ~ Treatment + Plot, data=gypsyData, FUN=mean) Overview Using aov Using lme 9 / 16
  • 20. What happens if we analyze plot-level means? The aggregate function is similar to tapply but it works on entire data.frames. Here we get averages for each whole plot. plotData <- aggregate(formula=larvae ~ Treatment + Plot, data=gypsyData, FUN=mean) plotData ## Treatment Plot larvae ## 1 Bt 1 15.50 ## 2 Bt 2 13.75 ## 3 Bt 3 14.00 ## 4 Control 4 18.25 ## 5 Control 5 18.75 ## 6 Control 6 19.25 ## 7 Dimilin 7 12.50 ## 8 Dimilin 8 13.50 ## 9 Dimilin 9 13.00 Overview Using aov Using lme 9 / 16
  • 21. F and p values are the same as before aov.plot <- aov(larvae ~ Treatment, data=plotData) summary(aov.plot) ## Df Sum Sq Mean Sq F value Pr(>F) ## Treatment 2 53.85 26.924 57.87 0.00012 *** ## Residuals 6 2.79 0.465 ## --- ## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Overview Using aov Using lme 10 / 16
  • 22. F and p values are the same as before aov.plot <- aov(larvae ~ Treatment, data=plotData) summary(aov.plot) ## Df Sum Sq Mean Sq F value Pr(>F) ## Treatment 2 53.85 26.924 57.87 0.00012 *** ## Residuals 6 2.79 0.465 ## --- ## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 summary(aov.correct) ## ## Error: Plot ## Df Sum Sq Mean Sq F value Pr(>F) ## Treatment 2 215.39 107.69 57.87 0.00012 *** ## Residuals 6 11.17 1.86 ## --- ## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 ## ## Error: Within ## Df Sum Sq Mean Sq F value Pr(>F) ## Residuals 27 13.92 0.5156 Overview Using aov Using lme 10 / 16
  • 23. Issues When using using aov with Error term: • You can’t use TukeyHSD • You don’t get a direct estimate of σ2 B • Doesn’t handle unbalanced designs well • But, you can use model.tables and se.contrast Overview Using aov Using lme 11 / 16
  • 24. Issues When using using aov with Error term: • You can’t use TukeyHSD • You don’t get a direct estimate of σ2 B • Doesn’t handle unbalanced designs well • But, you can use model.tables and se.contrast An alternative is to use lme function in nlme package Overview Using aov Using lme 11 / 16
  • 25. Issues When using using aov with Error term: • You can’t use TukeyHSD • You don’t get a direct estimate of σ2 B • Doesn’t handle unbalanced designs well • But, you can use model.tables and se.contrast An alternative is to use lme function in nlme package • Possible to get direct estimates of σ2 B and other variance parameters • Handles very complex models and unbalanced designs • Possible to do multiple comparisons and contrasts using the the glht function in the multcomp package. Overview Using aov Using lme 11 / 16
  • 26. Issues When using using aov with Error term: • You can’t use TukeyHSD • You don’t get a direct estimate of σ2 B • Doesn’t handle unbalanced designs well • But, you can use model.tables and se.contrast An alternative is to use lme function in nlme package • Possible to get direct estimates of σ2 B and other variance parameters • Handles very complex models and unbalanced designs • Possible to do multiple comparisons and contrasts using the the glht function in the multcomp package. • But. . . • Only works if there random effects • ANOVA tables aren’t as complete as aov Overview Using aov Using lme 11 / 16
  • 27. Using the lme function library(nlme) library(multcomp) lme1 <- lme(larvae ~ Treatment, random=~1|Plot, data=gypsyData) Overview Using aov Using lme 12 / 16
  • 28. Using the lme function library(nlme) library(multcomp) lme1 <- lme(larvae ~ Treatment, random=~1|Plot, data=gypsyData) anova(lme1, Terms="Treatment") ## F-test for: Treatment ## numDF denDF F-value p-value ## 1 2 6 57.86567 1e-04 Overview Using aov Using lme 12 / 16
  • 29. Variance parameter estimates The first row shows the estimates of σ2 B and σB. The second row shows the estimates of σ2 and σ VarCorr(lme1) ## Plot = pdLogChol(1) ## Variance StdDev ## (Intercept) 0.3363889 0.5799904 ## Residual 0.5155556 0.7180220 Overview Using aov Using lme 13 / 16
  • 30. Variance parameter estimates The first row shows the estimates of σ2 B and σB. The second row shows the estimates of σ2 and σ VarCorr(lme1) ## Plot = pdLogChol(1) ## Variance StdDev ## (Intercept) 0.3363889 0.5799904 ## Residual 0.5155556 0.7180220 There is more random variation within whole units than among whole units (after accounting for treatment effects) Overview Using aov Using lme 13 / 16
  • 31. Extract the plot-level random effects These are the βij’s round(ranef(lme1), 2) ## (Intercept) ## 1 0.78 ## 2 -0.48 ## 3 -0.30 ## 4 -0.36 ## 5 0.00 ## 6 0.36 ## 7 -0.36 ## 8 0.36 ## 9 0.00 Overview Using aov Using lme 14 / 16
  • 32. Multiple comparisons tuk <- glht(lme1, linfct=mcp(Treatment="Tukey")) Overview Using aov Using lme 15 / 16
  • 33. Multiple comparisons tuk <- glht(lme1, linfct=mcp(Treatment="Tukey")) summary(tuk) ## ## Simultaneous Tests for General Linear Hypotheses ## ## Multiple Comparisons of Means: Tukey Contrasts ## ## ## Fit: lme.formula(fixed = larvae ~ Treatment, data = gypsyData, random = ~1 | ## Plot) ## ## Linear Hypotheses: ## Estimate Std. Error z value Pr(>|z|) ## Control - Bt == 0 4.3333 0.5569 7.781 <0.001 *** ## Dimilin - Bt == 0 -1.4167 0.5569 -2.544 0.0295 * ## Dimilin - Control == 0 -5.7500 0.5569 -10.324 <0.001 *** ## --- ## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 ## (Adjusted p values reported -- single-step method) Overview Using aov Using lme 15 / 16
  • 34. Assignment To determine if salinity affects adult fish reproductive performance, a researcher places one pregnant female in a tank with one of three salinity levels: low, medium, and high, or a control tank. A week after birth, two offspring (fry) are measured. Run a nested ANOVA using aov and lme on the fishData.csv dataset. Answer the following questions: (1) What are the null and alternative hypotheses? (2) Does salinity affect fry growth? (3) If so, which salinity levels differ? (4) Is there more random variation among or within experimental units? Upload your self-contained R script to ELC at least one day before your next lab Overview Using aov Using lme 16 / 16