mirror of
https://github.com/gonum/gonum.git
synced 2025-10-06 07:37:03 +08:00
stat/spatial: new package for spatial statistic measures
This commit is contained in:
75
stat/spatial/spatial_example_test.go
Normal file
75
stat/spatial/spatial_example_test.go
Normal file
@@ -0,0 +1,75 @@
|
||||
// Copyright ©2017 The gonum Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package spatial_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"gonum.org/v1/gonum/mat"
|
||||
"gonum.org/v1/gonum/stat/spatial"
|
||||
)
|
||||
|
||||
func ExampleGlobalMoransI_linear() {
|
||||
data := []float64{0, 0, 0, 1, 1, 1, 0, 1, 0, 0}
|
||||
|
||||
// The locality here describes spatial neighbor
|
||||
// relationships.
|
||||
locality := mat.NewDense(10, 10, []float64{
|
||||
0, 1, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
1, 0, 1, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 1, 0, 1, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 1, 0, 1, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 1, 0, 1, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 1, 0, 1, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 1, 0, 1, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 1, 0, 1, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 1, 0, 1,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 1, 0,
|
||||
})
|
||||
|
||||
i, _, z := spatial.GlobalMoransI(data, nil, locality)
|
||||
|
||||
fmt.Printf("Moran's I=%.4v z-score=%.4v\n", i, z)
|
||||
|
||||
// Output:
|
||||
//
|
||||
// Moran's I=0.1111 z-score=0.6335
|
||||
}
|
||||
|
||||
func ExampleGetisOrd() {
|
||||
data := []float64{0, 0, 0, 1, 1, 1, 0, 1, 0, 0}
|
||||
|
||||
// The locality here describes spatial neighbor
|
||||
// relationships including self.
|
||||
locality := mat.NewDense(10, 10, []float64{
|
||||
1, 1, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
1, 1, 1, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 1, 1, 1, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 1, 1, 1, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 1, 1, 1, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 1, 1, 1, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 1, 1, 1, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 1, 1, 1, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 1, 1, 1,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 1, 1,
|
||||
})
|
||||
|
||||
for i, v := range data {
|
||||
fmt.Printf("v=%v G*i=% .4v\n", v, spatial.GetisOrdGStar(i, data, nil, locality))
|
||||
}
|
||||
|
||||
// Output:
|
||||
//
|
||||
// v=0 G*i=-1.225
|
||||
// v=0 G*i=-1.604
|
||||
// v=0 G*i=-0.2673
|
||||
// v=1 G*i= 1.069
|
||||
// v=1 G*i= 2.405
|
||||
// v=1 G*i= 1.069
|
||||
// v=0 G*i= 1.069
|
||||
// v=1 G*i=-0.2673
|
||||
// v=0 G*i=-0.2673
|
||||
// v=0 G*i=-1.225
|
||||
}
|
Reference in New Issue
Block a user