Class: SpatialStats::Local::GetisOrd
- Defined in:
- lib/spatial_stats/local/getis_ord.rb
Overview
GetisOrd's G and G* statistics compute the spatial autocorrelation of a variable, x. G computes the ratio of spatially lagged x to the sum of all other x's except xi for every entry. G* does the same calculation but includes xi in the spatial lag and denominator.
Instance Attribute Summary collapse
-
#star ⇒ Object
Returns the value of attribute star.
-
#x ⇒ Array
(also: #z)
Values of the
field
queried from thescope
.
Attributes inherited from Stat
Instance Method Summary collapse
-
#groups ⇒ Array
Computes the groups each observation belongs to.
-
#initialize(scope, field, weights, star = nil) ⇒ GetisOrd
constructor
A new instance of GetisOrd.
-
#star? ⇒ Boolean
True if G* is being used, false if G is being used.
-
#stat ⇒ Array
(also: #g)
Computes the G or G* statistic for every observation in x.
Methods inherited from Stat
#crand, #expectation, #mc, #mc_bv, #quads, #summary, #variance, #y=, #z_score
Constructor Details
#initialize(scope, field, weights, star = nil) ⇒ GetisOrd
A new instance of GetisOrd
20 21 22 23 24 25 26 |
# File 'lib/spatial_stats/local/getis_ord.rb', line 20 def initialize(scope, field, weights, star = nil) @scope = scope @field = field @weights = weights @star = star calc_weights end |
Instance Attribute Details
#star ⇒ Object
Returns the value of attribute star.
27 28 29 |
# File 'lib/spatial_stats/local/getis_ord.rb', line 27 def star @star end |
#x ⇒ Array Also known as: z
Values of the field
queried from the scope
64 65 66 |
# File 'lib/spatial_stats/local/getis_ord.rb', line 64 def x @x ||= SpatialStats::Queries::Variables.query_field(@scope, @field) end |
Instance Method Details
#groups ⇒ Array
Computes the groups each observation belongs to. Potential groups for G are:
- H
-
High
- L
-
Low
Group is high when standardized z is positive, low otherwise.
50 51 52 53 54 55 56 57 58 |
# File 'lib/spatial_stats/local/getis_ord.rb', line 50 def groups z.standardize.map do |val| if val.positive? 'H' else 'L' end end end |
#star? ⇒ Boolean
True if G* is being used, false if G is being used. If no value is passed in the constructor, it will be determined based off of the trace of the weights.
75 76 77 78 79 80 81 |
# File 'lib/spatial_stats/local/getis_ord.rb', line 75 def star? if @star.nil? @star = weights.dense.trace.positive? else @star end end |
#stat ⇒ Array Also known as: g
Computes the G or G* statistic for every observation in x.
34 35 36 37 38 |
# File 'lib/spatial_stats/local/getis_ord.rb', line 34 def stat x.each_with_index.map do |_x_val, idx| stat_i(idx) end end |