spatial_stats 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3e79499aff738642d7e50a0255239de6627e68b3e1553f8aa6fa21364c3b5acb
4
- data.tar.gz: 26a98ee5cb279af10e2cc324663e06ddfc7217eb6a6adc3d4052cc6469b5b6be
3
+ metadata.gz: 053a1b234d54d2231e35c7eb74547b086f7415fc96190bc7d3afb25f51dd879e
4
+ data.tar.gz: a85d682009559812fb20695c5bea8f2978acf49a12d0b3df2506d58ced8c5e77
5
5
  SHA512:
6
- metadata.gz: a184a7e6561ec950ecc97e08840c8e88ba7bb20567d140036c34e0552a0e11a339885094fa5380e59f1a7ebe4eee0cb371368e6a7384531c7704e9894c8c1948
7
- data.tar.gz: cd971928ff328e8daca3b0176b01903bdc98d7fcf1109cdbf9937dd84ff737d2d8072b7437e21dc0c2f26c73738c7c7f30c9a7bdca30b5cfd655ef5f3f760df1
6
+ metadata.gz: 868ec3b50f4b1b9fc261d6dd94439bba62a08d4c496a48d164c41590d1cd5a088c87de682a7cb96bcf4dbe0d534b5cf35e136e39d42c505ba8cc1f4c3569a3d4
7
+ data.tar.gz: b767cc6ed7f22ce4096965a6172f77d21a348d51bd84dc3b96f0d51bf16e2f4f92617e21e9bcda1a36eeda2cd5c07c51452dd55d9e5a62567e206bf7a06c8fe0
data/README.md CHANGED
@@ -1,10 +1,12 @@
1
+ ![Spatial Stats](/assets/ruby.svg)
2
+
1
3
  [![Build Status](https://travis-ci.com/keithdoggett/spatial_stats.svg?branch=master)](https://travis-ci.com/keithdoggett/spatial_stats)
2
4
 
3
- ![Spatial Stats](/assets/ruby.svg)
5
+ [Docs](https://keithdoggett.github.io/spatial_stats)
4
6
 
5
7
  # SpatialStats
6
8
 
7
- SpatialStats is an ActiveRecord plugin that utilizes PostGIS and Ruby to compute weights/statistics of spatial data sets in Rails Apps.
9
+ SpatialStats is an ActiveRecord/Rails plugin that utilizes PostGIS to compute weights/statistics of spatial data sets in Rails Apps.
8
10
 
9
11
  ## Installation
10
12
 
@@ -327,7 +329,9 @@ Summaries of milestones for v1.x and v2.0. These lists are subject to change. If
327
329
  - Add support for .gal/.swm file imports
328
330
  - Add support for Rate variables
329
331
  - Add support for Bayes smoothing
332
+ - ~Add support for Bonferroni Bounds and FDR~
330
333
  4. General
334
+ - ~Add new stat constructors that only rely on a weights matrix and data vector~
331
335
  - Point Pattern Analysis Module
332
336
  - Regression Module
333
337
 
@@ -336,6 +340,11 @@ Summaries of milestones for v1.x and v2.0. These lists are subject to change. If
336
340
  - Break gem into core `spatial_stats` that will not include queries module and `spatial_stats-activerecord`. This will remove the dependency on rails for the core gem.
337
341
  - Create `spatial_stats-import/geojson/shp` gem that will allow importing files and generating a `WeightsMatrix`. Will likely rely on `RGeo` or another spatial lib.
338
342
 
343
+ ### Other TODOs
344
+
345
+ - Update Docs to show `from_observation` when version is bumped
346
+ - Refactor `MultivariateGeary` so that it can be used without `activerecord` by adding `from_observations` and supporting methods.
347
+
339
348
  ## License
340
349
 
341
350
  The gem is available as open source under the terms of the [BSD-3-Clause](https://opensource.org/licenses/BSD-3-Clause).
@@ -22,6 +22,23 @@ module SpatialStats
22
22
  @weights = weights.standardize
23
23
  end
24
24
 
25
+ ##
26
+ # A new instance of BivariateMoran, from vector and weights.
27
+ #
28
+ # @param [Array] x observations of dataset
29
+ # @param [WeightsMatrix] weights to define relationships between observations
30
+ #
31
+ # @return [BivariateMoran]
32
+ def self.from_observations(x, y, weights)
33
+ n = weights.n
34
+ raise ArgumentError, 'Data size != weights.n' if x.size != n || y.size != n
35
+
36
+ instance = new(nil, nil, nil, weights.standardize)
37
+ instance.x = x
38
+ instance.y = y
39
+ instance
40
+ end
41
+
25
42
  ##
26
43
  # Computes the global spatial correlation of x against spatially lagged
27
44
  # y.
@@ -15,6 +15,21 @@ module SpatialStats
15
15
  end
16
16
  attr_accessor :scope, :field, :weights
17
17
 
18
+ ##
19
+ # A new instance of Stat, from vector and weights.
20
+ #
21
+ # @param [Array] x observations of dataset
22
+ # @param [WeightsMatrix] weights to define relationships between observations
23
+ #
24
+ # @return [Stat]
25
+ def self.from_observations(x, weights)
26
+ raise ArgumentError, 'Data size != weights.n' if x.size != weights.n
27
+
28
+ instance = new(nil, nil, weights.standardize)
29
+ instance.x = x
30
+ instance
31
+ end
32
+
18
33
  def stat
19
34
  raise NotImplementedError, 'method stat not defined'
20
35
  end
@@ -23,6 +23,24 @@ module SpatialStats
23
23
  end
24
24
  attr_accessor :scope, :x_field, :y_field, :weights
25
25
 
26
+ ##
27
+ # A new instance of BivariateMoran, from vector and weights.
28
+ #
29
+ # @param [Array] x observations of dataset
30
+ # @param [Array] y observations of dataset
31
+ # @param [WeightsMatrix] weights to define relationships between observations
32
+ #
33
+ # @return [BivariateMoran]
34
+ def self.from_observations(x, y, weights)
35
+ n = weights.n
36
+ raise ArgumentError, 'Data size != weights.n' if x.size != n || y.size != n
37
+
38
+ instance = new(nil, nil, nil, weights.standardize)
39
+ instance.x = x
40
+ instance.y = y
41
+ instance
42
+ end
43
+
26
44
  ##
27
45
  # Computes the local indicator of spatial correlation for
28
46
  # x against lagged y.
@@ -16,6 +16,21 @@ module SpatialStats
16
16
  end
17
17
  attr_accessor :scope, :field, :weights
18
18
 
19
+ ##
20
+ # A new instance of Stat, from vector and weights.
21
+ #
22
+ # @param [Array] x observations of dataset
23
+ # @param [WeightsMatrix] weights to define relationships between observations
24
+ #
25
+ # @return [Stat]
26
+ def self.from_observations(x, weights)
27
+ raise ArgumentError, 'Data size != weights.n' if x.size != weights.n
28
+
29
+ instance = new(nil, nil, weights.standardize)
30
+ instance.x = x
31
+ instance
32
+ end
33
+
19
34
  def stat
20
35
  raise NotImplementedError, 'method stat not defined'
21
36
  end
@@ -6,5 +6,30 @@ module SpatialStats
6
6
  ##
7
7
  # The Utils module contains various utilities used in the gem.
8
8
  module Utils
9
+ ##
10
+ # Compute the false discovery rate (FDR) of a set of p-values given
11
+ # an alpha value.
12
+ #
13
+ # If there is no FDR available in the dataset, the Bonferroni Bound is
14
+ # returned instead.
15
+ #
16
+ # @param [Array] pvals from an mc test
17
+ # @param [Float] alpha value for the fdr
18
+ #
19
+ # @returns [Float] either the FDR or Bonferroni Bound
20
+ def self.fdr(pvals, alpha)
21
+ n = pvals.size
22
+ b_bound = alpha / n
23
+ pvals.sort!
24
+
25
+ p_val = b_bound
26
+ (0..n - 1).each do |i|
27
+ p_fdr = (i + 1) * b_bound
28
+ break unless pvals[i] <= p_fdr
29
+
30
+ p_val = p_fdr
31
+ end
32
+ p_val
33
+ end
9
34
  end
10
35
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SpatialStats
4
- VERSION = '1.0.3'
4
+ VERSION = '1.0.4'
5
5
  end
@@ -21,6 +21,16 @@ module SpatialStats
21
21
  end
22
22
  attr_accessor :keys, :weights, :n
23
23
 
24
+ ##
25
+ # Equality operator
26
+ #
27
+ # @param [WeightsMatrix] other WeightsMatrix
28
+ #
29
+ # @return [TrueClass, FalseClass] equality result
30
+ def ==(other)
31
+ weights == other.weights
32
+ end
33
+
24
34
  ##
25
35
  # Compute the n x n Numo::Narray of the weights hash.
26
36
  #
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spatial_stats
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Keith Doggett
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-22 00:00:00.000000000 Z
11
+ date: 2020-12-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: numo-narray
@@ -28,14 +28,14 @@ dependencies:
28
28
  name: rails
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: 6.0.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: 6.0.0
41
41
  - !ruby/object:Gem::Dependency
@@ -112,14 +112,14 @@ dependencies:
112
112
  name: tzinfo
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - "~>"
115
+ - - ">="
116
116
  - !ruby/object:Gem::Version
117
117
  version: 1.2.6
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - "~>"
122
+ - - ">="
123
123
  - !ruby/object:Gem::Version
124
124
  version: 1.2.6
125
125
  description: An ActiveRecord/PostGIS extension that provides statistical methods to
@@ -189,7 +189,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
189
189
  - !ruby/object:Gem::Version
190
190
  version: '0'
191
191
  requirements: []
192
- rubygems_version: 3.0.3
192
+ rubygems_version: 3.0.8
193
193
  signing_key:
194
194
  specification_version: 4
195
195
  summary: An ActiveRecord/PostGIS extension that provides statistical methods to spatial