1 Week 6: EM Solutions

1.1 Lab Session

  1. 1.

    Write down the likelihood L⁢(p;𝐱) of 𝐱=(x1,x2,x3) given p, where xi denotes the total number of households with i people infected.

    The data is multinomial, in that, there are three possible outcomes for each household and the outcome in each household are independent and identically distributed. Hence,

    L⁢(p;𝐱) = (x1+x2+x3)!x1!⁢x2!⁢x3!⁢((1-p)2)x1⁢(2⁢p⁢(1-p)2)x2⁢{2⁢p2⁢(1-p)+p2}x3
    = (x1+x2+x3)!x1!⁢x2!⁢x3!⁢((1-p)2)x1⁢(2⁢p⁢(1-p)2)x2⁢{p2⁢(3-2⁢p)}x3
    = (x1+x2+x3)!x1!⁢x2!⁢x3!⁢2x2⁢(1-p)2⁢x1+2⁢x2⁢px2+2⁢x3⁢(3-2⁢p)x3

    The log-likelihood is

    l⁢(p;𝐱)=K+2⁢(x1+x2)⁢log⁡(1-p)+(x2+2⁢x3)⁢log⁡p+x3⁢log⁡(3-2⁢p).
  2. 2.

    (Leave this question to the end, if you are short on time.) Find dd⁢p⁢l⁢(p;𝐱)=dd⁢p⁢log⁡L⁢(p;𝐱). Solve dd⁢p⁢l⁢(p;𝐱)=0 to find the MLE, p^.

    This forms a useful check for the EM algorithm and should hopefully convince you of the advantages of using the EM algorithm for this problem.

    dd⁢p⁢l⁢(p;𝐱) = -2⁢(x1+x2)1-p+x2+2⁢x3p-2⁢x33-2⁢p
    = -1181-p+575p-5503-2⁢p

    Setting dd⁢p⁢l⁢(p;x)=0, we get

    -118⁢p⁢(3-2⁢p)+575⁢(1-p)⁢(3-2⁢p)-550⁢p⁢(1-p) = 0
    -354⁢p+236⁢p2+1725-2875⁢p+1150⁢p2-550⁢p+550⁢p2 = 0
    1936⁢p2-3779⁢p+1725 = 0.

    Solving the quadratic gives

    p^=3779±(-3779)2-4×1936×17252*1936=1.2240⁢ or ⁢0.7279.

    Therefore p^=0.7279 since 0<p<1.

  3. 3.

    Let y denote the total number of households where the initial infective infects both the other individuals in the household. i.e. Outcome {1,2} occurs.

    Write down the likelihood L⁢(p;𝐱,y) of 𝐱 and y given p.

    The data is again multinomial, but there are now four outcomes correspond as final size 3 is split into two. Hence,

    L⁢(p;𝐱,y) = (x1+x2+x3)!x1!⁢x2!⁢(x3-y)!⁢y!⁢((1-p)2)x1⁢(2⁢p⁢(1-p)2)x2⁢(2⁢p2⁢(1-p))x3-y⁢(p2)y
    = (x1+x2+x3)!x1!⁢x2!⁢(x3-y)!⁢y!2x2+x3-y)(1-p)2⁢x1+2⁢x2+x3-ypx2+2⁢x3
  4. 4.

    Simplify l⁢(p;𝐱,y)=log⁡L⁢(p;𝐱,y) and compute the MLE, p^ for (𝐱,y).
    (This will help form the M-step of the EM algorithm.)

    From the previous answer,

    l⁢(p;𝐱,y) = K+(2⁢x1+2⁢x2+x3-y)⁢log⁡(1-p)+(x2+2⁢x3)⁢log⁡p.

    Therefore

    dd⁢p⁢l⁢(p;𝐱,y)=-2⁢x1+2⁢x2+x3-y1-p+x2+2⁢x3p.

    Setting dd⁢p⁢l⁢(p;x,y)=0 gives

    -(2⁢x1+2⁢x2+x3-y)⁢p+(1-p)⁢(x2+2⁢x3) = 0
    x2+2⁢x3 = p⁢{2⁢x1+2⁢x2+x3-y+x2+2⁢x3}.

    Hence

    p^=x2+2⁢x32⁢x1+3⁢x2+3⁢x3-y.

    Notice the similarities with the genetic linkage example with

    l⁢(p;𝐱,y)=K+B⁢log⁡(1-p)+A⁢log⁡p

    and p^=A/(A+B).

  5. 5.

    What is the distribution of y given 𝐱 and p?
    Hint: Think about similarities between this problem and the genetics example.

    There are x3=275 households where all three individuals are infected. For each of these households there are two possibilities {1,1,1} and {1,2}. The conditional probability of {1,2} given that three people are infected in the household is

    P⁢({1,2}|{1,1,1}∪{1,2})=P⁢({1,2})P⁢({1,1,1})+P⁢({1,2})=p22⁢p2⁢(1-p)+p2=13-2⁢p.

    Hence, y|x,p∼Bin⁢(x3(=275),1/(3-2⁢p)).

  6. 6.

    Write down Q⁢(p,p*)=Ep*⁢[l⁢(p;𝐱,Y)|𝐱].
    (This will help form the E-step of the EM algorithm.)

    Q⁢(p,p*) = Ep*⁢[l⁢(p;𝐱,Y)|𝐱]
    = Ep*⁢[K+(2⁢x1+2⁢x2+x3-Y)⁢log⁡(1-p)+(x2+2⁢x3)⁢log⁡p|𝐱]
    = Ep*⁢[K|𝐱]+(2⁢x1+2⁢x2+x3-Ep*⁢[Y|𝐱])⁢log⁡(1-p)+(x2+2⁢x3)⁢log⁡p.

    Note that Ep*⁢[K|x] is not important since it is not a function of p. Therefore we only need to find Ep*⁢[Y|x] which using y|x,p∼Bin⁢(x3(=275),1/(3-2⁢p)), gives Ep*⁢[Y|x]=275/(3-2⁢p).

  7. 7.

    Write an EM algorithm in R to find the MLE p^.

    See R code solutions.

  8. 8.

    Calculate the standard error of the MLE p^.

    Firstly note that

    Q⁢(p,p*) = Ep*⁢[l⁢(p;𝐱,Y)|𝐱]
    = Ep*⁢[K+(2⁢x1+2⁢x2+x3-Y)⁢log⁡(1-p)+(x2+2⁢x3)⁢log⁡p|𝐱]
    = Ep*⁢[K|𝐱]+(2⁢x1+2⁢x2+x3-Ep*⁢[Y|𝐱])⁢log⁡(1-p)+(x2+2⁢x3)⁢log⁡p
    = Ep*⁢[K|𝐱]+(393-Ep*⁢[Y|𝐱])⁢log⁡(1-p)+575⁢log⁡p.

    Therefore Ep*⁢[Y|x]=275/(3-2⁢p*), we have that

    -∂2⁡Q⁢(p,p*)∂⁡p2|p=p∗=p^ = 393-275/(3-2⁢p^)(1-p^)2+575p^2=3987.977.

    Secondly, since y|x,p∗∼Bin⁢(275,1/(3-2⁢p∗)), we have that

    Var⁢(∂⁡log⁡f⁢(𝐱,Y|p)d⁢p|𝐱,p^) = Var⁢(-2⁢x1+2⁢x2+x3-Y1-p+x2+2⁢x3p|𝐱,p^)
    = 1(1-p^)2⁢Var⁢(Y|𝐱,p^)
    = 1(1-p^)2×275×13-2⁢p^×2⁢(1-p^)3-2⁢p^=847.6705

    Therefore the standard error of p^ is 1/(3987.977-847.6705)=0.01784.

