athuyvo
athuyvo

Reputation: 1

Same R script but different results when ran interactively vs automatically

I have an R script that processes a single-cell cds object by assigning hash barcodes to each cell. It outputs p-values, but for some reason I get different pvalues when the same exact script is ran an interactive session versus when the script is automated. It seems the p-values are inflated for 1 when the script is automated. The script is ran locally.

I read in the pvalues from the interactive session and the non-interactive session to evaluate the pvalues. This is histogram of the -log10(pvalues) when ran interactively vs automatically. interactive session: -log10(pvalue)

automated script: -log10(pvalue

This is the portion of my script where I am getting inconsistent pvalues when ran interactive vs automatically. I tried clearing my workspace when I run the script interactively, but that didn't solve the issue.

I compared the sessionInfo() between the two methods and there were no differences between package versions. I also tried setting a seed, but that didn't resolve the problem.

Does R interpret input files or scripts differently when using an interactive session vs when it's sourced?

chisq_vs_background <- function(test_hash_matrix, hash_frequencies) {
  hash_frequencies_nz <- which(hash_frequencies > 0)
  hash_frequencies <- hash_frequencies[hash_frequencies_nz]
  pvals <- pbapply(test_hash_matrix[, hash_frequencies_nz], 1, function(x) {
    tryCatch({
      res <- chisq.test(x, p=hash_frequencies, simulate.p.value=FALSE)
      unlist(res[["p.value"]])
    }, error=function(e) {
      # 1.0
      print("error")
    })
  })
  return(pvals)
}

Upvotes: 0

Views: 57

Answers (0)

Related Questions