# NOT RUN {
# G. P. Watkins (1933). An Ordinal Index of Correlation, Journal of the
# American Statistical Association, 28:182, 139-151.
# 20-item series for area and density have been made up to cover the
# original 13 states and the four others earliest admitted to the Union.
State<-c("Georgia","North_Carolina","New_York","Luisiana","Pennsylvania",
"Virginia","Tennessee","Ohio","Kentucky","Maine","South_Carolina",
"West_Virginia","Maryland","Vermont","New_Hampshire","Massachusetts",
"New_Jersey","Connecticut","Delaware","Rhode_Island")
Area<-c(1,2, 3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20)
Density<-c(17,13,5,18,6,14,12,7,11,20,15,10,8,19,16,2,3,4,9,1)
op<-par(mfrow=c(1,1))
plot(Area,Density,main="",xlab="Area",ylab="Density",pch=19,cex=0.9,
col="darkgreen" )
abline(h=mean(Area),col="black",lty=2,lwd=1)
abline(v=mean(Density),col="darkblue",lty=2,lwd=1)
par(op)
r<-comprank(Area,Density,"fy2","wgh")$r
ranktes(r, length(Area), "fy2", "ga",FALSE, "two", TRUE)
#####
#
# }
# NOT RUN {
data(Atar);attach(Atar)
op<-par(mfrow=c(1,1))
plot(TBL,TFL,main="",xlab="Backward Linkage Index",ylab=
"Forward Linkage Index",pch=19, cex=0.9,col="magenta")
abline(h=mean(TFL),col="black",lty=2,lwd=1)
abline(v=mean(TBL),col="black",lty=2,lwd=1)
par(op)
r<-comprank(TBL,TFL,"fy1","wgh")$r
ranktes(r, length(TBL), "fy1", "vggfr",FALSE, "two", TRUE)
detach(Atar)
# }
# NOT RUN {
#####
data(Sharpe);attach(Sharpe)
op<-par(mfrow=c(1,1))
plot(AVR,VAR, type = "p",pch=19,cex=1.1,col="tomato",main="Mutual fund
performance")
text(AVR,VAR, labels = rownames(Sharpe), cex=0.5, pos=3)
abline(h=mean(AVR),col="black",lty=2,lwd=1)
abline(v=mean(VAR),col="black",lty=2,lwd=1)
par(op)
r<-comprank(AVR,VAR,"sbz","wgh")$r
ranktes(r, length(AVR), "sbz", "st",FALSE, "greater", TRUE)
detach(Sharpe)
#####
#
# }
# NOT RUN {
# Sun,J.-G. and Jurisicova, A. and Casper, R.F. (1997). "Detection of
# Deoxyribonucleic Acid Fragmentation in Human Sperm: Correlation
# with Fertilization In Vitro". Biology of Reproduction, 56, 602-607.
n<-c(222,298,143,143,291,148)
r<-c(-0.18,-0.12,-0.16,-0.20,-0.06,-0.003)
App<-c("Ga","St","Vg")
N<-length(n);Ta<-matrix(NA,N,5)
for (i in 1:length(n)){Ta[i,1]<-r[i];Ta[i,2]<-n[i]
for (j in 1:3){
app<-App[j]
a<-ranktes(r[i],n[i],"S",app,FALSE,"t",FALSE);Ta[i,2+j]<-a$Cpv
}}
Df<-matrix(Ta,6,5)
rownames(Df)<-c("Conc. sperm/mL","Motility", "Fertilization rate",
"Cleavage rate", "Male age","Abstinence days")
colnames(Df)<-c("Spearman","n of samples","Appr. Gaussian",
"Appr. t-Student", "Appr. GGFR")
Df<-as.data.frame(Df)
print(round(Df,5))
# }
# NOT RUN {
#####
#
# }
# NOT RUN {
data(Starshi);attach(Starshi)
op<-par(mfrow=c(1,1))
plot(Sm15F,Sm15M, type = "p",pch=19,cex=0.9,col="darkorange",
main="Smokers ")
text(Sm15F,Sm15M,labels = rownames(Starshi),cex=0.6,pos=
c(1,rep(2,10),3,2))
abline(h=mean(Sm15M),col="black",lty=2,lwd=1)
abline(v=mean(Sm15F),col="black",lty=2,lwd=1)
par(op)
r<-comprank(Sm15F,Sm15M,"r4","wgh")$r
a<-ranktes(r, length(Sm15F), "r4", "ex",TRUE, "two", FALSE)
cat(a$Value,a$Cpv,a$Lpv,"\n")
r<-comprank(Sm15F,Sm15M,"sp","wgh")$r
a<-ranktes(r, length(Sm15F), "sp", "ex",TRUE, "two", FALSE)
cat(a$Value,a$Cpv,a$Lpv,"\n")
r<-comprank(Sm15F,Sm15M,"ke","wgh")$r
a<-ranktes(r, length(Sm15F), "ke", "ex",TRUE, "two", FALSE)
cat(a$Value,a$Cpv,a$Lpv,"\n")
r<-comprank(Sm15F,Sm15M,"gi","wgh")$r
a<-ranktes(r, length(Sm15F), "gi", "ex",TRUE, "two", FALSE)
cat(a$Value,a$Cpv,a$Lpv,"\n")
r<-comprank(Sm15F,Sm15M,"fy1","wgh")$r
a<-ranktes(r, length(Sm15F), "fy1", "ex",TRUE, "two", FALSE)
cat(a$Value,a$Cpv,a$Lpv,"\n")
r<-comprank(Sm15F,Sm15M,"fy2","wgh")$r
a<-ranktes(r, length(Sm15F), "fy2", "ex",TRUE, "two", FALSE)
cat(a$Value,a$Cpv,a$Lpv,"\n")
r<-comprank(Sm15F,Sm15M,"sbz","wgh")$r
a<-ranktes(r, length(Sm15F), "sbz", "ex",TRUE, "two", FALSE)
cat(a$Value,a$Cpv,a$Lpv,"\n")
detach(Starshi)
# }
# NOT RUN {
#####
#
# }
# NOT RUN {
All.App<-function(r,n,index,type){
# Computes p-values of an observed rank correlation statistic
A<-rep(r,9)
names(A)<-encodeString(c(index,"t-Student, CC=F","Gaussian, CC=F", "VGGFR,
CC=F","t-Student, CC=T","Gaussian, CC=T", "VGGFR, CC=T",
"Exact p Conservative","Exact p Liberal"),justify="right")
a<-ranktes(r,n,index,"St",FALSE,type,FALSE);A[2]<-a$Cpv
a<-ranktes(r,n,index,"Ga",FALSE,type,FALSE);A[3]<-a$Cpv
a<-ranktes(r,n,index,"Vg",FALSE,type,FALSE);A[4]<-a$Cpv
a<-ranktes(r,n,index,"St",TRUE,type,FALSE);A[5]<-a$Cpv
a<-ranktes(r,n,index,"Ga",TRUE,type,FALSE);A[6]<-a$Cpv
a<-ranktes(r,n,index,"Vg",TRUE,type,FALSE);A[7]<-a$Cpv
a<-ranktes(r,n,index,"Ex",FALSE,type,FALSE);A[8]<-a$Cpv;A[9]<-a$Lpv
A<-as.matrix(A)
return(A)}
data(Gabbs);attach(Gabbs)
B<-matrix(0,9,6)
colnames(B)<-colnames(Gabbs[1:6])
rownames(B)<-encodeString(c("index","t-Student, CC=F","Gaussian, CC=F",
"VGGFR, CC=F","t-Student, CC=T", "Gaussian, CC=T", "VGGFR, CC=T",
"Exact p Conservative","Exact p Liberal"), justify="right")
index<-"spearman"
for (i in 1:6){r<-comprank(Gabbs[,i],Gabbs[,7],index, print=FALSE)$r
B[,i]<-All.App(r,19,index,"less")}
print(round(B,5))
detach(Gabbs)
# }
# NOT RUN {
#####
#
# }
# NOT RUN {
data(Dalyww);attach(Dalyww)
op<-par(mfrow=c(1,1))
plot(ACLS,ASHR,main="The paradox of high rates of suicide in happy places",
xlab="Adjusted Life Satisfaction", ylab="Adjusted Suicide Risk",pch=19,
cex=0.8,col="steelblue")
text(ACLS,ASHR,labels=rownames(Dalyww),cex=0.7,pos=2)
abline(h=mean(ASHR),col="black",lty=2,lwd=1)
abline(v=mean(ACLS),col="black",lty=2,lwd=1)
par(op)
r<-comprank(ACLS,ASHR,"spearman")$r;n<-length(ASHR)
out<-ranktes(r,n,"s","ga",FALSE,"greater",FALSE)
cat(round(out$Value,3),round(out$Cpv,5),round(out$Lpv,5),"\n")
out<-ranktes(r,n,"s","st",FALSE,"greater",FALSE)
cat(round(out$Value,3),round(out$Cpv,5),round(out$Lpv,5),"\n")
out<-ranktes(r,n,"s","vg",FALSE,"greater",FALSE)
cat(round(out$Value,3),round(out$Cpv,5),round(out$Lpv,5),"\n")
#
r<-comprank(ACLS,ASHR,"kendall")$r
out<-ranktes(r,n,"kendall","st",FALSE,"greater",FALSE)
cat(round(out$Value,3),round(out$Cpv,5),round(out$Lpv,5),"\n")
#
r<-comprank(ACLS,ASHR,"r4")$r
out<-ranktes(r,n,"r4","st",FALSE,"greater",FALSE)
cat(round(out$Value,3),round(out$Cpv,5),round(out$Lpv,5),"\n")
detach(Dalyww)
# }
Run the code above in your browser using DataLab