1.2 Practice Questions

  1. 1.
    1. (a)

      The likelihood of p and λ is

      L⁢(p,λ|𝐱)=∏i=1n{p⁢δxi⁢0+(1-p)⁢λxixi!⁢e-λ},

      where δi⁢j=1 if i=j and δi⁢j=0 if i≠j

    2. (b)

      The log-likelihood of p and λ given 𝐮 is

      l⁢(p,λ|𝐱,𝐮) = ∑i;ui=1{log⁡p+log⁡f⁢(xi)}+∑i;ui=0{log⁡(1-p)+log⁡g⁢(xi)}
      = ∑i;ui=1{log⁡p+log⁡f⁢(xi)}+∑i;ui=0{log⁡(1-p)+xi⁢log⁡λ-log⁡xi!-λ}

      Now m=∑i;ui=11 and n-m=∑i;ui=01. Note that if ui=1 then xi=0, so ∑i;ui=0xi=∑i=1nxi=n⁢μ. (Since Ui=1 only if xi=0.)

      Therefore

      l⁢(p,λ|𝐱,𝐮) = m⁢log⁡p+(n-m)⁢log⁡(1-p)+n⁢μ⁢log⁡λ+∑i;ui=0log⁡xi!-(n-m)⁢λ (1.1)
      = m⁢log⁡p+(n-m)⁢log⁡(1-p)+n⁢μ⁢λ-(n-m)⁢λ+A

      as required.

    3. (c)

      To find the MLEs simply differentiate (1.1) with respect to p and λ, set the derivative equal to 0 and solve.

      Firstly,

      ∂⁡l∂⁡p = mp-n-m1-p

      Therefore p^ satisfies

      mp-n-m1-p = 0
      m⁢(1-p)-(n-m)⁢p = 0
      m-n⁢p = 0.

      Therefore p^=mn.

      Secondly,

      ∂⁡l∂⁡λ = n⁢μλ-(n-m)

      Therefore λ^ satisfies

      n⁢μλ-(n-m) = 0
      n⁢μ-(n-m)⁢λ = 0.

      Therefore λ^=nn-m⁢μ.

    4. (d)

      This involves find E⁢[Ui|p,xi] for i=1,2,…,n which is

      E⁢[Ui|p,xi] = P(Ui=1,Xi=0|p,λ)P(Xi=0|p,λ)
      = p⁢f⁢(xi)p⁢f⁢(xi)+(1-p)⁢g⁢(xi).

      For xi>0, f⁢(xi)=0 and so E⁢[Ui|p,xi]=0.

      For xi=0, f⁢(xi)=1 and g⁢(xi)=exp⁡(-λ). Therefore

      E⁢[Ui|p,xi]=p×1p×1+(1-p)×exp⁡(-λ)=pp+(1-p)⁢exp⁡(-λ)

      as required.

    5. (e)

      The EM algorithm alternates between:-

      • •

        E-step: E⁢[l⁢(p|𝐱,𝐔)] given the current estimate of p.

        Note that

        l⁢(p|𝐱,𝐔)=(∑i=1nUi)⁢log⁡p+(n-∑i=1nUi)⁢log⁡(1-p)+n⁢μ⁢log⁡λ+(n-∑i=1nUi)⁢λ+A.

        Therefore it suffices to compute E⁢[Ui|p,xi] (i=1,2,…,n) which is derived in (d).

      • •

        M-step: Maximizing l⁢(p,λ|𝐱,𝐮) with respect to p and λ where 𝐮 is replaced by the corresponding expected values from the E-step (part (d)) and the MLEs are given in the part (c).

  2. 2.
    1. (a)

      The likelihood is

      L⁢(β;𝐲,𝐳) = f⁢(𝐲,𝐳|β)
      = ∏i=1nf⁢(yi,zi|β)
      = ∏i=1nf⁢(yi|zi,β)⁢f⁢(zi|β)
      = ∏i=1n{1{zi>0}yi⁢1{zi≤0}1-yi}×12⁢π⁢exp⁡(-1/2⁢(zi-xi⁢β)2)
      = ∏i=1n{1{zi>0}yi⁢1{zi≤0}1-yi}⁢(2⁢π)-n/2⁢∏i=1nexp⁡(-1/2⁢(zi-xi⁢β)2)
      = ∏i=1n1{zi>0}yi⁢1{zi≤0}1-yi⁢(2⁢π)-n/2⁢exp⁡(-12⁢∑i=1n(zi-xi⁢β)2).
    2. (b)

      Note that the log-likelihood satisfies

      l⁢(β;𝐲,𝐳)=K-12⁢∑i=1n(zi-xi⁢β)2,

      where K is a constant not depending upon β.
      Hence

      d⁢l⁢(β;𝐲,𝐳)d⁢β = -12⁢∑i=1n2⁢(zi-xi⁢β)⁢(-xi)
      = -∑i=1nzi⁢xi+β⁢∑i=1nxi2.

      Setting d⁢l⁢(β;𝐲,𝐳)d⁢β=0 yields

      β~=∑i=1nzi⁢xi∑i=1nxi2.
    3. (c)

      Note that yi=1 implies that zi>0. Therefore zi|yi=1,xi,β follows N⁢(xi⁢β,1) conditioned to be positive.
      Therefore

      E[zi|yi=1,xi,β] = E⁢[zi⁢|zi>⁢0]
      = xi⁢β+ϕ⁢(-xi⁢β)1-Φ⁢(-xi⁢β)
      = xi⁢β+ϕ⁢(xi⁢β)Φ⁢(xi⁢β).
    4. (d)
      • •

        Choose an initial value for β, say β=0.

      • •

        E-step: For each i, compute E⁢[zi|yi,xi,β]. For yi=1, E⁢[zi|yi,xi,β] is given by (c) and E[zi|yi=0,xi,β] can be computed similarly.

      • •

        M-Step: Compute β~=∑i=1nzi⁢xi∑i=1nxi2.

      • •

        Stop when two consecutive estimates of β~ agree to a predefined precision, say 10-4.