[R-sig-Geo] random number generation

Forrest Stevens r-sig-geo at forreststevens.com
Sat Nov 14 15:44:29 CET 2015


Hi Leila, to generate spatially autocorrelated data, which I think is what
you're trying to get at, I use the gstat package.  You need to decide on
the geostatistical model that describes the nature of your correlation
structure, and then simulating a field is pretty easy:

library(gstat)

## Define your grid size:
xy <- expand.grid(1:100, 1:100)
names(xy) <- c('x','y')

## Generate geostatistical model:
vario_model <- vgm(psill=0.025, range=5, model='Exp')
geo_model <- gstat(formula=z~1, locations=~x+y, dummy=T, beta=1,
model=vario_model, nmax=20)

## Generate random field based on grid and model, visualize:
set.seed(1001) ## For reproducibiliity
rf <- predict(geo_model, newdata=xy, nsim=1)
image( rf )


Hopefully you found this helpful. When I was learning this process, I found
the illustrations in this blog post very helpful for different types of
geostatistical features:

http://santiago.begueria.es/2010/10/generating-spatially-correlated-random-fields-with-r/


Good luck,
Forrest

--
Forrest R. Stevens
Department of Geography & Geosciences
University of Louisville
www.forreststevens.com/teaching

On Sat, Nov 14, 2015 at 3:09 AM leila zamani <leila.zamani90 at gmail.com>
wrote:

> Hi every one,
>
> I'm new to R. I read about R and search all the packages but I couldn't
> find the package that I want. I want to generate 2D (matrices) random
> numbers that have correlation between them. One of my friends said that R
> has a function in geor like rand...(spherical (correlation
> coefficient=0.5)), but I read all packages with geo,like
> geor,geoRlgm,georob and etc, but I didn't find this! Consider this
> situation: we have a big square. We split it to smaller squares. Each
> square points values change independently from other squares, but in each
> square,values change proper to each other with a coefficient. For example a
> point in a square number 1 increase 1 unit, the point near to this will
> change too,but properly to the coefficient. So we give the coefficients of
> all small squares and the function give me back the random numbers in each
> square, that these numbers in each square are correlated with this
> coefficient. My search is on process variation & I need random numbers.
> Others told me that it's in geoR, but I can't find the function with these
> features. Can you help me? Many Thanks.
>
>         [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list