Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Likelihood theory

Introduction

There are many different strategies for estimating parameters when given a sample (X1,X2,X3,⋯ ,Xn)(X_{1},X_{2}, X_{3}, \cdots, X_{n}), and a single relation of all the random variables in this sample---what we call a dataset (D\mathcal{D}). Each strategy for estimating parameters has advantages and disadvantages. Up until this point we learned a single strategy called The Method of Moments. Lets explore a second, popular strategy for estimating parameters given a sample and a model called The likelihood approach.

The likelihood approach has as advantages that estimators are often simpler to compute than the method of moments, we can construct a straightforward method to compute the variance of estimators which is based on the curvature of a likelihood functions, and choosing parameters that "best fit" the data is an intuitive approach.

Probability of a dataset

Suppose that we are provided a single dataset D=(y1,y2,⋯ ,yn)\mathcal{D} = (y_{1},y_{2},\cdots,y_{n}), and we assume that this dataset was generated from a sample (Y1,Y2,Y3,⋯ ,Yn)(Y_{1},Y_{2},Y_{3},\cdots,Y_{n}).

The Probability of our dataset---P(D)P(\mathcal{D})---is defined as

P(D)=P(Y1=y1∩Y2=y2∩⋯∩Yn=yn)=P(Y1=y1,Y2=y2,⋯ ,Yn=yn)\begin{aligned} P(\mathcal{D}) &= P( Y_{1}=y_{1} \cap Y_{2}=y_{2} \cap \cdots \cap Y_{n}=y_{n} )\\ &=P( Y_{1}=y_{1} , Y_{2}=y_{2} , \cdots , Y_{n}=y_{n} ) \end{aligned}

where we use a comma to denote the ∩\cap symbol. The probability of our dataset is the probability that random variable Y1Y_{1} generates the realized value y1y_{1}, Y2Y_{2} generates y2y_{2} , and so on, all simultaneously.

If we assume that our sample is independent and identically distributed (i.i.d.) then we can simplify P(D)P(\mathcal{D}).

We need one fact first.

Conditional probability chains

Consider computing the probability of a sample of size three (X1,X2,X3)(X_{1},X_{2},X_{3}).

P(X1=x1∩X2=x2∩X3=x3)P(X_{1}=x_{1} \cap X_{2}=x_{2} \cap X_{3}=x_{3})

We can imagine that inside the event X1=x1∩X2=x2∩X3=x3X_{1}=x_{1} \cap X_{2}=x_{2} \cap X_{3}=x_{3} there exists two events.

[X1=x1]∩[X2=x2∩X3=x3][X_{1}=x_{1}] \cap [X_{2}=x_{2} \cap X_{3}=x_{3}]

Here, we partitioned the above event that contained three random variables into two events: one event that contains a single random variable and a second event that contains two random variables.

Now we can use an identity that we learned in the past to break this probability into two. For two events AA and BB, recall

P(A∩B)=P(B∣A)P(A).P(A \cap B) = P(B|A) P(A).

Then

P([X1=x1]∩[X2=x2∩X3=x3])=P(X1=x1∣[X2=x2∩X3=x3])P(X2=x2∩X3=x3).\begin{aligned} &P( [X_{1}=x_{1}] \cap [X_{2}=x_{2} \cap X_{3}=x_{3}]) = \\ &P( X_{1}=x_{1} | [X_{2}=x_{2} \cap X_{3}=x_{3}]) P(X_{2}=x_{2} \cap X_{3}=x_{3}). \end{aligned}

We could apply the same technique above to the event X2=x2∩X3=x3X_{2}=x_{2} \cap X_{3}=x_{3} and find that

P(X1=x1∣[X2=x2∩X3=x3])P(X2=x2∩X3=x3)=P(X1=x1∣[X2=x2∩X3=x3])P(X2=x2∣X3=x3)P(X3=x3)\begin{aligned} &P( X_{1}=x_{1} | [X_{2}=x_{2} \cap X_{3}=x_{3}]) P(X_{2}=x_{2} \cap X_{3}=x_{3}) = \\ &P( X_{1}=x_{1} | [X_{2}=x_{2} \cap X_{3}=x_{3}]) P(X_{2}=x_{2} | X_{3}=x_{3}) P(X_{3}=x_{3}) \end{aligned}

The process of breaking a single probability into several probabilities in this way is sometimes called producing a conditional chain of probabilities.

Probability of an i.i.d. sample

Given an i.i.d. sample (Y1,Y2,⋯ ,Yn)(Y_{1},Y_{2},\cdots,Y_{n}) the probability of this sample is

P(Y1=y1,Y2=y2,⋯Yn=yn)\begin{aligned} P(Y_{1} = y_{1}, Y_{2} = y_{2}, \cdots Y_{n} = y_{n}) \end{aligned}

We can break this probability into several conditional probabilities.

P(Y1=y1,Y2=y2,⋯Yn=yn)=P(Y1∣Y2∩Y3∩⋯Yn)P(Y2∣Y3∩⋯Yn)P(Y3∣Y4∩⋯Yn)⋯P(Yn−1∣Yn)P(Yn)\begin{aligned} &P(Y_{1} = y_{1}, Y_{2} = y_{2}, \cdots Y_{n} = y_{n}) =\\ &P(Y_{1} | Y_{2} \cap Y_{3} \cap \cdots Y_{n} ) P( Y_{2} | Y_{3} \cap \cdots Y_{n} ) P(Y_{3} | Y_{4} \cap \cdots Y_{n}) \cdots \\ &P(Y_{n-1} | Y_{n}) P(Y_{n}) \end{aligned}

But because we assume our sample is (mutually) independent then

P(Y1∣Y2∩Y3∩⋯Yn)P(Y2∣Y3∩⋯Yn)P(Y3∣Y4∩⋯Yn)⋯P(Yn−1∣Yn)P(Yn)=P(Y1)P(Y2)⋯P(Yn)\begin{aligned} &P(Y_{1} | Y_{2} \cap Y_{3} \cap \cdots Y_{n} ) P( Y_{2} | Y_{3} \cap \cdots Y_{n} ) P(Y_{3} | Y_{4} \cap \cdots\\ &Y_{n}) \cdots P(Y_{n-1} | Y_{n}) P(Y_{n}) = P(Y_1) P(Y_{2}) \cdots P(Y_{n}) \end{aligned}

