0
$\begingroup$

I am struggling in conducting at test on a board of 1000 genes in 50 individuals divided into to groups (A and B). I have a dataset of 1000 genes of two groups of people (total individuals=50) group A = 30 (healthy) individuals & group B = 20 sick) individuals

I created a matrix where rows are genes and ind are columns. now I need to perform a t-test for all the genes and find the p values of my alternative hypothesis (not the null one): i)A<B, A>B and A=!B(not equal). threshold is 0.05 after FDR (which I must include)

I am struggling with the code since t-test differ on sensitivity and each of my approach returns a different result. The dummy data is as follows:

import pandas as pd
import numpy as np

# Generate data for group A (healthy individuals) & group B (sick individuals)
A = np.random.rand(30, 1000)
B = np.random.rand(20, 1000)
# Create dataframe for group A & B with genes as columns
Adf = pd.DataFrame(A, columns=[f'Gene_{i}' for i in range(1, num_genes + 1)])
Bdf = pd.DataFrame(B, columns=[f'Gene_{i}' for i in range(1, num_genes + 1)])

# Add a column indicating the group
Adf['Group'] = 'A'
Bdf['Group'] = 'B'

df = pd.concat([Adf, Bdf], ignore_index=True)
df.head()

Any ideas?

$\endgroup$
10
  • $\begingroup$ can you please post the code that you've tried so far, along with a minimal example of your data? what are the approaches you've tried and why is it unexpected that different approaches yield different answers? $\endgroup$ Commented Jan 7 at 6:32
  • $\begingroup$ sure. thanks for the response. so basically i have a dataset that i turned into a python matrix (with pandas DataFrame) consisting of 50 individuals, 30 individuals in group A (the first 30 columns) and 20 individuals in group B. the individuals in group A are healthy and the individuals in group B are sick. i applied the t-test for all genes but i have to find the pvalues for Hypothesis 1 (alternative) if i) A < B, ii) A > B, iii) A != B (not equal); threshold is 0.05 after FDR (code at my next comment) $\endgroup$ Commented Jan 7 at 9:35
  • $\begingroup$ group_A = dataset.iloc[:, :30] # first 30 columns for gr A (up to 30, including 30) group_B = dataset.iloc[:, 30:] # next 20 columns for gr B (next 20, from 31 to 50) p_values_less = [] p_values_greater = [] p_values_not_equal = [] # t-tests for each gene for gene in range(dataset.shape[0]): #access to all genes t_stat, p_val_not_equal = stats.ttest_ind(group_A.iloc[gene], group_B.iloc[gene]) p_values_not_equal.append(p_val_not_equal) p_values_less.append(p_val_not_equal / 2 if t_stat < 0 else 1) p_values_greater.append(p_val_not_equal / 2 if t_stat > 0 else 1) $\endgroup$ Commented Jan 7 at 9:41
  • $\begingroup$ p_values_corrected_less = smm.multipletests(p_values_less, alpha=0.05, method='fdr_bh')[1] p_values_corrected_greater = smm.multipletests(p_values_greater, alpha=0.05, method='fdr_bh')[1] p_values_corrected_not_equal = smm.multipletests(p_values_not_equal, alpha=0.05, method='fdr_bh')[1] results = pd.DataFrame({ 'Gene': dataset.index, 'p_value_less': p_values_corrected_less, 'p_value_greater': p_values_corrected_greater, 'p_value_not_equal': p_values_corrected_not_equal }) $\endgroup$ Commented Jan 7 at 9:43
  • 3
    $\begingroup$ Please edit your question and add the code there. You can use the {} button to format it as code. $\endgroup$
    – terdon
    Commented Jan 7 at 12:46

1 Answer 1

1
$\begingroup$

Could it be that you are getting different results because you are not setting a seed on your random number generator?

The recommended way to make sure you get the same results when using numpy to generate dummy data is:

import numpy as np
# make random number generator with seed
rng = np.random.default_rng(seed=42)
rng.random([4,4])
#Out: 
#array([[0.77395605, 0.43887844, 0.85859792, 0.69736803],
#       [0.09417735, 0.97562235, 0.7611397 , 0.78606431],
#       [0.12811363, 0.45038594, 0.37079802, 0.92676499],
#       [0.64386512, 0.82276161, 0.4434142 , 0.22723872]])


```
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.