Skip to contents

Add errors to genotypes

Usage

add_errors_to_genotypes(Z, w, overdisp_var = NULL)

Arguments

Z

genotypes, e.g. created by sample_profiles_without_error()

w

error probability

overdisp_var

if set, use as modelling overdispersion in $w$ such that $w$ follows a Beta distribution with mean value $w$ and variance overdisp_var

Value

list, element for each locus is a matrix with n rows and two columns

Examples

Z <- sample_profiles_without_error(n = 5, p = list(
  c(0.25, 0.25, 0.5), c(0.1, 0.8, 0.1)))
to012(Z)
#>      [,1] [,2]
#> [1,]    0    1
#> [2,]    1    1
#> [3,]    2    1
#> [4,]    0    1
#> [5,]    1    1
X <- add_errors_to_genotypes(Z, 0.5)
X
#> [[1]]
#>      [,1] [,2]
#> [1,]    0    1
#> [2,]    0    0
#> [3,]    1    0
#> [4,]    0    1
#> [5,]    1    1
#> 
#> [[2]]
#>      [,1] [,2]
#> [1,]    1    0
#> [2,]    0    0
#> [3,]    1    0
#> [4,]    0    0
#> [5,]    1    1
#> 
to012(Z) - to012(add_errors_to_genotypes(Z, 0.0))
#>      [,1] [,2]
#> [1,]    0    0
#> [2,]    0    0
#> [3,]    0    0
#> [4,]    0    0
#> [5,]    0    0


Z <- sample_profiles_without_error(n = 1000, p = c(0.5, 0.4, 0.1))
X1 <- add_errors_to_genotypes(Z, 0.1)
X2 <- add_errors_to_genotypes(Z, 0.1)
tab <- table(to012(X1), to012(X2))
tab
#>    
#>       0   1   2
#>   0 352 106   8
#>   1 119 264  48
#>   2   2  39  62
estimate_w(tab)
#> [1] 0.1015527

X1 <- add_errors_to_genotypes(Z, 0.1, overdisp_var = 0.01)
X2 <- add_errors_to_genotypes(Z, 0.1, overdisp_var = 0.01)
tab <- table(to012(X1), to012(X2))
tab
#>    
#>       0   1   2
#>   0 369  98  14
#>   1  98 274  34
#>   2  11  28  74
estimate_w(tab)
#> [1] 0.09281881
# p <- get_beta_parameters(0.1, 0.01); curve(dbeta(x, p[1], p[2]), from = 0, to = 1)


# p <- get_beta_parameters(0.1, 0.01); curve(dbeta(x, p[1], p[2]), from = 0, to = 1)
X1 <- add_errors_to_genotypes(Z, 0.1, overdisp_var = 0.01)
X2 <- add_errors_to_genotypes(Z, 0.1, overdisp_var = 0.01)
tab <- table(to012(X1), to012(X2))
tab
#>    
#>       0   1   2
#>   0 382  97   7
#>   1 101 263  40
#>   2  10  36  64
estimate_w(tab)
#> [1] 0.09269558