To recap, the probability of a dataset generated by an i.i.d. sample is

P(X1=x1,X2=x2,X3=x3,⋯Xn=xn)=P(X1=x1)P(X2=x2)P(X3=x3)⋯P(Xn=xn)=∏i=1NP(Xi=xi)\begin{aligned} &P(X_{1} = x_{1}, X_{2} = x_{2}, X_{3} = x_{3}, \cdots X_{n} = x_{n} ) =\\ &P(X_{1}=x_{1}) P(X_{2}=x_{2}) P(X_{3}=x_{3})\cdots P(X_{n}=x_{n}) \\ &= \prod_{i=1}^{N} P(X_{i} = x_{i}) \end{aligned}

Suppose an i.i.d. sample (Y1,Y2,⋯ ,Yn)(Y_{1},Y_{2},\cdots, Y_{n}) generated a dataset D=(y1,y2,⋯ ,yn)\mathcal{D} = (y_{1},y_{2},\cdots,y_{n}). Further assume Yi∼Bern(θ)Y_{i} \sim Bern(\theta) for i=1i=1 to NN. Then

P(D∣θ)=P(Y1=y1)P(Y2=y2)⋯P(Yn=yn)=[θy1(1−θ)1−y1][θy2(1−θ)1−y2]⋯[θyn(1−θ)1−yn]=∏i=1N[θyi(1−θ)1−yi]=θ∑i=1Nyi(1−θ)N−∑i=1Nyi\begin{aligned} P(\mathcal{D} | \theta ) &= P(Y_{1}=y_{1}) P(Y_{2}=y_{2}) \cdots P(Y_{n}=y_{n}) \\ &= \left[\theta^{y_{1}}(1 - \theta)^{1-y_{1}}\right]\left[\theta^{y_{2}}(1 - \theta)^{1-y_{2}}\right] \cdots \left[\theta^{y_{n}}(1 - \theta)^{1-y_{n}}\right] \\ &= \prod_{i=1}^{N} \left[\theta^{y_{i}}(1 - \theta)^{1-y_{i}}\right] \\ &= \theta^{ \sum_{i=1}^{N} y_{i} } (1-\theta)^{N - \sum_{i=1}^{N} y_{i} } \end{aligned}

The likelihood function

The probability of our dataset P(D)P(\mathcal{D} ) depends on a set of parameters (θ)(\theta), and we can write P(D∣θ)P(\mathcal{D} | \theta). Different choices for our parameter values will result in different values of P(D∣θ)P(\mathcal{D} | \theta).

(Bernoulli example continued). Suppose that we are given the dataset D=(1,0,1,0,0,1,1)\mathcal{D} = (1,0,1,0,0,1,1) and we assume that these 7 datapoints were generated from an i.i.d. Bernoulli model. Then, as we saw above,

P(D∣θ)=θ∑i=1Nyi(1−θ)N−∑i=1NyiP(\mathcal{D} | \theta) = \theta^{ \sum_{i=1}^{N} y_{i} } (1-\theta)^{N - \sum_{i=1}^{N} y_{i} }

. For our dataset, we can fill in the yiy_{i} values to find

P(D∣θ)=θ4(1−θ)7−4P(\mathcal{D} | \theta) = \theta^{ 4 } (1-\theta)^{7 - 4 }

We can now compute the probability of our data for different choices of θ\theta

P(D∣θ=0.25)=0.254(1−0.25)3=P(D∣θ=0.50)=0.504(1−0.50)3=P(D∣θ=0.75)=0.754(1−0.75)3=\begin{aligned} P(\mathcal{D} | \theta=0.25) = 0.25^{ 4 } (1-0.25)^{3 } = \\ P(\mathcal{D} | \theta=0.50) = 0.50^{ 4 } (1-0.50)^{3 } = \\ P(\mathcal{D} | \theta=0.75) = 0.75^{ 4 } (1-0.75)^{3 } = \end{aligned}

The likelihood function, L\mathcal{L}, is the probability of our observed data as a function of a set of parameter values

L(θ∣D)=P(D∣θ)\mathcal{L}(\theta | \mathcal{D}) = P(\mathcal{D} | \theta)

The difference between P(D∣θ)P(\mathcal{D} | \theta) and L(θ∣D)\mathcal{L}(\theta | \mathcal{D}) is the argument. For P(D∣θ)P(\mathcal{D} | \theta) we expect, given a set of fixed parameter values, to compute the probability of different datasets. For L(θ∣D)\mathcal{L}(\theta | \mathcal{D}) we expect, given a fixed, observed dataset D\mathcal{D}, to compute the probability of D\mathcal{D} for different values of θ\theta.

The likelihood function allows us to investigate the plausability of different parameter values after we observed a dataset. The likelihood need not be a probability distribution, and often is not.

Suppose we observe for 7 days the number of patients who arrive at a specific hospital and are diagnosed with influenza. The data we collect is D=(10,13,4,17,34,11,3)\mathcal{D} = (10,13,4,17,34,11,3). We choose to consider our data a random sample (X1,X2,⋯ ,X7)(X_{1},X_{2},\cdots,X_{7}) where Xi∼Pois(λ)X_{i} \sim Pois(\lambda). Then

P(D∣λ)=∏i=17f(xi∣λ)=∏i=17e−λλxixi!=e−7λλ10+13+⋯+310!13!4!⋯3!\begin{aligned} P(\mathcal{D} | \lambda) &= \prod_{i=1}^{7} f( x_{i} | \lambda) \\ &= \prod_{i=1}^{7} \frac{e^{-\lambda} \lambda^{x_{i}}}{x_{i} !} \\ &= \frac{e^{-7\lambda} \lambda^{10+13+\cdots+3}}{10! 13! 4! \cdots 3!} \end{aligned}

