0.0.17 • Published 11 years ago

yagnus v0.0.17

Weekly downloads
41
License
-
Repository
github
Last release
11 years ago

Yagnus.js is a collection of classes that can be used to calculate statistics in browser, on servers or inside mongodb.

Descriptive Statistics

Descriptive statistics are numbers that we calculate to describe a large amount of data we have seen. The most important statistics are: mean, variance, skewness and kurtosis, and covariance for multivariate situations. Additionally, sometimes, one just wants to count things, such as number of times a word appear in a text. In the case of counting, we have created a couting contingency table which can count one things or analyze cooccurance of multiple discrete variables.

Yagnus implements gathering of these statistics without storing all the data. At time of observing each data point, a constant-time update is performed. At the completion of the calculation, one may chose to call a calc() method to remove machinery for calculating data. After calc is run, the object can no longer be updated or merged with other aggregator.

Basic descriptive statistics are not order sensitve so any permutation of the same set of data points will result in the identical statistics. This means that if we have two collection of statistics:

var statA = oy.UVar(); //for exampmle intialize a univariate statistics collector

//followed by some efforts of data gethering
 statA.inc(1);

var statB =oy.UVar(); //
 //followed by some separate effort of data gathering
 statB.inc(5);

//This followin operation adds all of the datapoints we observed in statB to statA as if we observed them directly using statA
 statA.inc(statB);
 statA.calc();

//prints 3
 console.log(statA.average);
//prints 2
 console.log(statA.count);

Univariate Statistics

Yagnus lib calculates sum, count, average, variance, skewness, kurtosis, min and max. To start calculating univariate stats call either the shorthand constructor or the constructor long form:

var stat = oy.UVar();
var stat = org.yagnus.stats.initUnivariateSummaryStatistics();

To add a number use the inc() method:

stat.inc(1);
stat.inc(3.1415);

Add a bunch of numbers all at once:

stat.inc(1,2,3,4,5,6,7);

Too merge in a second univeriate stat use "inc()" or "update()": stat.inc(stat2); stat.update(stat2);

When all the data is gathered call "calc()"

stat.calc();

At this point stat can no longer b updated or merged but you can get results from it:

stat.sum;
stat.count;
stat.min;
stat.max;
stat.average;   //if it exists, otherwise null
stat.variance;  //if it exists, otherwise null
stat.standardDeviation;//if it exists, otherwise null
stat.skew;      //if it exists, otherwise null
stat.kurtosis;  //if it exists, otherwise null
stat.bad;//contains the number of nan, infinity, or non-numerical strings passed to inc and excluded from above calculations

Multivariate Statistics

Multivariate stats collector must be constructed with the number of variables we plan to observe.

var ms = oy.MVar(3);
var ms = org.yagnus.stats.initMultivariateSummaryStatistics(3);

Observed data points must be entered separately using "inc()" with each parameter corresponding to the variable.

ms.inc(1,1,1);
ms.inc(2,2,2);
ms.inc(3,3,3);

add stats from another set of observation:

ms.update(ms2);

finalize using "calc()"

ms.calc();

the resulting object contains univariate stats for each of the variables. these univariate stats are also calc()'ed when the multivariate aggregator is calc()'ed

ms.univariates[0].sum;
ms.univariates[1].variance;

to get the covariance of two variables call "getCovariance()":

ms.getCovariance(0,1); //notice the variables uses 0-based  index
ms.getCovariance(0,2); //notice the variables uses 0-based  index

This object can also calculate the //Pearson's Product-moment Correlation Coefficient, again using 0-based index to refer to variables:

ms.getPPMCC(0,1);

Note, all operations are constant-time wrt data count.

Discrete Multivariate Statistics

Construction must specify dimensionality:

var ds = oy.DVar(3);
var ds = oy.Counter(3);

var ds = org.yagnus.stats.initDiscreteSummaryStatistics(3);

Observe things:

ds.inc('a','b','c');

Merge observations

ds.update(ds2);

Finalize:

ds.calc();

Get cell counts:

ds.getCount('a','b','c');

Get marginal count:

ds.getCount('a','b');

MongoDb

One can put it in the .mongorc.js

cat oy.js >> ~/.mongorc.js

Or install it into system so that mapreduce can use the stats:

mongo localhost:27017/analytics oy.js oy_mongo_install.js

After that, the stats observers can be used freely inside mapreduction:

db.rawData.mapReduce(
	  //map
    function(){
			emit(this.key, {us:[this.value1, this.value2, this.value3], ds:[this.kw1,this.kw2]});
    },
	  //reduce
    function(k,vs){
        var us = oy.UVar();
        var ds = oy.DVar();
        vs.forEach(function(v){
            us.inc(v.us);
            ds.inc(v.ds);
        }
        return {us:us, vs:vs};
    },
    //options
    {
        finalize:  function(k,v){ /*v.calc()*/ },
        out:       {reduce:  "statistics_table"},
			query:      ord_date: { $gt: new Date('01/01/2012')},
    }
);

And the statistics_table can be incrementally reduced into as needed.

node.js

require("yagnus");

Yagnus.js Banner

                                                                                                       ### 
                                                                                                       ### 
                                                                                                       ### 
                                                                                                       ### 
                                                                                                    ###### 
                                                                                                 ######### 
                                                                                               ########### 
                                                                                            ############## 
                                                                                         ################# 
                                                                                       ################### 
                                                                                 ######################### 
                                                                              ############################ 
                                                                            ############################## 
                                                                         ###########################   ### 
                        ###                                           ###########################      ### 
                        ###                                        ############################        ### 
                        ###                                      ###########################           ### 
                        ###                                   ########################### 
                        ############################################################## 
                        ############################################################ 
                        ###################################################### 
                        ####################################################
                        ################################################# 
                        ############################################## 
                        ########################################### 
                        ############################################## 
                        ###                                    ########### 
                        ###                                       ########## 
                        ###                                          ########### 
                        ###                                             ########### 
                                                                              ###########              ### 
                                                                                  ##########           ### 
                                                                                     ###########       ### 
                                                                                        ###########    ### 
                                                                                           ############### 
                                                                                               ########### 
                                                                                                 ######### 
                                                                                                     ##### 
                                                                                                       ### 
                                                                                                       ### 
                                                                                                       ### 
                                                                                                       ### 
                                                                                                       ### 
                                                                                                           
                                   ####### 
                               ###############
                             ################## 
                           ######################            #####
                          ########################         ######### 
                          #########################       ############ 
                         ###########################      ############# 
                         ########           ########      ############## 
                        #######               #######      ############# 
                        ######                #######        ####  ###### 
                        #####                  ######                #### 
                        #####                  ######                #### 
                         ####                  #####                 #### 
                         ####                  #####                ##### 
                          ####                #####                ###### 
                          #####               ####                ####### 
                           ######           #####               ######## 
                            ############################################ 
                          ############################################# 
                          ############################################ 
                        ############################################ 
                        ########################################## 
                        ######################################### 
                        ##################################### 
                        ##### 
                        ### 
                        ## 
                        ##
                          
       #########                                  ########## 
     ##############                           ################## 
   ##################                        #####################
  ######         #####    #####            ######################## 
######             ###############        ########################## 

####### ########### ######## ####### ######## ########### ########### ########### ######### ############# ################################ ########################### ############################# ######################### ############################ ####################### ######################## ## ### ################### ##################### ### ##### ############### ################## ########### ########### ########## ########## #########

                                                                         ###### 
                                                                           ### 
                                                                               
                        ###                                          #### 
                        ###                                          #### 
                        ################################################# 
                        ################################################# 
                        ################################################# 
                        ################################################# 
                        ################################################# 
                        ################################################# 
                        ################################################# 
                        ################################################# 
                        ###                                     #### 
                                                                 #### 
                                                                  #### 
                                                                  ##### 
                                                                  ###### 
                                                                  ###### 
                                                                  ####### 
                                                                  ####### 
                                                                  ####### 
                        ###                                      ######## 
                        ################################################# 
                        ################################################ 
                        ################################################ 
                        ############################################### 
                        ############################################## 
                        ############################################ 
                        ##########################################
                        ###################################### 
                        ### 
                        ### 
                                                                     #### 
                                                                     #### 
                                   ###################################### 
                               ########################################## 
                            ############################################# 
                          ############################################### 
                          ############################################### 
                         ################################################ 
                         ################################################ 
                        ################################################# 
                        ######## 
                        ####### 
                        ###### 
                        ###### 
                         ##### 
                         ##### 
                          ##### 
                          ##### 
                           ##### 
                            #####                                    #### 
                        ################################################# 
                        ################################################# 
                        ################################################# 
                        ################################################# 
                        ################################################# 
                        ################################################# 
                        ################################################# 
                        ################################################# 
                        ### 
                        ### 
                        ############                   ####### 
                        ############                ############# 
                        ############              ################ 
                        ############            #################### 
                          ########             ###################### 
                          ######              ######################## 
                          #####               ######################### 
                         #####               ##############       ###### 
                         ####                ############           #### 
                        ####                ############             #### 
                        ###                 ############             #### 
                        ###                 ###########              #### 
                        ###                ############              #### 
                        ###                ############              #### 
                        ###               ############              ##### 
                        ###               ############             ##### 
                        ####             #############            ###### 
                         ###             ############             ##### 
                         ####           #############            ###### 
                          ####         #############           ####### 
                          #########################          ############ 
                           ########################          ############ 
                            ######################           ############ 
                              ################## 
                                ############## 
                                    ######## 
                                             
                           ###### 
                          ######### 
                         ###########
                        ############ 
                        ############ 
                        ############ 
                         ###########
                          ######### 
                           ###### 
                                  
   ##### 
########## 

############ ############# ############## ##############

####### #### ###### ########################################################################### ######### ########################################################################## ########### ######################################################################### ############ ######################################################################## ############ ###################################################################### ############ ################################################################### ########### ################################################################ ######### ########################################################### ###### ############ ####### ############ ############# ############ ################ ############ #################### ######## ######################

                          ######              ######################## 
                          #####               ######################### 
                         #####               ##############       ###### 
                         ####                ############           #### 
                        ####                ############             #### 
                        ###                 ############             #### 
                        ###                 ###########              #### 
                        ###                ############              #### 
                        ###                ############              #### 
                        ###               ############              ##### 
                        ###               ############             ##### 
                        ####             #############            ###### 
                         ###             ############             ##### 
                         ####           #############            ###### 
                          ####         #############           ####### 
                          #########################          ############ 
                           ########################          ############ 
                            ######################           ############ 
                              ################## 
                                ############## 
                                    ######## 
                                             
                           ######                                             ##################
                          #########                             #################################### 
                         ###########                   ################################################ 
                        ############          ########################################################### 
                        ############         #############################################################
                        ############          ########################################################### 
                         ###########                   ################################################ 
                          #########                             #################################### 
                           ######                                             ##################
                                                                                                
0.0.17

11 years ago

0.0.16

11 years ago

0.0.15

11 years ago

0.0.14

11 years ago

0.0.12

11 years ago

0.0.11

11 years ago

0.0.10

11 years ago

0.0.7

11 years ago

0.0.6

11 years ago