How to Implement R's P.Adjust in Python

How to implement R's p.adjust in Python

If you wish to be sure of what you are getting from R, you can also indicate that you wish to use the function in the R package 'stats':

from rpy2.robjects.packages import importr
from rpy2.robjects.vectors import FloatVector

stats = importr('stats')

p_adjust = stats.p_adjust(FloatVector(pvalue_list), method = 'BH')

Calculating adjusted p-values in Python

It is available in statsmodels.

http://statsmodels.sourceforge.net/devel/stats.html#multiple-tests-and-multiple-comparison-procedures

http://statsmodels.sourceforge.net/devel/generated/statsmodels.sandbox.stats.multicomp.multipletests.html

and some explanations, examples and Monte Carlo
http://jpktd.blogspot.com/2013/04/multiple-testing-p-value-corrections-in.html

adjusted p-value for a list of genes

Short answer is if you're using differential expression data it's probably worth using deseq2.

https://bioconductor.org/packages/release/bioc/html/DESeq2.html

The tutorial is pretty good: https://bioconductor.org/packages/release/bioc/vignettes/DESeq2/inst/doc/DESeq2.html

It walks you through how to go from a count matrix data which is basically what you have to a set of adjusted p-values.

For future things like this you might have a better time going to https://bioinformatics.stackexchange.com/ than here.

Obtaining p values and adjusted R sq(python)

RegressionResults.rsquared() here
and pvalues here.

How to apply p.adjust to each row in matrix in R?

Using sapply like that you are running p.adjust on single values

Observe the following:

p.adjust( 0.05, method="bonferroni" ) # returns 0.05, unchanged!

This is what you are experiencing.

You likely meant to give p.adjust all the p-value of each experiment, hence the entire row of your p.val, like so:

padjBonf[k,] = p.adjust( p.val[k,], method="bonferroni" )

This should return all 1's as apropriate.

Or you could continue to correct each p-value and tell it that n=100 as documented in the manual, but there's no need really, and p.adjust was written with the above usage in mind.

Applying correction for multiple tests to get p-adjusted value

Suppose df is your original data frame.

library(tidyverse)
df_add_padj <- df %>% mutate("adjusted p-value" = p.adjust(p.value, method="fdr"))

method can be fdr, bonferroni and etc.



Related Topics



Leave a reply



Submit