If we consider the above as a function of λ\lambda---L(λ∣D)\mathcal{L}(\lambda | \mathcal{D}) then if L(λ1∣D)\mathcal{L}(\lambda_{1} | \mathcal{D}) > L(λ2∣D)\mathcal{L}(\lambda_{2} | \mathcal{D}) then the parameter value λ1\lambda_{1} may be a more plausible parameter value compared to λ2\lambda_{2}.

One way to use the likelihood function is to attempt to find the most plausible parameter value, the value that maximizes the likelihood. However this value may be difficult to find. Lets explore one strategy for simplifying the search for this optimal parameter value and a second strategy that can help us compute this optimal value.

The logarithm and the log likelihood

With a likelihood function in hand, one aim may be to find the set of parameter values that maximizes this function---the set of parameter values that are more plausible given an observed dataset. However, the likelihood function L\mathcal{L} can in many cases be difficult to compute because it is a sequence of multiplications. Our aims is to find a related function ℓℓ\ell \ell such that parameter values that maximize L\mathcal{L} also maximize this "easier to work with" ℓℓ\ell \ell function.

A function gg is monotone increasing if for two values x>yx>y then g(x)≥g(y)g(x) \geq g(y). If a monotone function gg is applied to a second function ff, the values that maximize ff also maximize this new function.

Hypothesis: Suppose the value x∗x^{*} maximizes the function ff. That is, for all xx the value f(x∗)≥f(x)f(x^{*}) \geq f(x). Then if gg is a monotone increasing function then x∗x^{*} also maximizes g(f(x))g(f(x)).

Evidence: We know that f(x∗)≥f(x)f(x^{*}) \geq f(x). gg is a monotone increasing function and so by definition for x≥yx \geq y, g(x)>g(y)g(x)>g(y). We can use as an input to gg the values f(x∗)f(x^{*}) and f(x)f(x) to find that because f(x∗)≥f(x)f(x^{*}) \geq f(x) then g(f(x∗))≥g(f(x))g( f(x^{*}) ) \geq g( f(x) ).

The above property of a monotone increasing function is useful if we can find such a function that simplifies our likelihood---a sequence of multiplications. The logarithm is a monotone increasing function (i.e. if x≥yx \geq y then log⁡(x)≥log⁡(y)\log(x) \geq \log(y) ), and the logarithm transforms multiplications (hard) into sums (easy).

The log likelihood function is the natural logarithm of the likelihood function

ℓℓ(θ∣D)=log⁡[L(θ∣D)]\ell \ell (\theta | \mathcal{D}) = \log \left[ \mathcal{L} (\theta | \mathcal{D}) \right]

The loglikelihood simplifies the likelihood by transforming a large sequence of multiplications into sums.

There is one more principle about maximizing functions that will be useful. Suppose we find the value (x∗)(x^{*}) that maximizes the function

g(x)=f(x)+cg(x) = f(x) + c

then that value x∗x^{*} also maximizes f(x)f(x). Also, suppose we find the value (x∗)(x^{*}) that maximizes the function

g(x)=c⋅f(x)g(x) = c \cdot f(x)

then that value x∗x^{*} also maximizes f(x)f(x).

The above two principles state that if we are interested in finding the maximum value of a function gg then we can consider a simpler function ff which does not contain unrelated constants.

The value x∗x^{*} that maximizes the function g(x)=−x2+3g(x) = -x^{2} + 3 is the same value that maximizes the function f(x)=−x2f(x) = -x^{2}.

The value x∗x^{*} that maximizes the function g(x)=e−x24g(x) = \frac{e^{-x^{2}}}{4} is the same value that maximizes the function f(x)=e−x2f(x) = e^{-x^{2}}.

We found in the previous section that the likelihood for the number of admitted patients with influenza was

L(λ∣D)=e−7λλ10+13+⋯+310!13!4!⋯3!.\mathcal{L}(\lambda | \mathcal{D}) = \frac{e^{-7\lambda} \lambda^{10+13+\cdots+3}}{10! 13! 4! \cdots 3!}.

The log likelihood of the above is, the simpler,

ℓℓ(λ∣D)=log⁡[e−7λλ10+13+⋯+310!13!4!⋯3!]=−7λ+(10+13+⋯+3)log⁡(λ)−[log⁡(10!)+log⁡(13!)+⋯+log⁡(3!)]\begin{aligned} \ell \ell (\lambda | \mathcal{D}) &= \log \left[ \frac{e^{-7\lambda} \lambda^{10+13+\cdots+3}}{10! 13! 4! \cdots 3!} \right] \\ &= -7 \lambda + (10+13+\cdots+3) \log(\lambda) - \left[ \log(10!) + \log(13!) + \cdots + \log(3!) \right] \end{aligned}

We see that the last term of factorials does not involve our parameter value λ\lambda. This term is then a constant and we could instead aim to find the maximium of the simpler function

ℓℓ(λ∣D)=−7λ+(10+13+⋯+3)log⁡(λ)=−7λ+83log⁡(λ)\begin{aligned} \ell \ell (\lambda | \mathcal{D}) &= -7 \lambda + (10+13+\cdots+3) \log(\lambda) \\ &= -7 \lambda + 83\log(\lambda) \end{aligned}

In some cases, we may be able to find the parameter value, or set of parameter values, that maximize the log likelihood function. To explore this topic we will need to briefly learn about the derivative of a continuous function.

Just in time derivatives

The derivative describes the tangential slope of a function at a point and can serve as a linear approximation to a more complicated function. We will see how we can use the derivative to setup and solve an equation that will return a parameter value that maximizes the log likelihood. This estimate of our parameter will be called a maximum likelihood estimate.

Sequences and limits

A sequence is defined as a function whose domain is the natural numbers N={1,2,3,4,5,6,⋯ }\mathbb{N} = \{1,2,3,4,5,6, \cdots \}. Often as annotate the value associated with the 1, f(1)f(1) as a1a_{1}, the value associated with 2, f(2)f(2), as a2a_{2}, and so on.

