class: center, middle, title-slide # Practical 3 ### Olivier Gimenez ### last updated: 2021-03-22 --- ## Moment matching * In the capture-recapture example, we know a priori that the mean of the probability we're interested in is `\(\mu = 0.57\)` and its variance is `\(\sigma^2 = 0.073^2\)`. * Parameters `\(\mu\)` and `\(\sigma^2\)` are seen as the moments of a `\(Beta(\alpha,\beta)\)` distribution. * Now we look for values of `\(\alpha\)` and `\(\beta\)` that match the observed moments of the `\(Beta\)` distribution. * We need another set of equations: `$$\alpha = \bigg(\frac{1-\mu}{\sigma^2}- \frac{1}{\mu} \bigg)\mu^2$$` `$$\beta = \alpha \bigg(\frac{1}{\mu}-1\bigg)$$` --- ## Moment matching * For our model, that means: .small-font[ ```r (alpha <- ( (1 - 0.57)/(0.073*0.073) - (1/0.57) )*0.57^2) ``` ``` ## [1] 25.64636 ``` ```r (beta <- alpha * ( (1/0.57) - 1)) ``` ``` ## [1] 19.34726 ``` ] --- ## Question * Use simulations to check that our estimates are correct. * Hint: The `R` function `rbeta()` might be of use. --- # Solution ```r alpha <- ( (1 - 0.57)/(0.073*0.073) - (1/0.57) )*0.57^2 beta <- alpha * ( (1/0.57) - 1) n <- 10000 samp <- rbeta(n, alpha, beta) ``` ```r (mu <- mean(samp)) ``` ``` ## [1] 0.5701544 ``` ```r (sigma <- sqrt(var(samp))) ``` ``` ## [1] 0.07389126 ```