- Bugs in Code
- Error in estimating mu
- Final Plots
- Relative Error Plots
- 2 CV Plot
- Using Reference Panel

- Difference in nvar
- T1D Results
- Microbenchmarking
- Posterior Probabilities of Null Model
- Comments and To Do

We found a couple of bugs in the code. I have corrected these and re-ran the simulations.

- In our correction, we find the PPs for many
**matrices**of simulated Z-scores. Our code for calculating PPs from a**vector**of Z-scores is correct and shown below:

```
ppfunc <- function(z, V, W = 0.2) {
stopifnot(class(z)=="numeric")
r = W^2/(W^2 + V)
bf = 0.5 * (log(1 - r) + (r * z^2)) # log BFs
denom = logsum(bf) # denominator (on log scale so don't sum to 100)
exp(bf - denom) # convert back from log scale
}
```

but it was **incorrect** for when `z`

is a matrix. How?

Our (log) BFs were wrong because we were multiplying

`r`

by`z`

column wise rather than row wise.I was calculating the logsum of the whole matrix of BFs (obtaining one value) rather than for each row seperately to obtain one for each simulation (although this didnâ€™t matter as we normalised the PPs afterwards).

- The method of calculating BFs from the simulated Z-score matrices was
`BF <- 0.5 * (log(1 - r) + (r * zstar^2))`

where`zstar`

is a nsim*nsnp matrix of Z-scores and`r`

is a vector of length nsnp of the shrinkage factors. So that`r`

is being recycled into a matrix to do the multiplications, but it is being recycled column wise rather than row wise!!!!! This was identified because Chris tried to match my results by applying the`ppfunc`

over each row of`zstar`

and we were getting different results. To fix this, I have created a`.zj_pp`

utility function that is used within all the corrected coverage functions (note the difference of calculating the BFs, which now recycles`r`

row wise):

```
.zj_pp = function(Zj, int.Sigma, int.nrep, int.ERR, int.r) {
stopifnot(class(Zj)=="numeric")
stopifnot(class(int.ERR)=="matrix")
stopifnot(class(int.r)=="numeric")
exp.zm = Zj %*% int.Sigma
mexp.zm = matrix(exp.zm, int.nrep, length(Zj), byrow = TRUE) # matrix of Zj replicated in each row
zstar = mexp.zm + int.ERR # MATRIX of z scores
bf = 0.5 * t(log(1 - int.r) + (int.r * t(zstar^2))) # row wise
denom = apply(bf, 1, logsum) # get different denom for each rep
exp(bf - denom) # convert back from log scale
}
```

The code for estimating \(\mu\) was incorrect and has now been ammended. We find that our standard 4 estimates of \(\mu\) are no longer accurate, where:

`A = max(abs(z))`

`B = sum(abs(z)*ppdash)`

`C = (1-ppdash[h0])*max(abs(z))`

`D = mean(B,C)`