The following is a sequence f(x)=2−xf(x) = 2^{-x} for x∈Nx \in \mathbb{N}.The first few values of this sequence are f(1)=a1=1/2f(1) = a_{1} = 1/2, f(2)=a2=1/4f(2) = a_{2} = 1/4, f(3)=a3=1/8f(3) = a_{3} = 1/8, and so on. We can also describe the above sequence using this notation {2−n}n=1∞\{ 2^{-n} \}_{n=1}^{\infty}.

Intuitively, we may wish to know how a sequence behaves as it is enumerated. A sequence may increase to infinity, decrease to negative infinity, oscillate or have some other periodic behavior, or a sequence may move closer and closer to a single value. If a sequence ann=1∞{a_{n}}_{n=1}^{\infty} gets closer and closer to a single value ll then we say that the sequence has a limit and that limit is the value ll.

The more formal definition of a limit is the following: For a sequence {an}n=1∞\{a_{n}\}_{n=1}^{\infty}, given any value ϵ>0\epsilon >0 the value ll is a limit if you can find an integer NN such that ∣aN−l∣<ϵ|a_{N} - l| < \epsilon for integers greater than NN (i.e. N+1N+1, N+2N+2, ⋯\cdots).

We may also define a limit LL of a function at the value aa if given a sequence of values a1,a2,⋯ana_{1}, a_{2}, \cdots a_{n} that approach the value aa, the sequence f(a1),f(a2),f(a3),⋯f(a_{1}), f(a_{2}), f(a_{3}), \cdots approaches the value LL. We call LL the limit of ff at the value aa and write

lim⁡x→af(x)=L\lim_{x \to a} f(x) = L

Intuitively, the above says that as the input of our function approaches the value aa, the function values approach the value LL.

To solve our problem of finding the parameter value that maximizes the log likelihood, we need to learn about a special type of limit called the derivative.

Derivative of a function

The derivative of a function at the value aa, or f′(a)f'(a), is

f′(a)=lim⁡x→af(x)−f(a)x−a\begin{aligned} f'(a) = \lim_{ x \to a } \frac{f(x) - f(a)}{x-a} \end{aligned}

For intuition, we can imagine building a sequence

a1,a2,a3,⋯ ,an→aa_{1},a_{2},a_{3},\cdots, a_{n} \to a

that approaches the value aa and computing the associated sequence

f(a1)−f(a)a1−a,f(a2)−f(a)a2−a,f(a3)−f(a)a3−a,⋯ ,f(an)−f(a)an−a→f′(a)\frac{f(a_{1}) - f(a)}{a_{1}-a},\frac{f(a_{2}) - f(a)}{a_{2}-a},\frac{f(a_{3}) - f(a)}{a_{3}-a},\cdots,\frac{f(a_{n}) - f(a)}{a_{n}-a} \to f'(a)

One common sequence that approaches aa is the sequence a+{hn}n=1∞a + \{h_{n}\}_{n=1}^{\infty} and where the sequence hh approaches 0. Then the definition of the derivative would be

f′(a)=lim⁡h→0f(a+h)−f(a)a+h−a=lim⁡h→0f(a+h)−f(a)h\begin{aligned} f'(a) &= \lim_{ h \to 0 } \frac{f(a+h) - f(a)}{a+h-a} \\ &= \lim_{ h \to 0 } \frac{f(a+h) - f(a)}{h} \end{aligned}

This is because as the sequence {hn}\{h_{n}\} approaches zero, the sequence {a+hn}\{a+h_{n}\} approaches the value aa.

Let g(x)=x2g(x) = x^{2}. The derivative of gg at the value 1 is by definition

g′(1)=lim⁡h→0g(1+h)−g(1)h=lim⁡h→0(1+h)2−12h=lim⁡h→0h2+2h+1−1h=lim⁡h→0h2+2hh=lim⁡h→0h+21=2\begin{aligned} g'(1) &= \lim_{ h \to 0 } \frac{g(1+h) - g(1) }{h} \\ &= \lim_{ h \to 0 } \frac{ (1+h)^{2} - 1^{2} }{h}\\ &= \lim_{ h \to 0 } \frac{ h^{2} + 2h + 1 - 1 }{h}\\ &= \lim_{ h \to 0 } \frac{ h^{2} + 2h }{h}\\ &= \lim_{ h \to 0 } \frac{ h + 2 }{1}\\ &=2 \end{aligned}

For any value cc we find that the derivative of gg is

g′(c)=lim⁡h→0g(c+h)−g(c)h=lim⁡h→0(c+h)2−c2h=lim⁡h→0h2+2hc+c2−c2h=lim⁡h→0h2+2hch=lim⁡h→0h+2c1=2c\begin{aligned} g'(c) &= \lim_{ h \to 0 } \frac{g(c+h) - g(c) }{h} \\ &= \lim_{ h \to 0 } \frac{ (c+h)^{2} - c^{2} }{h}\\ &= \lim_{ h \to 0 } \frac{ h^{2} + 2hc + c^{2} - c^{2} }{h}\\ &= \lim_{ h \to 0 } \frac{ h^{2} + 2hc }{h}\\ &= \lim_{ h \to 0 } \frac{ h + 2c }{1}\\ &=2c \end{aligned}

In some sense, the derivative g′(c)g'(c) too is a function, the function g′(c)=2cg'(c) = 2c.

When the derivative equals zero

When the derivative of a function at the point x∗x^{*} is 0 the point x∗x^{*} is either a minimum or a maximum value. This is the key to finding a parameter value that maximizes our log likelihood. If we can compute the derivative of our log likelihood ℓℓ′(θ)\ell \ell'(\theta) and find the value θ\theta such that ℓℓ′=0\ell \ell' = 0 then we know we have found either a parameter value that minimizes or maximizes our log likelhood, which then minimizes or maximizes our likelihood, which suggests that this parameter value is the most plausible value given our observed data. Phew.

