4
$\begingroup$

Here is a subset of my df. How can I run pairwise comparisons of median expression between disease status for each clus_ft and use Bonferroni correction?

For example, from this df subset, I would want to perform the following comparisons:

  1. A_CD1, no disease vs. A_CD1, with disease
  2. B_CD1, no disease vs. B_CD1, with disease
  3. A_IFN, no disease vs. A_IFN, with disease

I do not want to compute pvalues for all possible pairwise comparisons. For example, the following comparison is irrelevant and should not be computed:

A_CD1, no disease vs. A_IFN, with disease

| patient_id | median | disease | clus_ft |
| ---------- | ------ | ------- | ------- |
| 1          | 0.40   | no      | A_CD1   |
| 2          | 0.29   | no      | A_CD1   | 
| 1          | 0.43   | yes     | A_CD1   | 
| 2          | 0.32   | yes     | A_CD1   |
| 1          | 0.77   | no      | B_CD1   | 
| 2          | 0.65   | no      | B_CD1   |
| 1          | 0.01   | yes     | B_CD1   | 
| 2          | 0.06   | yes     | B_CD1   | 
| 1          | 0.86   | no      | A_IFN   | 
| 2          | 0.85   | no      | A_IFN   |
| 1          | 0.02   | yes     | A_IFN   | 
| 2          | 0.24   | yes     | A_IFN   | 
Showing 1 to 12 of 960 entries
$\endgroup$
1
  • 1
    $\begingroup$ Could you consider upvoting and accepting @RamRS answer? $\endgroup$
    – M__
    Commented Apr 28 at 1:02

1 Answer 1

2
$\begingroup$

You can use dplyr to extract relevant vectors of values for this comparison. Build out from there using, say, a vector of clus_ft values.

Step-1

## untested
run_t_test <- function(df, in_clus_ft) {
  t.test(x = df %>% filter(clus_ft == in_clus_ft & disease == "yes") %>% pull(median),
         y = df %>% filter(clus_ft == in_clus_ft & disease == "no") %>% pull(median))
}

run_t_test(df, "A_CD1")

Step-2: Now run it on a set of values

sapply(X = c("A_CD1","B_CD1","A_IFN"),
FUN = run_t_test,
df = df
)
$\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.