[R-sig-Geo] spBayes package spLM function
Helen Chen
hc10024 at gmail.com
Fri Jul 24 19:40:03 CEST 2015
Thanks for your help. I solve that problem.
I have another issue in the same function
I ran another chunks of code as following in order to predict
## Extract the coordinates of the BEF bounding polygon vertices and use the
pointsInPoly (spBayes) function to obtain the desired subset of the
prediction design matrix and associated prediction coordinates (i.e., pixel
centroids).
pred.coords <- SpatialPoints(BEF.grids)@coords
pred.covars <- pred.covars[pointsInPolyOut,]
pointsInPolyOut <- pointsInPoly(BEF.poly, pred.coords)
pred.covars <- p[pointsInPolyOut,]
#convert spdf to matrix
DF <- as.matrix(pred.covars at data)
pred.coords <- pred.coords[pointsInPolyOut,]
bef.bio.pred <- spPredict(bef.sp, start=burn.in, thin=2,
pred.coords=pred.coords, pred.covars=DF)
I got another error message:
bef.bio.pred <- spPredict(bef.sp, start=burn.in, thin=2,
pred.coords=pred.coords, pred.covars=DF)
Error in spPredict(bef.sp, start = burn.in, thin = 2, pred.coords =
pred.coords, :
error: pred.covars must have 2 columns
My "DF" looks like this:
row.names band1
1 2342 573.4432
2 2343 572.7695
3 2344 572.9942
4 2345 574.6914
5 2346 575.8411
6 2347 577.7388
7 2348 579.3783
8 2349 581.7493
9 2350 583.5519
10 12607 574.7918
11 12608 573.9687
12 12609 573.6502
13 12610 575.8325
14 12611 576.9496
15 12612 578.4088
16 12613 580.6917
17 12614 582.3503
18 12615 583.6110
19 22872 575.9836
20 22873 574.9182
21 22874 574.4495
22 22875 576.1238
23 22876 577.8916
24 22877 579.7219
25 22878 581.2625
26 22879 582.9403
27 22880 584.3701
28 33124 569.6010
29 33125 572.2399
Could anyone help me to figure out? Thanks for all your help.
Best,
Helen
On Thu, Jul 23, 2015 at 3:16 PM, Sarah Goslee <sarah.goslee at gmail.com>
wrote:
> Are you sure that cook is a matrix and not a data frame?
>
> What are the outputs of:
>
> dim(cook)
> is.matrix(cook)
> str(cook)
>
> Sarah
>
> On Thu, Jul 23, 2015 at 6:12 PM, Helen Chen <hc10024 at gmail.com> wrote:
> > Hi,
> >
> > I have tried to implement the spLM function from spBayes package to my
> data
> > (rainfall value, elevation, coordinates).
> >
> > However, the error message shows up when I run this chunk of codes:
> >
> > bef.sp <- spLM(S3~elv,
> > + data=A, coords=cook, starting=list("phi"=3/200,"sigma.sq"=0.08,
> > + "tau.sq"=0.02), tuning=list("phi"=0.1, "sigma.sq"=0.05, "tau.sq"=0.05),
> > + priors=list("phi.Unif"=c(3/1500, 3/50),
> "sigma.sq.IG"=c(2,
> > 0.08),"tau.sq.IG"=c(2, 0.02)), cov.model="spherical",n.samples=n.samples)
> >
> > the error message is
> >
> > Error in spLM(S3 ~ elv, data = A, coords = cook, starting = list(phi =
> > 3/200, :
> > error: coords must n-by-2 matrix of xy-coordinate locations
> >
> > I am sure that my coordinates is a 29 by 2 matrix, but it also tells me
> > this error message.
> >
> > Could anyone help me to figure out. Thanks for all your help.
> >
> >
> >
> > Helen
> >
>
> --
> Sarah Goslee
> http://www.functionaldiversity.org
>
[[alternative HTML version deleted]]
More information about the R-sig-Geo
mailing list