# Segment 22 Sanmit Narvekar

## Segment 22

#### To Compute

1. In lecture slide 3, suppose (for some perverse reason) we were interested in a quantity $\displaystyle f = b_3/b_5$ instead of $\displaystyle f = b_3b_5$ . Calculate a numerical estimate of this new $\displaystyle f$ and its standard error.

The mean is simply the function evaluated at the fitted parameters:

$\displaystyle \langle f \rangle = \frac{b_3}{b_5} = \frac{0.6582}{1.4832} = 0.4438$

The variance can be calculated using the following formula:

$\displaystyle \text{Var}(f) = \nabla f \Sigma \nabla f^T$

$\displaystyle \nabla f = \left[0, 0, \frac{1}{b_5}, 0, - \frac{b_3}{b_5^2} \right]$

By substituting this into the formula above and using the covariance matrix in the slides, we get the variance of f to be:

$\displaystyle \text{Var}(f) = \frac{1}{b_5^2}\Sigma_{33} + 2 \frac{1}{b_5} \left(- \frac{b_3}{b_5^2} \right) \Sigma_{35} + \frac{b_3^2}{b_5^4} \Sigma_{55}$

Plugging in the numbers and crunching gives a variance of 0.0145 and a standard deviation of 0.12044.

2. Same set up, but plot a histogram of the distribution of $\displaystyle f$ by sampling from its posterior distribution (using Python, MATLAB, or any other platform).

Here is the MATLAB code:


% Mean and cov of b's
bfit = [1.1235 1.5210 0.6582 3.2654 1.4832];

covar = [0.1349 0.2224 0.0068 -0.0309 0.0135;
0.2224 0.6918 0.0052 -0.1598 0.1585;
0.0068 0.0052 0.0049 0.0016 -0.0094;
-0.0309 -0.1598 0.0016 0.0746 -0.0444;
0.0135 0.1585 -0.0094 -0.0444 0.0948];

% Sample lots of b's
bs = mvnrnd(bfit, covar, 10000);

% Calculate f for each of those b's
fb = bs(:,3) ./ bs(:,5);

% Plot a histogram
hist(fb, 30)

% Report empirical mean and std dev
mean(fb)
std(fb)



This resulted in the following mean and standard deviation:


mu =

0.4720

stdDev =

0.1492



And here is the corresponding histogram of the posterior distribution of the parameter: