48 lines
37 KiB
JavaScript
48 lines
37 KiB
JavaScript
|
var vows = require('vows');
|
||
|
var assert = require('assert');
|
||
|
var suite = vows.describe('jStat');
|
||
|
|
||
|
require('../env.js');
|
||
|
|
||
|
suite.addBatch({
|
||
|
'model test': {
|
||
|
'topic': function() {
|
||
|
return jStat;
|
||
|
},
|
||
|
'array call': function(jStat) {
|
||
|
// The result is reviewed by R.
|
||
|
var exog = [[1, 0.9],
|
||
|
[1, 2.1],
|
||
|
[1, 2.9],
|
||
|
[1, 4.1],
|
||
|
[1, 4.9],
|
||
|
[1, 6.1],
|
||
|
[1, 6.9],
|
||
|
[1, 8.1],
|
||
|
[1, 8.9],
|
||
|
[1, 10.1]];
|
||
|
var endog = [11, 12, 13, 14, 15, 16, 17, 18, 19, 20];
|
||
|
//var exog = [[-2.302585093,7.0,36.0,3.0,1.0,1],[5.2475502495,3.0,20.0,4.0,1.0,1],[3.4372078192,2.0,24.0,6.0,1.0,1],[4.4200447019,3.0,28.0,6.0,1.0,1],[6.4616244141,5.0,68.0,6.0,1.0,1],[4.7013890437,3.0,21.0,4.0,1.0,1],[4.6061696863,5.0,77.0,4.0,1.0,1],[3.4372078192,5.0,21.0,4.0,1.0,1],[5.1935122522,4.0,31.0,4.0,1.0,1],[7.9374104098,3.0,39.0,3.0,1.0,1],[7.3778214063,3.0,26.0,2.0,1.0,1],[5.7993956389,4.0,31.0,4.0,1.0,1],[5.2475502495,5.0,22.0,4.0,1.0,1],[4.6061696863,4.0,42.0,5.0,1.0,1],[6.907855274,5.0,74.0,1.0,1.0,1],[-2.302585093,6.0,62.0,3.0,1.0,1],[4.8683033855,4.0,58.0,3.0,1.0,1],[1.6292405397,3.0,24.0,6.0,1.0,1],[3.4995332824,6.0,51.0,4.0,1.0,1],[2.9496883351,2.0,36.0,3.0,2.0,1],[4.3054155323,4.0,88.0,2.0,2.0,1],[5.2475502495,2.0,20.0,4.0,2.0,1],[2.4932054526,4.0,27.0,3.0,2.0,1],[-2.302585093,6.0,44.0,4.0,2.0,1],[2.9496883351,4.0,45.0,3.0,2.0,1],[-2.302585093,4.0,21.0,4.0,2.0,1],[5.9664031165,3.0,40.0,5.0,2.0,1],[3.6913763343,4.0,40.0,6.0,2.0,1],[1.1314021115,5.0,48.0,3.0,2.0,1],[6.1094697803,4.0,34.0,3.0,2.0,1],[5.858218828,3.0,26.0,2.0,2.0,1],[4.1604443639,4.0,60.0,2.0,3.0,1],[1.1314021115,4.0,32.0,3.0,3.0,1],[-2.302585093,4.0,31.0,3.0,3.0,1],[6.4616244141,7.0,33.0,3.0,3.0,1],[-2.302585093,3.0,57.0,3.0,3.0,1],[2.4932054526,4.0,84.0,3.0,3.0,1],[4.1287459889,7.0,75.0,3.0,3.0,1],[3.4372078192,7.0,19.0,4.0,3.0,1],[-2.302585093,3.0,47.0,6.0,3.0,1],[5.1935122522,5.0,51.0,2.0,3.0,1],[6.4616244141,6.0,40.0,3.0,3.0,1],[4.7013890437,2.0,22.0,6.0,3.0,1],[4.6061696863,7.0,35.0,2.0,3.0,1],[4.6061696863,4.0,43.0,5.0,3.0,1],[2.4069451083,6.0,76.0,6.0,3.0,1],[-2.302585093,4.0,45.0,3.0,3.0,1],[1.4109869737,4.0,88.0,2.0,3.0,1],[3.5582011305,4.0,46.0,3.0,4.0,1],[-2.302585093,3.0,22.0,6.0,4.0,1],[-2.302585093,5.0,68.0,3.0,4.0,1],[-2.302585093,5.0,38.0,3.0,4.0,1],[3.4995332824,4.0,69.0,2.0,4.0,1],[5.5987922608,5.0,67.0,3.0,4.0,1],[3.8088822465,2.0,88.0,4.0,4.0,1],[3.6913763343,6.0,68.0,3.0,4.0,1],[1.8082887712,5.0,76.0,3.0,4.0,1],[0.7419373447,4.0,72.0,2.0,4.0,1],[-2.302585093,6.0,37.0,6.0,4.0,1],[3.5582011305,4.0,69.0,3.0,4.0,1],[4.4200447019,2.0,33.0,6.0,4.0,1],[8.1605468185,2.0,34.0,4.0,4.0,1],[4.6061696863,4.0,30.0,3.0,4.0,1],[5.858218828,3.0,19.0,3.0,4.0,1],[4.6061696863,4.0,44.0,3.0,4.0,1],[4.206184044,4.0,64.0,3.0,4.0,1],[3.4045251718,7.0,37.0,4.0,4.0,1],[-2.302585093,6.0,31.0,5.0,5.0,1],[-2.302585093,6.0,88.0,4.0,5.0,1],[1.8082887712,6.0,77.0,4.0,5.0,1],[5.858218828,4.0,30.0,6.0,5.0,1],[5.9917145159,2.0,32.0,4.0,5.0,1],[2.7146947438,6.0,59.0,1.0,5.0,1],[-2.302585093,4.0,47.0,4.0,5.0,1],[1.1314021115,4.0,22.0,3.0,5.0,1],[3.0955776085,4.0,55.0,3.0,5.0,1],[4.1604443639,2.0,24.0,2.0,5.0,1],[3.4688560301,3.0,65.0,1.0,5.0,1],[5.9664031165,3.0,24.0,3.0,5.0,1],[-2.302585093,3.0,30.0,3.0,5.0,1],[-2.302585093,4.0,73.0,3.0,5.0,1],[4.0792309244,3.0,73.0,5.0,5.0,1],[-2.302585093,4.0,91.0,1.0,5.0,1],[3.5582011305,3.0,71.0,2.0,5.0,1],[-2.302585093,6.0,34.0,4.0,5.0,1],[5.1363864994,4.0,48.0,2.0,6.0,1],[2.4932054526,6.0,42.0,4.0,6.0,1],[3.6913763343,6.0,72.0,2.0,6.0,1],[3.4372078192,3.0,20.0,4.0,6.0,1],[3.4372078192,2.0,22.0,4.0,6.0,1],[7.3778214063,3.0,24.0,6.0,6.0,1],[0.0953101798,4.0,39.0,6.0,6.0,1],[1.4109869737,6.0,83.0,5.0,6.0,1],[5.2475502495,6.0,39.0,3.0,6.0,1],[3.9721769282,5.0,33.0,5.0,6.0,1],[3.4372078192,4.0,53.0,3.0,6.0,1],[2.778819272,5.0,82.0,3.0,6.0,1],[3.4995332824,4.0,82.0,3.0,6.0,1],[-2.302585093,5.0,47.0,6.0,7.0,1],[-2.302585093,4.0,68.0,3.0,7.0,1],[-2.302585093,4.0,84.0,6.0,7.0,1],[3.2995337279,6.0,35.0,5.0,7.0,1],[4.432006567,4.0,67.0,2.0,7.0,1],[3.0955776085,5.0,33.0,2.0,7.0,1],[-2.302585093,3.0,49.0,7.0,7.0,1],[8.1605468185,4.0,91.0,1.0,7.0,1],[5.9664031165,4.0,43.0,3.0,7.0,1],[-2.302585093,4.0,65.0,4.0,7.0,1],[2.778819272,5.0,69.0,3.0,7.0,1],[5.2988172416,5.0,56.0,4.0,8.0,1],[6.4616244141,2.0,24.0,6.0,8.0,1],[-2.302585093,4.0,77.0,3.0,8.0,1],[3.8088822465,6.0,74.0,3.0,8.0,1],[2.4932054526,7.0,25.0,6.0,8.0,1],[3.0007198151,6.0,85.0,1.0,8.0,1],[8.8956433257,7.0,21.0,2.0,8.0,1],[4.1604443639,6.0,24.0,4.0,8.0,1],[2.5726122302,5.0,73.0,4.0,8.0,1],[5.2475502495,4.0,37.0,3.0,8.0,1],[2.2082744135,4.0,35.0,4.0,8.0,1],[-
|
||
|
//var endog = [6.0,1.0,1.0,1.0,0.0,1.0,1.0,4.0,3.0,0.0,4.0,1.0,5.0,0.0,0.0,0.0,1.0,1.0,5.0,0.0,2.0,2.0,2.0,6.0,1.0,1.0,1.0,0.0,1.0,0.0,2.0,1.0,0.0,1.0,4.0,0.0,1.0,5.0,6.0,1.0,0.0,5.0,1.0,6.0,2.0,2.0,6.0,0.0,1.0,2.0,5.0,5.0,3.0,0.0,0.0,5.0,2.0,0.0,6.0,0.0,0.0,0.0,2.0,1.0,0.0,1.0,0.0,4.0,4.0,6.0,5.0,1.0,6.0,3.0,1.0,2.0,0.0,1.0,2.0,3.0,3.0,1.0,2.0,0.0,4.0,0.0,5.0,0.0,6.0,0.0,1.0,2.0,6.0,6.0,1.0,1.0,5.0,6.0,5.0,4.0,0.0,5.0,1.0,4.0,0.0,0.0,1.0,6.0,0.0,1.0,0.0,0.0,0.0,6.0,4.0,3.0,0.0,4.0,2.0,2.0,0.0,6.0,0.0,6.0,4.0,3.0,0.0,0.0,6.0,2.0,3.0,1.0,5.0,6.0,1.0,4.0,0.0,0.0,3.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0,2.0,4.0,6.0,3.0,1.0,1.0,1.0,6.0,6.0,6.0,4.0,0.0,1.0,4.0,2.0,2.0,6.0,4.0,0.0,5.0,6.0,2.0,2.0,1.0,5.0,4.0,2.0,6.0,6.0,6.0,0.0,6.0,4.0,6.0,5.0,6.0,3.0];
|
||
|
var model = jStat.models.ols(endog,exog);
|
||
|
var tol = 0.01;
|
||
|
|
||
|
// coff estimate
|
||
|
assert.epsilon(tol, model.coef[0], 10.0395 );
|
||
|
assert.epsilon(tol, model.coef[1], 0.9928 );
|
||
|
/*
|
||
|
assert.epsilon(tol, model.coef[2], -0.0033);
|
||
|
assert.epsilon(tol, model.coef[3], 0.1608);
|
||
|
assert.epsilon(tol, model.coef[4], 0.0520);
|
||
|
assert.epsilon(tol, model.coef[5], -2.6639);
|
||
|
*/
|
||
|
//R2
|
||
|
assert.epsilon(tol, model.R2, 0.9988);
|
||
|
// f test
|
||
|
assert.epsilon(tol, model.f.pvalue, 0.0000);
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
|
||
|
suite.export(module);
|