-
Notifications
You must be signed in to change notification settings - Fork 0
/
jannink-wu.Rmd
201 lines (158 loc) · 8.61 KB
/
jannink-wu.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
---
title: "Jannink and Wu 2003 MCMC methods"
author: "Frederick J. Boehm"
date: "1/19/2020"
output: html_document
params:
lastmod: !r lubridate::now()
bibliography: references.bib
---
Last modified: `r params$lastmod`.
Here is a chunk output
```{r}
params$lastmod
```
IN the notation of @jannink2003estimating, the sequence of updates per iteration is:
1. update QTL inheritance matrix $Q$
1. update QTL allelic effects $a$
1. update family means $\beta$ and residual variance $\sigma^2$
1. update configuration given number of alleles, ie, $C | l$
1. update the number of alleles $l$
The later @jannink2004optimal uses a similar sequence of updates:
1. Update the number of QTL alleles
1. Update the configuration given the number of alleles
1. update QTL variance (when there are multiple QTL)
1. update allelic effects
1. update position and genotypes jointly
1. update family means
## Simulate traits
```{r load_attie}
gg <- readRDS("../data/derived_data/attie_geno.rds")
```
```{r}
library(magrittr)
```
```{r}
config <- matrix(nrow = 8, ncol = 2)
config[, 1] <- rep(c(0, 1), each = 4)
config[, 2] <- 1 - config[, 1]
# simulate a trait
set.seed(2020-02-20)
tr <- reducedscan::sim1(aprobs = gg$`1`[ , , 100], allelic_series = config, allelic_effects = c(-2, 2), error_variance = 1)
s1_out <- qtl2::scan1(genoprobs = gg, pheno = tr)
map <- readRDS("../data/derived_data/attie_map.rds")
plot(s1_out, map = map, chr = 1)
peak_index <- qtl2::find_peaks(s1_out, map = map) %>%
dplyr::filter(chr == 1) %>%
dplyr::select(pos) %>%
unlist() %>%
(function(x) which(map$`1` == x))
# get the founder allele effects
s1c_out <- qtl2::scan1coef(genoprobs = gg[ , 1], pheno = tr)
qtl2::plot_coefCC(s1c_out, map)
effects <- s1c_out %>%
(function(x) qtl2pleio::get_effects(marker_index = peak_index, allele_effects_matrix = x, map = map$`1`))
```
```{r mcmc, eval = FALSE}
set.seed(2020-02-04)
mcmc_out_poisson2 <- reducedscan::jannink_mcmc(niter = 10000,
initial_values = list(configuration = diag(8),
effects = effects,
residual_variance = 1),
genoprobs = gg$`1`[ , , 100],
trait = tr,
allelic_number_prior = "poisson",
poisson_prior_mean = 2)
```
```{r}
mcmc_out_poisson2_rv <- jannink_mcmc_rv_only(niter = 10000,
initial_values = list(configuration = config,
effects = c(-2, 2),
residual_variance = 10),
genoprobs = geno$`1`[ , , 100],
trait = tr,
allelic_number_prior = "poisson",
poisson_prior_mean = 2)
mcmc_out_poisson2_rv_fx <- reducedscan::jannink_mcmc_rv_fx_only(niter = 10000,
initial_values = list(configuration = config,
effects = c(-10, 10),
residual_variance = 3),
genoprobs = geno$`1`[ , , 100],
trait = tr,
allelic_number_prior = "poisson",
poisson_prior_mean = 2)
mcmc_out_uniform <- reducedscan::jannink_mcmc(niter = 10000,
initial_values = list(configuration = diag(8),
effects = effects,
residual_variance = 1),
genoprobs = geno$`1`[ , , 100],
trait = tr,
allelic_number_prior = "uniform",
poisson_prior_mean = 2)
mcmc_out_poisson3 <- reducedscan::jannink_mcmc(niter = 10000,
initial_values = list(configuration = diag(8),
effects = effects,
residual_variance = 1),
genoprobs = geno$`1`[ , , 100],
trait = tr,
allelic_number_prior = "poisson",
poisson_prior_mean = 3)
```
## Multiple univariate traits analysis
I noticed that super-strong traits allow the MCMC to recover the true parameter values. However, in those with smaller LODs, the simulation's parameters tend to be poorly recovered. What gives? And where how weak is "weak" for a trait? I need an algorithm that recovers, reasonably well, the configuration for traits that have lods in the range of 5 to 10. If I can only recover the configuration for traits that have lods over 100, this is useless!
I'll try simulating a collection of traits. I hold constant the configuration among the traits and the residual variance. The traits differ in inputted effects.
```{r, eval=FALSE}
tr30 <- reducedscan::sim1(aprobs = geno$`1`[, , 1000], allelic_series = config, allelic_effects = c(-30, 30), error_variance = 1)
tr20 <- reducedscan::sim1(aprobs = geno$`1`[, , 1000], allelic_series = config, allelic_effects = c(-20, 20), error_variance = 1)
tr10 <- reducedscan::sim1(aprobs = geno$`1`[, , 1000], allelic_series = config, allelic_effects = c(-10, 10), error_variance = 1)
tr3 <- reducedscan::sim1(aprobs = geno$`1`[, , 1000], allelic_series = config, allelic_effects = c(-3, 3), error_variance = 1)
```
```{r, eval=FALSE}
set.seed(2020-02-10)
out30 <- reducedscan::jannink_mcmc(niter = 10000,
initial_values = list(configuration = config,
effects = c(-10, 10),
residual_variance = 1),
genoprobs = geno$`1`[ , , 1000],
trait = tr30,
allelic_number_prior = "poisson",
poisson_prior_mean = 2)
set.seed(2020-02-10)
out20 <- reducedscan::jannink_mcmc(niter = 10000,
initial_values = list(configuration = config,
effects = c(-10, 10),
residual_variance = 1),
genoprobs = geno$`1`[ , , 1000],
trait = tr20,
allelic_number_prior = "poisson",
poisson_prior_mean = 2)
set.seed(2020-02-10)
out10 <- reducedscan::jannink_mcmc(niter = 10000,
initial_values = list(configuration = config,
effects = c(-10, 10),
residual_variance = 1),
genoprobs = geno$`1`[ , , 1000],
trait = tr10,
allelic_number_prior = "poisson",
poisson_prior_mean = 2)
out3 <- reducedscan::jannink_mcmc(niter = 10000,
initial_values = list(configuration = config,
effects = c(-10, 10),
residual_variance = 1),
genoprobs = geno$`1`[ , , 1000],
trait = tr3,
allelic_number_prior = "poisson",
poisson_prior_mean = 2)
```
## Open questions about the inferences
1. Role of starting values
1. residual variance
1. configuration
1. allelic number
1. effects
1. Role of true effects
1. Role of poisson prior mean hyperparameter
1. How do mistaken inferences in configuration affect statistical power in QTL scans?
1. Too many alleles, but otherwise reasonable groupings of founders
1. Too few alleles
1. Too many alleles and unreasonable groupings of founders