Skip to content

Commit

Permalink
Simplified bootstrap pvalue interface
Browse files Browse the repository at this point in the history
  • Loading branch information
pakozm committed Jun 30, 2015
1 parent 183007a commit c9af75a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 31 deletions.
36 changes: 9 additions & 27 deletions packages/basics/stats/lua_src/statistics.lua
Expand Up @@ -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)
Expand All @@ -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 =
Expand Down
4 changes: 0 additions & 4 deletions packages/basics/stats/test/test_bootstrap.lua
Expand Up @@ -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)

0 comments on commit c9af75a

Please sign in to comment.