r - 如何使用ggplot2随着时间的推移绘制p值?
问题描述
所以我有一些看起来像这样的数据:
DATE GROUP Value Visitors
2021-01-01 Treatment 12 40
2021-01-01 Control 4 43
2021-01-02 Treatment 7 34
2021-01-02 Control 2 39
2021-01-03 Treatment 10 23
2021-01-03 Control 10 29
2021-01-04 Treatment 19 30
2021-01-04 Control 7 23
如果你总结所有这些数据,实验结束时的最终结果是
Group Value Visitors Conversion (Value/Size)
Control 23 134 .172
Treatment 48 127 .378
所以我需要计算这个数据的 p 值和置信区间(即转换),不仅在最后,而且在实验过程中,使用 t 检验。
我在这里寻找的是一个折线图,它绘制了 p 值如何随时间累积变化。我真的想不出任何方法来绘制随时间变化的置信区间,所以一张每日置信区间增长表就足够了
解决方案
那是你要找的吗?
df <- read.table(textConnection('DATE GROUP Value Visitors
2021-01-01 Treatment 12 40
2021-01-01 Control 4 43
2021-01-02 Treatment 7 34
2021-01-02 Control 2 39
2021-01-03 Treatment 10 23
2021-01-03 Control 10 29
2021-01-04 Treatment 19 30
2021-01-04 Control 7 23'),header=T)
library(tidyverse)
library(gridExtra)
new_df <- df %>%
mutate(Conversion=Value/Visitors) %>%
group_by(DATE,GROUP) %>%
summarise(Cumulative_Conversion=cumsum(Conversion),.groups='drop') %>%
group_by(DATE) %>%
summarise(P.Value=t.test(Cumulative_Conversion)$p.value,
Conf.Int=t.test(Cumulative_Conversion)$conf.int,
Mean=mean(Cumulative_Conversion),.groups='drop')
new_df %>%
ggplot(aes(x=DATE,y=P.Value,fill=P.Value))+
geom_col() -> plot1
new_df %>%
ggplot(aes(x=DATE,y=Mean,fill=Mean))+
geom_col()+
geom_point(aes(x=DATE,y=Conf.Int))+
geom_line(aes(x=DATE,y=Conf.Int)) -> plot2
final_plot <-grid.arrange(plot1,plot2)
final_plot
推荐阅读
- algorithm - DBSCAN/OPTICS 算法中是否包含半径 epsilon?
- ruby-on-rails-4 - Rails 服务器在 GCP VM 实例上运行,但无法在浏览器上访问 rails 应用程序
- python-3.x - Selenium-Webdriver 允许在一个窗口中打开多个选项卡,但在加载配置文件时不允许?
- node.js - nodejs自动维护winston日志
- windows - 我想用 Vagrant 在 OSX 上运行一个基本的 Windows 来宾,但我不断收到身份验证失败
- swift - 从初始化程序返回而不初始化所有存储的属性Swift Xcode 10.0
- sql - 使用别名或同义词的 SQL Server 跨数据库查询
- sql-server - 在同一查询中为 Oracle 和 SQL Server 转义特殊字符
- php - laravel 5.6 socialite auth by facebook email 为空
- android - 获取 Widevine 许可证服务器密钥