@turf/moran-index
Advanced tools
Comparing version 6.5.0 to 7.0.0-alpha.0
@@ -46,32 +46,32 @@ import spatialWeight from "@turf/distance-weight"; | ||
export default function (fc, options) { | ||
var inputField = options.inputField; | ||
var threshold = options.threshold || 100000; | ||
var p = options.p || 2; | ||
var binary = options.binary || false; | ||
var alpha = options.alpha || -1; | ||
var standardization = options.standardization || true; | ||
var weight = spatialWeight(fc, { | ||
alpha: alpha, | ||
binary: binary, | ||
p: p, | ||
standardization: standardization, | ||
threshold: threshold, | ||
const inputField = options.inputField; | ||
const threshold = options.threshold || 100000; | ||
const p = options.p || 2; | ||
const binary = options.binary || false; | ||
const alpha = options.alpha || -1; | ||
const standardization = options.standardization || true; | ||
const weight = spatialWeight(fc, { | ||
alpha, | ||
binary, | ||
p, | ||
standardization, | ||
threshold, | ||
}); | ||
var y = []; | ||
featureEach(fc, function (feature) { | ||
var feaProperties = feature.properties || {}; | ||
const y = []; | ||
featureEach(fc, (feature) => { | ||
const feaProperties = feature.properties || {}; | ||
// validate inputField exists | ||
y.push(feaProperties[inputField]); | ||
}); | ||
var yMean = mean(y); | ||
var yVar = variance(y); | ||
var weightSum = 0; | ||
var s0 = 0; | ||
var s1 = 0; | ||
var s2 = 0; | ||
var n = weight.length; | ||
const yMean = mean(y); | ||
const yVar = variance(y); | ||
let weightSum = 0; | ||
let s0 = 0; | ||
let s1 = 0; | ||
let s2 = 0; | ||
const n = weight.length; | ||
// validate y.length is the same as weight.length | ||
for (var i = 0; i < n; i++) { | ||
var subS2 = 0; | ||
for (var j = 0; j < n; j++) { | ||
for (let i = 0; i < n; i++) { | ||
let subS2 = 0; | ||
for (let j = 0; j < n; j++) { | ||
weightSum += weight[i][j] * (y[i] - yMean) * (y[j] - yMean); | ||
@@ -85,14 +85,14 @@ s0 += weight[i][j]; | ||
s1 = 0.5 * s1; | ||
var moranIndex = weightSum / s0 / yVar; | ||
var expectedMoranIndex = -1 / (n - 1); | ||
var vNum = n * n * s1 - n * s2 + 3 * (s0 * s0); | ||
var vDen = (n - 1) * (n + 1) * (s0 * s0); | ||
var vNorm = vNum / vDen - expectedMoranIndex * expectedMoranIndex; | ||
var stdNorm = Math.sqrt(vNorm); | ||
var zNorm = (moranIndex - expectedMoranIndex) / stdNorm; | ||
const moranIndex = weightSum / s0 / yVar; | ||
const expectedMoranIndex = -1 / (n - 1); | ||
const vNum = n * n * s1 - n * s2 + 3 * (s0 * s0); | ||
const vDen = (n - 1) * (n + 1) * (s0 * s0); | ||
const vNorm = vNum / vDen - expectedMoranIndex * expectedMoranIndex; | ||
const stdNorm = Math.sqrt(vNorm); | ||
const zNorm = (moranIndex - expectedMoranIndex) / stdNorm; | ||
return { | ||
expectedMoranIndex: expectedMoranIndex, | ||
moranIndex: moranIndex, | ||
stdNorm: stdNorm, | ||
zNorm: zNorm, | ||
expectedMoranIndex, | ||
moranIndex, | ||
stdNorm, | ||
zNorm, | ||
}; | ||
@@ -107,5 +107,4 @@ } | ||
function mean(y) { | ||
var sum = 0; | ||
for (var _i = 0, y_1 = y; _i < y_1.length; _i++) { | ||
var item = y_1[_i]; | ||
let sum = 0; | ||
for (const item of y) { | ||
sum += item; | ||
@@ -122,6 +121,5 @@ } | ||
function variance(y) { | ||
var yMean = mean(y); | ||
var sum = 0; | ||
for (var _i = 0, y_2 = y; _i < y_2.length; _i++) { | ||
var item = y_2[_i]; | ||
const yMean = mean(y); | ||
let sum = 0; | ||
for (const item of y) { | ||
sum += Math.pow(item - yMean, 2); | ||
@@ -128,0 +126,0 @@ } |
@@ -1,2 +0,2 @@ | ||
import { FeatureCollection } from "@turf/helpers"; | ||
import { FeatureCollection } from "geojson"; | ||
/** | ||
@@ -3,0 +3,0 @@ * Moran's I measures patterns of attribute values associated with features. |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var distance_weight_1 = __importDefault(require("@turf/distance-weight")); | ||
var meta_1 = require("@turf/meta"); | ||
const tslib_1 = require("tslib"); | ||
const distance_weight_1 = tslib_1.__importDefault(require("@turf/distance-weight")); | ||
const meta_1 = require("@turf/meta"); | ||
/** | ||
@@ -51,32 +49,32 @@ * Moran's I measures patterns of attribute values associated with features. | ||
function default_1(fc, options) { | ||
var inputField = options.inputField; | ||
var threshold = options.threshold || 100000; | ||
var p = options.p || 2; | ||
var binary = options.binary || false; | ||
var alpha = options.alpha || -1; | ||
var standardization = options.standardization || true; | ||
var weight = distance_weight_1.default(fc, { | ||
alpha: alpha, | ||
binary: binary, | ||
p: p, | ||
standardization: standardization, | ||
threshold: threshold, | ||
const inputField = options.inputField; | ||
const threshold = options.threshold || 100000; | ||
const p = options.p || 2; | ||
const binary = options.binary || false; | ||
const alpha = options.alpha || -1; | ||
const standardization = options.standardization || true; | ||
const weight = distance_weight_1.default(fc, { | ||
alpha, | ||
binary, | ||
p, | ||
standardization, | ||
threshold, | ||
}); | ||
var y = []; | ||
meta_1.featureEach(fc, function (feature) { | ||
var feaProperties = feature.properties || {}; | ||
const y = []; | ||
meta_1.featureEach(fc, (feature) => { | ||
const feaProperties = feature.properties || {}; | ||
// validate inputField exists | ||
y.push(feaProperties[inputField]); | ||
}); | ||
var yMean = mean(y); | ||
var yVar = variance(y); | ||
var weightSum = 0; | ||
var s0 = 0; | ||
var s1 = 0; | ||
var s2 = 0; | ||
var n = weight.length; | ||
const yMean = mean(y); | ||
const yVar = variance(y); | ||
let weightSum = 0; | ||
let s0 = 0; | ||
let s1 = 0; | ||
let s2 = 0; | ||
const n = weight.length; | ||
// validate y.length is the same as weight.length | ||
for (var i = 0; i < n; i++) { | ||
var subS2 = 0; | ||
for (var j = 0; j < n; j++) { | ||
for (let i = 0; i < n; i++) { | ||
let subS2 = 0; | ||
for (let j = 0; j < n; j++) { | ||
weightSum += weight[i][j] * (y[i] - yMean) * (y[j] - yMean); | ||
@@ -90,14 +88,14 @@ s0 += weight[i][j]; | ||
s1 = 0.5 * s1; | ||
var moranIndex = weightSum / s0 / yVar; | ||
var expectedMoranIndex = -1 / (n - 1); | ||
var vNum = n * n * s1 - n * s2 + 3 * (s0 * s0); | ||
var vDen = (n - 1) * (n + 1) * (s0 * s0); | ||
var vNorm = vNum / vDen - expectedMoranIndex * expectedMoranIndex; | ||
var stdNorm = Math.sqrt(vNorm); | ||
var zNorm = (moranIndex - expectedMoranIndex) / stdNorm; | ||
const moranIndex = weightSum / s0 / yVar; | ||
const expectedMoranIndex = -1 / (n - 1); | ||
const vNum = n * n * s1 - n * s2 + 3 * (s0 * s0); | ||
const vDen = (n - 1) * (n + 1) * (s0 * s0); | ||
const vNorm = vNum / vDen - expectedMoranIndex * expectedMoranIndex; | ||
const stdNorm = Math.sqrt(vNorm); | ||
const zNorm = (moranIndex - expectedMoranIndex) / stdNorm; | ||
return { | ||
expectedMoranIndex: expectedMoranIndex, | ||
moranIndex: moranIndex, | ||
stdNorm: stdNorm, | ||
zNorm: zNorm, | ||
expectedMoranIndex, | ||
moranIndex, | ||
stdNorm, | ||
zNorm, | ||
}; | ||
@@ -113,5 +111,4 @@ } | ||
function mean(y) { | ||
var sum = 0; | ||
for (var _i = 0, y_1 = y; _i < y_1.length; _i++) { | ||
var item = y_1[_i]; | ||
let sum = 0; | ||
for (const item of y) { | ||
sum += item; | ||
@@ -128,6 +125,5 @@ } | ||
function variance(y) { | ||
var yMean = mean(y); | ||
var sum = 0; | ||
for (var _i = 0, y_2 = y; _i < y_2.length; _i++) { | ||
var item = y_2[_i]; | ||
const yMean = mean(y); | ||
let sum = 0; | ||
for (const item of y) { | ||
sum += Math.pow(item - yMean, 2); | ||
@@ -134,0 +130,0 @@ } |
{ | ||
"name": "@turf/moran-index", | ||
"version": "6.5.0", | ||
"version": "7.0.0-alpha.0", | ||
"description": "turf moran-index module", | ||
@@ -61,7 +61,8 @@ "author": "Turf Authors", | ||
"dependencies": { | ||
"@turf/distance-weight": "^6.5.0", | ||
"@turf/helpers": "^6.5.0", | ||
"@turf/meta": "^6.5.0" | ||
"@turf/distance-weight": "^7.0.0-alpha.0", | ||
"@turf/helpers": "^7.0.0-alpha.0", | ||
"@turf/meta": "^7.0.0-alpha.0", | ||
"tslib": "^2.3.0" | ||
}, | ||
"gitHead": "5375941072b90d489389db22b43bfe809d5e451e" | ||
"gitHead": "0edc4c491b999e5ace770a61e1cf549f7c004189" | ||
} |
@@ -12,3 +12,3 @@ # @turf/moran-index | ||
Moran's I > 0 means a clusterd pattern. | ||
Moran's I < 0 means a dispersed pattern. | ||
Moran's I < 0 means a dispersed pattern. | ||
Moran's I = 0 means a random pattern. | ||
@@ -18,27 +18,28 @@ | ||
A positive enough z-score (ex. >1.96) indicates clustering, | ||
while a negative enough z-score (ex. <-1.96) indicates a dispersed pattern. | ||
while a negative enough z-score (ex. <-1.96) indicates a dispersed pattern. | ||
the z-score can be calculated based on a normal or random assumption. | ||
**Bibliography\*** | ||
**Bibliography**\* | ||
1. [Moran's I](https://en.wikipedia.org/wiki/Moran%27s_I) | ||
1. [Moran's I][1] | ||
2. [pysal](http://pysal.readthedocs.io/en/latest/index.html) | ||
2. [pysal][2] | ||
3. Andy Mitchell, The ESRI Guide to GIS Analysis Volume 2: Spatial Measurements & Statistics. | ||
**Parameters** | ||
### Parameters | ||
- `fc` **[FeatureCollection](https://tools.ietf.org/html/rfc7946#section-3.3)<any>** | ||
- `options` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** | ||
- `options.inputField` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** the property name, must contain numeric values | ||
- `options.threshold` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** the distance threshold (optional, default `100000`) | ||
- `options.p` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** the Minkowski p-norm distance parameter (optional, default `2`) | ||
- `options.binary` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** whether transfrom the distance to binary (optional, default `false`) | ||
- `options.alpha` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** the distance decay parameter (optional, default `-1`) | ||
- `options.standardization` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** wheter row standardization the distance (optional, default `true`) | ||
* `fc` **[FeatureCollection][3]\<any>** | ||
* `options` **[Object][4]** | ||
**Examples** | ||
* `options.inputField` **[string][5]** the property name, must contain numeric values | ||
* `options.threshold` **[number][6]** the distance threshold (optional, default `100000`) | ||
* `options.p` **[number][6]** the Minkowski p-norm distance parameter (optional, default `2`) | ||
* `options.binary` **[boolean][7]** whether transfrom the distance to binary (optional, default `false`) | ||
* `options.alpha` **[number][6]** the distance decay parameter (optional, default `-1`) | ||
* `options.standardization` **[boolean][7]** wheter row standardization the distance (optional, default `true`) | ||
### Examples | ||
```javascript | ||
@@ -48,3 +49,3 @@ const bbox = [-65, 40, -63, 42]; | ||
const result = moranIndex(pts, { | ||
const result = turf.moranIndex(dataset, { | ||
inputField: 'CRIME', | ||
@@ -54,3 +55,3 @@ }); | ||
Returns **[MoranIndex](#moranindex)** | ||
Returns **[MoranIndex][8]** | ||
@@ -61,7 +62,7 @@ ## mean | ||
**Parameters** | ||
### Parameters | ||
- `y` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)>** | ||
* `y` **[Array][9]<[number][6]>** | ||
Returns **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** | ||
Returns **[number][6]** | ||
@@ -72,19 +73,37 @@ ## variance | ||
**Parameters** | ||
### Parameters | ||
- `y` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)>** | ||
* `y` **[Array][9]<[number][6]>** | ||
Returns **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** | ||
Returns **[number][6]** | ||
## MoranIndex | ||
Type: [Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object) | ||
Type: [Object][4] | ||
**Properties** | ||
### Properties | ||
- `moranIndex` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** the moran's Index of the observed feature set | ||
- `expectedMoranIndex` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** the moran's Index of the random distribution | ||
- `stdNorm` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** the standard devitaion of the random distribution | ||
- `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 | ||
* `moranIndex` **[number][6]** the moran's Index of the observed feature set | ||
* `expectedMoranIndex` **[number][6]** the moran's Index of the random distribution | ||
* `stdNorm` **[number][6]** the standard devitaion of the random distribution | ||
* `zNorm` **[number][6]** the z-score of the observe samples with regard to the random distribution | ||
[1]: https://en.wikipedia.org/wiki/Moran%27s_I | ||
[2]: http://pysal.readthedocs.io/en/latest/index.html | ||
[3]: https://tools.ietf.org/html/rfc7946#section-3.3 | ||
[4]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object | ||
[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String | ||
[6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number | ||
[7]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean | ||
[8]: #moranindex | ||
[9]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array | ||
<!-- This file is automatically generated. Please don't edit it directly: | ||
@@ -91,0 +110,0 @@ if you find an error, edit the source file (likely index.js), and re-run |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
127
17672
4
329
1
+ Addedtslib@^2.3.0
+ Added@turf/centroid@7.2.0(transitive)
+ Added@turf/distance-weight@7.2.0(transitive)
+ Added@turf/helpers@7.2.0(transitive)
+ Added@turf/invariant@7.2.0(transitive)
+ Added@turf/meta@7.2.0(transitive)
+ Added@types/geojson@7946.0.16(transitive)
+ Addedtslib@2.8.1(transitive)
- Removed@turf/centroid@6.5.0(transitive)
- Removed@turf/distance-weight@6.5.0(transitive)
- Removed@turf/helpers@6.5.0(transitive)
- Removed@turf/invariant@6.5.0(transitive)
- Removed@turf/meta@6.5.0(transitive)
Updated@turf/helpers@^7.0.0-alpha.0
Updated@turf/meta@^7.0.0-alpha.0