【问题标题】:Isolating graphs with significant p values隔离具有显着 p 值的图
【发布时间】:2020-10-12 15:20:04
【问题描述】:

首先,数据来自us_contagious_diseases数据集,包是tidyverse和ggpubr

library(dslabs)
library(ggpubr)
library(tidyverse)
data("us_contagious_diseases")

我通过下面的代码修改了这个数据集:

sdf <- us_contagious_diseases %>% filter(., disease == 'Rubella' | disease == 'Mumps') %>% transmute(., disease, count, population, state)

然后我创建了一个箱线图来比较每个州的风疹和腮腺炎病例数:

sdf_plot <- ggplot(sdf, mapping = aes(x = disease, y = count)) + geom_boxplot(outlier.shape = NA) + facet_wrap('state', scales = 'free') + stat_compare_means(method = 't.test', label.y.npc = 0.8) 

问题是,这个图中有 51 个地块!!!包含在我的报告中的方式非常庞大。更重要的是,其中许多比较没有显着的 p 值。有没有办法只提取 p 值小于 0.01 的图?

【问题讨论】:

  • us_contagious_diseases 不是内置的。显然,它在dslabs 包中
  • 非常感谢,我已相应更新。很抱歉 - 我仍然是新的 r 用户。

标签: r ggplot2 ggpubr


【解决方案1】:

我猜你需要预先计算 p 值:

library(broom)
res = sdf %>% group_by(state) %>% do(tidy(t.test(count~disease,data=.)))
head(res)

# A tibble: 6 x 11
# Groups:   state [6]
  state estimate estimate1 estimate2 statistic p.value parameter conf.low
  <fct>    <dbl>     <dbl>     <dbl>     <dbl>   <dbl>     <dbl>    <dbl>
1 Alab…    125.       180.      55.4     2.46  0.0181       42.7     22.4
2 Alas…     66.1      104.      38.2     1.52  0.136        45.4    -21.7
3 Ariz…     78.6      266.     187.      0.657 0.513        68.0   -160. 
4 Arka…     84.3      113.      28.4     2.87  0.00628      45.5     25.1
5 Cali…    386.      1915.    1529.      0.540 0.592        59.3  -1046. 
6 Colo…     95.0      314.     219.      0.762 0.449        62.6   -154. 

keep = res$state[res$p.value<0.01]
[1] Arkansas             District Of Columbia Georgia             
[4] Kansas               Maryland             Nevada              
[7] Ohio 

然后使用此过滤器进行绘图:

sdf_plot <- ggplot(subset(sdf,state %in% keep),aes(x = disease, y = count)) + 
geom_boxplot(outlier.shape = NA) + 
facet_wrap('state', scales = 'free') + 
stat_compare_means(method = 't.test', label.y.npc = 0.8) 

【讨论】:

    猜你喜欢
    • 2013-10-12
    • 1970-01-01
    • 2023-03-08
    • 1970-01-01
    • 1970-01-01
    • 2022-07-22
    • 2022-07-22
    • 2011-04-11
    • 2018-05-31
    相关资源
    最近更新 更多