# [R-sig-Geo] question about simulating patchy landscapes [solved]

Steve_Friedman at nps.gov Steve_Friedman at nps.gov
Fri Oct 3 21:37:36 CEST 2008

```Dylan,

You might also want to explore cellular based models.

Here is an example, somebody else posted this to the R site but I don't
recall who to give credit to.
This a patch model which considers changes to the "landscape" over time.

Have fun.

library(simecol)

CA <- new("gridModel", main = function(time, init, parms) {
z <- init
nb <- eightneighbors(z)
pgen <- 1 - (1-parms\$pbirth)^nb
zgen <- ifelse(z == 0 &
runif(z) < pgen, 1, 0)
zsurv <- ifelse(z >= 1 &
runif(z) < (1 - parms\$pdeath), z + 1, 0)
zgen + zsurv
},
parms = list(pbirths = 0.02, pdeath = 0.01),
times = c(from = 1, to = 50, by = 1),
init = matrix(0, nrow = 30, ncol = 30),
solver = "iteration"
)

init(CA)[18:22, 18:22] <- 1

data(CA, package = "simecol")

times(CA)
times(CA) <- c(to = 1000)
CA <- sim(CA)
plot(CA)

Steve Friedman Ph. D.
Spatial Statistical Analyst
Everglades and Dry Tortugas National Park
950 N Krome Ave (3rd Floor)

Office (305) 224 - 4282
Steve_Friedman at nps.gov

Dylan Beaudette
<dylan.beaudette@
gmail.com>                                                 To
Sent by:                  r-sig-geo at stat.math.ethz.ch
r-sig-geo-bounces                                          cc
@stat.math.ethz.c
h                                                     Subject
simulating patchy landscapes
10/03/2008 10:49          [solved]
AM MST

dylan.beaudette at g
mail.com

On Friday 03 October 2008, Dylan Beaudette wrote:
> On Thursday 25 September 2008, Edzer Pebesma wrote:
> > demo(uisim)
>
> This seems work work with the demo code, but not with another example
using
> my own data:
>
> # setup
> library(gstat)
> library(spgrass6)
>
> # load GRASS region settings
> G <- gmeta6()
> grd <- gmeta2grd()
>
> # make a new grid from GRASS region
> new_data <- SpatialGrid(grd)
>
>
> # works fine:
> var.model <- vgm(psill=10, model="Exp", range=1000)
> sim <- predict(gstat(formula=z~1, dummy=TRUE, beta=0, model=var.model,
> nmax=20), newdata = new_data, nsim = 1)
>
> # does not work -- produces a field of '0' values
> sim <- predict(gstat(formula=z~1, dummy=TRUE, beta=0, model=var.model,
> nmax=20), newdata = new_data, nsim = 1, indicators=TRUE)
>

Oops. It looks like my second example works when I set 'beta=0.5'. Probably
my
lack of experience in this field that caused me to overlook the importance
of
this parameter. Anyone care to explain why?

Cheers,

Dylan

> # any ideas on why UISIM works in the demo, and not in my examples? I
have
> noticed that the syntax is slightly different in the demo, could this be
> the cause:
>
> # prediction grid:
> data(meuse.grid)
> gridded(meuse.grid) = ~x+y
>
> # define variable as dummy data
> v = vgm(.25, "Sph", 900)
> g = gstat(NULL, "var1", x~1, beta = .5, nmax = 20, model = v, dummy =
TRUE)
>
> # simulation of a single variable
> out = predict(g, meuse.grid, nsim = 20, indicators = TRUE)
>
> Thanks,
> Dylan

--
Dylan Beaudette
Soil Resource Laboratory
http://casoilresource.lawr.ucdavis.edu/
University of California at Davis
530.754.7341

_______________________________________________
R-sig-Geo mailing list
R-sig-Geo at stat.math.ethz.ch
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

```