我进行了A / B测试,我的数据如下:
control_conversion test_conversion
day1 0.10 0.10
day3 0.14 0.20
day5 0.20 0.32
day7 0.40 0.80
控制和测试组的流量为1000 因此转换率应为:
control = [0.1, 0.14, 0.20, 0.40]
test = [0.1,0.2,0.32,0.8]
我想使用python来计算 第1天,第3天,第5天,第7天用于控制和测试。
所以我需要列出两个清单:
abstract class MainDatabase: RoomDatabase() {
companion object {
val instance: MainDatabase by lazy {
if (_instance == null) throw IllegalStateException("someone should have called init fun")
_instance!!
}
private var _instance: MainDatabase? = null
fun init(mainApplication: MainApplication) {
_instance = init_(mainApplication)
//force db opening and if it fails, we try to destroy and recreate the db
try {
_instance!!.openHelper.writableDatabase
} catch (e: Exception) {
Log.e("Database", "there was an error during DB opening => trying to destroy and recreate", e)
_instance!!.openHelper.close()
val dbPath = mainApplication.getDatabasePath(DB_NAME)
if (SQLiteDatabase.deleteDatabase(dbPath)) {
_instance = init_(mainApplication)
_instance!!.openHelper.writableDatabase
}
}
}
private fun init_(mainApplication: MainApplication): MainDatabase {
return Room.databaseBuilder(mainApplication, MainDatabase::class.java, DB_NAME)
.addMigrations(MIGRATION_1, MIGRATION_2, MIGRATION_3, MIGRATION_4, MIGRATION_5, MIGRATION_6, MIGRATION_7, MIGRATION_8, MIGRATION_9, MIGRATION_10)
.build()
}
}
如何为两个列表计算四个p值?
就像我想看到的是p值的列表
pvalue = [0.1,0.2,0,1,0.2,0.1]
答案 0 :(得分:0)
快速且肮脏,假设控制和测试包含相同数量的项目:
control = [0.1, 0.14, 0.20, 0.40]
test = [0.1,0.2,0.32,0.8]
for idx in range(len(control)):
val_co = control[idx]
val_te = test[idx]
# do whatever you want to do with val_co and val_te
答案 1 :(得分:0)
您可以尝试在SciPy中使用binomial test function
from scipy.stats import binom_test
n = 1000
control = [100, 140,200,400]
test = [101,200,320,800]
pvals = []
for idx in range(len(control)):
pvals.append(binom_test(test[idx],n=n, p=control[idx]/n))
print(pvals)
[0.9160130517865064, 1.8593423831091924e-07, 4.004795877115897e-19, 1.644604962019165e-147]
(我刚刚对此做了basic 101 blog post)