380 likes | 538 Views
Nested and Paired recap. Nested and Paired sampling. When you have sampled one thing many times. Why? To handle pseudoreplication. or To reduce noise. Nested vs Paired tests. Nested A fixed factor above a random factor Paired A fixed factor within a random factor
E N D
Nested and Paired sampling • When you have sampled one thing many times. • Why? • To handle pseudoreplication. • or • To reduce noise.
Nested vs Paired tests • Nested • A fixed factor above a random factor • Paired • A fixed factor within a random factor • Both are examples of mixed models.
Nested recrap p = 0.00039
Nested recap p = 0.11
Nested recap p = 0.11
Test Nested designs • By hand. Calculate means.Make an ordinary anova or regression on those means. • With anova over nestingthing variance aov(y~x+Error(nestingthing))
Anova on oakmeans summary(aov(oakmeansY~oakhabitatsX)) Df Sum Sq Mean Sq F value Pr(>F) oakhabitatsX 1 38.920 38.920 2.8344 0.1095 Residuals 18 247.165 13.731
Nested Anova with Error summary(aov(oaktwig~habitat+Error(oak))) Error: oak Df Sum Sq Mean Sq F value Pr(>F) habitat 1 389.21 389.21 2.8344 0.1095 Residuals 18 2471.65 137.31 Error: Within Df Sum Sq Mean Sq F value Pr(>F) Residuals 180 3454.5 19.2
Linear Mixed Model with lmer mixoak<-lmer(oaktwig~habitat+(1|oak)) summary(mixoak) Random effects: Groups Name Variance Std.Dev. oak (Intercept) 11.812 3.4369 Residual 19.192 4.3808 Number of obs: 200, groups: oak, 20 Fixed effects: Estimate Std. Error t value (Intercept) 13.530 1.172 11.547 habitatopen 2.790 1.657 1.684
Linear Mixed Model with lmer mixoak<-lmer(oaktwig~habitat+(1|oak)) summary(mixoak) Random effects: Groups Name Variance Std.Dev. oak (Intercept) 11.812 3.4369 Residual 19.192 4.3808 Number of obs: 200, groups: oak, 20 Fixed effects: Estimate Std. Error t value (Intercept) 13.530 1.172 11.547 habitatopen 2.790 1.657 1.684 38 % 62 %
Paired recap p = 0.0050
Paired recap p = 0.0017
Test Paired designs • By hand. Calculate differences.Test if the differences differ from zero. a) Permutation b) 1-sample t-test • With a paired t-test. • With anova over pairingthing variance aov(y~x+Error(pairingthing))
One sample t-test t.test(diffr) One Sample t-test t = -3.6876, df = 18, p-value = 0.001685 alternative hypothesis: true mean is not equal to 0 mean of x -5.868421
Paired t-test t.test(groupA,groupB,paired=T) Paired t-test data: groupA and groupB t = -3.6876, df = 18, p-value = 0.001685 alternative hypothesis: true difference in means is not equal to 0 mean of the differences -5.868421
Paired Anova with Error summary(aov(shoot.cm~catkin.YN+Error(birch))) Error: birch Df Sum Sq Mean Sq F value Pr(>F) Residuals 18 852.41 47.36 Error: Within Df Sum Sq Mean Sq F value Pr(>F) Catkin.YN 1 327.16 327.16 13.598 0.001685 ** Residuals 18 433.06 24.06
Non-Paired Anova summary(aov(shoot.cm~catkin.YN)) Df Sum Sq Mean Sq F value Pr(>F) catkin.YN 1 327.16 327.16 9.1623 0.004544 ** Residuals 36 1285.47 35.71
Paired Anova with Error summary(aov(shoot.cm~catkin.YN+Error(birch))) Error: birch Df Sum Sq Mean Sq F value Pr(>F) Residuals 18 852.41 47.36 Error: Within Df Sum Sq Mean Sq F value Pr(>F) Catkin.YN 1 327.16 327.16 13.598 0.001685 ** Residuals 18 433.06 24.06
Nested Anova with Error summary(aov(oaktwig~habitat+Error(oak))) Error: oak Df Sum Sq Mean Sq F value Pr(>F) habitat 1 389.21 389.21 2.8344 0.1095 Residuals 18 2471.65 137.31 Error: Within Df Sum Sq Mean Sq F value Pr(>F) Residuals 180 3454.5 19.2
Nested vs Paired tests • Nested • A fixed factor above a random factor • Paired • A fixed factor within a random factor • Both are examples of mixed models.
How was the oakdata faked? habitat<-factor(rep(c("forest","open"),each=100))
How was the oakdata faked? habitat<-factor(rep(c("forest","open"),each=100)) oak<-rep(1:20,each=10)
How was the oakdata faked? habitat<-factor(rep(c("forest","open"),each=100)) oak<-rep(1:20,each=10) oak<-paste("O",oak,sep="")
How was the oakdata faked? habitat<-factor(rep(c("forest","open"),each=100)) oak<-rep(1:20,each=10) oak<-paste("O",oak,sep="") oak<-factor(oak)
How was the oakdata faked? habitat<-factor(rep(c("forest","open"),each=100)) oak<-rep(1:20,each=10) oak<-paste("O",oak,sep="") oak<-factor(oak) oaktwig<-c(rep(rnorm(10,12,3),each=10), rep(rnorm(10,15,3),each=10))
How was the oakdata faked? habitat<-factor(rep(c("forest","open"),each=100)) oak<-rep(1:20,each=10) oak<-paste("O",oak,sep="") oak<-factor(oak) oaktwig<-c(rep(rnorm(10,12,3),each=10), rep(rnorm(10,15,3),each=10)) oaktwig<-oaktwig+rnorm(200,0,5)
How was the oakdata faked? habitat<-factor(rep(c("forest","open"),each=100)) oak<-rep(1:20,each=10) oak<-paste("O",oak,sep="") oak<-factor(oak) oaktwig<-c(rep(rnorm(10,12,3),each=10), rep(rnorm(10,15,3),each=10)) oaktwig<-oaktwig+rnorm(200,0,5) oaktwig<-ifelse(oaktwig<1,1,oaktwig)
How was the oakdata faked? habitat<-factor(rep(c("forest","open"),each=100)) oak<-rep(1:20,each=10) oak<-paste("O",oak,sep="") oak<-factor(oak) oaktwig<-c(rep(rnorm(10,12,3),each=10), rep(rnorm(10,15,3),each=10)) oaktwig<-oaktwig+rnorm(200,0,5) oaktwig<-ifelse(oaktwig<1,1,oaktwig) oakdata<-data.frame(habitat,oak,oaktwig)
How was the oakdata faked? habitat<-factor(rep(c("forest","open"),each=100)) oak<-rep(1:20,each=10) oak<-paste("O",oak,sep="") oak<-factor(oak) oaktwig<-c(rep(rnorm(10,12,3),each=10), rep(rnorm(10,15,3),each=10)) oaktwig<-oaktwig+rnorm(200,0,5) oaktwig<-ifelse(oaktwig<1,1,oaktwig) oakdata<-data.frame(habitat,oak,oaktwig) write.xls(oakdata,"oakdata.xls") write.table(oakdata,file="clipboard",sep="\t",quote=F)
Tomorrows mission… • You should fake data (first in Excel), so: • What is your response variable? • What is your explanatory variables? • Are they categorical or continuous? • Bring two graphs on paper! • One with your hypothesised relationships. • One with non-significant effects. • Then we will do power analyses.