Add errors to genotypes
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
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 0
#> [2,] 2 1
#> [3,] 0 1
#> [4,] 2 2
#> [5,] 0 1
X <- add_errors_to_genotypes(Z, 0.5)
X
#> [[1]]
#> [,1] [,2]
#> [1,] 1 1
#> [2,] 0 0
#> [3,] 0 1
#> [4,] 1 1
#> [5,] 0 0
#>
#> [[2]]
#> [,1] [,2]
#> [1,] 0 1
#> [2,] 0 0
#> [3,] 1 0
#> [4,] 1 0
#> [5,] 0 0
#>
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 325 95 4
#> 1 133 266 46
#> 2 5 47 79
estimate_w(tab)
#> [1] 0.1042099
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 331 100 14
#> 1 99 288 47
#> 2 10 37 74
estimate_w(tab)
#> [1] 0.1014438
# 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 355 89 19
#> 1 93 294 34
#> 2 9 39 68
estimate_w(tab)
#> [1] 0.09397646