Simulate under the liability threshold model (single phenotype).
Source:R/Simulate_under_LTM.R
simulate_under_LTM_single.Rd
simulate_under_LTM_single
simulates families and thresholds under
the liability threshold model for a given family structure and a single
phenotype. Please note that it is not possible to simulate different
family structures.
Usage
simulate_under_LTM_single(
fam_vec = c("m", "f", "s1", "mgm", "mgf", "pgm", "pgf"),
n_fam = NULL,
add_ind = TRUE,
h2 = 0.5,
n_sim = 1000,
pop_prev = 0.1
)
Arguments
- fam_vec
A vector of strings holding the different family members. All family members must be represented by strings from the following list:
m
(Mother)f
(Father)c[0-9]*.[0-9]*
(Children)mgm
(Maternal grandmother)mgf
(Maternal grandfather)pgm
(Paternal grandmother)pgf
(Paternal grandfather)s[0-9]*
(Full siblings)mhs[0-9]*
(Half-siblings - maternal side)phs[0-9]*
(Half-siblings - paternal side)mau[0-9]*
(Aunts/Uncles - maternal side)pau[0-9]*
(Aunts/Uncles - paternal side). Defaults toc("m","f","s1","mgm","mgf","pgm","pgf")
.
- n_fam
A named vector holding the desired number of family members. See
setNames
. All names must be picked from the list mentioned above. Defaults toNULL
.- add_ind
A logical scalar indicating whether the genetic component of the full liability as well as the full liability for the underlying target individual should be included in the covariance matrix. Defaults to
TRUE
.- h2
A number representing the liability-scale heritability for a single phenotype. Must be non-negative. Note that under the liability threshold model, the heritability must also be at most 1. Defaults to 0.5.
- n_sim
A positive number representing the number of simulations. Defaults to 1000.
- pop_prev
A positive number representing the population prevalence, i.e. the overall prevalence in the population. Must be smaller than 1. Defaults to 0.1.
Value
If either fam_vec
or n_fam
is used as the argument,
if it is of the required format, if the liability-scale heritability h2
is a number satisfying \(0 \leq h^2\), n_sim
is a strictly positive number,
and pop_prev
is a positive number that is at most one,
then the output will be a list holding two tibbles.
The first tibble, sim_obs
, holds the simulated liabilities, the disease
status and the current age/age-of-onset for all family members in each of the
n_sim
families.
The second tibble, thresholds
, holds the family identifier, the personal
identifier, the role (specified in fam_vec or n_fam) as well as
the lower and upper thresholds for all individuals in all families.
Note that this tibble has the format required in estimate_liability
.
In addition, note that if neither fam_vec
nor n_fam
are specified, the function
returns the disease status, the current age/age-of-onset, the lower and upper
thresholds, as well as the personal identifier for a single individual, namely
the individual under consideration (called o
).
If both fam_vec
and n_fam
are defined, the user is asked to '
decide on which of the two vectors to use.
Examples
simulate_under_LTM_single()
#> $sim_obs
#> # A tibble: 1,000 × 26
#> fam_ID g o m f s1 mgm mgf pgm pgf
#> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 fam_I… -0.162 -0.0483 0.759 -0.0313 0.00167 0.847 0.217 -1.71 -0.597
#> 2 fam_I… -1.34 0.453 -1.40 -1.14 0.451 0.423 -0.953 -0.801 -2.70
#> 3 fam_I… -0.507 0.0789 0.420 -0.0629 0.824 -1.75 0.704 0.00638 -1.05
#> 4 fam_I… 0.700 0.153 -1.08 -1.02 1.25 -0.870 -0.373 -0.00811 0.892
#> 5 fam_I… 0.835 -0.0624 0.634 1.84 0.933 0.300 0.468 -0.277 1.85
#> 6 fam_I… 0.540 1.05 0.0659 -0.226 2.14 -1.08 -1.11 -0.354 0.854
#> 7 fam_I… -0.265 1.64 0.844 0.293 -0.777 -0.179 -0.372 1.99 -1.02
#> 8 fam_I… -1.10 -2.00 -0.205 -0.820 1.02 -0.944 1.74 0.0201 -1.19
#> 9 fam_I… -0.344 0.342 1.46 0.313 0.476 -0.0829 -0.107 -0.734 1.44
#> 10 fam_I… 0.152 1.78 -1.21 -0.510 0.949 0.204 0.130 -0.141 -0.187
#> # ℹ 990 more rows
#> # ℹ 16 more variables: o_status <lgl>, m_status <lgl>, f_status <lgl>,
#> # s1_status <lgl>, mgm_status <lgl>, mgf_status <lgl>, pgm_status <lgl>,
#> # pgf_status <lgl>, o_aoo <dbl>, m_aoo <dbl>, f_aoo <dbl>, s1_aoo <dbl>,
#> # mgm_aoo <dbl>, mgf_aoo <dbl>, pgm_aoo <dbl>, pgf_aoo <dbl>
#>
#> $thresholds
#> # A tibble: 8,000 × 5
#> fam_ID indiv_ID role lower upper
#> <chr> <chr> <chr> <dbl> <dbl>
#> 1 fam_ID_1 fam_ID_1_1 o -Inf 3.48
#> 2 fam_ID_2 fam_ID_2_1 o -Inf 3.52
#> 3 fam_ID_3 fam_ID_3_1 o -Inf 3.17
#> 4 fam_ID_4 fam_ID_4_1 o -Inf 2.63
#> 5 fam_ID_5 fam_ID_5_1 o -Inf 3.17
#> 6 fam_ID_6 fam_ID_6_1 o -Inf 3.45
#> 7 fam_ID_7 fam_ID_7_1 o 1.64 1.64
#> 8 fam_ID_8 fam_ID_8_1 o -Inf 3.17
#> 9 fam_ID_9 fam_ID_9_1 o -Inf 3.52
#> 10 fam_ID_10 fam_ID_10_1 o 1.78 1.78
#> # ℹ 7,990 more rows
#>
simulate_under_LTM_single(fam_vec = NULL, n_fam = stats::setNames(c(1,1,1,2),
c("m","mgm","mgf","mhs")))
#> $sim_obs
#> # A tibble: 1,000 × 20
#> fam_ID g o m mgm mgf mhs1 mhs2 o_status
#> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <lgl>
#> 1 fam_ID_1 -0.694 0.528 -0.479 -0.567 1.08 -0.917 0.253 FALSE
#> 2 fam_ID_2 -1.11 -0.771 -0.416 -0.574 -1.18 -0.428 -0.0341 FALSE
#> 3 fam_ID_3 0.916 1.55 -0.562 0.0641 -0.0181 -0.703 0.658 TRUE
#> 4 fam_ID_4 -0.0715 0.381 -0.0298 -0.621 0.693 0.255 -1.17 FALSE
#> 5 fam_ID_5 -0.833 -2.43 -0.918 1.04 -1.18 0.825 1.32 FALSE
#> 6 fam_ID_6 -0.815 -0.727 -0.960 -0.534 -0.110 0.858 -0.300 FALSE
#> 7 fam_ID_7 0.484 0.364 -1.02 0.0125 1.66 -0.101 -0.632 FALSE
#> 8 fam_ID_8 0.248 1.59 -1.30 0.592 1.96 0.466 -0.588 TRUE
#> 9 fam_ID_9 0.482 -0.658 0.171 1.66 1.04 0.697 1.42 FALSE
#> 10 fam_ID_10 0.219 1.12 -0.375 0.856 -1.30 -1.66 -1.01 FALSE
#> # ℹ 990 more rows
#> # ℹ 11 more variables: m_status <lgl>, mgm_status <lgl>, mgf_status <lgl>,
#> # mhs1_status <lgl>, mhs2_status <lgl>, o_aoo <dbl>, m_aoo <dbl>,
#> # mgm_aoo <dbl>, mgf_aoo <dbl>, mhs1_aoo <dbl>, mhs2_aoo <dbl>
#>
#> $thresholds
#> # A tibble: 6,000 × 5
#> fam_ID indiv_ID role lower upper
#> <chr> <chr> <chr> <dbl> <dbl>
#> 1 fam_ID_1 fam_ID_1_1 o -Inf 3.35
#> 2 fam_ID_2 fam_ID_2_1 o -Inf 2.95
#> 3 fam_ID_3 fam_ID_3_1 o 1.54 1.54
#> 4 fam_ID_4 fam_ID_4_1 o -Inf 2.99
#> 5 fam_ID_5 fam_ID_5_1 o -Inf 3.10
#> 6 fam_ID_6 fam_ID_6_1 o -Inf 2.55
#> 7 fam_ID_7 fam_ID_7_1 o -Inf 2.63
#> 8 fam_ID_8 fam_ID_8_1 o 1.59 1.59
#> 9 fam_ID_9 fam_ID_9_1 o -Inf 3.28
#> 10 fam_ID_10 fam_ID_10_1 o -Inf 2.91
#> # ℹ 5,990 more rows
#>
simulate_under_LTM_single(fam_vec = c("m","f","s1"), n_fam = NULL, add_ind = FALSE,
h2 = 0.5, n_sim = 500, pop_prev = .05)
#> $sim_obs
#> # A tibble: 500 × 10
#> fam_ID m f s1 m_status f_status s1_status m_aoo f_aoo
#> <chr> <dbl> <dbl> <dbl> <lgl> <lgl> <lgl> <dbl> <dbl>
#> 1 fam_ID_1 1.25 -0.620 -0.954 FALSE FALSE FALSE 36 44
#> 2 fam_ID_2 -0.335 -1.60 -0.232 FALSE FALSE FALSE 39 36
#> 3 fam_ID_3 -0.0678 -0.236 -0.241 FALSE FALSE FALSE 63 57
#> 4 fam_ID_4 -0.236 -1.00 -0.0947 FALSE FALSE FALSE 52 63
#> 5 fam_ID_5 0.0888 0.429 0.640 FALSE FALSE FALSE 39 31
#> 6 fam_ID_6 1.17 0.393 1.28 FALSE FALSE FALSE 57 55
#> 7 fam_ID_7 -0.722 -0.00746 0.531 FALSE FALSE FALSE 41 42
#> 8 fam_ID_8 -0.904 1.52 0.851 FALSE FALSE FALSE 50 49
#> 9 fam_ID_9 0.696 0.848 -0.945 FALSE FALSE FALSE 49 49
#> 10 fam_ID_10 -0.511 -1.51 -1.56 FALSE FALSE FALSE 46 57
#> # ℹ 490 more rows
#> # ℹ 1 more variable: s1_aoo <dbl>
#>
#> $thresholds
#> # A tibble: 1,500 × 5
#> fam_ID indiv_ID role lower upper
#> <chr> <chr> <chr> <dbl> <dbl>
#> 1 fam_ID_1 fam_ID_1_1 m -Inf 2.82
#> 2 fam_ID_2 fam_ID_2_1 m -Inf 2.71
#> 3 fam_ID_3 fam_ID_3_1 m -Inf 1.89
#> 4 fam_ID_4 fam_ID_4_1 m -Inf 2.21
#> 5 fam_ID_5 fam_ID_5_1 m -Inf 2.71
#> 6 fam_ID_6 fam_ID_6_1 m -Inf 2.05
#> 7 fam_ID_7 fam_ID_7_1 m -Inf 2.63
#> 8 fam_ID_8 fam_ID_8_1 m -Inf 2.29
#> 9 fam_ID_9 fam_ID_9_1 m -Inf 2.32
#> 10 fam_ID_10 fam_ID_10_1 m -Inf 2.44
#> # ℹ 1,490 more rows
#>
simulate_under_LTM_single(fam_vec = c(), n_fam = NULL, add_ind = TRUE, h2 = 0.5,
n_sim = 200, pop_prev = 0.05)
#> Warning: Neither fam_vec nor n_fam is specified...
#> $sim_obs
#> # A tibble: 200 × 5
#> fam_ID g o o_status o_aoo
#> <chr> <dbl> <dbl> <lgl> <dbl>
#> 1 fam_ID_1 -0.343 -1.46 FALSE 22
#> 2 fam_ID_2 -0.00162 -0.361 FALSE 32
#> 3 fam_ID_3 -0.881 -1.82 FALSE 25
#> 4 fam_ID_4 0.669 0.315 FALSE 36
#> 5 fam_ID_5 0.627 0.964 FALSE 22
#> 6 fam_ID_6 -0.157 -0.422 FALSE 29
#> 7 fam_ID_7 -0.582 -0.628 FALSE 26
#> 8 fam_ID_8 -0.366 0.149 FALSE 38
#> 9 fam_ID_9 0.921 0.709 FALSE 15
#> 10 fam_ID_10 0.733 -0.0112 FALSE 32
#> # ℹ 190 more rows
#>
#> $thresholds
#> # A tibble: 200 × 5
#> fam_ID indiv_ID role lower upper
#> <chr> <chr> <chr> <dbl> <dbl>
#> 1 fam_ID_1 fam_ID_1_1 o -Inf 3.33
#> 2 fam_ID_2 fam_ID_2_1 o -Inf 2.97
#> 3 fam_ID_3 fam_ID_3_1 o -Inf 3.23
#> 4 fam_ID_4 fam_ID_4_1 o -Inf 2.82
#> 5 fam_ID_5 fam_ID_5_1 o -Inf 3.33
#> 6 fam_ID_6 fam_ID_6_1 o -Inf 3.09
#> 7 fam_ID_7 fam_ID_7_1 o -Inf 3.19
#> 8 fam_ID_8 fam_ID_8_1 o -Inf 2.75
#> 9 fam_ID_9 fam_ID_9_1 o -Inf 3.57
#> 10 fam_ID_10 fam_ID_10_1 o -Inf 2.97
#> # ℹ 190 more rows
#>