Created
May 14, 2015 01:44
-
-
Save SwadicalRag/36084e9968f138655ca8 to your computer and use it in GitHub Desktop.
Statistics. Why?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cookie.statistics.juxtapose = function(tbl1,tbl2) | |
local t1 = {} | |
local t2 = {} | |
local t1_total = 0 | |
t1.count = 0 | |
for k,v in ipairs(tbl1) do | |
t1.count = t1.count + 1 | |
t1_total = t1_total + tonumber(v) | |
end | |
t1.mean = t1_total/t1.count | |
local t1_rawvar = 0 | |
for k,v in ipairs(tbl1) do | |
t1_rawvar = t1_rawvar + (v-t1.mean)^2 | |
end | |
t1.var = t1_rawvar/t1.count | |
local t2_total = 0 | |
t2.count = 0 | |
for k,v in ipairs(tbl2) do | |
t2.count = t2.count + 1 | |
t2_total = t2_total + tonumber(v) | |
end | |
t2.mean = t2_total/t2.count | |
local t2_rawvar = 0 | |
for k,v in ipairs(tbl2) do | |
t2_rawvar = t2_rawvar + (v-t2.mean)^2 | |
end | |
t2.var = t2_rawvar/t2.count | |
local out = { | |
"'Anal'ysis: ", | |
"Table 1: ", | |
". Mean: "..t1.mean, | |
". Variance: "..t1.var, | |
". Elements: "..t1.count, | |
". Cumulation of elements: "..t1_total, | |
"Table 2: ", | |
". Mean: "..t2.mean, | |
". Variance: "..t2.var, | |
". Elements: "..t2.count, | |
". Cumulation of elements: "..t2_total, | |
"Direct juxtaposition: ", | |
". Mean: "..(t1.mean/t2.mean*100).."%", | |
". Variance: "..(t1.var/t2.var*100).."%" | |
} | |
return table.concat(out,"\n") | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment