Class: SpatialStats::Local::Geary

Inherits:
Stat
  • Object
show all
Defined in:
lib/spatial_stats/local/geary.rb

Overview

Geary's C statistic computes the spatial lag of the difference between variable zi and it's neighbors squared, in the set z. The local version returns a value for each entry.

Instance Attribute Summary

Attributes inherited from Stat

#field, #scope, #weights

Instance Method Summary collapse

Methods inherited from Stat

#crand, #expectation, #mc, #mc_bv, #quads, #summary, #variance, #x=, #y=, #z_score

Constructor Details

#initialize(scope, field, weights) ⇒ Geary

A new instance of Geary

Parameters:

  • scope (ActiveRecord::Relation)
  • field (Symbol, String)

    to query from scope

  • weights (WeightsMatrix)

    to define relationship between observations in scope



18
19
20
# File 'lib/spatial_stats/local/geary.rb', line 18

def initialize(scope, field, weights)
  super(scope, field, weights)
end

Instance Method Details

#groupsArray

Computes the groups each observation belongs to. Potential groups for Geary's C are:

HH

High-High

LL

Low-Low

N

Negative - Group traditionally for HL and LH, but since the difference is squared they are in the same group.

Returns:

  • (Array)

    groups for each observation



44
45
46
47
48
49
50
51
52
# File 'lib/spatial_stats/local/geary.rb', line 44

def groups
  quads.map do |quad|
    if %w[HL LH].include?(quad)
      'N'
    else
      quad
    end
  end
end

#statArray Also known as: c

Computes Geary's C for every observation in the scoe. Geary's C is defined as the square distance between an observation and it's neighbors, factored to their weights.

Returns:

  • (Array)

    the C value for each observation



28
29
30
31
32
# File 'lib/spatial_stats/local/geary.rb', line 28

def stat
  z.each_with_index.map do |_zi, idx|
    stat_i(idx)
  end
end

#xArray Also known as: z

Values of the field queried from the scope

Returns:

  • (Array)


58
59
60
61
# File 'lib/spatial_stats/local/geary.rb', line 58

def x
  @x ||= SpatialStats::Queries::Variables.query_field(@scope, @field)
                                         .standardize
end