From c9af75a8a4a3ca6488ccf22541bbbb6bbb7b3859 Mon Sep 17 00:00:00 2001 From: Paco Zamora Martinez Date: Tue, 30 Jun 2015 10:41:43 +0200 Subject: [PATCH] Simplified bootstrap pvalue interface --- packages/basics/stats/lua_src/statistics.lua | 36 +++++-------------- packages/basics/stats/test/test_bootstrap.lua | 4 --- 2 files changed, 9 insertions(+), 31 deletions(-) diff --git a/packages/basics/stats/lua_src/statistics.lua b/packages/basics/stats/lua_src/statistics.lua index 23cc40177..9aca7d579 100644 --- a/packages/basics/stats/lua_src/statistics.lua +++ b/packages/basics/stats/lua_src/statistics.lua @@ -1366,10 +1366,16 @@ stats.boot.percentile = -- Taylor Berg-Kirkpatrick David Burkett Dan Klein. -- http://www.cs.berkeley.edu/~tberg/papers/emnlp2012.pdf stats.boot.pvalue = - function(data, pivot, index, alternative, h0) - local h0 = h0 or 0.0 + function(data, pivot, index, params) + local params = get_table_fields( + { + h0 = { mandatory = false, default = 0.0, type_match = "number" }, + alternative = { mandatory = false, default = "two-sided", type_match = "string" }, + }, + params or {}) + local h0 = params.h0 local p50 = stats.boot.percentile(data, 0.50, index) - local alternative = alternative or "two-sided" + local alternative = params.alternative april_assert(alternatives[alternative], "Unknown alternative value %s", alternative) local data = data:select(2, index or 1) @@ -1393,30 +1399,6 @@ stats.boot.pvalue = return pvalue end -stats.boot.rprob = - april_doc{ - class = "function", - summary = "Computes one-sided probability for a given pivot in a bootstrap sample", - description = { - "This function returns the one-sided probability of given pivot, that is, the", - "probability of the sample to be greater than the pivot. The probability", - "is computed to avoid bias problems as: (C(>pivot)+1)/(N+1)", - }, - params = { - "The result of stats.boot function.", - "The pivot [optional], by default it is 0.0", - "The statistic index for which you want compute the percentile [optional], by default it is 1", - }, - outputs = { - "The one-sided right probability", - }, - } .. - function(data, pivot, index) - assert(data, "Needs a data argument as first argument") - local ge_pivot = data:select(2, index or 1):gt(pivot or 0.0):count_ones() - return (1+ge_pivot) / (data:dim(1)+1) - end - ---------------------------------------------------------------------------- stats.percentile = diff --git a/packages/basics/stats/test/test_bootstrap.lua b/packages/basics/stats/test/test_bootstrap.lua index 19ae05b88..78fb4c87c 100644 --- a/packages/basics/stats/test/test_bootstrap.lua +++ b/packages/basics/stats/test/test_bootstrap.lua @@ -47,8 +47,4 @@ T("BootstrapTest", check.number_eq(m, -0.012237) check.number_eq(p0, -0.117945) check.number_eq(pn, 0.092709) - -- p-value tests - check.number_eq(stats.boot.rprob(boot_result, b), 0.025, 0.05) - check.number_eq(1.0 - stats.boot.rprob(boot_result, a), 0.025, 0.05) - check.number_eq(stats.boot.rprob(boot_result, m, 1), 0.500) end)