P values in wilcox.test gone mad :(

Posted by Error404 on Stack Overflow See other posts from Stack Overflow or by Error404
Published on 2012-11-26T16:38:08Z Indexed on 2012/11/26 17:04 UTC
Read the original article Hit count: 312

Filed under:

I have a code that isn't doing what it should do. I am testing P value for a wilcox.test for a huge set of data.

the code i am using is the following

library(MASS)
data1 <- read.csv("file1path.csv",header=T,sep=",")
data2 <- read.csv("file2path.csv",header=T,sep=",")
data3 <- read.csv("file3path.csv",header=T,sep=",")
data4 <- read.csv("file4path.csv",header=T,sep=",")


data1$K <- with(data1,{"N"})
data2$K <- with(data2,{"E"})
data3$K <- with(data3,{"M"})
data4$K <- with(data4,{"U"})

new=rbind(data1,data2,data3,data4) 

i=3

for (o in 1:4800){ 
x1 <- data1[,i]
x2 <- data2[,i]
x3 <- data3[,i]
x4 <- data4[,i]
wt12 <- wilcox.test(x1,x2, na.omit=TRUE)
wt13 <- wilcox.test(x1,x3, na.omit=TRUE)
wt14 <- wilcox.test(x1,x4, na.omit=TRUE)

if (wt12$p.value=="NaN"){
print("This is wrong")
    }
else if (wt12$p.value < 0.05){
print(wt12$p.value)         
mypath=file.path("C:", "all1-less-05", (paste("graph-data1-data2",names(data1[i]), ".pdf", sep="-")))
pdf(file=mypath)
mytitle = paste("graph",names(data1[i]))
boxplot(new[,i] ~ new$K, main = mytitle, names.arg=c("data1","data2","data3","data4"))
dev.off()
}   

if (wt13$p.value=="NaN"){
print("This is wrong")
}
else if (wt13$p.value < 0.05){
    print(wt13$p.value)

mypath=file.path("C:", "all2-less-05", (paste("graph-data1-data3",names(data1[i]), ".pdf", sep="-")))
pdf(file=mypath)
mytitle = paste("graph",names(data1[i]))
boxplot(new[,i] ~ new$K, main = mytitle, names.arg=c("data1","data2","data3","data4"))
dev.off()
}

if (wt14$p.value=="NaN"){
print("This is wrong")
}
else if (wt14$p.value < 0.05){
    print(wt14$p.value)

mypath=file.path("C:", "all3-less-05", (paste("graph-data1-data4",names(data1[i]), ".pdf", sep="-")))
pdf(file=mypath)
mytitle = paste("graph",names(data1[i]))
boxplot(new[,i] ~ new$K, main = mytitle, names.arg=c("data1","data2","data3","data4"))
dev.off()
}
i=i+1
} 

I am having 2 problems with this long command:

1- Without specifying a certain P value, the code gives me arouind 14,000 graphs, when specifying a p value less than 0.05 the number of graphs generated goes down to 9,0000. THE FIRST PROBLEM IS: Some P value are more than 0.05 and are still showing up!

2- I designed the program to give me a result of "This is wrong" when the Value of P is "NaN", I am getting results of "NaN"

Here's a screenshot from the results unexpected data

do you know what the mistake i made with the command to get these errors?

Thanks in advance

© Stack Overflow or respective owner

Related posts about r