RFoptions(seed=0) ## *ANY* simulation will have the random seed 0; set
## RFoptions(seed=NA) to make them all random again
## define the model:
model <- RMtrend(mean=0.5) + # mean
RMstable(alpha=1, var=4, scale=10) +
# see help("RMstable")
# for additional arguments
RMnugget(var=1) # nugget
#############################################################
## Plot of covariance structure
plot(model, xlim=c(0, 30))
plot(model, xlim=c(0, 30), fct.type="Variogram")
plot(model, xlim=c(-10, 20), fct.type="Variogram", dim=2)
#############################################################
## Plot of simulation results
## define the locations:
from <- 0
step <- .1
len <- if (interactive()) 50 else 5 ## nicer, but also time consuming if len <- 200
x1D <- GridTopology(from, step, len)
x2D <- GridTopology(rep(from, 2), rep(step, 2), rep(len, 2))
x3D <- GridTopology(rep(from, 3), rep(step, 3), rep(len, 3))
## 1-dimensional
sim1D <- RFsimulate(model = model, x=x1D, n=6)
plot(sim1D, nmax=4)
## 2-dimensional
sim2D <- RFsimulate(model = model, x=x2D, n=6)
plot(sim2D, nmax=4)
plot(sim2D, nmax=4, col=terrain.colors(64),
main="My simulation", xlab="my_xlab")
## 3-dimensional
model <- RMmatern(nu=1.5, var=4, scale=2)
sim3D <- RFsimulate(model = model, x=x3D)
plot(sim3D, MARGIN=c(2,3), MARGIN.slices=1, n.slices=4)
#############################################################
## empirical variogram plots
x <- c(0,.05,200)
bin <- seq(from=0, by=.2, to=3)
model <- RMexp()
X <- RFsimulate(x=cbind(x), model=model, grid=TRUE)
ev1 <- RFempiricalvariogram(data=X, bin=bin)
plot(ev1)
model <- RMexp(Aniso = cbind(c(10,0), c(0,1)))
X <- RFsimulate(x=cbind(x,x), model=model, grid=TRUE)
ev2 <- RFempiricalvariogram(data=X, bin=bin, phi=3)
plot(ev2, model=list(Exp = model))
#############################################################
## plot Fitting results
x <- c(0,.1,20)
model <- RMexp(Aniso = cbind(c(10,0), c(0,1)))
X <- RFsimulate(x=cbind(x,x), model=model, grid=TRUE)
fit <- RFfit(~RMexp(Aniso=matrix(nc=2, nr=2, NA)), data=X, fit.nphi = 2)
plot(fit)
#############################################################
## plot Kriging results
model <- RMwhittle(nu=1.2, scale=2)
x <- runif(200, max=step*len/2)
y <- runif(200, max=step*len/2) # 200 points in 2 dimensional space
sim <- RFsimulate(model = model, x=x, y=y)
interpolate <- RFinterpolate(model=model, x=x2D, data=sim)
plot(interpolate)
plot(interpolate, sim)
#############################################################
## plotting vector-valued results
model <- RMdivfree(RMgauss(), scale=4)
x <- y <- seq(-10,10, if (interactive()) 0.5 else 5)
simulated <- RFsimulate(model = model, x=x, y=y, grid=TRUE, n=1)
plot(simulated)
plot(simulated, select.variables=list(1, 1:3, 4))
#############################################################
## options for the zlim argument
model <- RMdelay(RMstable(alpha=1.9, scale=2), s=c(0, 4)) +
RMdelay(RMstable(alpha=1.9, scale=2), s=c(4, 0))
simu <- RFsimulate(model, x, y, grid=TRUE)
plot(simu, zlim=list(data=cbind(c(-6,2), c(-2,1)), var=c(5,6)))
plot(simu, zlim=cbind(c(-6,2), c(-2,1)))
plot(simu, zlim=c(-6,2))
plot(simu, zlim="joint")
FinalizeExample()
Run the code above in your browser using DataLab