time-to-botec

Benchmark sampling in different programming languages
Log | Files | Refs | README

R2-test.js (1320B)


      1 var vows = require('vows');
      2 var assert = require('assert');
      3 var suite = vows.describe('jStat');
      4 
      5 require('../env.js');
      6 
      7 suite.addBatch({
      8   'model test': {
      9     'topic': function() {
     10       return jStat;
     11     },
     12     'array call': function(jStat) {
     13       var A = [
     14         [1, 2, 3],
     15         [1, 1, 0],
     16         [1, -2, 3],
     17         [1, 3, 4],
     18         [1, -10, 2],
     19         [1, 4, 4],
     20         [1, 10, 2],
     21         [1, 3, 2],
     22         [1, 4, -1]
     23       ];
     24         var b = [1, -2, 3, 4, -5, 6, 7, -8, 9];
     25         var model = jStat.models.ols(b, A);
     26         var tol = 0.01;
     27         // R2
     28         assert.epsilon(tol, model.R2, 0.309);
     29         // Adjusted R^2
     30         // This Adjusted R^2 is variously called the:
     31         // - Wherry Formula
     32         // - Ezekiel Formula
     33         // - Wherry/McNemar Formula
     34         // - Cohen/Cohen Formula
     35         //
     36         // It is the same as the adjusted R^2 value given by R's linear model
     37         // summary method
     38         assert.epsilon(tol, model.adjust_R2, 0.078);
     39         // t test
     40         assert.epsilon(tol, model.t.p[0], 0.8377444317889267);
     41         assert.epsilon(tol, model.t.p[1], 0.1529673615844231);
     42         assert.epsilon(tol, model.t.p[2], 0.9909627983826588);
     43         // f test
     44         assert.epsilon(tol, model.f.pvalue, 0.33063636718598743);
     45     }
     46   }
     47 });
     48 
     49 suite.export(module);