'Statistical Tests in R

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



Solution 1:[1]

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 

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Quinten