簡體   English   中英

在 R 中使用 pwr() 包的 A/B 測試持續時間和樣本大小計算器

[英]A/B Test Duration & Sample Size Calculator Using pwr() Package in R

我在 R 中使用 googleAnalyticsR 包來提取一些網站訪問統計數據並計算轉化率。 到目前為止沒有問題。

但是,在嘗試使用名為 pwr 的包計算所需的人口規模和測試持續時間時,我遇到了困難,我根據從其他用戶在線找到的一些建議對其進行了修改。 代碼如下。

average_daily_traffic <-  10.63 #cvr$all_users/30
control <- 0.30721 #cvr$cvr_perc
uplift <- 0.01

sample_size_calculator <- function(control, uplift){
  variant <- (uplift + 1) * control
  baseline <- ES.h(control, variant)
  sample_size_output <- pwr.p.test(h = baseline,
                                   n = ,
                                   sig.level = 0.05,
                                   power = 0.8)
  if(variant >= 0)
  {return(sample_size_output)}
  else
  {paste("N/A")}
}


duration_calculator <- function(sample_size_output, average_daily_traffic){
  days_required <- c((sample_size_output)*2)/(average_daily_traffic)
  if(days_required >= 0)
  {paste0("It will take approximately ", round(days_required, digits = 0), " days or ", round(round(days_required, digits = 0)/365, digits = 0) ," years for this test to reach significance, based on average traffic in the last 30 days")}
  else
  {paste("N/A")}
}


sample_size_calculator <- sample_size_calculator(control, uplift)
sample_size_output <-   sample_size_calculator$n
sample_size_output

duration_calculator(sample_size_output, average_daily_traffic)

我在網上看到的建議是創建 2 個函數。 一個稱為“sample_size_calculator”,另一個稱為“days_calculator”,兩者都是不言自明的。 至少我很清楚兩者的預期功能是什么。

我的輸出是這樣的:

[1] "It will take approximately 33394 days or 91 years for this test to reach significance, based on average traffic in the last 30 days"

這對我來說似乎相當現實,直到我嘗試使用其他一些在線工具(包括VWOUnbounceAB Tasty )驗證我的結果,所有這些都表明我距離我應該在數量上的位置有 0.5 倍的距離運行測試所需的天數。 我很欣賞上述計算器之間的一些差異將是由於每個公式如何處理舍入,但我更關心我在計算中出錯的原因和位置,例如將測試持續時間低估了一半。

我可以簡單地將結果數乘以 2 並上床睡覺,但我很想了解我的錯誤,甚至學習一種更統計和語法上更優雅的編碼方式。

提前致謝。

就個人而言,我建議嘗試模擬數據,而不是依賴預先打包的功率計算。 您似乎對在 R 中編寫函數有很好的掌握,因此使用迭代(例如使用for循環,或者我個人更推薦的矢量化迭代)來模擬數據對您來說並不是一個很大的進步有purrr )。

模擬數據的優勢在於它迫使您提前考慮您的模型,這在您對真實數據建模時非常寶貴。

這是一個很棒的教程,如果有點過時的話: http : //disjointedthinking.jeffhughes.ca/2017/09/power-simulations-r/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM