rspdep

spdep: How to extract variables of localG object


I used the localG_perm() function which unlike localmoran_perm() doesn't return a dataframe but instead a localG num object. I'm having trouble extracting the variables ("Gi", "E.Gi", "Var.Gi", "StdDev.Gi", "Pr(z != E(Gi))", "Pr(z != E(Gi)) Sim", "Pr(folded) Sim", "Skewness", "Kurtosis") from that object as I've never seen such thing in R. I've already tried the usual r_auto["Pr(z != E(Gi))"] (returns NA) or r_auto[, "Pr(z != E(Gi))"] (returns incorrect number of dimensions). How can I access the variables by name? Working example below.

library("terra")
library("spdep")


r <- terra::rast(
    ncols = 100,
    nrows = 100,
    vals = rnorm(100 * 100)
)

nb <- spdep::cell2nb(
    terra::nrow(r),
    terra::ncol(r),
    type = "queen",
    torus = TRUE
    )

r_auto <- spdep::localG_perm(
    as.vector(terra::values(r)),
    spdep::nb2listw(nb, style = "B"),
    nsim = 100,
    zero.policy = TRUE
)

Solution

  • To get the variables stored in localG as dataframe do:

    r_auto_df <- attr(r_auto, "internals")