Homework 2 for Biostat 778

Due: December 4, 2013

Setup

In order to do this homework you must

  1. Fork the Biostat778_HW2 repository on GitHub

  2. Once you have forked the repository on GitHub, you can clone it to your local computer to actually do the work.

  3. As you are working, make sure to commit changes at logical points via git add and git commit.

  4. Once you have completed the assignment, you can push your changes back to your GitHub repository via git push.

  5. Once you have pushed your changes, make a pull request on GitHub so that I can see that you're ready to submit your homework.

  6. Your finished code should be submitted in the form of an R package. The R package should be named Homework2.

  7. Your R package should pass R CMD check without any warnings, errors, or notes.

  8. I will put unit tests in the tests directory of the R package for the master branch. Please DO NOT make any changes in the tests directory.

  9. You can use the tests in the tests directory to check your code as the expected results will also be in the tests directory.

Mixture Model

Consider data \(y_1,y_2,\dots,y_n\) which are iid from a mixture of 2 Normal distributions,

\[ y_i \sim \lambda\mathcal{N}(\mu_1,\sigma_1^2)+(1-\lambda)\mathcal{N}(\mu_2,\sigma_2^2) \]

Write a function that estimates the unknown parameters \(\lambda\), \(\mu_1\), \(\mu_2\), \(\sigma_1^2\), and \(\sigma_2^2\) using either Newton's method or the EM algorithm.

Your function should follow the following prototype:

mixture <- function(y, method, maxit = NULL, tol = 1e-08, param0 = NULL) {
    ## Your code goes here

    ## Return a list with elements `mle' for the maximum likelhood estimates and
    ## `stderr' for their standard errors.
}