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

Difference between revisions of "Module:Stat"

From Kancolle Wiki
Jump to navigation Jump to search
(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])...")
 
Line 19: Line 19:
 
     local q = tonumber(frame.args[3])
 
     local q = tonumber(frame.args[3])
 
     if a and b and q then
 
     if a and b and q then
         return string.format("%.f", log(1 - q) / log(1 - a / b))
+
         return string.format("%.f", log(1 - q / 100) / log(1 - a / b))
 
     else
 
     else
 
         return "undefined"
 
         return "undefined"
Line 33: Line 33:
 
         local p = a / b
 
         local p = a / b
 
         local se = math.sqrt(p * (1 - p) / b)
 
         local se = math.sqrt(p * (1 - p) / b)
         return string.format("%." .. f .. "f", 100 * pc * se)
+
         return string.format("%." .. f .. "f", 100 * (pc * se + 0.5 / b))
 
     else
 
     else
 
         return "undefined"
 
         return "undefined"

Revision as of 08:15, 12 October 2015

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 / 100) / 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 + 0.5 / b))
    else
        return "undefined"
    end
end

return Stat