Title: | Relative Simulator |
---|---|
Description: | A set of tools to explore the behaviour statistics used for forensic DNA interpretation when close relatives are involved. The package also offers some useful tools for exploring other forensic DNA situations. |
Authors: | James M. Curran |
Maintainer: | James M. Curran <[email protected]> |
License: | GPL (>= 2) |
Version: | 1.0.0 |
Built: | 2025-03-06 04:18:20 UTC |
Source: | https://github.com/jmcurran/relsim |
This function takes every pair of profiles in a database of profiles and computes
the likelihood ratio (LR) for a specific relationship given by nCode
. That means
there will be LRs computed for N profiles.
allPairsLR(Profiles, listFreqs, nCode)
allPairsLR(Profiles, listFreqs, nCode)
Profiles |
an integer vector of stacked profiles representing the database. This vector has |
listFreqs |
is a set of allele frequencies representing a particular multiplex. The function assumes that that loci in the profiles
are in the same order as the loci in this list. The data structure is a |
nCode |
if |
a NumericVector
containing the LRs. They are stored in sequential order so if for example there were three
profiles, then there are 3 possible LRs, and the result vector would contain the LRs for the profile pairs (1, 2),
(1, 3), and (2, 3).
James Curran
data("USCaucs") N = 600 profs = relSim:::.randomProfiles(USCaucs$freqs, N) system.time({lr = relSim:::allPairsLR(profs, USCaucs$freqs, 1)}) plot(density(log10(lr))) mean(lr > 1) ## estimate the probability that the LR is incorrectly above 1
data("USCaucs") N = 600 profs = relSim:::.randomProfiles(USCaucs$freqs, N) system.time({lr = relSim:::allPairsLR(profs, USCaucs$freqs, 1)}) plot(density(log10(lr))) mean(lr > 1) ## estimate the probability that the LR is incorrectly above 1
Generate N pairs with a given relationship, calculate the LR for sibs, parent-child and the number of matching alleles and count the number of pairs that meet the threshold criteria.
blockSim( N, Freqs, rel = "UN", ibsthresh = NULL, kithresh = NULL, code = 1, falseNeg = TRUE, BlockSize = N/10, showProgress = FALSE )
blockSim( N, Freqs, rel = "UN", ibsthresh = NULL, kithresh = NULL, code = 1, falseNeg = TRUE, BlockSize = N/10, showProgress = FALSE )
N |
The number of iterations to carry out |
Freqs |
A list containing two lists labelled loci and freqs. The second list is a list of vectors containing the allele frequencies of each allele at each locus in the multiplex. |
rel |
generate unrelated ( |
ibsthresh |
A vector of one or more IBS thresholds |
kithresh |
A vector of one or more KI/LR thresholds |
code |
A code from 1 to 6 which dictates the events that will be counted.
|
falseNeg |
if TRUE then the number of results that DO NOT satisfy the conditions are counted, otherwise the number of results DO satisfy the conditions are counted |
BlockSize |
Sets the number of random profiles to be generated in each
iteration. By default the block size is set to 10 percent of the total
sample size. It is unclear whether the procedure is more efficient if a
bigger percentage of the total is used. Users must take care to make sure
that the block size evenly divides |
showProgress |
If |
This function is used for fast accurate estimation of false positive and false negative rates. It achieves part of its speed by block exectution in C, and part by not saving the LR or IBS results. It can do 1 billion iterations in about an hour.
A vector containing the number of profile pairs that satisfied the threshold conditions
James M. Curran
sim
## not run ## this counts the number of unrelated pairs that are falsely identified ## as siblings using the policy that there are 16 or more matching ## alleles, and the LR/KI is greater than 100,000 ## this is a very rare event for the FBI Caucasians with a frequency of ## about 4-5 times in 10 million pairs ## Not run: data(fbiCaucs) N = 1e8 ki = 1e5 ibs = 16 code = 5 BlockSize = 1e6 blockSim(N, fbiCaucs, rel = "UN", ibsthresh = ibs, kithresh = ki, code = code, falseNeg = FALSE, BlockSize = BlockSize) ## End(Not run)
## not run ## this counts the number of unrelated pairs that are falsely identified ## as siblings using the policy that there are 16 or more matching ## alleles, and the LR/KI is greater than 100,000 ## this is a very rare event for the FBI Caucasians with a frequency of ## about 4-5 times in 10 million pairs ## Not run: data(fbiCaucs) N = 1e8 ki = 1e5 ibs = 16 code = 5 BlockSize = 1e6 blockSim(N, fbiCaucs, rel = "UN", ibsthresh = ibs, kithresh = ki, code = code, falseNeg = FALSE, BlockSize = BlockSize) ## End(Not run)
(
)This function simulates a population with an approximate level of population substructure. This is achieved by subdividing a population into equal sized subpopulations and allowing them to breed within themselves for
generations, where is
the number of individuals in each subpopulation. This will produce a
population with an estimated coancestry coefficient approximately equal to
breedFst(Freqs, theta = 0.01, N = 10000, ns = 10, DNAtools = FALSE)
breedFst(Freqs, theta = 0.01, N = 10000, ns = 10, DNAtools = FALSE)
Freqs |
A list with an element, |
theta |
A desired level of inbreeding, where |
N |
Total population size |
ns |
The number of subpopulations. |
DNAtools |
If |
An object of class 'population' which is a list with the following elements
profiles
- a vector of profiles where the
level of inbreeding is approximately equal to
nProfiles
- the total number of individuals in the population
nSubpops
- the number of sub-populations in the population
nLoci
- the number of loci each individual is typed at
theta
- the desired level of substructure in the population. The
actual value will be near to this.
Freqs
- a Freq object
representing the ancestral frequencies of the population
James M. Curran
data(USCaucs) pop = breedFst(USCaucs)
data(USCaucs) pop = breedFst(USCaucs)
valuesThis procedure uses the method of Weir and Cockerham to estimate
(
) for a population with substructure
calcFst(Pop, subPopIdx = NULL)
calcFst(Pop, subPopIdx = NULL)
Pop |
An object type 'population' |
subPopIdx |
If this vector is not null, then it must consist of
|
A vector of length with locus-wise
values and an overall
value for the
population
James M. Curran
Weir, B.S., Genetic Data Analysis II, (1996) p.173–179, Sinauer, Sunderland, MA.
breedFst
data(USCaucs) p = breedFst(USCaucs) fst = calcFst(p) fst
data(USCaucs) p = breedFst(USCaucs) fst = calcFst(p) fst
,
, and
valuesThis procedure uses the method of Weir and Cockerham to estimate
,
, and
for a population with known substructure
calcFStats(Pop, subPopIdx = NULL)
calcFStats(Pop, subPopIdx = NULL)
Pop |
An object type 'population' |
subPopIdx |
If this vector is not null, then it must consist of
|
A vector of length with locus-wise
values and an overall
value for the
population
James M. Curran
Weir, B.S., Genetic Data Analysis II, (1996) p.173–179, Sinauer, Sunderland, MA.
breedFst
data(USCaucs) set.seed(123) p = breedFst(USCaucs) fstats = calcFStats(p) fstats
data(USCaucs) set.seed(123) p = breedFst(USCaucs) fstats = calcFStats(p) fstats
Checks whether a list of frequencies at a series of genetic loci both sum to one and lie between 0 and 1.
checkFreqs(Freqs)
checkFreqs(Freqs)
Freqs |
A list containg elements |
If a locus fails to sum to one, or there are alleles which fall below zero or above one, then a warning message will be returned for each item in error.
James M. Curran
normalizeFreqs
data(fbiCaucs) checkFreqs(fbiCaucs) ## induce an error fbiCaucs$freqs[[1]] = runif(10) checkFreqs(fbiCaucs)
data(fbiCaucs) checkFreqs(fbiCaucs) ## induce an error fbiCaucs$freqs[[1]] = runif(10) checkFreqs(fbiCaucs)
This function is used to calcalate the various tables in the work of Ge et al. and Balding et al. Specifically it can be used to calculate the false positive rate for unrelated pairs being identified as full-sibs or parent-child pairs under differing levels of IBS or KI (or both) thresholds. It can also be used to calculate the false negative rates for full-sib, or parent-child, pairs being identified as unrelated, again with differing levels of IBS, KI or both.
errorRate( simResults, bIBS = TRUE, bKI = FALSE, rel = "UN", IBSthresh = 14:17, KIthresh = c(1000, 10000, 1e+05, 1e+06), nLoci = 13 )
errorRate( simResults, bIBS = TRUE, bKI = FALSE, rel = "UN", IBSthresh = 14:17, KIthresh = c(1000, 10000, 1e+05, 1e+06), nLoci = 13 )
simResults |
A data.frame with three columns labelled sib, pc and ibs.
This will usually be obtained from a call to |
bIBS |
If |
bKI |
If |
rel |
The relationship used in the simulation. Must be one of 'UN', 'FS' or 'PC'. |
IBSthresh |
A vector of IBS values that can be used to classify the results as being related (or not). |
KIthresh |
A vector of KI threshold values that can be used to classify the results as being related (or not). |
nLoci |
The number of loci being used in the multiplex. This dictates the upper bound on the IBS values. |
A vector (or a two-column matrix) of false negative or false positive rates. If the relationship is 'UN' then false positive rates are returned for parent-child and full-sibs, with parent-child being in column 1 and full-sibs in column 2. If the relationship is 'PC' then the false negative rate is returned for parent-child pairs, and if it is 'FS' then the false negative rate for full-sibs.
James M. Curran
sim, readResults
## not run ## Not run: data(fbiCaucs) unrel = sim(10000) errorRate(unrel) ## End(Not run)
## not run ## Not run: data(fbiCaucs) unrel = sim(10000) errorRate(unrel) ## End(Not run)
Calculates the exclusion power
at each locus for a set of allele frequencies.
exclusionPower(Freqs)
exclusionPower(Freqs)
Freqs |
A list containing two vectors and a list, called loci, counts, and freqs. The elements of loci are the loci present in the multiplex. The elements are freqs a vectors of allele frequencies for the locus. The elements of counts are irrelevant here. |
The exclusion power for each locus.
James M. Curran
NRC II, Evaluation of Forensic Evidence, (1996), p.96, National Academy Press.
data(USCaucs) ep(USCaucs) ## get the multiplex wide exclusion power 1 - prod(1-ep(USCaucs))
data(USCaucs) ep(USCaucs) ## get the multiplex wide exclusion power 1 - prod(1-ep(USCaucs))
This function searches a database of profiles for either a sibling or a child
famSearch(profiles, siblings, children, listFreqs, step)
famSearch(profiles, siblings, children, listFreqs, step)
profiles |
an integer vector of stacked profiles representing the database. This vector has |
siblings |
an integer vector of stacked profiles representing the siblings of the profiles in database.
The first entry is a sibling of the first entry in |
children |
an integer vector of stacked profiles representing the children of the profiles in database.
The first entry is a child of the first entry in |
listFreqs |
is a set of allele frequencies representing a particular multiplex. The function assumes that that loci in the profiles
are in the same order as the loci in this list. The data structure is a |
step |
A step size for progress reporting, i.e. print out progress every |
a List
containing two dataframes, one called sibs
and one called children
. Each dataframe has results from searching for
either the sibling or the child in the database. For each entry there is a record of which profile gave the highest LR (and its value),
and the position of the actual sibling or parent/child in the database (and its respective LR).
James Curran
This data structure
This data set is a list which has two sub-lists. The lists are named loci and freqs. loci is a vector of the 13 CODIS STR locus names. freqs is a list of 13 vectors, each vector contains the allele frequencies published for US Caucasians in Budowle et al. (2001).
James M. Curran
Budowle B, Shea B, Niezgoda S, Chakraborty R. (2001), CODIS STR loci data from 41 sample populations, J. Forensic Sci. 46:453-89.
USCaucs
data(fbiCaucs) names(fbiCaucs) fbiCaucs$loci names(fbiCaucs$freqs) fbiCaucs$freqs[[1]] names(fbiCaucs$freqs[[1]]) fbiCaucs$freqs[[1]][1]
data(fbiCaucs) names(fbiCaucs) fbiCaucs$loci names(fbiCaucs$freqs) fbiCaucs$freqs[[1]] names(fbiCaucs$freqs[[1]]) fbiCaucs$freqs[[1]][1]
Retreives the Budowle and Moretti (1999) and compiles the allele frequency
tables needed for the other parts of this package such as sim
.
fetchBMdata(url = NULL, id = NULL)
fetchBMdata(url = NULL, id = NULL)
url |
- the location of the webpage this data is stored on. If
|
id |
- the id of the HTML element where the data is stored on the
webpage. If |
The first three populations have data on 20 loci, the second three on 13 loci. The missing values (0's in the raw data) have been dropped and are not used in calculating the frequencies. This function will not work if you are not connected to the internet, or access to the internet is blocked.
A list consisting of six elements corresponding to the six
populations detailed in the data set. Each of the list elements is a list in
itself with three further elements named loci
, profiles
and freqs
.
loci
is a vector of the 13-20 STR locus names. freqs
is a list of 13-20
vectors, each vector contains the allele frequencies. profiles
contains the
raw profiles that the allele frequency tables were constructed from.
James M. Curran
Budowle, B. and Moretti, T.R. (1999), Genotype Profiles for Six Population Groups at the 13 CODIS Short Tandem Repeat Core Loci and Other PCR Based Loci, Forensic Science Communications 1(2).
fbiCaucs, USCaucs
## not run ## Not run: db = fetchBMdata() names(db) f = db[["TRINIDADIAN"]]$freqs dbExpect(f, k = "UN", collapse = TRUE) ## End(Not run)
## not run ## Not run: db = fetchBMdata() names(db) f = db[["TRINIDADIAN"]]$freqs dbExpect(f, k = "UN", collapse = TRUE) ## End(Not run)
Calculates the total number of alleles that are shared by two profiles. If the two profiles in question are indeed relatives then the matching alleles may be identical by descent, or by random chance alone, hence identity by state.
IBS(prof1, prof2, nLoci = length(prof1)/2, bPrint = FALSE)
IBS(prof1, prof2, nLoci = length(prof1)/2, bPrint = FALSE)
prof1 |
A matrix consisting of 2 columns and nLoci rows. Each entry in the matrix is the (coded) allele held by the individual. |
prof2 |
See |
nLoci |
The number of loci in the profiles. Specifying this value speeds up computation enormously. |
bPrint |
If true then the result is printed locus by locus. This feature exists primarily for debugging purposes. |
An integer between 0 and 2*nLoci representing the total number of alleles that match in the two profiles.
James M. Curran
data(fbiCaucs) P1 = randomProfile(fbiCaucs) C1 = randomChild(P1, fbiCaucs) IBS(P1, C1) IBS(P1, C1, bPrint = TRUE)
data(fbiCaucs) P1 = randomProfile(fbiCaucs) C1 = randomChild(P1, fbiCaucs) IBS(P1, C1) IBS(P1, C1, bPrint = TRUE)
WARNING: This function is experimental.
IS( Freqs, numContributors = 4, maxPeaks = NULL, numIterations = 100, bTail = FALSE )
IS( Freqs, numContributors = 4, maxPeaks = NULL, numIterations = 100, bTail = FALSE )
Freqs |
a set of allele frequencies. The format can be found in |
numContributors |
the number of contributors to each mixture. Must be >= 1. |
maxPeaks |
either the number of peaks observed in the mixture or such that 1 <=1 maxPeaks <= min(2 * numContribuors, numAlleles). That is, if used in this way maxPeaks must be between 1 and the smaller of twice the number of contributors or the number of possible alleles because you cannot see more peaks than there are possible alleles. |
numIterations |
the number of iterations to use in the importance sampling scheme. |
bTail |
if |
a list with as many elements as loci. If tail probabilities are selected then each locus element will be a vector of probabilities
## Not run: data(USCaucs) IS(USCaucs, numContributors = 4, maxPeaks = 3, numIterations = 1e4) ## End(Not run)
## Not run: data(USCaucs) IS(USCaucs, numContributors = 4, maxPeaks = 3, numIterations = 1e4) ## End(Not run)
Calculates the number of alleles that are shared by two profiles at a single locus. If the two profiles in question are indeed relatives then the matching alleles may be identical by descent, or by random chance alone, hence identity by state.
locusIBS(profMat)
locusIBS(profMat)
profMat |
A matrix consisting of 4 columns and N rows. Each row in the matrix consists of the genotypes of two individuals. |
A vector of length N containing values 0, 1, or 2 depending on how many alleles each pair of profiles share at a locus.
James M. Curran
data(fbiCaucs) G = randomSample(1, fbiCaucs, rel = 'FS', N = 1000) ibs = locusIBS(G) barplot(tabulate(ibs+1, nbins = 3))
data(fbiCaucs) G = randomSample(1, fbiCaucs, rel = 'FS', N = 1000) ibs = locusIBS(G) barplot(tabulate(ibs+1, nbins = 3))
Calculates the likelihood ratio for pairs of profiles under the propositions
and
, where
,
and
are the victim, the
suspect and someone unrelated to the suspect respectively. The calculation
does not employ
so there are no assumptions about the
subpopulations of the contributors.
lrMix(profiles, Freqs)
lrMix(profiles, Freqs)
profiles |
A vector of profile lists, from |
Freqs |
A list containing elements |
A matrix of LRs calculated at each locus for every pair of profiles.
Note this is the set of profile pairs supplied in
profiles
, not a pairwise comparison.
James M. Curran
data(USCaucs) p = randomProfilePairs(USCaucs, 10000) log.lrs = log10(lrMix(p, USCaucs)) boxplot(log.lrs, las = 2)
data(USCaucs) p = randomProfilePairs(USCaucs, 10000) log.lrs = log10(lrMix(p, USCaucs)) boxplot(log.lrs, las = 2)
Calculates Likelihood Ratio comparing the probability of two profiles if they are indeed parent-child compared to unrelated. This is the paternity index or PI.
lrPC(parent, child, Freqs = NULL, nLoci = length(parent)/2, f = NULL, n = NULL)
lrPC(parent, child, Freqs = NULL, nLoci = length(parent)/2, f = NULL, n = NULL)
parent |
A matrix consisting of 2 columns and nLoci rows. Each entry in the matrix is the (coded) allele held by the individual. This represents the alleged parent. The relationship is reflexive so it does not matter which profile is labelled parent and child. |
child |
See |
Freqs |
A list containing two lists labelled loci and freqs. The second list is a list of vectors containing the allele frequencies of each allele at each locus in the multiplex. This argument or both f and n must be specified |
nLoci |
The number of loci in the profiles |
f |
A concatenated vector of allele frequencies. Specifying this speeds up computation enormously |
n |
A vector of length |
A value between 0 and infinity representing support (or lack of support if the value is less than 1) for the hypothesis that the two profiles are parent and child. There is no mutation built into this calculation. This means that the LR will be zero if the profiles do not share at least one allele in common at each locus in the multiplex.
James M. Curran
Buckleton, J, Triggs, C.M., and Walsh, S.J. (2005)Forensic DNA Evidence Interpretation, CRC Press., Boca Raton, FL. p.410
lrSib, IBS
data(fbiCaucs) P1 = randomProfile(fbiCaucs) C1 = randomChild(P1, fbiCaucs) lrPC(P1, C1, fbiCaucs)
data(fbiCaucs) P1 = randomProfile(fbiCaucs) C1 = randomChild(P1, fbiCaucs) lrPC(P1, C1, fbiCaucs)
Calculates Likelihood Ratio comparing the probability of two profiles if they are indeed full-sibs compared to unrelated. This is sometimes called the kinship index (KI) for full-sibs.
lrSib(sib1, sib2, Freqs = NULL, nLoci = length(sib1)/2, f = NULL, n = NULL)
lrSib(sib1, sib2, Freqs = NULL, nLoci = length(sib1)/2, f = NULL, n = NULL)
sib1 |
A matrix consisting of 2 columns and nLoci rows. Each entry in the matrix is the (coded) allele held by the individual. This represents the alleged sibling. The relationship is reflexive so it does not matter which profile is labelled sib1 and sib2. |
sib2 |
See |
Freqs |
A list containing two lists labelled loci and freqs. The second list is a list of vectors containing the allele frequencies of each allele at each locus in the multiplex. This argument or both f and n must be specified |
nLoci |
The number of loci in the profiles |
f |
A concatenated vector of allele frequencies. Specifying this speeds up computation enormously |
n |
A vector of length |
A value between 0 and infinity representing support (or lack of support if the value is less than 1) for the hypothesis that the two profiles are full-siblings. There is no mutation built into this calculation.
James M. Curran
Buckleton, J, Triggs, C.M., and Walsh, S.J. (2005)Forensic DNA Evidence Interpretation, CRC Press., Boca Raton, FL. p.411
lrSibDebug, lrPC, IBS
data(fbiCaucs) P1 = randomProfile(fbiCaucs) S1 = randomSib(P1, fbiCaucs) P2 = randomProfile(fbiCaucs) lrSib(P1, S1, fbiCaucs) lrSib(P1, P2, fbiCaucs)
data(fbiCaucs) P1 = randomProfile(fbiCaucs) S1 = randomSib(P1, fbiCaucs) P2 = randomProfile(fbiCaucs) lrSib(P1, S1, fbiCaucs) lrSib(P1, P2, fbiCaucs)
Calculates Likelihood Ratio comparing the probability of two profiles if they are indeed full-sibs compared to unrelated. This is sometimes called the kinship index (KI) for full-sibs. This function is identical to lrSib except that the calculation is performed in R, and provides full calculation detail at each locus. It exists primarily to check that the correct formula and logic is being applied in the LR calculation so that the result can be manually verified.
lrSibDebug(sib1, sib2, Freqs)
lrSibDebug(sib1, sib2, Freqs)
sib1 |
A matrix consisting of 2 columns and nLoci rows. Each entry in the matrix is the (coded) allele held by the individual. This represents the alleged sibling. The relationship is reflexive so it does not matter which profile is labelled sib1 and sib2. |
sib2 |
See |
Freqs |
A list containing two lists labelled loci and freqs. The second list is a list of vectors containing the allele frequencies of each allele at each locus in the multiplex. |
A list containing three elements Lines, lr, and Cases. Lines is a list of strings containing the calculation at each locus so that the result can be written to file for example. Cases is a numeric code listing which logical case (1-11) the locus falls into for the profiles in question. lr is the KI for full-sibs for the two profiles.
James M. Curran
Buckleton, J, Triggs, C.M., and Walsh, S.J. (2005)Forensic DNA Evidence Interpretation, CRC Press., Boca Raton, FL. p.411
lrSib, lrPC, IBS
data(fbiCaucs) P1 = randomProfile(fbiCaucs) S1 = randomSib(P1, fbiCaucs) P2 = randomProfile(fbiCaucs) cat(paste(lrSibDebug(P1, S1, fbiCaucs)$Lines)) cat(paste(lrSibDebug(P1, P2, fbiCaucs)$Lines))
data(fbiCaucs) P1 = randomProfile(fbiCaucs) S1 = randomSib(P1, fbiCaucs) P2 = randomProfile(fbiCaucs) cat(paste(lrSibDebug(P1, S1, fbiCaucs)$Lines)) cat(paste(lrSibDebug(P1, P2, fbiCaucs)$Lines))
Normalize a list of frequencies at a series of genetic loci both sum to one. Not that this does not deal with the problem of values larger than one or smaller than zero.
normalizeFreqs(Freqs)
normalizeFreqs(Freqs)
Freqs |
A list containg elements |
Divides vector in Freqs$freqs by the vector sum.
A list containg elements loci
and freqs
. freqs
is a list of vectors containing the frequencies at the given loci.
James M. Curran
checkFreqs
data(fbiCaucs) ## induce an error fbiCaucs$freqs[[1]] = rgamma(10,1,1) checkFreqs(fbiCaucs) fbiCaucs = normalizeFreqs(fbiCaucs) checkFreqs(fbiCaucs)
data(fbiCaucs) ## induce an error fbiCaucs$freqs[[1]] = rgamma(10,1,1) checkFreqs(fbiCaucs) fbiCaucs = normalizeFreqs(fbiCaucs) checkFreqs(fbiCaucs)
Nicely prints summary information about a substructured population created
using breedFst
## S3 method for class 'population' print(x, ...)
## S3 method for class 'population' print(x, ...)
x |
The population object to be printed |
... |
Ignored - really should be passed to print, but given cat is actually called they are ignored |
James M. Curran
breedFst
data(fbiCaucs) p = breedFst(fbiCaucs) print(p)
data(fbiCaucs) p = breedFst(fbiCaucs) print(p)
Nicely prints a profile object out in genotype pairs
## S3 method for class 'profile' print(x, horizontal = FALSE, ...)
## S3 method for class 'profile' print(x, horizontal = FALSE, ...)
x |
The profile object to be printed |
horizontal |
if |
... |
Ignored - really should be passed to print, but given cat is actually called they are ignored |
James M. Curran
data(fbiCaucs) P1 = randomProfile(fbiCaucs) P2 = randomProfile(fbiCaucs) P1 print(P1, horizontal = TRUE) print(P2, horizontal = TRUE)
data(fbiCaucs) P1 = randomProfile(fbiCaucs) P2 = randomProfile(fbiCaucs) P1 print(P1, horizontal = TRUE) print(P2, horizontal = TRUE)
Generates a random child (or parent) from a given DNA profile from a given set of allele frequencies. At each locus, the child inherits the first allele of the given profile with one half, or the second allele with probability one half. The second allele is chosen at random with probability proportional to the allele frequencies.
randomChild(profile, Freqs)
randomChild(profile, Freqs)
profile |
A vector of length 2*nLoci. Each entry in the vector is the (coded) allele held by the individual. This represents the parent. The relationship is reflexive so it does not matter if the profile is a parent or a child. |
Freqs |
A list containing two lists labelled loci and freqs. The second list is a list of vectors containing the allele frequencies of each allele at each locus in the multiplex. |
The alleles are simply integers rather than the STR repeat numbers. This speeds up computation immensely when calculating any of the LRs or IBS.
A vector with 2*nLoci elements. Each pair of elements represents the genotpe of the random individual at that locus. The genotype alleles are always ordered so that allele1 <= allele2.
James M. Curran
randomChild, randomSample, randomSib
data(fbiCaucs) P1 = randomProfile(fbiCaucs) C1 = randomChild(P1,fbiCaucs) P1 C1
data(fbiCaucs) P1 = randomProfile(fbiCaucs) C1 = randomChild(P1,fbiCaucs) P1 C1
Generates one or more pairs random parent/child pairs from a given set of allele frequencies.
randomPCPairs(Freqs, BlockSize = 1)
randomPCPairs(Freqs, BlockSize = 1)
Freqs |
A list containing two lists labelled loci and freqs. The second list is a list of vectors containing the allele frequencies of each allele at each locus in the multiplex. |
BlockSize |
The number of pairs of profiles to generate |
The alleles are simply integers rather than the STR repeat numbers. This speeds up computation immensely when calculating any of the LRs or IBS.
A list of length BlockSize
. Each element of the list has a
sublist containing two profiles called parent
and child
James M. Curran
randomSibPairs, randomProfilePairs
data(fbiCaucs) P = randomPCPairs(fbiCaucs) P$parent P$child
data(fbiCaucs) P = randomPCPairs(fbiCaucs) P$parent P$child
Generates a random DNA profile from a given set of allele frequencies.
randomProfile(Freqs)
randomProfile(Freqs)
Freqs |
A list containing two lists labelled loci and freqs. The second list is a list of vectors containing the allele frequencies of each allele at each locus in the multiplex. |
The alleles are simply integers rather than the STR repeat numbers. This speeds up computation immensely when calculating any of the LRs or IBS.
A vector with 2*nLoci elements. Each pair of elements represents the genotpe of the random individual at that locus. The genotype alleles are always ordered so that allele1 <= allele2.
James M. Curran
randomChild, randomSample, randomSib
data(fbiCaucs) P1 = randomProfile(fbiCaucs)
data(fbiCaucs) P1 = randomProfile(fbiCaucs)
Generates one or more random DNA profile pairs from a given set of allele frequencies.
randomProfilePairs(Freqs, BlockSize = 1)
randomProfilePairs(Freqs, BlockSize = 1)
Freqs |
A list containing two lists labelled loci and freqs. The second list is a list of vectors containing the allele frequencies of each allele at each locus in the multiplex. |
BlockSize |
The number of pairs of profiles to generate |
The alleles are simply integers rather than the STR repeat numbers. This speeds up computation immensely when calculating any of the LRs or IBS.
A list of length BlockSize
. Each element of the list has a
sublist containing two profiles called prof1
and prof2
James M. Curran
randomPCPairs, randomSibPairs
data(fbiCaucs) P = randomProfilePairs(fbiCaucs) P$prof1 P$prof2
data(fbiCaucs) P = randomProfilePairs(fbiCaucs) P$prof1 P$prof2
Generate a random sample of unrelated, full-sib, or parent/child pairs of profiles at a single locus.
randomSample(nLoc, Freqs, rel = "UN", N = 10000)
randomSample(nLoc, Freqs, rel = "UN", N = 10000)
nLoc |
The locus number to sample from |
Freqs |
A list containg elements |
rel |
One of 'UN', 'FS', or 'PC' for unrelated, full-sib, or parent/child pairs respectively. |
N |
The sample size |
An N by 4 matrix of random profiles. The first two columns represent the genotype of person one and the second two columns represent the genotype of column two. Note that the random profiles do not use the orginal allele designations.
James M. Curran
randomProfile, randomSib, randomChild
data(fbiCaucs) G = randomSample(1, fbiCaucs, "FS", 100)
data(fbiCaucs) G = randomSample(1, fbiCaucs, "FS", 100)
Generates a random sibling from a given DNA profile from a given set of allele frequencies. At each locus, the sibling inherits the first allele of the given profile with one quarter, or the second allele with probability one quarter, both alleles with probability one quarter, or neither with probability one quarter. If the sibling inherits zero or one identical alleles, the missing alleles are chosen at random with probability proportional to the allele frequencies.
randomSib(profile, Freqs)
randomSib(profile, Freqs)
profile |
A vector consisting of 2*nLoci elements. Each element in the vector is the (coded) allele held by the individual. This represents the sibling. |
Freqs |
A list containing two lists labelled loci and freqs. The second list is a list of vectors containing the allele frequencies of each allele at each locus in the multiplex. |
The alleles are simply integers rather than the STR repeat numbers. This speeds up computation immensely when calculating any of the LRs or IBS.
A vector with 2*nLoci elements. Each pair of elements represents the genotpe of the random individual at that locus. The genotype alleles are always ordered so that allele1 <= allele2.
James M. Curran
randomChild, randomSample
data(fbiCaucs) P1 = randomProfile(fbiCaucs) S1 = randomSib(P1,fbiCaucs) P1 S1
data(fbiCaucs) P1 = randomProfile(fbiCaucs) S1 = randomSib(P1,fbiCaucs) P1 S1
Generates one or more pairs of random siblings from a given set of allele frequencies.
randomSibPairs(Freqs, BlockSize = 1)
randomSibPairs(Freqs, BlockSize = 1)
Freqs |
A list containing two lists labelled loci and freqs. The second list is a list of vectors containing the allele frequencies of each allele at each locus in the multiplex. |
BlockSize |
The number of pairs of profiles to generate |
The alleles are simply integers rather than the STR repeat numbers. This speeds up computation immensely when calculating any of the LRs or IBS.
A list of length BlockSize
. Each element of the list has a
sublist containing two profiles called sib1
and sib2
James M. Curran
randomPCPairs, randomProfilePairs
data(fbiCaucs) P = randomSibPairs(fbiCaucs) P$sib1 P$sib2
data(fbiCaucs) P = randomSibPairs(fbiCaucs) P$sib1 P$sib2
Reads in a file of alleles in a particular format.
readFreqs(strPath, FSIGenFormat = TRUE, delim = ",")
readFreqs(strPath, FSIGenFormat = TRUE, delim = ",")
strPath |
The file from which to read the frequencies |
FSIGenFormat |
Tells the function whether the file is either in FSI Genetics format (see below) or 'Curran' format |
delim |
This argument is used when |
This function reads frequencies in the rectangular allele freqency table format used by FSI Genetics and other journals. This file format assumes a comma separated value file (CSV) (although the column delimeter can be specified). The first column should be labelled 'Allele' and contain the STR allele designations that are used in the data set. The remaining columns will have the locus name as a header, and frequencies that are either blank, zero, or non-zero. Blanks or zeros are used to specify that the allele is not observed (and not used) at the locus. The final row of the file should start with 'N' or 'n' in the first column and give the number of individuals typed (or the number of alleles recorded) in assessing the frequency of the alleles.
The second format is a very particular 'Curran' text format. The first line contains the number of loci in the multiplex. The next line will contain the name of the first locus and the number of alleles, nA, the locus separated by a comma. The next nA lines contain the allele number (from 1 to nA), the STR designation of the allele, and the frequency separated by commas. This pattern is repeated for each locus. In the future this function will read the rectangular allele freqency table used by FSI Genetics and other journals.
a list containing two vectors and a list, loci, counts, and freqs. The vector loci is a vector of the locus names in the frequency file. The vector counts is a vector of the number of individuals (or sometimes alleles) typed at each locus. This will null if the 'Curran' format is used. The list freqs, is a list of vectors with each vector containing the frequencies of the alleles at the locus. The names of the elements of the vectors are the STR allele designations.
James M. Curran
Reads a set of profiles from a file
readProfiles( fileName, freqs = NULL, sep = "\t", header = FALSE, id = 1, discardMissing = TRUE )
readProfiles( fileName, freqs = NULL, sep = "\t", header = FALSE, id = 1, discardMissing = TRUE )
fileName |
a path to the profile file. |
freqs |
A list containing two lists labelled loci and freqs. The second
list is a list of vectors containing the allele frequencies of each allele
at each locus in the multiplex. If this is left |
sep |
a character that delimits the fields in the profile file. |
header |
a boolean which is |
id |
a column number indicating which column the profile id's are stored. If |
discardMissing |
if |
The alleles are recorded integers rather than the STR repeat numbers. This speeds up computation immensely when calculating any of the LRs or IBS.
a list containing a data.frame
of profiles where the alleles have been recoded
to the allele index number, rather than the allele itself, and a set of frequencies in the same
format as you would get from readFreqs
. If freqs
have been supplied, then this
will just be the same set of frequencies, if they have not, then this will be calculated
from the profiles. Given that the profiles generally do not have any locus name information
the loci will just be labelled Locus1, Locus2, .... If there are missing values then the raw missing profiles are returned
James M. Curran
This function will read the output from sim
that has been saved to
disk
readResults( N = 0, rel = "UN", gzip = TRUE, strPath = "", strVer = "", fileName = NULL )
readResults( N = 0, rel = "UN", gzip = TRUE, strPath = "", strVer = "", fileName = NULL )
N |
The number of iterations in the simulation |
rel |
'UN' = unrelated, 'FS' = full-sib, 'PC' = parent-child |
gzip |
If |
strPath |
Optional location of files. Must terminate with / otherwise it will not work |
strVer |
A version string, useful if more than simulation has been run |
fileName |
This argument allows the user to override the default file naming conventions of the result file |
The arguments to this file are used to generate the input file name. The
format is very rigid, being 'results-sim-rel-N(-strVer).csv(.gz)' That is,
if strVer is something than an empty string then it is included after the
number of interations. Similarly if gzip == TRUE
then the filename is
assumed to end with '.gz'
a data frame with three columns labelled sib, pc, and ibs. These represent the LRs for sibs and parent-child calculated on each simulated profile pair, and the number of matching alleles (IBS).
James M. Curran
sim
data(fbiCaucs) ## not run ## write the results of 100 unrelated profile pairs to ## results-sim-UN-100.csv.gz ## and read it back in ## Not run: sim(100, save = T) unrel = readResults(100) sim(100, rel = "FS", strVer = "01", save = T) sibs = readResults(100, rel = "FS", strVer = "01") ## End(Not run)
data(fbiCaucs) ## not run ## write the results of 100 unrelated profile pairs to ## results-sim-UN-100.csv.gz ## and read it back in ## Not run: sim(100, save = T) unrel = readResults(100) sim(100, rel = "FS", strVer = "01", save = T) sibs = readResults(100, rel = "FS", strVer = "01") ## End(Not run)
Generate N pairs with a given relationship and calculate the LR for sibs, parent-child and the number of matching alleles
sim( N, Freqs, rel = "UN", save = FALSE, strPath = "", strVer = "", BlockSize = N/100, fileName = NULL )
sim( N, Freqs, rel = "UN", save = FALSE, strPath = "", strVer = "", BlockSize = N/100, fileName = NULL )
N |
The number of iterations to carry out |
Freqs |
A list containing two lists labelled loci and freqs. The second list is a list of vectors containing the allele frequencies of each allele at each locus in the multiplex. |
rel |
generate unrelated ( |
save |
Write the results to disk if |
strPath |
Optional prefix to add to the results file path so that the output location can be specified |
strVer |
Optional suffix for the results file. This is useful when running multiple instances of R |
BlockSize |
Sets the number of random profiles to be generated in each
iteration. By default the block size is set to 1 percent of the total sample
size. It is unclear whether the procedure is more efficient if a bigger
percentage of the total is used. Users must take care to make sure that the
block size evenly divides |
fileName |
This argument lets the user override the default result file naming scheme |
This is the function that generates all the data for the results in the paper. WARNING: this function is not especially fast. To achieve the 100 million iterations used in the paper, 30 instances of R were launched on a multicore server. Each instance represented one relationship with 10 million iterations. The compute time for this arrangement was approximately 1 hours, meaning a full serial run would have taken over 30 hours to achieve the same result.
a data frame with three columns: sib, pc, ibs containing the LRs for full-siblings, parent-child, and the number of matching alleles for each generated pair of profiles.
James M. Curran
readResults, errorRate
## not run ## this replicates Ge et al.'s experiment and takes about 45 minutes ## to run (I think) ## Not run: data(fbiCaucs) N = 1000000 sim(N, fbiCaucs, save = T) sim(N, fbiCaucs, 'FS', save = T) sim(N, fbiCaucs, 'PC', save = T) ## End(Not run)
## not run ## this replicates Ge et al.'s experiment and takes about 45 minutes ## to run (I think) ## Not run: data(fbiCaucs) N = 1000000 sim(N, fbiCaucs, save = T) sim(N, fbiCaucs, 'FS', save = T) sim(N, fbiCaucs, 'PC', save = T) ## End(Not run)
This function simulates N persons mixtures using the supplied frequencies and records the number of times they share 1, 2, ..., 2N alleles locus by locus.
simNpersonMixture(freqs, numContributors, numIterations = 10000)
simNpersonMixture(freqs, numContributors, numIterations = 10000)
freqs |
a set of allele frequencies. The format can be found in |
numContributors |
the number of contributors to each mixture. Must be >= 2. |
numIterations |
the number of N person mixtures to simulate in total. |
an object of class npmresult
Exports a population with population substructure to a Nexus formatted file so that GDA can be used to check the Fst calculations
toNexus(Pop, fileName = "output.nex")
toNexus(Pop, fileName = "output.nex")
Pop |
An object of type 'population' - see |
fileName |
The name of the file output file |
James M. Curran
Maddison DR, Swofford DL, Maddison WP (1997), NEXUS: An extensible file format for systematic information, Systematic Biology 46 (4): 590–621.
Zaykin, D. and Lewis, P., GDA - software to accompany Genetic Data Analysis II, <http://phylogeny.uconn.edu/software/>.
breedFst
## Don't run ## Not run: data(USCaucs) p = breedFst(USCaucs) toNexus(p) ## End(Not run)
## Don't run ## Not run: data(USCaucs) p = breedFst(USCaucs) toNexus(p) ## End(Not run)
This data structure
This data set is a list which has two sub-lists. The lists are named loci and freqs. loci is a vector of the 13 CODIS STR locus names. freqs is a list of 13 vectors, each vector contains the allele frequencies published for US Caucasians in Budowle and Moretti (1999). The raw data is available from https://www.fbi.gov/about-us/lab/forensic-science-communications/fsc/july1999/dnaloci.txt
James M. Curran
Budowle, B. and Moretti, T.R. (1999), Genotype Profiles for Six Population Groups at the 13 CODIS Short Tandem Repeat Core Loci and Other PCR Based Loci, Forensic Science Communications 1(2).
fbiCaucs
data(USCaucs) names(USCaucs) USCaucs$loci names(USCaucs$freqs) USCaucs$freqs[[1]] names(USCaucs$freqs[[1]]) USCaucs$freqs[[1]][1]
data(USCaucs) names(USCaucs) USCaucs$loci names(USCaucs$freqs) USCaucs$freqs[[1]] names(USCaucs$freqs[[1]]) USCaucs$freqs[[1]][1]
Writes a population of profiles to disk using the original allele designations rather than the internal integer representations that are used for the other functions.
writeCSV(fileName, pop, n = 100, delim = ",")
writeCSV(fileName, pop, n = 100, delim = ",")
fileName |
the name and path where the population profiles are to be saved to. |
pop |
a |
n |
the number of people in the database. This is arbitrarily set to 100 by default. |
delim |
The allele delimiter. |
a matrix which contains the table written to file.
Rare alleles are recoded to 108.1. This is unlikely to do the right thing when you have things like <5 or >20 in your allele names. Given it is impossible to predict what a user would like to do, I suggest you recode them yourself before using this function.
James M. Curran
breedFst USCaucs
data(USCaucs) ## Not run: writeCSV("USCaucs.csv", USCaucs) ## End(Not run)
data(USCaucs) ## Not run: writeCSV("USCaucs.csv", USCaucs) ## End(Not run)
Writes a population of profiles to disk using the original allele designations rather than the internal integer representations that are used for the other functions.
writePop(fileName, pop, addAmelo = FALSE, delim = ",", dupLoci = TRUE)
writePop(fileName, pop, addAmelo = FALSE, delim = ",", dupLoci = TRUE)
fileName |
the name and path where the population profiles are to be saved to. |
pop |
an object of class |
addAmelo |
The simulated populations do not have Amelogenin. If
|
delim |
The allele delimiter. |
dupLoci |
If |
Rare alleles are recoded to 108.1.
James M. Curran
breedFst
data(USCaucs) pop = breedFst(USCaucs) ## Not run: writePop("USCaucs.csv", pop) ## End(Not run)
data(USCaucs) pop = breedFst(USCaucs) ## Not run: writePop("USCaucs.csv", pop) ## End(Not run)