GithubHelp home page GithubHelp logo

Comments (3)

plato-cambrian avatar plato-cambrian commented on May 22, 2024

here's what I wrote for my use case:

function findShiftedVariance(data){
  if(data.length === 0){ 
    throw new Error('Calculating variance of empty array')
  }

  var n;
  var K;
  var variance;
  var sum;
  var sumSqr;

  K = data[0];
  sum = 0;
  sumSqr = 0;
  for(n=0; n<data.length; n++){
    var x = data[n];
    sum = sum + (x - K);
    sumSqr = sumSqr + ((x - K) * (x - K));
  }
  variance = (sumSqr - ( (sum*sum)/n ) ) / n;
  return variance;
}

from simple-statistics.

plato-cambrian avatar plato-cambrian commented on May 22, 2024

hmm re-reading I note that I am dividing by n in the last step because I have a complete data set; but if the data set is a sample of a larger data set you should divide by n-1. how annoying :D

from simple-statistics.

tmcw avatar tmcw commented on May 22, 2024

Happy to accept a PR implementing this feature, but reading more about these algorithms doesn't uncover any that are sufficiently canonical.

from simple-statistics.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.