Lets prove that when the derivative equal zero then we are at a maximum. Hypothesis: If f(x∗)>f(x)f(x^{*}) > f(x) for any possible input xx then f′(x∗)=0f'(x^{*})=0.
Let us build a two sequences, one sequence {x1,x2,⋯ }\{x_{1}, x_{2}, \cdots \} that approaches x∗x^{*} such that all the values are smaller than x∗x^{*} and a second sequence {y1,y2,⋯ }\{y_{1}, y_{2}, \cdots \} such that all values are larger than x∗x^{*}.

If we choose any xnx_{n} in the sequence, the following must be true:

Can't use function '$' in math mode at position 79: …q 0 & \;\; &bc $̲f(x^{*)$ is a m…

\begin{aligned}
    \frac{f(x_{n}) - f(x^{*})}{x_{n}-x^{*}} \geq 0 & \;\; &bc $f(x^{*)$ is a max and } x_{n}< x^{*} \\ 
\end{aligned}

If we choose any yny_{n} in the sequence, the following must also be true:

Can't use function '$' in math mode at position 79: …q 0 & \;\; &bc $̲f(x^{*)$ is a m…

\begin{aligned}
    \frac{f(y_{n}) - f(y^{*})}{y_{n}-x^{*}} \leq 0 & \;\; &bc $f(x^{*)$ is a max and } y_{n}>y^{*} \\ 
\end{aligned}

If we assume that there exists a derivative value f′(x∗)f'(x^{*}) then that value must be greater than or equal to zero and also less than or equal to zero. The only options then is f′(x∗)=0f'(x^{*}) = 0.

derivative "rules"

There are several rules that can make computing derivatives of complicated functions easier.

Computing the maximum likelihood estimator

Given a i.i.d sample (X1,X2,⋯ ,Xn)(X_{1},X_{2},\cdots,X_{n}) such that X∼f(x∣θ)X \sim f(x | \theta) we can compute a maximum likelihood estimator of the parameter θ\theta by following these steps: (i) form the likelihood function (ii) convert the likelihood to a log likelihood (iii) compute the derivative of the log likelihood ℓℓ′(θ)\ell \ell ' (\theta) (iv) find the parameter value θ\theta such that ℓℓ′(θ)=0\ell \ell ' (\theta) = 0.

Given (X1,X2,X3,⋯ ,Xn)(X_{1},X_{2},X_{3}, \cdots, X_{n}), the distribution for each Xi∼Bern(θ)X_{i} \sim Bern(\theta), and the dataset D=(0,1,1,0,1)\mathcal{D} = (0,1,1,0,1) we can compute the maximum likelihood estimate for θ\theta.

  1. The likelihood of D\mathcal{D} is $$\begin{aligned} \ell(\theta) &= f(0) \cdot f(1) \cdot f(1) \cdot f(0) \cdot f(1)\ &= \left(\theta^{x_{1}} (1-\theta)^{1-x_{1}}\right) \left(\theta^{x_{2}} (1-\theta)^{1-x_{2}}\right) \left(\theta^{x_{3}} (1-\theta)^{1-x_{3}}\right) \left(\theta^{x_{4}} (1-\theta)^{1-x_{4}}\right) \left(\theta^{x_{5}} (1-\theta)^{1-x_{5}}\right)\ &= \left(\theta^{0} (1-\theta)^{1-0}\right) \left(\theta^{1} (1-\theta)^{1-1}\right) \left(\theta^{1} (1-\theta)^{1-1}\right) \left(\theta^{0} (1-\theta)^{1-0}\right) \left(\theta^{1} (1-\theta)^{1-1}\right)\ &= \left( 1-\theta \right) \left(\theta \right) \left(\theta \right) \left( 1-\theta\right) \left(\theta \right)\ &= \theta^{3} (1-\theta)^{2}

    \end{aligned}$$

  2. Compute the log likelihood $$\begin{aligned} \ell \ell (\theta) &= \log \left[ \ell(\theta) \right] \ &= \log \left[ \theta^{3} (1-\theta)^{2} \right] \ &= \log \left[ \theta^{3}] + \log \left[ (1-\theta)^{2} \right] \ &= 3 \log \left[\theta] + 2 \log \left[ (1-\theta)\right] \

    \end{aligned}$$

  3. Compute the derivative of the log likelihood $$\begin{aligned} \ell \ell (\theta)’ &= \left( 3 \log [\theta] + 2 \log [ (1-\theta)] \right)’ \ &= \left( 3 \log [\theta] \right)’ + \left(2 \log [ (1-\theta)] \right)’ & Addition rule\ &= 3 \left( \log [\theta] \right)’ + 2 \left( \log [ (1-\theta)] \right)’ & Constants rule\ &= 3 \frac{1}{\theta} + 2 \left( \log [ (1-\theta)] \right)’ & Derivative of log\ &= 3 \frac{1}{\theta} + 2 \left( \log [ z ] \right)’ & let z=(1-\theta)\ &= 3 \frac{1}{\theta} + 2 \frac{1}{z} (z)’ & Chain rule \ &= 3 \frac{1}{\theta} + 2 \frac{1}{1-\theta} (1-\theta)’ & Replace z \ &= 3 \frac{1}{\theta} + 2 \frac{1}{1-\theta} (1)’ - (\theta)’ & Addition rule \ &= 3 \frac{1}{\theta} + 2 \frac{1}{1-\theta} 0 - (\theta)’ & Derivative of a constant \ &= 3 \frac{1}{\theta} + 2 \frac{1}{1-\theta} (-1) & Derivative of \theta \ &= 3 \frac{1}{\theta} - 2 \frac{1}{1-\theta}\ &= \frac{3}{\theta} - \frac{2}{1-\theta}

    \end{aligned}$$

  4. Set ℓℓ(θ)′=0\ell \ell(\theta)' = 0 and solve for θ\theta $$\begin{aligned} \ell \ell ’ (\theta) &= \frac{3}{\theta} - \frac{2}{1-\theta} = 0\ \frac{3}{\theta} &= \frac{2}{1-\theta}\ 3 - 3\theta &= 2 \theta \ 3 &= 5 \theta \ \theta &= 3/5\ \hat {\theta} &= 3/5

    \end{aligned}$$

    For our observed data D\mathcal{D} and our assumed model that the random variables generating each data point are i.i.d and distributed Bern(θ)Bern(\theta) our maximum likelihood estimate for θ\theta is θ^mle=3/5\hat{\theta}_{mle} = 3/5.

