Problem in calculating p values
1
0
Entering edit mode
3.8 years ago
anasjamshed ▴ 120
## pvalues are given to retrieve the genes which pass the p values
for (i in c(0.01, 0.05, 0.001, 1e-04, 1e-05, 1e-06, 1e-07)) print(paste("genes with p-values smaller than",
i, length(which(pvals < i))))


when I try to run this script the following error comes :

Error in which(pvals < i) : object 'pvals' not found


help to overcome this problem

p-value RNA-Seq R • 1.0k views
2
Entering edit mode
3.8 years ago

You have no variable called pvals in your workspace. Go back to the beginning of your code and determine why.

Thank you!

Kevin

0
Entering edit mode

brother pvals is a function to calculate p value its not variable

2
Entering edit mode

You sure dude? In your code, you are passing it as the first argument to the which() function

1
Entering edit mode

The way you have written your code, pvals is a variable.

Functions need inputs. They don't just sit there as barewords.

0
Entering edit mode

sorry I already declared the variable after making t-test function

ttest =
function(x) {
tt = t.test(x[logX.cl == 0], x[logX.cl == 1])
return(c(tt$statistic, tt$p.value))
}

ans = apply(logX, 1, ttest)
ts <- ans[1, ]
pvals <- ans[2, ]
for (i in c(0.01, 0.05, 0.001, 1e-04, 1e-05, 1e-06, 1e-07)) print(paste("genes with p-values smaller than",
i, length(which(pvals < i))))

0
Entering edit mode

What you're trying to do I would have done a different way, i.e., using Limma (as I know that you are working on microarray data). After that, simple subset() commands on the Limma output could get you want.

If you want to continue with your current code, then:

• check the output of every command and become familiar with all variables in your workspace
• try not to blindly run for loops without first testing a few passes (by setting pre-specified values of i, in this case)
• add message() commands to your loop, too, so that you can verify and QC check each pass.
0
Entering edit mode

Functions do not always need inputs: foo <- function(){ 1+1 } or Sys.Date(), they could also sit as "barewords": do.call(rbind, mydata).

But, yes, agree, in this case pvals is a variable.