fgrand: Floating Grid randomizations In FGM: Floating Grid Method

Description

The `fgrand` function produces sets of randomized observations or indices using the Floating Grid Method, which is a method for spatially restricted randomizations. `fgrm` offers additional functionality to manipulate observations within grid cells, for instance observations could be scaled with grid cells.

Usage

 ```1 2``` ```fgrand(xy,z=1:dim(xy), scale, group=1, iter=999, ratio=1, FUN=fyshuffle, ..., add.obs=FALSE, as.matrix=FALSE) fgrm(xy,z=1:dim(xy), scale, group=1, iter=999, ratio=1, FUN=fyshuffle, FUN.mani, ..., marks, pass.rand=FALSE) ```

Arguments

 `xy` Two-column matrix with the geographical locations of observations. `z` Vector with the observations. If left empty `z` will be a vector of indices from 1 to the total number of geographical locations. Those indices can be later be used for calculating statistics with `cal.stat`. `scale` Value indicating the spatial scale of the randomizations. `scale` should be positive. `group` Optional group membership of observations. `group` can be used when observations are for instance collected over multiple years. `iter` Number of iterations for every grid cell size. Default is 999. Note that in order to produce a probability an observation is assigned to any of the geographical locations is a negative function of the distance between its original and assigned location many iterations are needed. `ratio` The ratio between the sides of the grid cells. Default is 1. `FUN` Function to perform randomizations. Note that the function must be able to randomize one value, which is for instance a issue if using `sample`. For solutions see the Details and Examples of `sample`. The default is the Fisher-Yates shuffle `fyshuffle`. `FUN.mani` Function to perform manipulations of the observations within grid cells. This functionality should be used together with `cal.stat` to calculate specific statistics. `...` Optional arguments to `FUN` and `FUN.mani`. `marks` Should either be left empty, be a vector or a matrix. When `z` contains observations `marks` should be left empty. If the randomization procedure is for testing one variable, `marks` should be a vector for which the row numbers correspond to the index values in `z`. If the randomization procedure is for testing two variables (for instance the distance between them), `marks` should be a matrix for which the row numbers correspond to the index values in `z`. `add.obs` If `TRUE` the first set in the output will be the observed values. `as.matrix` If `TRUE` the output will be a matrix. If `FALSE` the output will be a list, which is needed when analyzing the data with `cal.stat`.

Details

Before using those functions please read the reference or vignette. Alternatively use the more user-friendly function `fgm`. If there are missing values for the observations, leave `z` empty and enter the observations as `marks` in the `cal.stat` function.

Value

`fgrand` returns a `list` or a `matrix`, depending on the setting of argument `as.matrix`.

Author(s)

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30``` ```## 200 random geographical locations xy <- array(runif(400,0,2), dim=c(200,2)) ## run fgrand to produce 99 randomizations for scale 1 test <- fgrand(xy, scale=1, iter=99, add.obs=TRUE) ## run fgrand to produce 99 bootstraps for scale 1 test <- fgrand(xy, scale=1, iter=99, FUN=function(x){x[sample.int(length(x),replace=TRUE)]}, add.obs=TRUE) ## 200 times 200 random distances (e.g. genetic relatedness between mated pairs) trait <- array(rnorm(200*200,0.6,0.1), dim=c(200,200)) ## make the observed pairs more alike diag(trait) <- diag(trait)+0.02 ## make two rows and two colums empty trait[,3] <- NA trait[,50] <- NA trait[6,] <- NA trait[12,] <- NA ## calculate means; will give NAs because there are missing values calc <- cal.stat(test,trait,mean) ## calculate means calc <- cal.stat(test,trait,mean, na.rm=TRUE) ## plot means hist(calc) abline(v=calc, col="red", lwd=2) ```