phensim: A function to simulated phenotypic data

Description Usage Arguments Details Value Author(s) References Examples

Description

Simulates phenotypic data across arbitrary pedigrees. phensim simulate direct, maternal and paternal genetica and environmental effects for an arbitrary number of traits with arbitrary patterns of missing data.

Usage

1
2
3
phensim(pedigree, traits = 1, randomA = NULL, randomE = NULL, 
        parentalA = NULL, parentalE = NULL, sampled = NULL, 
              records = NULL, returnAllEffects = FALSE)

Arguments

pedigree

A pedigree

traits

The number of traits for which data should be simulated.

randomA

An additive genetic covariance matrix, with dimensions a multiple of traits - see details

randomE

An additive environmental covariance matrix, with dimensions a multiple of traits - see details

parentalA

A vector indicating which effects in randomA (if any) to treat as parental effects

parentalE

A vector indicating which effects in randomE (if any) to treat as parental effects

sampled

A vector indicating which individuals are sampled

records

A single value, array of matrix specifying data record availability - see details

returnAllEffects

If TRUE then all individual breeding values and environmental effects are returned

Details

randomA and randomE are square matrices with dimension equal to the sum of the number direct and indirect effects. This must be a multiple of the number of traits, i.e. if an indirect effect is to be simulated for only one of multiple traits, those traits with no indirect effect should be included with (co)variances of zero.

parentalA and parentalE are optional vectors of characters indicating which trait positions in randomA and randomE are to be treated as indirect effects, and which effects to treat as maternal or paternal. Valid values are 'd', 'm', and 'p', for direct, maternal indirect and paternal indirect effects, respectively.

records can be specified either (1) as asingle value to be applied to all individuals and traits, (2) as a vector the same length as the number of traits, representing trait-specific rates to be applied uniformly to all individuals, or (3) as data frames with rows for each individual and columns for each trait. In the third option, observed patterns of data availability can be simulated by supplying 0s and 1s for missing and available individual genotypes, respectively.

Value

phenotypes

A dataframe containing phenotypes for all indivduals specified to have records.

allEffects

(optional) A dataframe with all direct and indirect genetic and environmental effects.

Author(s)

Michael Morrissey michael.morrissey@st-andrews.ac.uk

References

Morrissey et al. 2007. Journal of Evolutionary Biology 20:2309-2321., Morrissey, M.B, and A.J. Wilson, 2009. pedantics, an R package for pedigree-based genetic simulation, and pedigree manipulation, characterisation, and viewing. Molecular Ecology Resources.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
## make up a pedigree
id<-   c("a1","a2","a3","a4","a5","a6","a7","a8","a9")
dam<-  c(NA,NA,NA,"a1","a1","a1","a4","a4","a4")
sire<- c(NA,NA,NA,"a2","a2","a2","a5","a6","a6")
pedigree<-as.data.frame(cbind(id,sire,dam))

traits<-2
## no correlations
randomA<-diag(4)
randomE<-diag(4)
parentalA<-c("d","d","m","m")
parentalE<-c("d","d","m","m")

## generate phenoypic data based on this architecture
phensim(pedigree=pedigree,traits=2,randomA=randomA,randomE=randomE,
          parentalA=parentalA,parentalE=parentalE)

## let's do it again but see how the phenotypes were composed
phensim(pedigree=pedigree,traits=2,randomA=randomA,randomE=randomE,
          parentalA=parentalA,parentalE=parentalE,returnAllEffects=TRUE)

Example output

Loading required package: MasterBayes
Loading required package: coda
Loading required package: genetics
Loading required package: combinat

Attaching package: 'combinat'

The following object is masked from 'package:utils':

    combn

Loading required package: gdata
sh: 1: cannot create /dev/null: Permission denied
gdata: Unable to locate valid perl interpreter
gdata: 
gdata: read.xls() will be unable to read Excel XLS and XLSX files
gdata: unless the 'perl=' argument is used to specify the location of a
gdata: valid perl intrpreter.
gdata: 
gdata: (To avoid display of this message in the future, please ensure
gdata: perl is installed and available on the executable search path.)
sh: 1: cannot create /dev/null: Permission denied
gdata: Unable to load perl libaries needed by read.xls()
gdata: to support 'XLX' (Excel 97-2004) files.

gdata: Unable to load perl libaries needed by read.xls()
gdata: to support 'XLSX' (Excel 2007+) files.

gdata: Run the function 'installXLSXsupport()'
gdata: to automatically download and install the perl
gdata: libaries needed to support Excel XLS and XLSX formats.

Attaching package: 'gdata'

The following object is masked from 'package:stats':

    nobs

The following object is masked from 'package:utils':

    object.size

