-1

I want to run Bonferroni P Adjusted Value Test on a stacked data set.

This is my code:

stat.2 <- stack.2 %>%
group_by(modules) %>%
t_test(values ~ phenotype) %>%
adjust_pvalue(method = "bonferroni") %>%
add_significance("p.adj")

The error which I'm facing is the following:

Error in mutate(): ! Problem while computing data = map(.data$data, .f, ...). Caused by error in t.test.default(): ! not enough 'y' observations Run rlang::last_error() to see where the error occurred.

Here's the data which I'm working on:

enter image description here

r2evans
  • 141,215
  • 6
  • 77
  • 149
driver
  • 273
  • 1
  • 13
  • Thats your entire code? Because the dataframe is missing. Your to write: "yourdata" %>% before the group_by() – Lucca Nielsen May 14 '22 at 12:33
  • 2
    The error is quite informative - it is telling you that at least some `phenotype` groups are not sufficiently large to do a t-test. – DaveArmstrong May 14 '22 at 14:45
  • driver, please read https://stackoverflow.com/editing-help and https://meta.stackexchange.com/a/22189 for formatting code in questions. Namely, blocks of code use code fences (often `\`\`\``) before and after the block. What you missed is that there can be no code on the same line, they must be alone (e.g., `\`\`\`\n`). The only except is the first code fence _may_ include a language hint, as in `\`\`\`r`, but that is neither required nor is the "r" shown. – r2evans May 14 '22 at 17:47
  • The Stack tag-recommendation system is imperfect, please be mindful of the tags attached to a question. There is nothing about [tag:sql] here; the [tag:file] tag is not justified because at some point the data resided in a text file; and frankly in the [tag:r] tag, it seems most questions could technically include the [tag:error-handling] tag, a bit unnecessary (_receiving_ an error is not the same as _exception handling_). – r2evans May 14 '22 at 17:50
  • Please do not post (only) an image of code/data/errors: it breaks screen-readers and it cannot be copied or searched (ref: https://meta.stackoverflow.com/a/285557 and https://xkcd.com/2116/). Please include the code, console output, or data (e.g., `data.frame(...)` or the output from `dput(head(x))`) directly. – r2evans May 14 '22 at 17:50
  • Lastly, I think it might be beneficial for you to look quickly at https://stackoverflow.com/q/5963269 (and [mcve] and https://stackoverflow.com/tags/r/info) for their discussions on framing a question in a more _reproducible_ manner, including representative, unambiguous data that is easy for us to use (and does not require us transcribing your image of data). – r2evans May 14 '22 at 17:52

1 Answers1

0

First I created reproducible data:

df <- data.frame(phenotype = c("Mesenchymal", "Classical", "Classical", "Mesenchymal", "Proneural", "Mesenchymal", "Proneural", "Messenchymal", "Messenchymal", "Classical", "Mesenchymal"),
                 values = runif(11, 0, 1),
                 modules = rep("MEmaroon", 11))

You can use this code:

library(dplyr)
library(rstatix)
df %>%
  group_by(modules) %>%
  t_test(values ~ phenotype) %>%
  adjust_pvalue(method = "bonferroni") %>%
  add_significance("p.adj")

Output:

# A tibble: 6 × 11
  modules  .y.    group1       group2      n1    n2 statistic    df     p p.adj p.adj.signif
  <chr>    <chr>  <chr>        <chr>    <int> <int>     <dbl> <dbl> <dbl> <dbl> <chr>       
1 MEmaroon values Classical    Mesench…     3     4    0.668   4.25 0.538     1 ns          
2 MEmaroon values Classical    Messenc…     3     2    0.361   1.48 0.763     1 ns          
3 MEmaroon values Classical    Proneur…     3     2   -0.0161  2.90 0.988     1 ns          
4 MEmaroon values Mesenchymal  Messenc…     4     2   -0.0136  1.32 0.991     1 ns          
5 MEmaroon values Mesenchymal  Proneur…     4     2   -0.749   2.84 0.511     1 ns          
6 MEmaroon values Messenchymal Proneur…     2     2   -0.380   1.33 0.756     1 ns 
Quinten
  • 35,235
  • 5
  • 20
  • 53