@turf/moran-index 7.1.0 → 7.3.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 +25 -47
- package/dist/cjs/index.cjs +2 -2
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +16 -8
- package/dist/esm/index.d.ts +16 -8
- package/dist/esm/index.js +2 -2
- package/dist/esm/index.js.map +1 -1
- package/package.json +13 -13
package/README.md
CHANGED
|
@@ -2,6 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
|
|
4
4
|
|
|
5
|
+
## MoranIndex
|
|
6
|
+
|
|
7
|
+
Type: [object][1]
|
|
8
|
+
|
|
9
|
+
### Properties
|
|
10
|
+
|
|
11
|
+
* `moranIndex` **[number][2]** the moran's Index of the observed feature set
|
|
12
|
+
* `expectedMoranIndex` **[number][2]** the moran's Index of the random distribution
|
|
13
|
+
* `stdNorm` **[number][2]** the standard devitaion of the random distribution
|
|
14
|
+
* `zNorm` **[number][2]** the z-score of the observe samples with regard to the random distribution
|
|
15
|
+
|
|
5
16
|
## moranIndex
|
|
6
17
|
|
|
7
18
|
Moran's I measures patterns of attribute values associated with features.
|
|
@@ -20,22 +31,22 @@ the z-score can be calculated based on a normal or random assumption.
|
|
|
20
31
|
|
|
21
32
|
**Bibliography**\*
|
|
22
33
|
|
|
23
|
-
1. [Moran's I][
|
|
34
|
+
1. [Moran's I][3]
|
|
24
35
|
|
|
25
|
-
2. [pysal][
|
|
36
|
+
2. [pysal][4]
|
|
26
37
|
|
|
27
38
|
3. Andy Mitchell, The ESRI Guide to GIS Analysis Volume 2: Spatial Measurements & Statistics.
|
|
28
39
|
|
|
29
40
|
### Parameters
|
|
30
41
|
|
|
31
|
-
* `fc` **[FeatureCollection][
|
|
32
|
-
* `options` **[Object][
|
|
42
|
+
* `fc` **[FeatureCollection][5]\<any>** 
|
|
43
|
+
* `options` **[Object][1]** 
|
|
33
44
|
|
|
34
|
-
* `options.inputField` **[string][
|
|
35
|
-
* `options.threshold` **[number][
|
|
36
|
-
* `options.p` **[number][
|
|
45
|
+
* `options.inputField` **[string][6]** the property name, must contain numeric values
|
|
46
|
+
* `options.threshold` **[number][2]** the distance threshold (optional, default `100000`)
|
|
47
|
+
* `options.p` **[number][2]** the Minkowski p-norm distance parameter (optional, default `2`)
|
|
37
48
|
* `options.binary` **[boolean][7]** whether transfrom the distance to binary (optional, default `false`)
|
|
38
|
-
* `options.alpha` **[number][
|
|
49
|
+
* `options.alpha` **[number][2]** the distance decay parameter (optional, default `-1`)
|
|
39
50
|
* `options.standardization` **[boolean][7]** wheter row standardization the distance (optional, default `true`)
|
|
40
51
|
|
|
41
52
|
### Examples
|
|
@@ -51,55 +62,22 @@ const result = turf.moranIndex(dataset, {
|
|
|
51
62
|
|
|
52
63
|
Returns **[MoranIndex][8]** 
|
|
53
64
|
|
|
54
|
-
|
|
65
|
+
[1]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
|
|
55
66
|
|
|
56
|
-
|
|
67
|
+
[2]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
|
|
57
68
|
|
|
58
|
-
|
|
69
|
+
[3]: https://en.wikipedia.org/wiki/Moran%27s_I
|
|
59
70
|
|
|
60
|
-
|
|
71
|
+
[4]: http://pysal.readthedocs.io/en/latest/index.html
|
|
61
72
|
|
|
62
|
-
|
|
73
|
+
[5]: https://tools.ietf.org/html/rfc7946#section-3.3
|
|
63
74
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
get variance of a list
|
|
67
|
-
|
|
68
|
-
### Parameters
|
|
69
|
-
|
|
70
|
-
* `y` **[Array][9]<[number][6]>** 
|
|
71
|
-
|
|
72
|
-
Returns **[number][6]** 
|
|
73
|
-
|
|
74
|
-
## MoranIndex
|
|
75
|
-
|
|
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
|
|
75
|
+
[6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
|
|
96
76
|
|
|
97
77
|
[7]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
|
|
98
78
|
|
|
99
79
|
[8]: #moranindex
|
|
100
80
|
|
|
101
|
-
[9]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array
|
|
102
|
-
|
|
103
81
|
<!-- This file is automatically generated. Please don't edit it directly. If you find an error, edit the source file of the module in question (likely index.js or index.ts), and re-run "yarn docs" from the root of the turf project. -->
|
|
104
82
|
|
|
105
83
|
---
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -68,9 +68,9 @@ function variance(y) {
|
|
|
68
68
|
}
|
|
69
69
|
return sum / y.length;
|
|
70
70
|
}
|
|
71
|
-
var
|
|
71
|
+
var index_default = moranIndex;
|
|
72
72
|
|
|
73
73
|
|
|
74
74
|
|
|
75
|
-
exports.default =
|
|
75
|
+
exports.default = index_default; exports.moranIndex = moranIndex;
|
|
76
76
|
//# sourceMappingURL=index.cjs.map
|
package/dist/cjs/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../index.ts"],"names":["moranIndex"],"mappings":";
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/turf/turf/packages/turf-moran-index/dist/cjs/index.cjs","../../index.ts"],"names":["moranIndex"],"mappings":"AAAA;ACCA,uDAAgD;AAChD,kCAA4B;AA2D5B,SAAS,UAAA,CACP,EAAA,EACA,OAAA,EAQY;AAvEd,EAAA,IAAA,EAAA,EAAA,EAAA;AAwEE,EAAA,MAAM,WAAA,EAAa,OAAA,CAAQ,UAAA;AAC3B,EAAA,MAAM,UAAA,EAAY,OAAA,CAAQ,UAAA,GAAa,GAAA;AACvC,EAAA,MAAM,EAAA,EAAI,OAAA,CAAQ,EAAA,GAAK,CAAA;AACvB,EAAA,MAAM,OAAA,EAAA,CAAS,GAAA,EAAA,OAAA,CAAQ,MAAA,EAAA,GAAR,KAAA,EAAA,GAAA,EAAkB,KAAA;AACjC,EAAA,MAAM,MAAA,EAAQ,OAAA,CAAQ,MAAA,GAAS,CAAA,CAAA;AAC/B,EAAA,MAAM,gBAAA,EAAA,CAAkB,GAAA,EAAA,OAAA,CAAQ,eAAA,EAAA,GAAR,KAAA,EAAA,GAAA,EAA2B,IAAA;AAEnD,EAAA,MAAM,OAAA,EAAS,4CAAA,EAAc,EAAI;AAAA,IAC/B,KAAA;AAAA,IACA,MAAA;AAAA,IACA,CAAA;AAAA,IACA,eAAA;AAAA,IACA;AAAA,EACF,CAAC,CAAA;AAED,EAAA,MAAM,EAAA,EAAc,CAAC,CAAA;AACrB,EAAA,+BAAA,EAAY,EAAI,CAAC,OAAA,EAAA,GAAY;AAC3B,IAAA,MAAM,cAAA,EAAgB,OAAA,CAAQ,WAAA,GAAc,CAAC,CAAA;AAE7C,IAAA,CAAA,CAAE,IAAA,CAAK,aAAA,CAAc,UAAU,CAAC,CAAA;AAAA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AA,EAAM,CAAA,CAAE,MAAA;AACjB;AAGA,IAAO,cAAA,EAAQ,UAAA;AD5Ff;AACE;AACA;AACF,iEAAC","file":"/home/runner/work/turf/turf/packages/turf-moran-index/dist/cjs/index.cjs","sourcesContent":[null,"import { FeatureCollection } from \"geojson\";\nimport { distanceWeight as spatialWeight } from \"@turf/distance-weight\";\nimport { featureEach } from \"@turf/meta\";\n\n/**\n * @typedef {object} MoranIndex\n * @property {number} moranIndex the moran's Index of the observed feature set\n * @property {number} expectedMoranIndex the moran's Index of the random distribution\n * @property {number} stdNorm the standard devitaion of the random distribution\n * @property {number} zNorm the z-score of the observe samples with regard to the random distribution\n */\ntype MoranIndex = {\n moranIndex: number;\n expectedMoranIndex: number;\n stdNorm: number;\n zNorm: number;\n};\n\n/**\n * Moran's I measures patterns of attribute values associated with features.\n * The method reveal whether similar values tend to occur near each other,\n * or whether high or low values are interspersed.\n *\n * Moran's I > 0 means a clusterd pattern.\n * Moran's I < 0 means a dispersed pattern.\n * Moran's I = 0 means a random pattern.\n *\n * In order to test the significance of the result. The z score is calculated.\n * A positive enough z-score (ex. >1.96) indicates clustering,\n * while a negative enough z-score (ex. <-1.96) indicates a dispersed pattern.\n *\n * the z-score can be calculated based on a normal or random assumption.\n *\n * **Bibliography***\n *\n * 1. [Moran's I](https://en.wikipedia.org/wiki/Moran%27s_I)\n *\n * 2. [pysal](http://pysal.readthedocs.io/en/latest/index.html)\n *\n * 3. Andy Mitchell, The ESRI Guide to GIS Analysis Volume 2: Spatial Measurements & Statistics.\n *\n * @function\n * @param {FeatureCollection<any>} fc\n * @param {Object} options\n * @param {string} options.inputField the property name, must contain numeric values\n * @param {number} [options.threshold=100000] the distance threshold\n * @param {number} [options.p=2] the Minkowski p-norm distance parameter\n * @param {boolean} [options.binary=false] whether transfrom the distance to binary\n * @param {number} [options.alpha=-1] the distance decay parameter\n * @param {boolean} [options.standardization=true] wheter row standardization the distance\n * @returns {MoranIndex}\n * @example\n *\n * const bbox = [-65, 40, -63, 42];\n * const dataset = turf.randomPoint(100, { bbox: bbox });\n *\n * const result = turf.moranIndex(dataset, {\n * inputField: 'CRIME',\n * });\n */\n\nfunction moranIndex(\n fc: FeatureCollection<any>,\n options: {\n inputField: string;\n threshold?: number;\n p?: number;\n binary?: boolean;\n alpha?: number;\n standardization?: boolean;\n }\n): MoranIndex {\n const inputField = options.inputField;\n const threshold = options.threshold || 100000;\n const p = options.p || 2;\n const binary = options.binary ?? false;\n const alpha = options.alpha || -1;\n const standardization = options.standardization ?? true;\n\n const weight = spatialWeight(fc, {\n alpha,\n binary,\n p,\n standardization,\n threshold,\n });\n\n const y: number[] = [];\n featureEach(fc, (feature) => {\n const feaProperties = feature.properties || {};\n // validate inputField exists\n y.push(feaProperties[inputField]);\n });\n\n const yMean = mean(y);\n const yVar = variance(y);\n let weightSum = 0;\n let s0 = 0;\n let s1 = 0;\n let s2 = 0;\n const n = weight.length;\n // validate y.length is the same as weight.length\n for (let i = 0; i < n; i++) {\n let subS2 = 0;\n for (let j = 0; j < n; j++) {\n weightSum += weight[i][j] * (y[i] - yMean) * (y[j] - yMean);\n s0 += weight[i][j];\n s1 += Math.pow(weight[i][j] + weight[j][i], 2);\n subS2 += weight[i][j] + weight[j][i];\n }\n s2 += Math.pow(subS2, 2);\n }\n s1 = 0.5 * s1;\n\n const moranIndex = weightSum / s0 / yVar;\n const expectedMoranIndex = -1 / (n - 1);\n const vNum = n * n * s1 - n * s2 + 3 * (s0 * s0);\n const vDen = (n - 1) * (n + 1) * (s0 * s0);\n const vNorm = vNum / vDen - expectedMoranIndex * expectedMoranIndex;\n const stdNorm = Math.sqrt(vNorm);\n const zNorm = (moranIndex - expectedMoranIndex) / stdNorm;\n\n return {\n expectedMoranIndex,\n moranIndex,\n stdNorm,\n zNorm,\n };\n}\n\n/**\n * get mean of a list\n *\n * @private\n * @param {number[]} y\n * @returns {number}\n *\n */\nfunction mean(y: number[]): number {\n let sum = 0;\n for (const item of y) {\n sum += item;\n }\n return sum / y.length;\n}\n/**\n * get variance of a list\n *\n * @private\n * @param {number[]} y\n * @returns {number}\n *\n */\nfunction variance(y: number[]): number {\n const yMean = mean(y);\n let sum = 0;\n for (const item of y) {\n sum += Math.pow(item - yMean, 2);\n }\n return sum / y.length;\n}\n\nexport { moranIndex, MoranIndex };\nexport default moranIndex;\n"]}
|
package/dist/cjs/index.d.cts
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
import { FeatureCollection } from 'geojson';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* @typedef {object} MoranIndex
|
|
5
|
+
* @property {number} moranIndex the moran's Index of the observed feature set
|
|
6
|
+
* @property {number} expectedMoranIndex the moran's Index of the random distribution
|
|
7
|
+
* @property {number} stdNorm the standard devitaion of the random distribution
|
|
8
|
+
* @property {number} zNorm the z-score of the observe samples with regard to the random distribution
|
|
9
|
+
*/
|
|
10
|
+
type MoranIndex = {
|
|
11
|
+
moranIndex: number;
|
|
12
|
+
expectedMoranIndex: number;
|
|
13
|
+
stdNorm: number;
|
|
14
|
+
zNorm: number;
|
|
15
|
+
};
|
|
3
16
|
/**
|
|
4
17
|
* Moran's I measures patterns of attribute values associated with features.
|
|
5
18
|
* The method reveal whether similar values tend to occur near each other,
|
|
@@ -23,7 +36,7 @@ import { FeatureCollection } from 'geojson';
|
|
|
23
36
|
*
|
|
24
37
|
* 3. Andy Mitchell, The ESRI Guide to GIS Analysis Volume 2: Spatial Measurements & Statistics.
|
|
25
38
|
*
|
|
26
|
-
* @
|
|
39
|
+
* @function
|
|
27
40
|
* @param {FeatureCollection<any>} fc
|
|
28
41
|
* @param {Object} options
|
|
29
42
|
* @param {string} options.inputField the property name, must contain numeric values
|
|
@@ -49,11 +62,6 @@ declare function moranIndex(fc: FeatureCollection<any>, options: {
|
|
|
49
62
|
binary?: boolean;
|
|
50
63
|
alpha?: number;
|
|
51
64
|
standardization?: boolean;
|
|
52
|
-
}):
|
|
53
|
-
moranIndex: number;
|
|
54
|
-
expectedMoranIndex: number;
|
|
55
|
-
stdNorm: number;
|
|
56
|
-
zNorm: number;
|
|
57
|
-
};
|
|
65
|
+
}): MoranIndex;
|
|
58
66
|
|
|
59
|
-
export { moranIndex as default, moranIndex };
|
|
67
|
+
export { type MoranIndex, moranIndex as default, moranIndex };
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
import { FeatureCollection } from 'geojson';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* @typedef {object} MoranIndex
|
|
5
|
+
* @property {number} moranIndex the moran's Index of the observed feature set
|
|
6
|
+
* @property {number} expectedMoranIndex the moran's Index of the random distribution
|
|
7
|
+
* @property {number} stdNorm the standard devitaion of the random distribution
|
|
8
|
+
* @property {number} zNorm the z-score of the observe samples with regard to the random distribution
|
|
9
|
+
*/
|
|
10
|
+
type MoranIndex = {
|
|
11
|
+
moranIndex: number;
|
|
12
|
+
expectedMoranIndex: number;
|
|
13
|
+
stdNorm: number;
|
|
14
|
+
zNorm: number;
|
|
15
|
+
};
|
|
3
16
|
/**
|
|
4
17
|
* Moran's I measures patterns of attribute values associated with features.
|
|
5
18
|
* The method reveal whether similar values tend to occur near each other,
|
|
@@ -23,7 +36,7 @@ import { FeatureCollection } from 'geojson';
|
|
|
23
36
|
*
|
|
24
37
|
* 3. Andy Mitchell, The ESRI Guide to GIS Analysis Volume 2: Spatial Measurements & Statistics.
|
|
25
38
|
*
|
|
26
|
-
* @
|
|
39
|
+
* @function
|
|
27
40
|
* @param {FeatureCollection<any>} fc
|
|
28
41
|
* @param {Object} options
|
|
29
42
|
* @param {string} options.inputField the property name, must contain numeric values
|
|
@@ -49,11 +62,6 @@ declare function moranIndex(fc: FeatureCollection<any>, options: {
|
|
|
49
62
|
binary?: boolean;
|
|
50
63
|
alpha?: number;
|
|
51
64
|
standardization?: boolean;
|
|
52
|
-
}):
|
|
53
|
-
moranIndex: number;
|
|
54
|
-
expectedMoranIndex: number;
|
|
55
|
-
stdNorm: number;
|
|
56
|
-
zNorm: number;
|
|
57
|
-
};
|
|
65
|
+
}): MoranIndex;
|
|
58
66
|
|
|
59
|
-
export { moranIndex as default, moranIndex };
|
|
67
|
+
export { type MoranIndex, moranIndex as default, moranIndex };
|
package/dist/esm/index.js
CHANGED
|
@@ -68,9 +68,9 @@ function variance(y) {
|
|
|
68
68
|
}
|
|
69
69
|
return sum / y.length;
|
|
70
70
|
}
|
|
71
|
-
var
|
|
71
|
+
var index_default = moranIndex;
|
|
72
72
|
export {
|
|
73
|
-
|
|
73
|
+
index_default as default,
|
|
74
74
|
moranIndex
|
|
75
75
|
};
|
|
76
76
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../index.ts"],"sourcesContent":["import { FeatureCollection } from \"geojson\";\nimport { distanceWeight as spatialWeight } from \"@turf/distance-weight\";\nimport { featureEach } from \"@turf/meta\";\n\n/**\n * Moran's I measures patterns of attribute values associated with features.\n * The method reveal whether similar values tend to occur near each other,\n * or whether high or low values are interspersed.\n *\n * Moran's I > 0 means a clusterd pattern.\n * Moran's I < 0 means a dispersed pattern.\n * Moran's I = 0 means a random pattern.\n *\n * In order to test the significance of the result. The z score is calculated.\n * A positive enough z-score (ex. >1.96) indicates clustering,\n * while a negative enough z-score (ex. <-1.96) indicates a dispersed pattern.\n *\n * the z-score can be calculated based on a normal or random assumption.\n *\n * **Bibliography***\n *\n * 1. [Moran's I](https://en.wikipedia.org/wiki/Moran%27s_I)\n *\n * 2. [pysal](http://pysal.readthedocs.io/en/latest/index.html)\n *\n * 3. Andy Mitchell, The ESRI Guide to GIS Analysis Volume 2: Spatial Measurements & Statistics.\n *\n * @
|
|
1
|
+
{"version":3,"sources":["../../index.ts"],"sourcesContent":["import { FeatureCollection } from \"geojson\";\nimport { distanceWeight as spatialWeight } from \"@turf/distance-weight\";\nimport { featureEach } from \"@turf/meta\";\n\n/**\n * @typedef {object} MoranIndex\n * @property {number} moranIndex the moran's Index of the observed feature set\n * @property {number} expectedMoranIndex the moran's Index of the random distribution\n * @property {number} stdNorm the standard devitaion of the random distribution\n * @property {number} zNorm the z-score of the observe samples with regard to the random distribution\n */\ntype MoranIndex = {\n moranIndex: number;\n expectedMoranIndex: number;\n stdNorm: number;\n zNorm: number;\n};\n\n/**\n * Moran's I measures patterns of attribute values associated with features.\n * The method reveal whether similar values tend to occur near each other,\n * or whether high or low values are interspersed.\n *\n * Moran's I > 0 means a clusterd pattern.\n * Moran's I < 0 means a dispersed pattern.\n * Moran's I = 0 means a random pattern.\n *\n * In order to test the significance of the result. The z score is calculated.\n * A positive enough z-score (ex. >1.96) indicates clustering,\n * while a negative enough z-score (ex. <-1.96) indicates a dispersed pattern.\n *\n * the z-score can be calculated based on a normal or random assumption.\n *\n * **Bibliography***\n *\n * 1. [Moran's I](https://en.wikipedia.org/wiki/Moran%27s_I)\n *\n * 2. [pysal](http://pysal.readthedocs.io/en/latest/index.html)\n *\n * 3. Andy Mitchell, The ESRI Guide to GIS Analysis Volume 2: Spatial Measurements & Statistics.\n *\n * @function\n * @param {FeatureCollection<any>} fc\n * @param {Object} options\n * @param {string} options.inputField the property name, must contain numeric values\n * @param {number} [options.threshold=100000] the distance threshold\n * @param {number} [options.p=2] the Minkowski p-norm distance parameter\n * @param {boolean} [options.binary=false] whether transfrom the distance to binary\n * @param {number} [options.alpha=-1] the distance decay parameter\n * @param {boolean} [options.standardization=true] wheter row standardization the distance\n * @returns {MoranIndex}\n * @example\n *\n * const bbox = [-65, 40, -63, 42];\n * const dataset = turf.randomPoint(100, { bbox: bbox });\n *\n * const result = turf.moranIndex(dataset, {\n * inputField: 'CRIME',\n * });\n */\n\nfunction moranIndex(\n fc: FeatureCollection<any>,\n options: {\n inputField: string;\n threshold?: number;\n p?: number;\n binary?: boolean;\n alpha?: number;\n standardization?: boolean;\n }\n): MoranIndex {\n const inputField = options.inputField;\n const threshold = options.threshold || 100000;\n const p = options.p || 2;\n const binary = options.binary ?? false;\n const alpha = options.alpha || -1;\n const standardization = options.standardization ?? true;\n\n const weight = spatialWeight(fc, {\n alpha,\n binary,\n p,\n standardization,\n threshold,\n });\n\n const y: number[] = [];\n featureEach(fc, (feature) => {\n const feaProperties = feature.properties || {};\n // validate inputField exists\n y.push(feaProperties[inputField]);\n });\n\n const yMean = mean(y);\n const yVar = variance(y);\n let weightSum = 0;\n let s0 = 0;\n let s1 = 0;\n let s2 = 0;\n const n = weight.length;\n // validate y.length is the same as weight.length\n for (let i = 0; i < n; i++) {\n let subS2 = 0;\n for (let j = 0; j < n; j++) {\n weightSum += weight[i][j] * (y[i] - yMean) * (y[j] - yMean);\n s0 += weight[i][j];\n s1 += Math.pow(weight[i][j] + weight[j][i], 2);\n subS2 += weight[i][j] + weight[j][i];\n }\n s2 += Math.pow(subS2, 2);\n }\n s1 = 0.5 * s1;\n\n const moranIndex = weightSum / s0 / yVar;\n const expectedMoranIndex = -1 / (n - 1);\n const vNum = n * n * s1 - n * s2 + 3 * (s0 * s0);\n const vDen = (n - 1) * (n + 1) * (s0 * s0);\n const vNorm = vNum / vDen - expectedMoranIndex * expectedMoranIndex;\n const stdNorm = Math.sqrt(vNorm);\n const zNorm = (moranIndex - expectedMoranIndex) / stdNorm;\n\n return {\n expectedMoranIndex,\n moranIndex,\n stdNorm,\n zNorm,\n };\n}\n\n/**\n * get mean of a list\n *\n * @private\n * @param {number[]} y\n * @returns {number}\n *\n */\nfunction mean(y: number[]): number {\n let sum = 0;\n for (const item of y) {\n sum += item;\n }\n return sum / y.length;\n}\n/**\n * get variance of a list\n *\n * @private\n * @param {number[]} y\n * @returns {number}\n *\n */\nfunction variance(y: number[]): number {\n const yMean = mean(y);\n let sum = 0;\n for (const item of y) {\n sum += Math.pow(item - yMean, 2);\n }\n return sum / y.length;\n}\n\nexport { moranIndex, MoranIndex };\nexport default moranIndex;\n"],"mappings":";AACA,SAAS,kBAAkB,qBAAqB;AAChD,SAAS,mBAAmB;AA2D5B,SAA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AM,QAAQ,IAAI,MAAM,IAAI,MAAM,KAAK;AACvC,QAAM,QAAQ,OAAO,OAAO,qBAAqB;AACjD,QAAM,UAAU,KAAK,KAAK,KAAK;AAC/B,QAAM,SAASA,cAAa,sBAAsB;AAElD,SAAO;AAAA,IACL;AAAA,IACA,YAAAA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;AAUA,SAAS,KAAK,GAAqB;AACjC,MAAI,MAAM;AACV,aAAW,QAAQ,GAAG;AACpB,WAAO;AAAA,EACT;AACA,SAAO,MAAM,EAAE;AACjB;AASA,SAAS,SAAS,GAAqB;AACrC,QAAM,QAAQ,KAAK,CAAC;AACpB,MAAI,MAAM;AACV,aAAW,QAAQ,GAAG;AACpB,WAAO,KAAK,IAAI,OAAO,OAAO,CAAC;AAAA,EACjC;AACA,SAAO,MAAM,EAAE;AACjB;AAGA,IAAO,gBAAQ;","names":["moranIndex"]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@turf/moran-index",
|
|
3
|
-
"version": "7.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "7.3.0",
|
|
4
|
+
"description": "Measures patterns of attribute values associated with features. Reveals whether similar values tend to occur near each other, or whether high or low values are interspersed",
|
|
5
5
|
"author": "Turf Authors",
|
|
6
6
|
"contributors": [
|
|
7
7
|
"Haoming Zhuang <@zhuang-hao-ming>"
|
|
@@ -53,22 +53,22 @@
|
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@types/benchmark": "^2.1.5",
|
|
56
|
-
"@types/tape": "^
|
|
56
|
+
"@types/tape": "^5.8.1",
|
|
57
57
|
"benchmark": "^2.1.4",
|
|
58
58
|
"load-json-file": "^7.0.1",
|
|
59
59
|
"npm-run-all": "^4.1.5",
|
|
60
|
-
"tape": "^5.
|
|
61
|
-
"tsup": "^8.0
|
|
62
|
-
"tsx": "^4.
|
|
63
|
-
"typescript": "^5.
|
|
64
|
-
"write-json-file": "^
|
|
60
|
+
"tape": "^5.9.0",
|
|
61
|
+
"tsup": "^8.4.0",
|
|
62
|
+
"tsx": "^4.19.4",
|
|
63
|
+
"typescript": "^5.8.3",
|
|
64
|
+
"write-json-file": "^6.0.0"
|
|
65
65
|
},
|
|
66
66
|
"dependencies": {
|
|
67
|
-
"@turf/distance-weight": "
|
|
68
|
-
"@turf/helpers": "
|
|
69
|
-
"@turf/meta": "
|
|
67
|
+
"@turf/distance-weight": "7.3.0",
|
|
68
|
+
"@turf/helpers": "7.3.0",
|
|
69
|
+
"@turf/meta": "7.3.0",
|
|
70
70
|
"@types/geojson": "^7946.0.10",
|
|
71
|
-
"tslib": "^2.
|
|
71
|
+
"tslib": "^2.8.1"
|
|
72
72
|
},
|
|
73
|
-
"gitHead": "
|
|
73
|
+
"gitHead": "9f58a103e8f9a587ab640307ed03ba5233913ddd"
|
|
74
74
|
}
|