MLE of Normal parameters

Dataset download


[1]:
import numpy as np
import pandas as pd

import bokeh_catplot

import bokeh.io
bokeh.io.output_notebook()
Loading BokehJS ...

Recall our first model for spindle length.

\begin{align} l_i \sim \text{Norm}(\phi, \sigma) \;\;\forall i. \end{align}

For this model, we have analytically worked out the maximum likelihood estimate for the parameters \(\phi\) and \(\sigma\) in lecture to be given by their respective plug-in estimates.

\begin{align} &\phi^* = \hat{\phi}\\[1em] &\sigma^* = \hat{\sigma}. \end{align}

We can directly compute these and use parametric bootstrap to get their confidence intervals. We start by loading in the data and computing the MLEs for \(\phi\) and \(\sigma\).

[2]:
df = pd.read_csv('../data/good_invitro_droplet_data.csv', comment='#')

spindle_length = df['Spindle Length (um)'].values

phi_mle = np.mean(spindle_length)
sigma_mle = np.std(spindle_length)

print('φ MLE:', phi_mle, 'µm')
print('σ MLE:', sigma_mle, 'µm')
φ MLE: 32.86402985074626 µm
σ MLE: 4.784665043782949 µm

Now we use parametric bootstrap to compute the confidence intervals. First, we’ll write functions to perform the bootstrapping.

[3]:
rg = np.random.default_rng()

def draw_parametric_bs_reps(data, phi, sigma, size=1):
    """Parametric bootstrap replicates of parameters of
    Normal distribution."""
    bs_reps_phi = np.empty(size)
    bs_reps_sigma = np.empty(size)

    for i in range(size):
        bs_sample = np.random.normal(phi, sigma, size=len(data))
        bs_reps_phi[i] = np.mean(bs_sample)
        bs_reps_sigma[i] = np.std(bs_sample)

    return bs_reps_phi, bs_reps_sigma

Now we can get the bootstrap replicates.

[4]:
bs_reps_phi, bs_reps_sigma = draw_parametric_bs_reps(
    spindle_length, phi_mle, sigma_mle, size=10000
)

With the bootstrap replicates in hand, we can compute the 95% confidence intervals using percentiles.

[5]:
print('φ conf int:', np.percentile(bs_reps_phi, [2.5, 97.5]))
print('σ conf int:', np.percentile(bs_reps_sigma, [2.5, 97.5]))
φ conf int: [32.51198689 33.22973265]
σ conf int: [4.52226723 5.03489485]

So, we have estimated the parameters under this model.

Computing environment

[6]:
%load_ext watermark
%watermark -v -p numpy,pandas,bokeh,bokeh_catplot,jupyterlab
CPython 3.7.5
IPython 7.1.1

numpy 1.17.3
pandas 0.24.2
bokeh 1.4.0
bokeh_catplot 0.1.6
jupyterlab 1.2.3