Error correcting for spatial autocorrelation with gls function in the nlme package

1.3k Views Asked by At

I am trying to connect for spatial autocorrelation using the gls function in the nlme package using the following code:

modelExp<- gls(avg_diff ~ burnsev/Species, data= burn, na.action = na.omit,
                              correlation = corExp(form = ~Lat + Long, nugget = TRUE)

However, I keep getting the error:

Error in getCovariate.corSpatial(object, data = data) : 
  cannot have zero distances in "corSpatial"

Despite having removed all duplicate coordinates from my data frame, this error persists. Does anyone know how to fix this error? Could there perhaps be an issue of spatial resolution? Some of my points are separated by < 0.0001 decimal degrees.

Thank you!

1

There are 1 best solutions below

0
On

This is happening because your Lat Lon are repeating in your dataset. Often this happens because you've taken samples from point locations over many years. A solution would be to do the following assuming that your grouping factor is year:

modelExp<- gls(avg_diff ~ burnsev/Species, data= burn, na.action = na.omit,
                              correlation = corExp(form = ~Lat + Long|year, nugget = TRUE)