Zero distance error in corSpatial - correlation structure using lme
I believe you are stuck with what the error says -- i.e. you 'Cannot have zero distances in "corSpatial"'. If you recorded locations for observations within transects then you should be able to model the spatial autocorrelation, either within transects or across the study area (although the latter may be difficualt, depending on the spatial layout of your study). I don't know of a regression tool in R that allows for estimation of the spatial correlation strructure at levels higher than than the observations. Kingsford Jones
On Mon, Mar 9, 2009 at 7:28 AM, John Poulsen <jpoulsen at zoo.ufl.edu> wrote:
Hello, I am having a problem specifying the correlation structure in lme which leads to the error: Error in getCovariate.corSpatial(object, data = data) : Cannot have zero distances in "corSpatial". ?I have specified a grouping variable which is the only fix I could find by searching this error on R-help. ISee the below example. ?When my samples (tran) - which are transects sampled several times - have different coordinates (STX1 and STY1), everything seems to work fine. ?But in my actual data set, there are multiple observations per sample and the coordinates are the same for the same sample. ?This is demonstrated below using the coordinates STX2 and STY2, which are the same for a single transect. ?How can I properly specify this structure in Variogram() and corSpatial()? library(nlme) set.seed(1001) ntrans <- 30 npertrans <- 5 ntot <- ntrans*npertrans STX1<-runif(ntot, min=16.0921, max=16.4823) STY1<-runif(ntot, min=1.9812, max=2.3932) STX2<-rep(runif(ntrans, min=16.0921, max=16.4823), each=npertrans) STY2<-rep(runif(ntrans, min=1.9812, max=2.3932), each=npertrans) site<-rep(c(1,2,3), each=ntot/3) tran<-rep(1:ntrans,each=npertrans) log<-rep(rbinom(n=ntrans, 1, 0.5), each=npertrans) yabund<-rnorm(ntot, 5, 0.4) dat<-data.frame(STX1, STY1, STX2, STY2, site, tran, log, yabund) test1<-lme(yabund~factor(log)+STX1+STY1, random=~1|tran,data=dat) test2<-lme(yabund~factor(log)+STX2+STY2, random=~1|tran,data=dat) Variogram(test1, form=~STX1+STY1|tran) plot(Variogram(test1, form=~STX1+STY1|tran)) Variogram(test2, form=~STX2+STY2|tran) ? # Varigoram has distance of 0! plot(Variogram(test2, form=~STX2+STY2|tran)) mod1<-lme(log(yabund)~factor(log)+STX1+STY1, random=~1|tran, data=dat, ? ? ? ? ? ? ?corr=corSpatial(form=~STY1+STX1|tran, type="exponential", nugget=T), method="REML") mod2<-lme(log(yabund)~factor(log)+STX2+STY2, random=~1|tran, data=dat, ? ? ? ? ? ? ?corr=corSpatial(form=~STY2+STX2, type="exponential", nugget=T), method="REML") # Error in getCovariate.corSpatial(object, data = data) : # Cannot have zero distances in "corSpatial"
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.