[R-sig-Geo] Random number seed and unconditional simulation

Nick Hamm nick at hamm.org
Tue Nov 17 13:09:41 CET 2009


Dear all

I have a question about the random number seeding in R.

I want to simulate several random fields.  Each RF should have zero
nugget, the same sill but a different range (e.g., 100x100, range: 1
-> 30).  Let's stick with the Gaussian case for now.  I use the
following code

################################
require(geoR)

sigma2 = 10 # Set the sill
s2 = data.frame(phi=1, s2=1, s=1) # phi is the range

for(phi in 1:30)
{

   set.seed(234)
   sim1 = grf(100*100, grid="reg", nx=100, ny=100, xlims=c(1,100),
ylims=c(1,100), cov.model="exponential", cov.pars=c(sigma2, phi),
messages=FALSE)

   image(sim1)
   s2[phi,] = c(phi, var(sim1$data), sd(sim1$data))

}

# Plot the range against  the a priori variance.
plot(s2$phi, s2$s2, ylim=c(0,15))
abline(v=23)

############################

Note that, for each simulation, I use the same random number seed.
This results in a series of images that look like they have the same
"starting point" (sorry, this is not very technical), but with
progressively more spatial structure.  Note that ther is a sudden
change at phi=23.  The logic for using the same random number seed is
that we want to simulate a series of RFs where the differentiating
factor is the range (phi) and not something else.  Hence the observed
similar patterns, but with increasing spatial structure, is a useful
feature.

I have two questions

1) Is this last point true?  What is the effect of fixing every
argument to the function (including the random number seed) and just
varying one (in this case the range (phi))?  Note that Diggle and
Ribeiro do something similar in their examples at the end of the help
for GRF (see below).

2) Why do I get the sudden change at phi=23?  This also occurs for
other random number seeds (e.g, 230, 231, 234, 456, 5683432).  The
change occurs at the same point (phi=23).  Note that there is no
sudden change if I choose the spherical model rather than the
exponential.

If anybody has any thoughts, I would be interested.

best wishes

Nick




Here is the example given in the grf(geoR) help.

## 1-D simulations using the same seed and different noise/signal ratios
##
set.seed(234)
sim11 <- grf(100, ny=1, cov.pars=c(1, 0.25), nug=0)
set.seed(234)
sim12 <- grf(100, ny=1, cov.pars=c(0.75, 0.25), nug=0.25)
set.seed(234)
sim13 <- grf(100, ny=1, cov.pars=c(0.5, 0.25), nug=0.5)
##
par.ori <- par(no.readonly = TRUE)
par(mfrow=c(3,1), mar=c(3,3,.5,.5))
yl <- range(c(sim11$data, sim12$data, sim13$data))
image(sim11, type="l", ylim=yl)
image(sim12, type="l", ylim=yl)
image(sim13, type="l", ylim=yl)
par(par.ori)



More information about the R-sig-Geo mailing list