Natively built for computing Moran's I on dgCMatrix
objects, this
routine allows computing the I on large sparse matrices (graphs). Part of
its implementation was based on ape::Moran.I
,
which computes the I for dense matrices.
moran(x, w, normalize.w = TRUE, alternative = "two.sided")
Numeric vector of size \(n\).
Numeric matrix of size \(n\times n\). Weights. It can be
either a object of class matrix
or dgCMatrix
from the Matrix
package.
Logical scalar. When TRUE normalizes rowsums to one (or zero).
Character String. Specifies the alternative hypothesis that
is tested against the null of no autocorrelation; must be of one "two.sided"
,
"less"
, or "greater"
.
A list of class diffnet_moran
with the following elements:
Numeric scalar. Observed correlation index.
Numeric scalar. Expected correlation index equal to \(-1/(N-1)\).
Numeric scalar. Standard error under the null.
Numeric scalar. p-value of the specified alternative
.
In the case that the vector x
is close to constant (degenerate random
variable), the statistic becomes irrelevant, and furthermore, the standard error
tends to be undefined (NaN
).
Moran's I. (2015, September 3). In Wikipedia, The Free Encyclopedia. Retrieved 06:23, December 22, 2015, from https://en.wikipedia.org/w/index.php?title=Moran%27s_I&oldid=679297766
Other statistics:
bass
,
classify_adopters()
,
cumulative_adopt_count()
,
dgr()
,
ego_variance()
,
exposure()
,
hazard_rate()
,
infection()
,
struct_equiv()
,
threshold()
,
vertex_covariate_dist()
Other Functions for inference:
bootnet()
,
struct_test()
if (require("ape")) {
# Generating a small random graph
set.seed(123)
graph <- rgraph_ba(t = 4)
w <- approx_geodesic(graph)
x <- rnorm(5)
# Computing Moran's I
moran(x, w)
# Comparing with the ape's package version
ape::Moran.I(x, as.matrix(w))
}
#> Loading required package: ape
#>
#> Attaching package: ‘ape’
#> The following objects are masked from ‘package:sna’:
#>
#> consensus, degree
#> $observed
#> [1] -0.1427118
#>
#> $expected
#> [1] -0.25
#>
#> $sd
#> [1] 0.1768444
#>
#> $p.value
#> [1] 0.5440623
#>