# cal.stat: Calculate statistics for FGM In FGM: Floating Grid Method

## Description

Calculates a set of values for a particular statistic or sets of observations, typically for observed values and multiple sets of randomized observations.

## Usage

 `1` ```cal.stat(rand,marks,FUN=mean, ...) ```

## Arguments

 `rand` A list for which the elements are either sets of randomized variables or randomized index values. `rand` can, but not necessarily is, the output of the function `fgrand`. `marks` Should either be left empty, be a vector or a matrix. When `rand` contains randomized variables `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 used in `rand`. 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 used in `rand`. `FUN` Any function used to calculate the statistic of interest (e.g. `mean`, `median`, `var`, `sd`). Default for `FUN` is `mean`. `...` Optional arguments to `FUN`. A particular useful one if dealing with missing values and using one of the functions from `base` is `na.rm=TRUE`.

## Details

`cal.stat` is designed to calculate statistics for spatial explicit data for which randomized data sets are generated with `fgrand`.

## Value

`cal.stat` returns a vector of statistics. If `rand` is the output of `fgrand` and `add.obs=TRUE`, the first value is the statistic for the observed data and the rest for randomizations.

## 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 31 32 33 34``` ```#### Example for fgrand ## 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) ```