Created
March 25, 2013 16:33
-
-
Save pedroj/5238486 to your computer and use it in GitHub Desktop.
Testing the difference between two CV's
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #----------------------------------------------------------------------------- | |
| # Testing the difference between two CV's | |
| # From Example 8.12 in Zar, p. 144-145 | |
| #----------------------------------------------------------------------------- | |
| w<-c(72.5,71.5,60.8,63.2,71.4,73.1,77.9,75.7,72.0,69.0) | |
| h<-c(183.0,172.3,180.1,190.2,191.4,169.6,166.4,177.6,184.7,187.5,179.8) | |
| #----------------------------------------------------------------------------- | |
| # Testing the difference between two CV's | |
| library(MBESS) | |
| n1<-length(w); n2<-length(h) | |
| v1<-cv(mean=mean(w,na.rm=T), sd=var(w,na.rm=T)^.5, N=n1, unbiased=TRUE) | |
| v2<-cv(mean=mean(h,na.rm=T), sd=var(h,na.rm=T)^.5, N=n2, unbiased=TRUE) | |
| # Formula in Example 8.12 of Zar, p. 145 | |
| vp<-(((n1-1)*v1)+((n2-1)*v2))/((n1-1)+(n2-1)) | |
| Z<-(v1-v2)/(sqrt((vp^2/(n1-1))+(vp^2/(n2-1))*(0.5+vp^2))) | |
| # P for z value | |
| 2*(1-pt(Z,2)) | |
| #----------------------------------------------------------------------------- | |
| # Confidence intervals for the CV's | |
| library(MBESS) | |
| set.seed(113) | |
| n1<-length(data$w) | |
| meanX<-mean(data$w,na.rm=T) | |
| sdX <- var(data$w,na.rm=T)^.5 | |
| ci.cv(mean=meanX, sd=sdX, n=n1, alpha.lower=.025, alpha.upper=.025, | |
| conf.level=NULL) | |
| #----------------------------------------------------------------------------- | |
| # Variance test | |
| F<-var(data$w,na.rm=T)/var(data$h,na.rm=T) | |
| 2*(1-pf(F,length(data$w)-1,length(data$h)-1)) | |
| var.test(data$w,data$h) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment