1

I am using the spRecover function in package spBayes to produce a spatial univariate model.

Here is a reproducible example where there I made a duplicate coordinate point. The modeling procedure itself executes just fine, but it won't let me recover the spatial effects for each site:

require(spBayes)
set.seed(444)
N = 200
y = rnorm(N,0,100)
x = rnorm(N,2,7)
df <- as.data.frame(cbind((rnorm(N,5,2.5)),rep('location1',N)))
coord <- cbind(runif(N,-30,30),runif(N,-180,180))
coord[2,] <- coord [1,]
n.samples <- 1000
bef.sp <- spLM(y ~ x, ## the equation
               data = df, coords=coord, ## data and coordinates
               starting=list("phi"=3/200,"sigma.sq"=0.08,"tau.sq"=0.02),## start values
               tuning=list("phi"=0.1, "sigma.sq"=0.05, "tau.sq"=0.05), ## tuning values
               priors=list("phi.Unif"=c(3/1500, 3/50), "sigma.sq.IG"=c(2, 0.08),"tau.sq.IG"=c(2, 0.02)), ## priors
               cov.model="exponential",n.samples=n.samples)
burn.in <- floor(0.75*n.samples)
bef.sp <- spRecover(bef.sp, start=burn.in, thin=2)

The error received is:

Error in spRecover(bef.sp, start = burn.in, thin = 2) : 
  c++ error: dpotrf failed

I found a post by the package author indicating this error might come up if one has replicated coordinates. I definitely have duplicated coordinates, since many sites were sampled many times (on the same day; this is not a time-series issue). How do I get the model to accept that there is lots of replication within each coordinate pair, and to recover individual spatial effects values for each site?

Thanks!

makai
  • 31
  • 1
  • 8
  • what if you add some `jitter` or other small amount to duplicated coordinates? `dup <- duplicated(bef.sp$coords); bef.sp$coords[dup] <- bef.sp$coords[dup] + 1e-3` then `spRecover` runs fine – rawr Sep 09 '16 at 00:02
  • Thank you so much! This is a nifty fix. Since I'm working with a global dataset, the minimal differences acquired in jitter shouldn't manipulate my results significantly. – makai Sep 09 '16 at 18:33

0 Answers0