# Estimates the rate of false positives in a fixed difference analysis

`gl.fdsim.Rd`

This function takes two populations and generates allele frequency profiles for them. It then samples an allele frequency for each, at random, and estimates a sampling distribution for those two allele frequencies. Drawing two samples from those sampling distributions, it calculates whether or not they represent a fixed difference. This is applied to all loci, and the number of fixed differences so generated are counted, as an expectation. The script distinguished between true fixed differences (with a tolerance of delta), and false positives. The simulation is repeated a given number of times (default=1000) to provide an expectation of the number of false positives, given the observed allele frequency profiles and the sample sizes. The probability of the observed count of fixed differences is greater than the expected number of false positives is calculated.

## Usage

```
gl.fdsim(
x,
poppair,
obs = NULL,
sympatric = FALSE,
reps = 1000,
delta = 0.02,
verbose = NULL
)
```

## Arguments

- x
Name of the genlight containing the SNP genotypes [required].

- poppair
Labels of two populations for comparison in the form c(popA,popB) [required].

- obs
Observed number of fixed differences between the two populations [default NULL].

- sympatric
If TRUE, the two populations are sympatric, if FALSE then allopatric [default FALSE].

- reps
Number of replications to undertake in the simulation [default 1000].

- delta
The threshold value for the minor allele frequency to regard the difference between two populations to be fixed [default 0.02].

- verbose
Verbosity: 0, silent or fatal errors; 1, begin and end; 2, progress log; 3, progress and results summary; 5, full report [default 2].

## Value

A list containing the following square matrices [[1]] observed fixed differences; [[2]] mean expected number of false positives for each comparison; [[3]] standard deviation of the no. of false positives for each comparison; [[4]] probability the observed fixed differences arose by chance for each comparison.

## Author

Custodian: Arthur Georges (Post to https://groups.google.com/d/forum/dartr)

## Examples

```
fd <- gl.fdsim(testset.gl[,1:100],poppair=c('EmsubRopeMata','EmmacBurnBara'),
sympatric=TRUE,verbose=3)
#> Starting gl.fdsim
#> Processing genlight object with SNP data
#> Populations EmsubRopeMata vs EmmacBurnBara [sympatric]
#> Sample sizes: 11 5
#> No. of loci: 15
#> Calculating false positive rate with 1000 replications. Please be patient
#> Threshold minor allele frequency for generating a false positive: 0.02
#> Estimated mean count of false positives: 0
#> Estimated SD of the count of false positives: 0
#> Prob that observed count of 3 are false positives: 0
#> Completed: gl.fdsim
#>
```