• Welcome to the Kancolle Wiki!
  • If you have any questions regarding site content, account registration, etc., please visit the KanColle Wiki Discord

Module:Stat

From Kancolle Wiki
Revision as of 08:07, 12 October 2015 by がか (talk | contribs) (Created page with " local Stat = {} function Stat.rate(frame) local a = tonumber(frame.args[1]) local b = tonumber(frame.args[2]) local n = frame.args[3] and tonumber(frame.args[3])...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Documentation for this module may be created at Module:Stat/doc

local Stat = {}

function Stat.rate(frame)
    local a = tonumber(frame.args[1])
    local b = tonumber(frame.args[2])
    local n = frame.args[3] and tonumber(frame.args[3]) or 1
    local f = frame.args["format"] and tonumber(frame.args["format"]) or 2
    if a and b and n and f then
        return string.format("%." .. f .. "f", 100 * (1 - (1 - a / b) ^ n))
    else
        return "undefined"
    end
end

function Stat.trials(frame)
    local a = tonumber(frame.args[1])
    local b = tonumber(frame.args[2])
    local q = tonumber(frame.args[3])
    if a and b and q then
        return string.format("%.f", log(1 - q) / log(1 - a / b))
    else
        return "undefined"
    end
end

function Stat.error(frame)
    local a = tonumber(frame.args[1])
    local b = tonumber(frame.args[2])
    local f = frame.args["format"] and tonumber(frame.args["format"]) or 2
    local pc = frame.args["percentile"] and tonumber(frame.args["percentile"]) or 1.96
    if a and b and f and pc then
        local p = a / b
        local se = math.sqrt(p * (1 - p) / b)
        return string.format("%." .. f .. "f", 100 * pc * se)
    else
        return "undefined"
    end
end

return Stat