# [R] grid with random or clustered distribution

Sarah Goslee sarah.goslee at gmail.com
Wed Sep 9 15:11:28 CEST 2015

```You can use gstat, as in:
https://www.researchgate.net/publication/43279659_Behavior_of_Vegetation_Sampling_Methods_in_the_Presence_of_Spatial_Autocorrelation

If you need more detail, I can dig up the code.

Sarah

On Wed, Sep 9, 2015 at 8:49 AM, SH <emptican at gmail.com> wrote:
> Hi R-users,
>
> I hope this is not redundant questions.  I tried to search similar threads
> relevant to my questions but could not find.  Any input would be greatly
> appreciated.
>
> I want to generate grid with binary values (1 or 0) in n1 by n2 (e.g., 100
> by 100 or 200 by 500, etc.) given proportions of 1 and 0 values (e.g., 1,
> 5, or 10% of 1 from 100 by 100 grid).  For clustered distributed grid, I
> hope to be able to define cluster size if possible.  Is there a simple way
> to generate random/clustered grids with 1 and 0 values with a
> pre-defined proportion?
>
> So far, the function "EVariogram" in the "CompRandFld" package generates
> clustered grid with 1 and 0.  Especially, the example #4 in the
> "EVariogram" function description is a kind of what I want. Below is the
> slightly modified code from the original one.  However, the code below
> can't control proportion of 1 and 0 values and complicated or I have no
> idea how to do it.  I believe there may be easies ways to
> generate random/clustered grids with proportional 1 and 0 values.
>
> Thank you very much in advance,
>
> Steve
>
>
> library(CompRandFld)
> library(RandomFields)
>
> x0 <- seq(1, 50, length.out=50)
> y0 <- seq(1, 60, length.out=60)
> d <- expand.grid(x=x0, y=y0)
> dim(d)
> x <- d\$x
> y <- d\$y
> # Set the model's parameters:
> corrmodel <- 'exponential'
> mean <- 0
> sill <- 1
> nugget <- 0
> scale <- 3
> set.seed(1221)
> # Simulation of the Binary-Gaussian random field:
> data <- RFsim(x, y, corrmodel="exponential", model="BinaryGauss",
>               param=list(mean=mean,sill=sill,scale=scale,nugget=nugget),
>               threshold=0)\$data
> # Empirical lorelogram estimation:
> fit <- EVariogram(data, x, y, numbins=20, maxdist=7, type="lorelogram")
> # Results:
> plot(fit\$centers, fit\$variograms, xlab='Distance', ylab="Lorelogram",
>      ylim=c(min(fit\$variograms), max(fit\$variograms)),
>      xlim=c(0, max(fit\$centers)), pch=20, main="Spatial Lorelogram")
> # Plotting
> plot(d, type='n')
> text(d, label=data)
>

--
Sarah Goslee
http://www.functionaldiversity.org

```
{"ft_lang_label":"__label__en","ft_lang_prob":0.6970474,"math_prob":0.6599077,"size":2497,"snap":"2020-10-2020-16","text_gpt3_token_len":776,"char_repetition_ratio":0.09105495,"word_repetition_ratio":0.0050125313,"special_character_ratio":0.31878254,"punctuation_ratio":0.17107943,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9878186,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-02-23T21:04:44Z\",\"WARC-Record-ID\":\"<urn:uuid:0d278df9-d828-44be-a86b-0ba39bc6af25>\",\"Content-Length\":\"6190\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:1e0d7e98-b156-48be-bb87-897881ec2219>\",\"WARC-Concurrent-To\":\"<urn:uuid:6c88531d-015e-4051-8bb9-e59d82c14199>\",\"WARC-IP-Address\":\"129.132.119.195\",\"WARC-Target-URI\":\"https://stat.ethz.ch/pipermail/r-help/2015-September/432009.html\",\"WARC-Payload-Digest\":\"sha1:BNVZ65PTK6JA3CLB6PVQO3ISXFA4OK45\",\"WARC-Block-Digest\":\"sha1:G45BWGYNYT2JQIL7USO2TE634Z54HRVS\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-10/CC-MAIN-2020-10_segments_1581875145839.51_warc_CC-MAIN-20200223185153-20200223215153-00162.warc.gz\"}"}