Skip to content

Commit 103eff7

Browse files
committed
Add US birth data
1 parent c5fb126 commit 103eff7

File tree

21 files changed

+5243
-0
lines changed

21 files changed

+5243
-0
lines changed

lib/node_modules/@stdlib/datasets/cdc-nchs-us-births-1994-2003/LICENSE

Lines changed: 356 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2019 The Stdlib Authors.
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
19+
-->
20+
21+
# US Birth Data (1994-2003)
22+
23+
> US birth data from 1994 to 2003, as provided by the Center for Disease Control and Prevention's National Center for Health Statistics.
24+
25+
<section class="usage">
26+
27+
## Usage
28+
29+
```javascript
30+
var dataset = require( '@stdlib/datasets/cdc-nchs-us-births-1994-2003' );
31+
```
32+
33+
#### dataset()
34+
35+
Returns US birth data from 1994 to 2003, as provided by the Center for Disease Control and Prevention's National Center for Health Statistics.
36+
37+
```javascript
38+
var data = dataset();
39+
// returns [ {...}, ... ]
40+
```
41+
42+
Each element in the returned database has the following fields:
43+
44+
- **year**: year.
45+
- **month**: month, where January is denoted by `1`.
46+
- **date_of_month**: day number of the month.
47+
- **day_of_week**: day of week, where Monday is `1` and Sunday is `7`.
48+
- **births**: number of births.
49+
50+
</section>
51+
52+
<!-- /.usage -->
53+
54+
<section class="examples">
55+
56+
## Examples
57+
58+
<!-- eslint no-undef: "error" -->
59+
60+
```javascript
61+
var incrmean = require( '@stdlib/stats/incr/mean' );
62+
var dataset = require( '@stdlib/datasets/cdc-nchs-us-births-1994-2003' );
63+
64+
function mean( a, b ) {
65+
return ( a + b ) / 2.0;
66+
}
67+
68+
function reldiff( a, b ) {
69+
return 100.0 * ( (a-b)/a );
70+
}
71+
72+
/*
73+
* GOAL: determine whether people avoid giving birth on the 13th of each month.
74+
*
75+
* NOTE: for a more thorough analysis, we'd account for holidays.
76+
*/
77+
78+
// Retrieve the data:
79+
var data = dataset();
80+
81+
// Initialize arrays for storing births for particular day numbers:
82+
var d6or20 = [ [], [], [], [], [], [], [] ];
83+
var d13 = [ [], [], [], [], [], [], [] ];
84+
85+
// Extract the day number data...
86+
var d;
87+
var w;
88+
var i;
89+
for ( i = 0; i < data.length; i++ ) {
90+
d = data[ i ].date_of_month;
91+
w = data[ i ].day_of_week;
92+
if ( d === 6 ) {
93+
// Average of days 6 and 20 for the same month:
94+
d6or20[ w-1 ].push( mean( data[ i ].births, data[ i+14 ].births ) );
95+
} else if ( d === 13 ) {
96+
d13[ w-1 ].push( data[ i ].births );
97+
}
98+
}
99+
100+
// Initialize accumulators for computing the average relative difference...
101+
var means = [];
102+
for ( i = 0; i < 7; i++ ) {
103+
means.push( incrmean() );
104+
}
105+
106+
// Compute the average relative difference between days 6/20 with day 13...
107+
var l1;
108+
var l2;
109+
var mu;
110+
var j;
111+
for ( i = 0; i < 7; i++ ) {
112+
l1 = d13[ i ];
113+
l2 = d6or20[ i ];
114+
mu = means[ i ];
115+
for ( j = 0; j < l1.length; j++ ) {
116+
mu( reldiff( l1[ j ], l2[ j ] ) );
117+
}
118+
}
119+
120+
// Print the results...
121+
for ( i = 0; i < 7; i++ ) {
122+
console.log( '%d: %d%', i+1, means[ i ]().toFixed( 3 ) );
123+
}
124+
```
125+
126+
</section>
127+
128+
<!-- /.examples -->
129+
130+
* * *
131+
132+
<section class="cli">
133+
134+
## CLI
135+
136+
<section class="usage">
137+
138+
### Usage
139+
140+
```text
141+
Usage: cdc-nchs-us-births-1994-2003 [options]
142+
143+
Options:
144+
145+
-h, --help Print this message.
146+
-V, --version Print the package version.
147+
```
148+
149+
</section>
150+
151+
<!-- /.usage -->
152+
153+
<section class="notes">
154+
155+
### Notes
156+
157+
- Data is written to `stdout` as comma-separated values ([CSV][csv]), where the first line is a header line.
158+
159+
<section class="examples">
160+
161+
### Examples
162+
163+
```bash
164+
$ cdc-nchs-us-births-1994-2003
165+
```
166+
167+
</section>
168+
169+
<!-- /.examples -->
170+
171+
</section>
172+
173+
<!-- /.cli -->
174+
175+
<!-- <license> -->
176+
177+
## License
178+
179+
The data files (databases) are licensed under an [Open Data Commons Public Domain Dedication & License 1.0][pddl-1.0] and their contents are licensed under [Creative Commons Zero v1.0 Universal][cc0]. The software is licensed under [Apache License, Version 2.0][apache-license].
180+
181+
<!-- </license> -->
182+
183+
<section class="links">
184+
185+
[pddl-1.0]: http://opendatacommons.org/licenses/pddl/1.0/
186+
187+
[cc0]: https://creativecommons.org/publicdomain/zero/1.0
188+
189+
[apache-license]: https://www.apache.org/licenses/LICENSE-2.0
190+
191+
[csv]: https://tools.ietf.org/html/rfc4180
192+
193+
</section>
194+
195+
<!-- /.links -->
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2019 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var bench = require( '@stdlib/bench' );
24+
var isArray = require( '@stdlib/assert/is-array' );
25+
var pkg = require( './../package.json' ).name;
26+
var dataset = require( './../lib/browser.js' );
27+
28+
29+
// MAIN //
30+
31+
bench( pkg+'::browser', function benchmark( b ) {
32+
var data;
33+
var i;
34+
b.tic();
35+
for ( i = 0; i < b.iterations; i++ ) {
36+
data = dataset();
37+
if ( data.length === 0 ) {
38+
b.fail( 'should have a length greater than 0' );
39+
}
40+
}
41+
b.toc();
42+
if ( !isArray( data ) ) {
43+
b.fail( 'should return an array' );
44+
}
45+
b.pass( 'benchmark finished' );
46+
b.end();
47+
});
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2019 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var bench = require( '@stdlib/bench' );
24+
var IS_BROWSER = require( '@stdlib/assert/is-browser' );
25+
var isArray = require( '@stdlib/assert/is-array' );
26+
var pkg = require( './../package.json' ).name;
27+
var dataset = require( './../lib' );
28+
29+
30+
// VARIABLES //
31+
32+
var opts = {
33+
'skip': IS_BROWSER
34+
};
35+
36+
37+
// MAIN //
38+
39+
bench( pkg, opts, function benchmark( b ) {
40+
var data;
41+
var i;
42+
b.tic();
43+
for ( i = 0; i < b.iterations; i++ ) {
44+
data = dataset();
45+
if ( data.length === 0 ) {
46+
b.fail( 'should have a length greater than 0' );
47+
}
48+
}
49+
b.toc();
50+
if ( !isArray( data ) ) {
51+
b.fail( 'should return an array' );
52+
}
53+
b.pass( 'benchmark finished' );
54+
b.end();
55+
});
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#!/usr/bin/env node
2+
3+
/**
4+
* @license Apache-2.0
5+
*
6+
* Copyright (c) 2019 The Stdlib Authors.
7+
*
8+
* Licensed under the Apache License, Version 2.0 (the "License");
9+
* you may not use this file except in compliance with the License.
10+
* You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing, software
15+
* distributed under the License is distributed on an "AS IS" BASIS,
16+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* See the License for the specific language governing permissions and
18+
* limitations under the License.
19+
*/
20+
21+
'use strict';
22+
23+
// MODULES //
24+
25+
var createReadStream = require( 'fs' ).createReadStream;
26+
var resolve = require( 'path' ).resolve;
27+
var readFileSync = require( '@stdlib/fs/read-file' ).sync;
28+
var stdout = require( '@stdlib/streams/node/stdout' );
29+
var CLI = require( '@stdlib/tools/cli' );
30+
31+
32+
// MAIN //
33+
34+
/**
35+
* Main execution sequence.
36+
*
37+
* @private
38+
*/
39+
function main() {
40+
var flags;
41+
var fpath;
42+
var cli;
43+
44+
// Create a command-line interface:
45+
cli = new CLI({
46+
'pkg': require( './../package.json' ),
47+
'options': require( './../etc/cli_opts.json' ),
48+
'help': readFileSync( resolve( __dirname, '..', 'docs', 'usage.txt' ), {
49+
'encoding': 'utf8'
50+
})
51+
});
52+
53+
// Get any provided command-line options:
54+
flags = cli.flags();
55+
if ( flags.help || flags.version ) {
56+
return;
57+
}
58+
59+
// Resolve the data file path:
60+
fpath = resolve( __dirname, '..', 'data', 'data.csv' );
61+
62+
// Print the data to stdout:
63+
createReadStream( fpath )
64+
.pipe( stdout )
65+
.on( 'close', onClose );
66+
67+
/**
68+
* Exits the CLI.
69+
*
70+
* @private
71+
*/
72+
function onClose() {
73+
cli.close( 0 );
74+
}
75+
}
76+
77+
main();

0 commit comments

Comments
 (0)