0

I'm trying to run a local Moran's I from the sp package in R and am unable to include a bonferroni adjustment in the code. I can run the localmoran function without the p.adjust code no problem, but none of the variations of the adjustment code run successfully. I've added two variations of my code below along with the errors that are returned.

library(spdep)

library(rgdal)

gb<-readOGR("gb_corrected.shp")

attach(gb@data)

gb.adj.listw<-nb2listw(poly2nb(gb), style = "W")

lmi78 <- localmoran(GDPPC78, gb.adj.listw, p.adjust.method ="bonferroni", alternative = "two.sided")

Error:

"Error in localmoran(GDPPC78, gb.adj.listw, p.adjust.method = "bonferroni", : unused argument (p.adjust.method = "bonferroni")"

lmi78<-localmoran(GDPPC78, gb.adj.listw, p.adjust(method ="bonferroni"), alternative = "two.sided")

Error:

"Error in p.adjust(method = "bonferroni") : argument "p" is missing, with no default"

My version of R is below and all packages here are up-to-date. I have tried in both R and R Studio. I apologize for any missing information, this is my first time posting here.

RStudio 2022.02.0+443 "Prairie Trillium" Release (9f7969398b90468440a501cf065295d9050bb776, 2022-02-16) for Windows Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) QtWebEngine/5.12.8 Chrome/69.0.3497.128 Safari/537.36

JayPeerachai
  • 3,499
  • 3
  • 14
  • 29
CJ Knoble
  • 11
  • 3
  • You must be looking at a guide or something of that nature that is out-of-date. The function has changed. There is no longer an argument called `p.adjust.method`. I don't know what version you have, but it looks like [the version changes](https://r-spatial.github.io/spdep/articles/CO69.html) included changes to that function over each of the last several versions. They also *briefly* discuss why Bonferroni adjustment isn't there in one of the articles they reference for that function. (The article by Sauer et al., [2021].) – Kat Mar 01 '22 at 00:46
  • You're absolutely right, the code I was referencing is significantly older. Thank you for the help and the article, that's a huge help! – CJ Knoble Mar 01 '22 at 16:44

0 Answers0