The following object is masked from 'package:base':

    startsWith

Loading required package: gtools
Loading required package: MASS
Loading required package: mvtnorm


NOTE: THIS PACKAGE IS NOW OBSOLETE.



  The R-Genetics project has developed an set of enhanced genetics

  packages to replace 'genetics'. Please visit the project homepage

  at http://rgenetics.org for informtion.




Attaching package: 'genetics'

The following objects are masked from 'package:base':

    %in%, as.factor, order

Loading required package: kinship2
Loading required package: Matrix
Loading required package: quadprog
Loading required package: MCMCglmm
Loading required package: ape
Loading required package: grid
Simulating breeding values and environmental effects...done. 
Calculating phenotypes...done. 
$phenotypes
   id    trait_1    trait_2
a1 a1  1.0487781  2.4472884
a2 a2  3.0452697 -1.1442135
a3 a3 -1.6374299  3.4483629
a4 a4 -3.6505283 -3.1271656
a5 a5 -2.0810044 -0.4234333
a6 a6 -1.5498008 -0.3506640
a7 a7 -0.1811708 -2.9708133
a8 a8  0.3119768 -3.0094373
a9 a9 -1.2004595 -1.3257141

Simulating breeding values and environmental effects...done. 
Calculating phenotypes...done. 
$phenotypes
   id    trait_1    trait_2
a1 a1 -0.9074163 -1.2676404
a2 a2 -1.9267712 -0.3722607
a3 a3  0.1135589  0.5751808
a4 a4 -1.9790749 -1.7100500
a5 a5 -0.7289441 -0.8708415
a6 a6 -1.3254944 -1.5006264
a7 a7  0.1745394 -3.1193564
a8 a8 -0.9452083 -2.9575521
a9 a9 -3.9278365  2.1365328

$allEffects
   id sire  dam      a_tr1       a_tr2   bv_m_tr1    bv_m_tr2      e_tr1
a1 a1 <NA> <NA> -2.3428609 -1.31809148  0.3303417  0.12635799  0.4155993
a2 a2 <NA> <NA> -1.3789138  1.08686915 -0.7072837  0.07619064  1.1219204
a3 a3 <NA> <NA> -0.7359603 -0.16974135 -0.3840293 -1.05844393  1.1790411
a4 a4   a2   a1 -2.4416217  0.01437769 -0.3057462 -0.04442020 -0.2644825
a5 a5   a2   a1 -1.2672429 -0.91798292 -0.3819309  0.76981274 -0.1887305
a6 a6   a2   a1 -2.2207205 -0.73445628  0.5342522  1.71959531  0.1681968
a7 a7   a5   a4 -2.3894794 -1.75158453 -0.8153384  1.52699215  1.3634639
a8 a8   a6   a4 -0.5930887 -1.75319508 -0.2145590 -0.09484102 -1.5526745
a9 a9   a6   a4 -3.3327608 -0.01352010 -1.1258245 -0.14467449 -1.7956306
         e_tr2    e_m_tr1    e_m_tr2 P_bv_m_tr1 P_bv_m_tr2  P_e_m_tr1
a1  0.39265350  0.3966876 -1.9210690  0.3136885 -1.1940188  0.7061568
a2 -0.79273043  0.2244939 -0.9898643 -1.4692700 -0.5534572 -0.2005078
a3  0.12161139 -0.7876112 -0.2056679  0.5239935  0.3467990 -0.8535154
a4  0.07028331  1.5063011  0.3249545  0.3303417  0.1263580  0.3966876
a5  1.84185249 -0.8199456  0.1804672  0.3303417  0.1263580  0.3966876
a6  1.02854096 -0.1951587  1.4986843  0.3303417  0.1263580  0.3966876
a7 -1.64830617  0.6154965 -0.2271301 -0.3057462 -0.0444202  1.5063011
a8 -1.48489131  0.3231452  0.1750152 -0.3057462 -0.0444202  1.5063011
a9  1.86951861  0.1779707 -1.1502322 -0.3057462 -0.0444202  1.5063011
    P_e_m_tr2   Phen_tr1   Phen_tr2
a1  0.8518164 -0.9074163 -1.2676404
a2 -0.1129422 -1.9267712 -0.3722607
a3  0.2765118  0.1135589  0.5751808
a4 -1.9210690 -1.9790749 -1.7100500
a5 -1.9210690 -0.7289441 -0.8708415
a6 -1.9210690 -1.3254944 -1.5006264
a7  0.3249545  0.1745394 -3.1193564
a8  0.3249545 -0.9452083 -2.9575521
a9  0.3249545 -3.9278365  2.1365328

pedantics documentation built on May 1, 2019, 10:54 p.m.