[R] R version 3.3.2, Windows 10 -- gstat.predict() function often return NaN values (GSTAT Package)

Rathore, Saubhagya Singh saubhagya at gatech.edu
Thu Feb 16 20:40:58 CET 2017


I am adding my message in the mail body as I found it missing from the mail that finally got posted on the list. 

I am trying to simulate a combination of two different random fields (yy1 and yy2 different mean and correlation length) with an irregular boundary. I have attached the picture of my expected outcome. The code is not giving such output consistently and I am frequently getting atleast one of the yy1 and yy2 as as NaN, which results in the Undesired output as shown in image. 

The key steps I used are:

1)	Created two gsat objects with different means and psill (rf1 and rf2)
2)	Created two computational grids (one for each random field) in the form of data frame with two variables "x" and "y" coordinates. 
3)	Predicted two random fields using unconditional simulation. 

The code is fairly small hence I am pasting in here itself. Any help in this regard would be highly appreciated. 

## Code starts ===================================================================================
library(gstat)

xy <- expand.grid(1:150, 1:200) # grid is created in the form of a dataframe with x and y vectors
names(xy)<-c('x','y') # giving names to the variables

# Creating gsat objects

rf1<-gstat(formula=z~1,locations=~x+y,dummy = T,beta=c(1,0,0), model=vgm(psill=0.025, range=5, model='Exp'), nmax=20)  # dummy=T treats this as a unditional simulation
rf2<-gstat(formula=z~1,locations=~x+y,dummy = T,beta=c(4,0,0), model=vgm(psill=0.025, range=10, model='Exp'), nmax=20)  # dummy=T treats this as a unditional simulation

# Splitting the computational grid into two

rows<-nrow(xy)
xy_shift <- expand.grid(60:90, 75:100)
names(xy_shift)<-c('x','y')

library(dplyr) # for antijoin
xy1<-xy[1:(rows/2),]
xy1<-anti_join(xy1, xy_shift, by = c("x","y")) # creating the irregular boundary
xy2<-rbind(xy[(rows/2+1):rows,],xy_shift)

# Simulation

yy1<- predict(rf1, newdata=xy1, nsim=1) # random field 1
yy2<- predict(rf2, newdata=xy2, nsim=1) # random field 2

yy<-rbind(yy1,yy2)

# Plotting the field

library(sp)
gridded(yy) = ~x+y
spplot(obj=yy[1])

## Code ends=====================================================================

-----Original Message-----
From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of Rathore, Saubhagya Singh
Sent: Wednesday, February 15, 2017 12:37 PM
To: r-help at r-project.org
Subject: [R] R version 3.3.2, Windows 10 -- gstat.predict() function often return NaN values (GSTAT Package)

______________________________________________
R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Expected Output.png
Type: image/png
Size: 10081 bytes
Desc: Expected Output.png
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20170216/5fb8244d/attachment.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Undesired Output.png
Type: image/png
Size: 7668 bytes
Desc: Undesired Output.png
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20170216/5fb8244d/attachment-0001.png>


More information about the R-help mailing list