I am a very novice R user and I have some code I am trying to run, but I am getting this error.
I was provided this code to control the false discovery rate using first the Benjamini-Hochberg method that has worked fine for me with other data:
BH1995<-function(pvals, alpha=0.05)
{
#
# Benjamini and Hochberg (1995) step-up procedure to control FDR
# pvals: sequence of all p-values
# alpha: nominal level, defaults to 0.05
#
M<-length(pvals)
a<-alpha*(1:M)/M
ord<-order(pvals)
psmall<- pvals[ord]<=a
if (sum(psmall)==0) reject<-NULL else {
mreject<-max((1:M)[psmall])
reject<-ord[1:mreject]
is.na(pvals)
}
reject
}
But when I am trying it with my new data (pvals):
BH1995mass<-length(BH1995(pvals,alpha=0.1))
BH1995mass
I get this exact error:
Error in if (sum(psmall) == 0) reject <- NULL else { : missing value where TRUE/FALSE needed
From what I've found online, what I think I need a is.na(pvals) statement? But since I did not write this code (and I don't entirely understnad R), I am not sure where to put it. Thanks for any help in advance!!
CodePudding user response:
How about inserting pvals <- pvals[!is.na(pvals)]
before M <- length(pvals)
?