Advertisement
JiiCeii

[Stats] index.lua

Sep 11th, 2011
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.32 KB | None | 0 0
  1. local SIGMA = function(t)
  2.     local sum = 0
  3.     for i = 1, #t do
  4.         sum = sum + t[i]
  5.     end
  6.     return sum
  7. end
  8.  
  9. local MEANS = function(t)
  10.     local sigma = {xini = 0, ni = SIGMA(t[1])}
  11.     local p_xini = {}
  12.     for i = 1, #t[1] do
  13.         p_xini[i] = t[1][i]*t[2][i]
  14.     end
  15.     sigma.xini = SIGMA(p_xini)
  16.     return(sigma.xini/sigma.ni)
  17. end
  18.  
  19. local VARIANCE = function(t)
  20.     local sigma = {ni = SIGMA(t[1]), nixix2 = 0}
  21.     local means_t = MEANS(t)
  22.     local p_nixix2 = {}
  23.     for i = 1, #t[1] do
  24.         p_nixix2[i] = t[1][i]*(t[2][i]-means_t)^2
  25.     end
  26.     sigma.nixix2 = SIGMA(p_nixix2)
  27.     return(sigma.nixix2/sigma.ni)
  28. end
  29.  
  30. local STANDARD_DEVIATION = function(v)
  31.     return math.sqrt(v)
  32. end
  33.  
  34. local MEDIAN = function(t)
  35.     local n = #t[1]
  36.     return((n % 2 == 0) and t[2][(n/2)+1] or t[2][(n+1)/2])
  37. end
  38.  
  39. --! en cours
  40. local QUARTILES = function(t)
  41.     local q = {0, MEDIAN(t), 0}
  42.     return unpack(q)
  43. end
  44.  
  45. local serie = {
  46.     {4,     20,     43,     100,    200,    250,    190,    113,    50,     19,     6,      5}, -- ni
  47.     {8,     8.1,    8.2,    8.3,    8.4,    8.5,    8.6,    8.7,    8.8,    8.9,    9,      9.1} -- xi
  48. }
  49.  
  50.  
  51. print("sommes des lignes du tableau : " .. SIGMA(serie[1]) .. " " .. SIGMA(serie[2]))
  52. print("moyenne : " .. MEANS(serie), "\nvariance : " .. VARIANCE(serie), "\necart type : " .. STANDARD_DEVIATION(VARIANCE(serie)))
  53. print("mediane : " .. MEDIAN(serie))
  54. print("quartiles : ", QUARTILES(serie))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement