@smockle/regression 3.0.4 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -13
- package/README.md +14 -15
- package/dist/index.d.ts +53 -0
- package/dist/index.js +62 -0
- package/package.json +29 -40
- package/.editorconfig +0 -7
- package/.eslintrc.json +0 -6
- package/.flowconfig +0 -27
- package/.prettierignore +0 -1
- package/.travis.yml +0 -19
- package/appveyor.yml +0 -21
- package/flow-typed/npm/@smockle/matrix_vx.x.x.js +0 -192
- package/flow-typed/npm/@std/esm_vx.x.x.js +0 -32
- package/flow-typed/npm/codecov_vx.x.x.js +0 -276
- package/flow-typed/npm/colortape_vx.x.x.js +0 -80
- package/flow-typed/npm/eslint-config-standard_vx.x.x.js +0 -47
- package/flow-typed/npm/eslint-plugin-import_vx.x.x.js +0 -377
- package/flow-typed/npm/eslint-plugin-node_vx.x.x.js +0 -293
- package/flow-typed/npm/eslint-plugin-promise_vx.x.x.js +0 -170
- package/flow-typed/npm/eslint-plugin-standard_vx.x.x.js +0 -103
- package/flow-typed/npm/eslint_vx.x.x.js +0 -2401
- package/flow-typed/npm/flow-bin_v0.x.x.js +0 -6
- package/flow-typed/npm/flow-typed_vx.x.x.js +0 -193
- package/flow-typed/npm/husky_vx.x.x.js +0 -88
- package/flow-typed/npm/jsdoc-to-markdown_vx.x.x.js +0 -95
- package/flow-typed/npm/lint-staged_vx.x.x.js +0 -145
- package/flow-typed/npm/lodash_v4.x.x.js +0 -522
- package/flow-typed/npm/mathjs_vx.x.x.js +0 -6187
- package/flow-typed/npm/nyc_vx.x.x.js +0 -108
- package/flow-typed/npm/prettier-eslint-cli_vx.x.x.js +0 -78
- package/jsdoc.json +0 -6
- package/jsdoc2md/README.hbs +0 -32
- package/lib/regression.js +0 -3
- package/lib/regression.mjs +0 -93
- package/test/regression.mjs +0 -264
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
// flow-typed signature: f6e603c55941b36c9d8577c99c4196b5
|
|
2
|
-
// flow-typed version: <<STUB>>/nyc_v^11.0.2/flow_v0.53.1
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* This is an autogenerated libdef stub for:
|
|
6
|
-
*
|
|
7
|
-
* 'nyc'
|
|
8
|
-
*
|
|
9
|
-
* Fill this stub out by replacing all the `any` types.
|
|
10
|
-
*
|
|
11
|
-
* Once filled out, we encourage you to share your work with the
|
|
12
|
-
* community by sending a pull request to:
|
|
13
|
-
* https://github.com/flowtype/flow-typed
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
declare module 'nyc' {
|
|
17
|
-
declare module.exports: any
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* We include stubs for each file inside this npm package in case you need to
|
|
22
|
-
* require those files directly. Feel free to delete any files that aren't
|
|
23
|
-
* needed.
|
|
24
|
-
*/
|
|
25
|
-
declare module 'nyc/bin/nyc' {
|
|
26
|
-
declare module.exports: any
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
declare module 'nyc/bin/wrap' {
|
|
30
|
-
declare module.exports: any
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
declare module 'nyc/lib/commands/instrument' {
|
|
34
|
-
declare module.exports: any
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
declare module 'nyc/lib/config-util' {
|
|
38
|
-
declare module.exports: any
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
declare module 'nyc/lib/hash' {
|
|
42
|
-
declare module.exports: any
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
declare module 'nyc/lib/instrumenters/istanbul' {
|
|
46
|
-
declare module.exports: any
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
declare module 'nyc/lib/instrumenters/noop' {
|
|
50
|
-
declare module.exports: any
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
declare module 'nyc/lib/process-args' {
|
|
54
|
-
declare module.exports: any
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
declare module 'nyc/lib/process' {
|
|
58
|
-
declare module.exports: any
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
declare module 'nyc/lib/self-coverage-helper' {
|
|
62
|
-
declare module.exports: any
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
declare module 'nyc/lib/source-maps' {
|
|
66
|
-
declare module.exports: any
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
// Filename aliases
|
|
70
|
-
declare module 'nyc/bin/nyc.js' {
|
|
71
|
-
declare module.exports: $Exports<'nyc/bin/nyc'>
|
|
72
|
-
}
|
|
73
|
-
declare module 'nyc/bin/wrap.js' {
|
|
74
|
-
declare module.exports: $Exports<'nyc/bin/wrap'>
|
|
75
|
-
}
|
|
76
|
-
declare module 'nyc/index' {
|
|
77
|
-
declare module.exports: $Exports<'nyc'>
|
|
78
|
-
}
|
|
79
|
-
declare module 'nyc/index.js' {
|
|
80
|
-
declare module.exports: $Exports<'nyc'>
|
|
81
|
-
}
|
|
82
|
-
declare module 'nyc/lib/commands/instrument.js' {
|
|
83
|
-
declare module.exports: $Exports<'nyc/lib/commands/instrument'>
|
|
84
|
-
}
|
|
85
|
-
declare module 'nyc/lib/config-util.js' {
|
|
86
|
-
declare module.exports: $Exports<'nyc/lib/config-util'>
|
|
87
|
-
}
|
|
88
|
-
declare module 'nyc/lib/hash.js' {
|
|
89
|
-
declare module.exports: $Exports<'nyc/lib/hash'>
|
|
90
|
-
}
|
|
91
|
-
declare module 'nyc/lib/instrumenters/istanbul.js' {
|
|
92
|
-
declare module.exports: $Exports<'nyc/lib/instrumenters/istanbul'>
|
|
93
|
-
}
|
|
94
|
-
declare module 'nyc/lib/instrumenters/noop.js' {
|
|
95
|
-
declare module.exports: $Exports<'nyc/lib/instrumenters/noop'>
|
|
96
|
-
}
|
|
97
|
-
declare module 'nyc/lib/process-args.js' {
|
|
98
|
-
declare module.exports: $Exports<'nyc/lib/process-args'>
|
|
99
|
-
}
|
|
100
|
-
declare module 'nyc/lib/process.js' {
|
|
101
|
-
declare module.exports: $Exports<'nyc/lib/process'>
|
|
102
|
-
}
|
|
103
|
-
declare module 'nyc/lib/self-coverage-helper.js' {
|
|
104
|
-
declare module.exports: $Exports<'nyc/lib/self-coverage-helper'>
|
|
105
|
-
}
|
|
106
|
-
declare module 'nyc/lib/source-maps.js' {
|
|
107
|
-
declare module.exports: $Exports<'nyc/lib/source-maps'>
|
|
108
|
-
}
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
// flow-typed signature: 56ebe15a26b55410ff353983dbf8c878
|
|
2
|
-
// flow-typed version: <<STUB>>/prettier-eslint-cli_v^4.0.0/flow_v0.53.1
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* This is an autogenerated libdef stub for:
|
|
6
|
-
*
|
|
7
|
-
* 'prettier-eslint-cli'
|
|
8
|
-
*
|
|
9
|
-
* Fill this stub out by replacing all the `any` types.
|
|
10
|
-
*
|
|
11
|
-
* Once filled out, we encourage you to share your work with the
|
|
12
|
-
* community by sending a pull request to:
|
|
13
|
-
* https://github.com/flowtype/flow-typed
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
declare module 'prettier-eslint-cli' {
|
|
17
|
-
declare module.exports: any
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* We include stubs for each file inside this npm package in case you need to
|
|
22
|
-
* require those files directly. Feel free to delete any files that aren't
|
|
23
|
-
* needed.
|
|
24
|
-
*/
|
|
25
|
-
declare module 'prettier-eslint-cli/dist/add-exception-handler' {
|
|
26
|
-
declare module.exports: any
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
declare module 'prettier-eslint-cli/dist/format-files' {
|
|
30
|
-
declare module.exports: any
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
declare module 'prettier-eslint-cli/dist/index' {
|
|
34
|
-
declare module.exports: any
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
declare module 'prettier-eslint-cli/dist/messages' {
|
|
38
|
-
declare module.exports: any
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
declare module 'prettier-eslint-cli/dist/no-main' {
|
|
42
|
-
declare module.exports: any
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
declare module 'prettier-eslint-cli/dist/parser' {
|
|
46
|
-
declare module.exports: any
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
declare module 'prettier-eslint-cli/dist/uncaught-exception-handler' {
|
|
50
|
-
declare module.exports: any
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// Filename aliases
|
|
54
|
-
declare module 'prettier-eslint-cli/dist/add-exception-handler.js' {
|
|
55
|
-
declare module.exports: $Exports<
|
|
56
|
-
'prettier-eslint-cli/dist/add-exception-handler'
|
|
57
|
-
>
|
|
58
|
-
}
|
|
59
|
-
declare module 'prettier-eslint-cli/dist/format-files.js' {
|
|
60
|
-
declare module.exports: $Exports<'prettier-eslint-cli/dist/format-files'>
|
|
61
|
-
}
|
|
62
|
-
declare module 'prettier-eslint-cli/dist/index.js' {
|
|
63
|
-
declare module.exports: $Exports<'prettier-eslint-cli/dist/index'>
|
|
64
|
-
}
|
|
65
|
-
declare module 'prettier-eslint-cli/dist/messages.js' {
|
|
66
|
-
declare module.exports: $Exports<'prettier-eslint-cli/dist/messages'>
|
|
67
|
-
}
|
|
68
|
-
declare module 'prettier-eslint-cli/dist/no-main.js' {
|
|
69
|
-
declare module.exports: $Exports<'prettier-eslint-cli/dist/no-main'>
|
|
70
|
-
}
|
|
71
|
-
declare module 'prettier-eslint-cli/dist/parser.js' {
|
|
72
|
-
declare module.exports: $Exports<'prettier-eslint-cli/dist/parser'>
|
|
73
|
-
}
|
|
74
|
-
declare module 'prettier-eslint-cli/dist/uncaught-exception-handler.js' {
|
|
75
|
-
declare module.exports: $Exports<
|
|
76
|
-
'prettier-eslint-cli/dist/uncaught-exception-handler'
|
|
77
|
-
>
|
|
78
|
-
}
|
package/jsdoc.json
DELETED
package/jsdoc2md/README.hbs
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
[](https://www.npmjs.com/package/@smockle/regression)
|
|
2
|
-
[](https://travis-ci.org/smockle/regression)
|
|
3
|
-
[](https://ci.appveyor.com/project/smockle/regression)
|
|
4
|
-
[](https://codecov.io/gh/smockle/regression)
|
|
5
|
-
[](https://snyk.io/test/github/smockle/regression)
|
|
6
|
-
[](https://greenkeeper.io/)
|
|
7
|
-
|
|
8
|
-
# regression
|
|
9
|
-
|
|
10
|
-
Estimate multiple linear regression fit using least squares.
|
|
11
|
-
|
|
12
|
-
## Installation
|
|
13
|
-
|
|
14
|
-
Run `npm install --save @smockle/regression` to add `regression` to your project.
|
|
15
|
-
|
|
16
|
-
## Usage
|
|
17
|
-
|
|
18
|
-
```JavaScript
|
|
19
|
-
const regression = require('@smockle/regression')
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
## API Reference
|
|
23
|
-
{{#module name="regression"}}
|
|
24
|
-
{{>body~}}
|
|
25
|
-
{{>member-index~}}
|
|
26
|
-
{{>separator~}}
|
|
27
|
-
{{>members~}}
|
|
28
|
-
{{/module}}
|
|
29
|
-
|
|
30
|
-
## Testing
|
|
31
|
-
|
|
32
|
-
`regression` includes several unit tests. After cloning the `regression` repo locally, run `npm install` in the project folder to install dependencies. Run `npm test` to execute the tests.
|
package/lib/regression.js
DELETED
package/lib/regression.mjs
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
|
|
3
|
-
/** @module regression */
|
|
4
|
-
|
|
5
|
-
import Matrix from '@smockle/matrix'
|
|
6
|
-
import math from 'mathjs'
|
|
7
|
-
import fill from 'lodash/fill'
|
|
8
|
-
import unzip from 'lodash/unzip'
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Estimate multiple linear regression fit using least squares
|
|
12
|
-
* @constructor
|
|
13
|
-
* @alias module:regression
|
|
14
|
-
* @param {Matrix} X - Input matrix
|
|
15
|
-
* @param {Matrix} Y - Input matrix
|
|
16
|
-
* @return {Regression} Multiple linear regression
|
|
17
|
-
*/
|
|
18
|
-
function Regression (X /* : Matrix */, Y /* : Matrix */) /* : Regression */ {
|
|
19
|
-
const r /* : Regression */ = Object.create(Regression.prototype)
|
|
20
|
-
r.n = X[0].length
|
|
21
|
-
r.p = X.length
|
|
22
|
-
r.X = Matrix([fill(Array(r.n), 1)].concat(X)).transpose()
|
|
23
|
-
r.Y = Matrix(Y).transpose()
|
|
24
|
-
|
|
25
|
-
r.B = Matrix.multiply(
|
|
26
|
-
r.X.transpose().multiply(r.X).invert(),
|
|
27
|
-
r.X.transpose().multiply(r.Y)
|
|
28
|
-
)
|
|
29
|
-
r.fitted = r.X.multiply(r.B).__value
|
|
30
|
-
r.mean = math.mean(r.Y.__value)
|
|
31
|
-
|
|
32
|
-
r.residuals = math.subtract(r.Y.__value, r.fitted)
|
|
33
|
-
r.SST = r.Y.__value.reduce((xs, y, i) => xs + math.pow(y - r.mean, 2), 0)
|
|
34
|
-
r.SSE = r.fitted.reduce(
|
|
35
|
-
(xs, _fitted) => xs + math.pow(_fitted[0] - r.mean, 2),
|
|
36
|
-
0
|
|
37
|
-
)
|
|
38
|
-
r.SSR = r.Y.__value.reduce(
|
|
39
|
-
(xs, y, i) => xs + math.pow(y[0] - r.fitted[i], 2),
|
|
40
|
-
0
|
|
41
|
-
)
|
|
42
|
-
r.Rsquared = r.SSE / r.SST
|
|
43
|
-
r.Rsquaredadj = r.Rsquared - (1 - r.Rsquared) * (r.p - 1) / (r.n - r.p)
|
|
44
|
-
r.stderr = math.sqrt(
|
|
45
|
-
r.residuals.reduce((xs, residual) => xs + math.pow(residual[0], 2), 0) /
|
|
46
|
-
(r.n - r.p - 1)
|
|
47
|
-
)
|
|
48
|
-
|
|
49
|
-
r.MSE = math.sqrt(
|
|
50
|
-
r.fitted.reduce(
|
|
51
|
-
(xs, _fitted, i) => xs + math.pow(_fitted[0] - r.Y.__value[i][0], 2),
|
|
52
|
-
0
|
|
53
|
-
) /
|
|
54
|
-
(r.n - 2)
|
|
55
|
-
)
|
|
56
|
-
r.VAR = Matrix(
|
|
57
|
-
math.multiply(r.MSE, r.X.transpose().multiply(r.X).invert().__value)
|
|
58
|
-
)
|
|
59
|
-
r.STDERR = math.sqrt(math.diag(r.VAR.__value))
|
|
60
|
-
r.TSTAT = r.STDERR.map((err, i) => r.B.__value[i] / err)
|
|
61
|
-
return r
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Format and print this regression
|
|
66
|
-
* @alias module:regression#inspect
|
|
67
|
-
* @return {string} Regression results
|
|
68
|
-
*/
|
|
69
|
-
Regression.prototype.inspect = function () /*: string */ {
|
|
70
|
-
var output /* : string */ = ''
|
|
71
|
-
output += math.format(
|
|
72
|
-
this.Rsquared,
|
|
73
|
-
x => `R²: ${math.multiply(x, 100).toFixed(2)}%\n`
|
|
74
|
-
)
|
|
75
|
-
output += math.format(
|
|
76
|
-
this.Rsquaredadj,
|
|
77
|
-
x => `Adj R²: ${math.multiply(x, 100).toFixed(2)}%\n`
|
|
78
|
-
)
|
|
79
|
-
output += math.format(this.stderr, x => `Std Err: ${x.toFixed(2)}\n\n`)
|
|
80
|
-
const labels = ['y'].concat(fill(Array(this.B.__value.length - 1), 'x'))
|
|
81
|
-
unzip([unzip(this.B.__value)[0], this.TSTAT]).forEach((x, i) => {
|
|
82
|
-
output += `${labels[i]}${labels[i] === 'y' ? '' : i}: ${math.format(x[0], {
|
|
83
|
-
notation: 'fixed',
|
|
84
|
-
precision: 2
|
|
85
|
-
})} (t-stat ${math.format(x[1], {
|
|
86
|
-
notation: 'fixed',
|
|
87
|
-
precision: 2
|
|
88
|
-
})})${i === this.B.__value.length - 1 ? '' : '\n'}`
|
|
89
|
-
})
|
|
90
|
-
return output
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
export default Regression
|
package/test/regression.mjs
DELETED
|
@@ -1,264 +0,0 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
|
|
3
|
-
import Regression from '../lib/regression'
|
|
4
|
-
import Matrix from '@smockle/matrix'
|
|
5
|
-
import math from 'mathjs'
|
|
6
|
-
import test from 'tape'
|
|
7
|
-
import util from 'util'
|
|
8
|
-
const { inspect } = util
|
|
9
|
-
|
|
10
|
-
test('Regression', function (t) {
|
|
11
|
-
t.plan(20)
|
|
12
|
-
|
|
13
|
-
// VBR Return (Return-RF)
|
|
14
|
-
const RAR = [
|
|
15
|
-
-3.299606018,
|
|
16
|
-
5.660926073,
|
|
17
|
-
1.300771693,
|
|
18
|
-
-1.297986198,
|
|
19
|
-
1.370615722,
|
|
20
|
-
-1.507395904,
|
|
21
|
-
-0.946105019,
|
|
22
|
-
-4.841277527,
|
|
23
|
-
-3.586533681,
|
|
24
|
-
6.628808772,
|
|
25
|
-
1.316931792,
|
|
26
|
-
-4.898786803
|
|
27
|
-
]
|
|
28
|
-
|
|
29
|
-
// Market (MKT-RF)
|
|
30
|
-
const MKT = [
|
|
31
|
-
-3.11,
|
|
32
|
-
6.13,
|
|
33
|
-
-1.12,
|
|
34
|
-
0.59,
|
|
35
|
-
1.36,
|
|
36
|
-
-1.53,
|
|
37
|
-
1.54,
|
|
38
|
-
-6.04,
|
|
39
|
-
-3.07,
|
|
40
|
-
7.75,
|
|
41
|
-
0.56,
|
|
42
|
-
-2.17
|
|
43
|
-
]
|
|
44
|
-
|
|
45
|
-
// Size
|
|
46
|
-
const SMB = [
|
|
47
|
-
-0.62,
|
|
48
|
-
0.47,
|
|
49
|
-
3.14,
|
|
50
|
-
-3.03,
|
|
51
|
-
0.95,
|
|
52
|
-
2.84,
|
|
53
|
-
-4.17,
|
|
54
|
-
0.43,
|
|
55
|
-
-2.71,
|
|
56
|
-
-1.86,
|
|
57
|
-
3.55,
|
|
58
|
-
-2.99
|
|
59
|
-
]
|
|
60
|
-
|
|
61
|
-
// Value
|
|
62
|
-
const HML = [
|
|
63
|
-
-3.06,
|
|
64
|
-
-2.16,
|
|
65
|
-
-0.73,
|
|
66
|
-
2.13,
|
|
67
|
-
-1.9,
|
|
68
|
-
-1.04,
|
|
69
|
-
-4.49,
|
|
70
|
-
2.88,
|
|
71
|
-
0.73,
|
|
72
|
-
-0.32,
|
|
73
|
-
-1.23,
|
|
74
|
-
-2.07
|
|
75
|
-
]
|
|
76
|
-
|
|
77
|
-
// Momentum
|
|
78
|
-
const UMD = [
|
|
79
|
-
3.76,
|
|
80
|
-
-2.88,
|
|
81
|
-
3.02,
|
|
82
|
-
-7.41,
|
|
83
|
-
5.92,
|
|
84
|
-
3.05,
|
|
85
|
-
10.24,
|
|
86
|
-
-2.16,
|
|
87
|
-
5.26,
|
|
88
|
-
-3.92,
|
|
89
|
-
2.43,
|
|
90
|
-
3.38
|
|
91
|
-
]
|
|
92
|
-
|
|
93
|
-
const r = Regression([MKT, SMB, HML, UMD], RAR)
|
|
94
|
-
t.equal(r.n, 12, 'n observations')
|
|
95
|
-
t.equal(r.p, 4, 'p factor terms')
|
|
96
|
-
t.deepEqual(
|
|
97
|
-
r.X,
|
|
98
|
-
Matrix([
|
|
99
|
-
[1, -3.11, -0.62, -3.06, 3.76],
|
|
100
|
-
[1, 6.13, 0.47, -2.16, -2.88],
|
|
101
|
-
[1, -1.12, 3.14, -0.73, 3.02],
|
|
102
|
-
[1, 0.59, -3.03, 2.13, -7.41],
|
|
103
|
-
[1, 1.36, 0.95, -1.9, 5.92],
|
|
104
|
-
[1, -1.53, 2.84, -1.04, 3.05],
|
|
105
|
-
[1, 1.54, -4.17, -4.49, 10.24],
|
|
106
|
-
[1, -6.04, 0.43, 2.88, -2.16],
|
|
107
|
-
[1, -3.07, -2.71, 0.73, 5.26],
|
|
108
|
-
[1, 7.75, -1.86, -0.32, -3.92],
|
|
109
|
-
[1, 0.56, 3.55, -1.23, 2.43],
|
|
110
|
-
[1, -2.17, -2.99, -2.07, 3.38]
|
|
111
|
-
]),
|
|
112
|
-
'X matrix'
|
|
113
|
-
)
|
|
114
|
-
t.deepEqual(
|
|
115
|
-
r.Y,
|
|
116
|
-
Matrix([
|
|
117
|
-
[-3.299606018],
|
|
118
|
-
[5.660926073],
|
|
119
|
-
[1.300771693],
|
|
120
|
-
[-1.297986198],
|
|
121
|
-
[1.370615722],
|
|
122
|
-
[-1.507395904],
|
|
123
|
-
[-0.946105019],
|
|
124
|
-
[-4.841277527],
|
|
125
|
-
[-3.586533681],
|
|
126
|
-
[6.628808772],
|
|
127
|
-
[1.316931792],
|
|
128
|
-
[-4.898786803]
|
|
129
|
-
]),
|
|
130
|
-
'Y matrix'
|
|
131
|
-
)
|
|
132
|
-
|
|
133
|
-
t.deepEqual(
|
|
134
|
-
r.B,
|
|
135
|
-
Matrix([
|
|
136
|
-
[-0.11570512587416651],
|
|
137
|
-
[0.9965414089434049],
|
|
138
|
-
[0.46406431951315674],
|
|
139
|
-
[0.29410972011067305],
|
|
140
|
-
[0.0758741075412841]
|
|
141
|
-
]),
|
|
142
|
-
'β coefficients factor terms'
|
|
143
|
-
)
|
|
144
|
-
t.deepEqual(
|
|
145
|
-
r.fitted,
|
|
146
|
-
[
|
|
147
|
-
[-4.117357884969744],
|
|
148
|
-
[5.3574095159621375],
|
|
149
|
-
[0.23977016847441873],
|
|
150
|
-
[-0.8696340157676041],
|
|
151
|
-
[1.5708185422604861],
|
|
152
|
-
[-0.3969288950543946],
|
|
153
|
-
[-1.0597813505453595],
|
|
154
|
-
[-5.25211965687211],
|
|
155
|
-
[-3.818903655863128],
|
|
156
|
-
[6.352789547145502],
|
|
157
|
-
[1.912405522995039],
|
|
158
|
-
[-4.018104935765246]
|
|
159
|
-
],
|
|
160
|
-
'fitted Y values'
|
|
161
|
-
)
|
|
162
|
-
t.equal(r.mean, -0.3416364248333333, 'mean Y value')
|
|
163
|
-
|
|
164
|
-
t.deepEqual(
|
|
165
|
-
r.residuals,
|
|
166
|
-
[
|
|
167
|
-
[0.8177518669697439],
|
|
168
|
-
[0.3035165570378622],
|
|
169
|
-
[1.0610015245255813],
|
|
170
|
-
[-0.4283521822323959],
|
|
171
|
-
[-0.2002028202604862],
|
|
172
|
-
[-1.1104670089456055],
|
|
173
|
-
[0.1136763315453595],
|
|
174
|
-
[0.4108421298721101],
|
|
175
|
-
[0.23236997486312783],
|
|
176
|
-
[0.27601922485449837],
|
|
177
|
-
[-0.5954737309950389],
|
|
178
|
-
[-0.8806818672347543]
|
|
179
|
-
],
|
|
180
|
-
'residual Y values'
|
|
181
|
-
)
|
|
182
|
-
t.equal(r.SST, 155.93033742014742, 'SST total sum of squares')
|
|
183
|
-
t.equal(r.SSE, 151.14498353223317, 'SSE explained sum of squares')
|
|
184
|
-
t.equal(r.SSR, 4.785353887914211, 'SSR residual sum of squares')
|
|
185
|
-
t.equal(
|
|
186
|
-
math.format(r.SST, { notation: 'fixed', precision: 8 }),
|
|
187
|
-
math.format(r.SSE + r.SSR, { notation: 'fixed', precision: 8 }),
|
|
188
|
-
'SST = SSE + SSR'
|
|
189
|
-
)
|
|
190
|
-
t.equal(r.Rsquared, 0.969310950216055, 'R² coefficient of determination')
|
|
191
|
-
t.equal(r.Rsquaredadj, 0.9578025565470756, 'adjusted R²')
|
|
192
|
-
t.equal(r.stderr, 0.8268143588422642, 'standard error of regression')
|
|
193
|
-
|
|
194
|
-
t.equal(r.MSE, 0.6917625234077234, 'MSE mean standard error')
|
|
195
|
-
t.deepEqual(
|
|
196
|
-
r.VAR,
|
|
197
|
-
Matrix([
|
|
198
|
-
[
|
|
199
|
-
0.07196948249766646,
|
|
200
|
-
0.0025212277747416315,
|
|
201
|
-
0.0025208085553061446,
|
|
202
|
-
0.015445877772156624,
|
|
203
|
-
0.00047794386911134755
|
|
204
|
-
],
|
|
205
|
-
[
|
|
206
|
-
0.0025212277747416315,
|
|
207
|
-
0.008540646610658573,
|
|
208
|
-
0.0005674745970637586,
|
|
209
|
-
0.01395071899820061,
|
|
210
|
-
0.005872357927868933
|
|
211
|
-
],
|
|
212
|
-
[
|
|
213
|
-
0.002520808555306144,
|
|
214
|
-
0.0005674745970637586,
|
|
215
|
-
0.009048264369132409,
|
|
216
|
-
-0.00017904322635722093,
|
|
217
|
-
0.00016540723502594728
|
|
218
|
-
],
|
|
219
|
-
[
|
|
220
|
-
0.015445877772156624,
|
|
221
|
-
0.01395071899820061,
|
|
222
|
-
-0.00017904322635722077,
|
|
223
|
-
0.04885262790234827,
|
|
224
|
-
0.016993607738073208
|
|
225
|
-
],
|
|
226
|
-
[
|
|
227
|
-
0.00047794386911134755,
|
|
228
|
-
0.0058723579278689335,
|
|
229
|
-
0.00016540723502594734,
|
|
230
|
-
0.01699360773807321,
|
|
231
|
-
0.008750503967407862
|
|
232
|
-
]
|
|
233
|
-
])
|
|
234
|
-
)
|
|
235
|
-
t.deepEqual(
|
|
236
|
-
r.STDERR,
|
|
237
|
-
[
|
|
238
|
-
0.26827128526487226,
|
|
239
|
-
0.09241561886747593,
|
|
240
|
-
0.09512236524147415,
|
|
241
|
-
0.22102630590576378,
|
|
242
|
-
0.09354412844966734
|
|
243
|
-
],
|
|
244
|
-
'standard error matrix (diagonal of variance)'
|
|
245
|
-
)
|
|
246
|
-
t.deepEqual(
|
|
247
|
-
r.TSTAT,
|
|
248
|
-
[
|
|
249
|
-
-0.4312989582911469,
|
|
250
|
-
10.783257431543538,
|
|
251
|
-
4.878603663135374,
|
|
252
|
-
1.3306548236664144,
|
|
253
|
-
0.8111049704430051
|
|
254
|
-
],
|
|
255
|
-
'test statistic (significance)'
|
|
256
|
-
)
|
|
257
|
-
|
|
258
|
-
// Regression#inspect
|
|
259
|
-
t.equal(
|
|
260
|
-
inspect(r),
|
|
261
|
-
'R²: 96.93%\nAdj R²: 95.78%\nStd Err: 0.83\n\ny: -0.12 (t-stat -0.43)\nx1: 1.00 (t-stat 10.78)\nx2: 0.46 (t-stat 4.88)\nx3: 0.29 (t-stat 1.33)\nx4: 0.08 (t-stat 0.81)',
|
|
262
|
-
'inspect regression'
|
|
263
|
-
)
|
|
264
|
-
})
|