Groovy web console

subscribe to the feed Subscribe
to this
site
Variancia - Estat?tica (via #groovywebconsole)
tweet this snippet Tweet
this
script

Variancia - Estat?tica

Published 6 months ago by Anderson Lira with tags Estat?tica c?culo matem?ica
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
/**
*  2         _ 2
* s =   (x - x)
      ∑ ( i   )
*     ---------
*        n - 1
**/

class Variancia  {
    def rol = []
    
    def calcular(){
        def total = 0
        rol.each{
            total+= it;
        }
        def n = rol.size()
        def media = total/n
        def sum = 0
        rol.each{
            sum+= (it - media).pow(2)
        }
        sum / (n -1) 
    }
}
def variancia = new Variancia(rol:[4,5,5,6,6,7,7,8])
println variancia.calcular()