Learn R Programming

fgpt (version 2.3)

fgstat: Calculate statistics for FGPT

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

fgstat(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 fgperm.
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.

Value

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

Details

fgstat is designed to calculate statistics for spatial explicit data for which randomized data sets are generated with fgperm.

References

Reinder Radersma & Ben C. Sheldon, 2015. A new permutation technique to explore and control for spatial autocorrelation. Submitted

Examples

Run this code

#### Example for fgrand

## 200 random geographical locations
xy <- array(runif(400,0,2), dim=c(200,2))

## run fgperm to produce 99 randomizations for scale 1
test <- fgperm(xy, scale=1, iter=99, add.obs=TRUE) 

## run fgperm to produce 99 bootstraps for scale 1
test <- fgperm(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 <- fgstat(test,trait,mean)

## calculate means
calc <- fgstat(test,trait,mean, na.rm=TRUE)

## plot means
hist(calc)
abline(v=calc[1], col="red", lwd=2)
  

  

Run the code above in your browser using DataLab