Given (Y1,Y2,Y3,⋯ ,Yn)(Y_{1},Y_{2},Y_{3}, \cdots, Y_{n}), the distribution for each Yi∼Geom(p)Y_{i} \sim Geom(p), and the dataset D=(7,19,1,11)\mathcal{D} = (7, 19, 1, 11) we can compute the maximum likelihood estimate for the parameter pp.

  1. The likelihood of D\mathcal{D} is $$\begin{aligned} \ell(p) &= f(9) \cdot f(19) \cdot f(1) \cdot f(11)\ &= p(1-p)^{8} \cdot p(1-p)^{18} \cdot p(1-p)^{0} \cdot p(1-p)^{10}\ &= p^{4} (1-p)^{8+18+0+10}\ &= p^{4} (1-p)^{36}\

    \end{aligned}$$

  2. Form the log likelihood $$\begin{aligned} \ell \ell(p) &= \log\left[ \ell(p) \right] \ &= \log \left[ p^{4} (1-p)^{36} \right] \ &= \log \left[ p^{4} \right] + \log \left[(1-p)^{36} \right] \ &= 4\log \left[ p \right] + 36\log \left[(1-p) \right]

    \end{aligned}$$

  3. Compute the derivative of the log likelihood $$\begin{aligned} \ell \ell’(p) &= 4\frac{1}{p} + 36 \log( h(x) ) where h(x) = 1-p\ &= \frac{4}{p} + 36\frac{1}{h(x)} \cdot -1\ &= \frac{4}{p} - 36\frac{1}{1-p} \ &= \frac{4}{p} - \frac{36}{1-p}

    \end{aligned}$$

  4. Set the derivative equal to zero and solve for the parameter $$\begin{aligned} \ell \ell’(p) &= \frac{4}{p} - \frac{36}{1-p} = 0 \ &= \frac{ 4p(1-p) }{p} - \frac{36 p(1-p)}{1-p} = 0 \ &= 4(1-p) - 36 p = 0 \ &= 4 - 4p - 36 p = 0 \ &= 4 = 40p \ p &= 4/40 = 1/10

    \end{aligned}$$

    For our observed data D\mathcal{D} and our assumed model that the random variables generating each data point are i.i.d and distributed Geom(p)Geom(p), our maximum likelihood estimate for pp is p^mle=110\hat{p}_{mle} = \frac{1}{10}.

Fisher information

A maximum likelihood estimate for a parameter describes what single parameter value most probably generated our observed dataset. However, intuitively, if we had a collected a different dataset of the same size then we would likely have arrived at a different maximum likelihood estimate. Repeating the steps: (i) generate dataset of same size, (ii) compute maximum likelihood estimate, (iii) store estimate would lead to many estimates of the same model. To better characterize our model, we will need in addition to a single maximum likelihood estimate a measure of how that estimate may vary.

The Fisher Information I(θ)\mathcal{I}(\theta) about a parameter θ\theta is defined as

