mercredi 3 mars 2021

ifelse returning incorrect values for condition x < very.small.number

I am trying to identify outliers if they are less than a bonferroni corrected p value. When using ifelse(df$score < bonferroni, 'yes', 'no'), all values are 'yes'. Which makes NO sense. When I use a p value of 0.05 instead of bonferroni, it works properly. What is going on here? super annoying.

df<- data.frame("cell.id"= c(1:ncol(atac)), "count"=atac$peak_region_fragments, stringsAsFactors = FALSE)

lambda <- mean(df$count)
mypoisson$score <- ""
for (i in 1:nrow(df)){
  message(i)
  df$score[i] <- 1 - ppois(df$count[i], lambda = lambda)
}
bonferroni <- 0.05/ncol(atac)
df$outler <- ifelse(df$score < bonferroni, 'yes', 'no')

bonferroni
[1] 6.52912e-06

head(df)
                   cell.id count             score outler
99_AAACGAAAGCTACGCC-1    1  9618                 1    yes
99_AAACGAAAGGCAGTAC-1    2  5142                 1    yes
99_AAACGAAAGGGCGAAG-1    3  7990                 1    yes
99_AAACGAAAGTCGACCC-1    4  8521                 1    yes
99_AAACGAAAGTTACCAC-1    5  6444                 1    yes
99_AAACGAACAAGCCTTA-1    6 11280 0.964436427969221    yes

Yeah... 1 is definitely less than 6.52912e-06... smh

Aucun commentaire:

Enregistrer un commentaire