@turf/moran-index 6.5.0 → 7.0.0-alpha.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/README.md CHANGED
@@ -9,77 +9,96 @@ The method reveal whether similar values tend to occur near each other,
9
9
  or whether high or low values are interspersed.
10
10
 
11
11
  Moran's I > 0 means a clusterd pattern.
12
- Moran's I < 0 means a dispersed pattern.
12
+ Moran's I < 0 means a dispersed pattern.
13
13
  Moran's I = 0 means a random pattern.
14
14
 
15
15
  In order to test the significance of the result. The z score is calculated.
16
16
  A positive enough z-score (ex. >1.96) indicates clustering,
17
- while a negative enough z-score (ex. &lt;-1.96) indicates a dispersed pattern.
17
+ while a negative enough z-score (ex. <-1.96) indicates a dispersed pattern.
18
18
 
19
19
  the z-score can be calculated based on a normal or random assumption.
20
20
 
21
- **Bibliography\***
21
+ **Bibliography**\*
22
22
 
23
- 1. [Moran's I](https://en.wikipedia.org/wiki/Moran%27s_I)
23
+ 1. [Moran's I][1]
24
24
 
25
- 2. [pysal](http://pysal.readthedocs.io/en/latest/index.html)
25
+ 2. [pysal][2]
26
26
 
27
27
  3. Andy Mitchell, The ESRI Guide to GIS Analysis Volume 2: Spatial Measurements & Statistics.
28
28
 
29
- **Parameters**
29
+ ### Parameters
30
30
 
31
- - `fc` **[FeatureCollection](https://tools.ietf.org/html/rfc7946#section-3.3)&lt;any>**
32
- - `options` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**
33
- - `options.inputField` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** the property name, must contain numeric values
34
- - `options.threshold` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** the distance threshold (optional, default `100000`)
35
- - `options.p` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** the Minkowski p-norm distance parameter (optional, default `2`)
36
- - `options.binary` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** whether transfrom the distance to binary (optional, default `false`)
37
- - `options.alpha` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** the distance decay parameter (optional, default `-1`)
38
- - `options.standardization` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** wheter row standardization the distance (optional, default `true`)
31
+ * `fc` **[FeatureCollection][3]\<any>**
32
+ * `options` **[Object][4]**
39
33
 
40
- **Examples**
34
+ * `options.inputField` **[string][5]** the property name, must contain numeric values
35
+ * `options.threshold` **[number][6]** the distance threshold (optional, default `100000`)
36
+ * `options.p` **[number][6]** the Minkowski p-norm distance parameter (optional, default `2`)
37
+ * `options.binary` **[boolean][7]** whether transfrom the distance to binary (optional, default `false`)
38
+ * `options.alpha` **[number][6]** the distance decay parameter (optional, default `-1`)
39
+ * `options.standardization` **[boolean][7]** wheter row standardization the distance (optional, default `true`)
40
+
41
+ ### Examples
41
42
 
42
43
  ```javascript
43
44
  const bbox = [-65, 40, -63, 42];
44
45
  const dataset = turf.randomPoint(100, { bbox: bbox });
45
46
 
46
- const result = moranIndex(pts, {
47
+ const result = turf.moranIndex(dataset, {
47
48
  inputField: 'CRIME',
48
49
  });
49
50
  ```
50
51
 
51
- Returns **[MoranIndex](#moranindex)**
52
+ Returns **[MoranIndex][8]**
52
53
 
53
54
  ## mean
54
55
 
55
56
  get mean of a list
56
57
 
57
- **Parameters**
58
+ ### Parameters
58
59
 
59
- - `y` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)>**
60
+ * `y` **[Array][9]<[number][6]>**
60
61
 
61
- Returns **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)**
62
+ Returns **[number][6]**
62
63
 
63
64
  ## variance
64
65
 
65
66
  get variance of a list
66
67
 
67
- **Parameters**
68
+ ### Parameters
68
69
 
69
- - `y` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)>**
70
+ * `y` **[Array][9]<[number][6]>**
70
71
 
71
- Returns **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)**
72
+ Returns **[number][6]**
72
73
 
73
74
  ## MoranIndex
74
75
 
75
- Type: [Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)
76
+ Type: [Object][4]
77
+
78
+ ### Properties
79
+
80
+ * `moranIndex` **[number][6]** the moran's Index of the observed feature set
81
+ * `expectedMoranIndex` **[number][6]** the moran's Index of the random distribution
82
+ * `stdNorm` **[number][6]** the standard devitaion of the random distribution
83
+ * `zNorm` **[number][6]** the z-score of the observe samples with regard to the random distribution
84
+
85
+ [1]: https://en.wikipedia.org/wiki/Moran%27s_I
86
+
87
+ [2]: http://pysal.readthedocs.io/en/latest/index.html
88
+
89
+ [3]: https://tools.ietf.org/html/rfc7946#section-3.3
90
+
91
+ [4]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
92
+
93
+ [5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
94
+
95
+ [6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
96
+
97
+ [7]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
76
98
 
77
- **Properties**
99
+ [8]: #moranindex
78
100
 
79
- - `moranIndex` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** the moran's Index of the observed feature set
80
- - `expectedMoranIndex` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** the moran's Index of the random distribution
81
- - `stdNorm` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** the standard devitaion of the random distribution
82
- - `zNorm` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** the z-score of the observe samples with regard to the random distribution
101
+ [9]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array
83
102
 
84
103
  <!-- This file is automatically generated. Please don't edit it directly:
85
104
  if you find an error, edit the source file (likely index.js), and re-run
package/dist/es/index.js CHANGED
@@ -43,36 +43,36 @@ import { featureEach } from "@turf/meta";
43
43
  * });
44
44
  */
45
45
  export default function (fc, options) {
46
- var inputField = options.inputField;
47
- var threshold = options.threshold || 100000;
48
- var p = options.p || 2;
49
- var binary = options.binary || false;
50
- var alpha = options.alpha || -1;
51
- var standardization = options.standardization || true;
52
- var weight = spatialWeight(fc, {
53
- alpha: alpha,
54
- binary: binary,
55
- p: p,
56
- standardization: standardization,
57
- threshold: threshold,
46
+ const inputField = options.inputField;
47
+ const threshold = options.threshold || 100000;
48
+ const p = options.p || 2;
49
+ const binary = options.binary || false;
50
+ const alpha = options.alpha || -1;
51
+ const standardization = options.standardization || true;
52
+ const weight = spatialWeight(fc, {
53
+ alpha,
54
+ binary,
55
+ p,
56
+ standardization,
57
+ threshold,
58
58
  });
59
- var y = [];
60
- featureEach(fc, function (feature) {
61
- var feaProperties = feature.properties || {};
59
+ const y = [];
60
+ featureEach(fc, (feature) => {
61
+ const feaProperties = feature.properties || {};
62
62
  // validate inputField exists
63
63
  y.push(feaProperties[inputField]);
64
64
  });
65
- var yMean = mean(y);
66
- var yVar = variance(y);
67
- var weightSum = 0;
68
- var s0 = 0;
69
- var s1 = 0;
70
- var s2 = 0;
71
- var n = weight.length;
65
+ const yMean = mean(y);
66
+ const yVar = variance(y);
67
+ let weightSum = 0;
68
+ let s0 = 0;
69
+ let s1 = 0;
70
+ let s2 = 0;
71
+ const n = weight.length;
72
72
  // validate y.length is the same as weight.length
73
- for (var i = 0; i < n; i++) {
74
- var subS2 = 0;
75
- for (var j = 0; j < n; j++) {
73
+ for (let i = 0; i < n; i++) {
74
+ let subS2 = 0;
75
+ for (let j = 0; j < n; j++) {
76
76
  weightSum += weight[i][j] * (y[i] - yMean) * (y[j] - yMean);
77
77
  s0 += weight[i][j];
78
78
  s1 += Math.pow(weight[i][j] + weight[j][i], 2);
@@ -81,18 +81,18 @@ export default function (fc, options) {
81
81
  s2 += Math.pow(subS2, 2);
82
82
  }
83
83
  s1 = 0.5 * s1;
84
- var moranIndex = weightSum / s0 / yVar;
85
- var expectedMoranIndex = -1 / (n - 1);
86
- var vNum = n * n * s1 - n * s2 + 3 * (s0 * s0);
87
- var vDen = (n - 1) * (n + 1) * (s0 * s0);
88
- var vNorm = vNum / vDen - expectedMoranIndex * expectedMoranIndex;
89
- var stdNorm = Math.sqrt(vNorm);
90
- var zNorm = (moranIndex - expectedMoranIndex) / stdNorm;
84
+ const moranIndex = weightSum / s0 / yVar;
85
+ const expectedMoranIndex = -1 / (n - 1);
86
+ const vNum = n * n * s1 - n * s2 + 3 * (s0 * s0);
87
+ const vDen = (n - 1) * (n + 1) * (s0 * s0);
88
+ const vNorm = vNum / vDen - expectedMoranIndex * expectedMoranIndex;
89
+ const stdNorm = Math.sqrt(vNorm);
90
+ const zNorm = (moranIndex - expectedMoranIndex) / stdNorm;
91
91
  return {
92
- expectedMoranIndex: expectedMoranIndex,
93
- moranIndex: moranIndex,
94
- stdNorm: stdNorm,
95
- zNorm: zNorm,
92
+ expectedMoranIndex,
93
+ moranIndex,
94
+ stdNorm,
95
+ zNorm,
96
96
  };
97
97
  }
98
98
  /**
@@ -102,9 +102,8 @@ export default function (fc, options) {
102
102
  *
103
103
  */
104
104
  function mean(y) {
105
- var sum = 0;
106
- for (var _i = 0, y_1 = y; _i < y_1.length; _i++) {
107
- var item = y_1[_i];
105
+ let sum = 0;
106
+ for (const item of y) {
108
107
  sum += item;
109
108
  }
110
109
  return sum / y.length;
@@ -116,10 +115,9 @@ function mean(y) {
116
115
  *
117
116
  */
118
117
  function variance(y) {
119
- var yMean = mean(y);
120
- var sum = 0;
121
- for (var _i = 0, y_2 = y; _i < y_2.length; _i++) {
122
- var item = y_2[_i];
118
+ const yMean = mean(y);
119
+ let sum = 0;
120
+ for (const item of y) {
123
121
  sum += Math.pow(item - yMean, 2);
124
122
  }
125
123
  return sum / y.length;
@@ -1,4 +1,4 @@
1
- import { FeatureCollection } from "@turf/helpers";
1
+ import { FeatureCollection } from "geojson";
2
2
  /**
3
3
  * Moran's I measures patterns of attribute values associated with features.
4
4
  * The method reveal whether similar values tend to occur near each other,
package/dist/js/index.js CHANGED
@@ -1,10 +1,8 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
- var distance_weight_1 = __importDefault(require("@turf/distance-weight"));
7
- var meta_1 = require("@turf/meta");
3
+ const tslib_1 = require("tslib");
4
+ const distance_weight_1 = tslib_1.__importDefault(require("@turf/distance-weight"));
5
+ const meta_1 = require("@turf/meta");
8
6
  /**
9
7
  * Moran's I measures patterns of attribute values associated with features.
10
8
  * The method reveal whether similar values tend to occur near each other,
@@ -48,36 +46,36 @@ var meta_1 = require("@turf/meta");
48
46
  * });
49
47
  */
50
48
  function default_1(fc, options) {
51
- var inputField = options.inputField;
52
- var threshold = options.threshold || 100000;
53
- var p = options.p || 2;
54
- var binary = options.binary || false;
55
- var alpha = options.alpha || -1;
56
- var standardization = options.standardization || true;
57
- var weight = distance_weight_1.default(fc, {
58
- alpha: alpha,
59
- binary: binary,
60
- p: p,
61
- standardization: standardization,
62
- threshold: threshold,
49
+ const inputField = options.inputField;
50
+ const threshold = options.threshold || 100000;
51
+ const p = options.p || 2;
52
+ const binary = options.binary || false;
53
+ const alpha = options.alpha || -1;
54
+ const standardization = options.standardization || true;
55
+ const weight = distance_weight_1.default(fc, {
56
+ alpha,
57
+ binary,
58
+ p,
59
+ standardization,
60
+ threshold,
63
61
  });
64
- var y = [];
65
- meta_1.featureEach(fc, function (feature) {
66
- var feaProperties = feature.properties || {};
62
+ const y = [];
63
+ meta_1.featureEach(fc, (feature) => {
64
+ const feaProperties = feature.properties || {};
67
65
  // validate inputField exists
68
66
  y.push(feaProperties[inputField]);
69
67
  });
70
- var yMean = mean(y);
71
- var yVar = variance(y);
72
- var weightSum = 0;
73
- var s0 = 0;
74
- var s1 = 0;
75
- var s2 = 0;
76
- var n = weight.length;
68
+ const yMean = mean(y);
69
+ const yVar = variance(y);
70
+ let weightSum = 0;
71
+ let s0 = 0;
72
+ let s1 = 0;
73
+ let s2 = 0;
74
+ const n = weight.length;
77
75
  // validate y.length is the same as weight.length
78
- for (var i = 0; i < n; i++) {
79
- var subS2 = 0;
80
- for (var j = 0; j < n; j++) {
76
+ for (let i = 0; i < n; i++) {
77
+ let subS2 = 0;
78
+ for (let j = 0; j < n; j++) {
81
79
  weightSum += weight[i][j] * (y[i] - yMean) * (y[j] - yMean);
82
80
  s0 += weight[i][j];
83
81
  s1 += Math.pow(weight[i][j] + weight[j][i], 2);
@@ -86,18 +84,18 @@ function default_1(fc, options) {
86
84
  s2 += Math.pow(subS2, 2);
87
85
  }
88
86
  s1 = 0.5 * s1;
89
- var moranIndex = weightSum / s0 / yVar;
90
- var expectedMoranIndex = -1 / (n - 1);
91
- var vNum = n * n * s1 - n * s2 + 3 * (s0 * s0);
92
- var vDen = (n - 1) * (n + 1) * (s0 * s0);
93
- var vNorm = vNum / vDen - expectedMoranIndex * expectedMoranIndex;
94
- var stdNorm = Math.sqrt(vNorm);
95
- var zNorm = (moranIndex - expectedMoranIndex) / stdNorm;
87
+ const moranIndex = weightSum / s0 / yVar;
88
+ const expectedMoranIndex = -1 / (n - 1);
89
+ const vNum = n * n * s1 - n * s2 + 3 * (s0 * s0);
90
+ const vDen = (n - 1) * (n + 1) * (s0 * s0);
91
+ const vNorm = vNum / vDen - expectedMoranIndex * expectedMoranIndex;
92
+ const stdNorm = Math.sqrt(vNorm);
93
+ const zNorm = (moranIndex - expectedMoranIndex) / stdNorm;
96
94
  return {
97
- expectedMoranIndex: expectedMoranIndex,
98
- moranIndex: moranIndex,
99
- stdNorm: stdNorm,
100
- zNorm: zNorm,
95
+ expectedMoranIndex,
96
+ moranIndex,
97
+ stdNorm,
98
+ zNorm,
101
99
  };
102
100
  }
103
101
  exports.default = default_1;
@@ -108,9 +106,8 @@ exports.default = default_1;
108
106
  *
109
107
  */
110
108
  function mean(y) {
111
- var sum = 0;
112
- for (var _i = 0, y_1 = y; _i < y_1.length; _i++) {
113
- var item = y_1[_i];
109
+ let sum = 0;
110
+ for (const item of y) {
114
111
  sum += item;
115
112
  }
116
113
  return sum / y.length;
@@ -122,10 +119,9 @@ function mean(y) {
122
119
  *
123
120
  */
124
121
  function variance(y) {
125
- var yMean = mean(y);
126
- var sum = 0;
127
- for (var _i = 0, y_2 = y; _i < y_2.length; _i++) {
128
- var item = y_2[_i];
122
+ const yMean = mean(y);
123
+ let sum = 0;
124
+ for (const item of y) {
129
125
  sum += Math.pow(item - yMean, 2);
130
126
  }
131
127
  return sum / y.length;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@turf/moran-index",
3
- "version": "6.5.0",
3
+ "version": "7.0.0-alpha.0",
4
4
  "description": "turf moran-index module",
5
5
  "author": "Turf Authors",
6
6
  "contributors": [
@@ -58,9 +58,10 @@
58
58
  "write-json-file": "*"
59
59
  },
60
60
  "dependencies": {
61
- "@turf/distance-weight": "^6.5.0",
62
- "@turf/helpers": "^6.5.0",
63
- "@turf/meta": "^6.5.0"
61
+ "@turf/distance-weight": "^7.0.0-alpha.0",
62
+ "@turf/helpers": "^7.0.0-alpha.0",
63
+ "@turf/meta": "^7.0.0-alpha.0",
64
+ "tslib": "^2.3.0"
64
65
  },
65
- "gitHead": "5375941072b90d489389db22b43bfe809d5e451e"
66
+ "gitHead": "0edc4c491b999e5ace770a61e1cf549f7c004189"
66
67
  }