I(θ)=E([ℓ′(x∣θ)]2)=V(ℓ(θ))\mathcal{I}(\theta) = \mathbb{E}\left( \left[ \ell'(x | \theta) \right]^{2} \right) = \mathbb{V}\left(\ell(\theta)\right)

the intuition behind the Fisher information is that log likelihood function that are very peaked around their maximum likelihood estimate will have large Fisher information values. On the contrary, if a log-likelihood is very flat near it’s maximum likelihood estimate then the Fisher information will be small.

In some sense, the Fisher information describes the curvature of the log likelihood around the maximum likelihood estimate and that curvature is also related to the variability of our estimate.

We will not explore this topic in class, but it is often easier to compute an equivalent definition of the Fisher information

−E(ℓℓ′′(θ∣X))=V(ℓℓ′(θ∣X)).-\mathbb{E}( \ell \ell ''(\theta | X) ) = \mathbb{V}( \ell \ell ' (\theta | X) ).

This definition says that in order to compute the Fisher information we will need to compute the second derivative of the log likelihood, compute the expedctation, and then multiply that second derivative by negative one.

Lets look at an example of using this alternative definition to compute the Fisher information for a Bernoulli model.

Suppose a sample (X1,X2,X3,⋯ ,Xn)(X_{1},X_{2},X_{3},\cdots,X_{n}) that we assume Xi∼Bernoulli(θ)X_{i} \sim Bernoulli(\theta). Then the log likelihood for a single data point is

ℓ(θ)=log⁡[f(d1∣θ)]=log⁡[θd1(1−θ)1−d1]=d1log⁡(θ)+(1−d1)log⁡(1−θ)\begin{aligned} \ell(\theta) &= \log \left[ f(d_{1} | \theta) \right] \\ &= \log \left[ \theta^{d_{1}}(1-\theta)^{1-d_{1}} \right] \\ &= d_{1}\log(\theta) + (1-d_{1})\log(1-\theta) \\ \end{aligned}

and the derivative of the log likelihood is

ℓ′(θ)=d1θ−1−d11−θ\begin{aligned} \ell'(\theta) = \frac{d_{1}}{\theta} - \frac{1-d_{1}}{1-\theta} \end{aligned}

To compute the second derivative, we take the derivative of ℓ′(θ)\ell'(\theta).

ℓ′(θ)=d1θ−1−(1−d1)(1−θ)−1ℓ′′(θ)=−d1θ−2−(1−d1)(1−θ)−2\begin{aligned} \ell'(\theta) &= d_{1} \theta^{-1} - (1-d_{1})(1-\theta)^{-1} \\ \ell''(\theta) &= -d_{1} \theta^{-2} - (1-d_{1})(1-\theta)^{-2} \end{aligned}

The above if the second derivative of the log likelihood for a single datapoint. However that data point was generated from a random variable X1X_{1} and so we can then treat ℓ′′(θ)\ell''(\theta) as a transformation of the random variable X1X_{1}.

ℓ′′(X∣θ)=−Xθ−2−(1−X)(1−θ)−2ℓ′′(X∣θ)=−Xθ2−1−X(1−θ)2\begin{aligned} \ell''(X | \theta) &= -X \theta^{-2} - (1-X)(1-\theta)^{-2} \\ \ell''(X | \theta) &= - \frac{X}{\theta^{2}} - \frac{1-X}{ (1-\theta)^{2}} \\ \end{aligned}

The above transformation is a complicated function, but the fisher information only requires that we understand as single quantity from this transformation---the expected value.

E[ℓ′′(X∣θ)]=−E(X)θ2−1−E(X)(1−θ)2=−θθ2−1−θ(1−θ)2=−1θ−1(1−θ)\begin{aligned} \mathbb{E}\left[\ell''(X | \theta)\right] &= - \frac{ \mathbb{E}(X)}{\theta^{2}} - \frac{1-\mathbb{E}(X)}{ (1-\theta)^{2}} \\ &= -\frac{\theta}{\theta^{2}} - \frac{1-\theta}{ (1-\theta)^{2}} \\ &= -\frac{1}{\theta} - \frac{1}{(1-\theta)} \end{aligned}

The final steps asks that we take the negative of the quantity above

I(θ∣X)=1θ+1(1−θ)=1−θ+θθ(1−θ)=1θ(1−θ)\begin{aligned} \mathcal{I}(\theta | X) &= \frac{1}{\theta} + \frac{1}{(1-\theta)} \\ &= \frac{ 1- \theta + \theta }{\theta(1-\theta)} \\ &= \frac{1}{\theta(1-\theta)} \end{aligned}

Fisher for a sample of size n

The Fisher information for a sample of size n (X1,X2,⋯ ,Xn)(X_{1},X_{2},\cdots, X_{n}) is equal to

I(x1,x2,⋯ ,xn)=nI(θ)\mathcal{I}(x_{1},x_{2},\cdots,x_{n}) = n \mathcal{I}(\theta)

Intuitively, a sample of size 8 is twice as informative as a sample of size 4.

CLT-like thm that involves the Fisher information

An important theorem that will allow us to construct confidence intervals and hypothesis tests about our parameters states the following:

n(θ^−θ)∼N(0,1I(θ))\sqrt{n}(\hat{\theta} - \theta) \sim \mathcal{N}\left(0,\frac{1}{\mathcal{I}(\theta)}\right)

where θ^\hat{\theta} is our maximum likelihood estimate, θ\theta is our true, and unknown, parameter, and I\mathcal{I} is the information about θ\theta.

This theorem

Homework

  1. Suppose that we collected a dataset with a single observation D={12}\mathcal{D} = \{ 12 \}. Please compute the probability of D\mathcal{D} if we assume our data was generated by a random variable XX

    1. Such that X∼Geom(p)X \sim Geom(p). Assume we know the parameter value pp.

    2. Such that X∼Pois(λ)X \sim Pois(\lambda). Assume we know the parameter value λ\lambda.

    3. Such that X∼N(μ,σ2)X \sim \mathcal{N}(\mu,\sigma^{2}). Assume we know the parameter values (μ,σ2)(\mu, \sigma^{2}).

  2. Suppose that we collected a dataset with a two observations D={12,2}\mathcal{D} = \{ 12, 2 \}. Please compute the likelihood function for D\mathcal{D} if we assume our data was generated by a random variable XX

    1. Such that X∼Geom(p)X \sim Geom(p). Assume we know the parameter value pp.

    2. Such that X∼Pois(λ)X \sim Pois(\lambda) Assume we know the parameter value λ\lambda.

    3. Such that X∼Binom(20,θ)X \sim Binom(20, \theta). Assume we know the parameter value θ\theta.

  3. Suppose that we collected a dataset with a nn observations D={x1,x2,⋯ ,xn}\mathcal{D} = \{ x_{1}, x_{2}, \cdots, x_{n} \}. Please compute the log likelihood if we assume our data was generated by a random variable XX

    1. Such that X∼Geom(p)X \sim Geom(p). Assume we know the parameter value pp.

    2. Such that X∼Pois(λ)X \sim Pois(\lambda) Assume we know the parameter value λ\lambda.

    3. Such that X∼Binom(N,θ)X \sim Binom(N, \theta). Assume we know the parameter value θ\theta.

    4. Such that X∼N(μ,σ2)X \sim \mathcal{N}(\mu,\sigma^{2}). Assume we know the parameter values

  4. Suppose you collect a dataset D=(x1,x2,⋯ ,xn)\mathcal{D} = (x_{1},x_{2},\cdots,x_{n}) that you assume is generated from an i.i.d. sample X1,X2,⋯ ,XnX_{1}, X_{2},\cdots, X_{n}, where Xi∼f(x∣θ)X_{i} \sim f(x | \theta) and θ\theta is a parameter. You decide to compute the loglikelihood $$\begin{aligned} \ell \ell (\theta | \mathcal{D}) = \sum_{i=1}^{n} \log \left [ f(x_{i} | \theta) \right]

    \end{aligned}

    Can't use function '$' in math mode at position 48: …ding the value $̲\theta^{*}$ tha…
    
    Because we are interested in finding the value $\theta^{*}$ that maximizes $\mathcal{\ell \ell}$ then multiplying the log likelihood by a constant will not change the optimal $\theta^{*}$

    \begin{aligned} \frac{1}{n} \ell \ell (\theta | x_{1}, x_{2}, \cdots, x_{n}) = \frac{1}{n} \sum_{i=1}^{n} \log \left [ f(x_{i} | \theta) \right]

    \end{aligned}$$

    1. The law of large numbers states that the above quantity will approach?

  5. Suppose that we are asked to help better understand the burden of influenza circulating in in the state of Pennsylvania. Over the course of 6 weeks we collect the following number of cases of reported influenza D=(143,12,124,56,66)\mathcal{D} = (143, 12, 124, 56, 66).

    1. Please propose a model for this data and a short description for why you chose this model.

    2. Please compute the likelihood for your model parameters given the data

    3. Please compute the log likelihood.

  6. Consider the sequence an=2−na_{n} = 2^{-n} for n=1n=1 to ∞\infty.

    1. Write down the first 3 items in this sequence

    2. Please compute

      lim⁡n→∞an\lim_{n \to \infty} a_{n}
  7. Does the infinite sequence {−1,1,−1,1,−1,1,⋯ }\{-1,1,-1,1,-1,1, \cdots \} have a limit? Why or why not?

  8. Consider the finite sequence an=2−na_{n} = 2^{-n} for n=1n=1 to 100, a sequence that ends at 2-100.

    1. Does this sequence have a limit point? Why or why not?

  9. Compute the derivative of

    1. f(x)=e2xf(x) = e^{2x}

    2. f(x)=log⁡(12x)f(x) = \log(\frac{1}{2x})

    3. f(x)=x2+e−xf(x) = x^{2} + e^{-x}

    4. f(x)=10f(x) = 10

    5. f(x)=−3xf(x) = -3x

    6. f(x)=12x2f(x) = \frac{1}{2}x^{2}

    7. f(x)=log⁡(x)f(x) = \log(x)

    8. f(x)=log⁡(x2)f(x) = \log(x^{2})

    9. f(x)=log⁡(10)f(x) = \log(10)

  10. Consider the function g(x)=−x2+3g(x) = -x^{2} + 3.

    1. Compute the derivative of gg

    2. Does the xx value that maximizes gg not depend on the value of cc? Why or why not?

  11. Consider the function g(x)=f(x)+cg(x) = f(x) + c where cc is a constant.

    1. Compute the derivative of gg

    2. Does the xx value that maximizes gg depend on the value of cc? Why or why not?

  12. Consider the function g(x)=cf(x)g(x) = cf(x) where cc is a constant.

    1. Compute the derivative of gg

    2. Does the xx value that maximizes gg depend on the value of cc? Why or why not?

  13. Assume a set of random variables Z1,Z2,⋯ ,ZnZ_{1}, Z_{2}, \cdots, Z_{n} such that Zi∼exp(β)Z_{i} \sim exp(\beta) generated an observed dataset. An exponential distribution assign a density over continuous numbers from 0 to infinity. The probability density function is $$\begin{aligned} f(z) = \beta e^{-\beta z}

    \end{aligned}$Supposewecollectadataset Suppose we collect a dataset \mathcal{D} = (2,4,0.5,3)$.

    1. Please compute the log likelihood of an arbitrary dataset D=(z1,z2,z3⋯ ,zn)\mathcal{D} = (z_{1},z_{2},z_{3}\cdots,z_{n})

    2. Compute the derivative of the log likelihood above

    3. Set the derivative of the log likelihood equal to zero and solve for β\beta (ie find the parameter value that maximizes the log likelhiood).

    4. Apply the maximum likelihood estimate you found to the dataset D=(2,4,0.5,3)\mathcal{D} = (2,4,0.5,3).

  14. Assume a set of random variables Y1,Y2,⋯ ,YnY_{1}, Y_{2}, \cdots, Y_{n} such that Yi∼Geom(p)Y_{i} \sim Geom(p) generated an observed dataset D\mathcal{D}. Please compute the maximum likelihood estimate for pp. Include the log likelihood, derivative, and solution when setting the derivative to zero:

    1. Given a dataset D={12,1,0,3,8}\mathcal{D} = \{ 12, 1, 0, 3, 8 \}

    2. Given a dataset D={y1,y2,…,yn}\mathcal{D} = \{y_{1}, y_{2}, \dots, y_{n}\}

  15. Assume a set of random variables A1,A2,⋯ ,AnA_{1}, A_{2}, \cdots, A_{n} such that Ai∼Bern(θ)A_{i} \sim Bern(\theta) generated an observed dataset. Please compute the maximum likelihood estimate for pp. Include the log likelihood, derivative, and solution when setting the derivative to zero:

    1. Given a dataset D={0,0,0,0}\mathcal{D} = \{ 0,0,0,0 \}

    2. Do you think the estimate you computed above is reasonable? Why or why not?

    3. Given a dataset D={a1,a2,…,an}\mathcal{D} = \{a_{1}, a_{2}, \dots, a_{n}\}

  16. Assume a set of random variables A1,A2,⋯ ,AnA_{1}, A_{2}, \cdots, A_{n} such that Ai∼Pois(λ)A_{i} \sim Pois(\lambda) generated an observed dataset. Please compute the maximum likelihood estimate for pp. Include the log likelihood, derivative, and solution when setting the derivative to zero:

    1. Given a dataset D={11,12,2,10}\mathcal{D} = \{ 11,12,2,10 \}

    2. Given a dataset D={a1,a2,…,an}\mathcal{D} = \{a_{1}, a_{2}, \dots, a_{n}\}

  17. Assume that we model a sample (X1,X2,⋯ ,Xn)(X_{1},X_{2},\cdots,X_{n}) with a Poisson distribution (X∼Pois(λ)X \sim Pois(\lambda)). Please derive the Fisher information I(λ)\mathcal{I}(\lambda)

  18. The number of influenza A and influenza B cases each week is recorded by the Pennsylvania Department of health. For the year 2022 the number of cases in Northampton county, PA is

    Flu A Flu B


    100      0
    89       0
    10      10
    45      12
    12      98

    Please pose a model for the number of influenza A cases, and compute the maximum likelihood estimate for any parameters in this model. Explain why you chose your particular model and explain parameter estimates. In addition, use the Fisher information about your parameter to build a 95CI around this estimated parameter value.