R studio_Optimization and standard errors

profilemfa646
hw-05.rmd

--- title: "STAT 206 Homework 4" output: pdf_document --- **Due Monday, November 6, 5:00 PM** ***General instructions for homework***: Homework must be completed as an R Markdown file. Be sure to include your name in the file. Give the commands to answer each question in its own code block, which will also produce plots that will be automatically embedded in the output file. Each answer must be supported by written statements as well as any code used. (Examining your various objects in the "Environment" section of RStudio is insufficient -- you must use scripted commands.) Part I - Optimization and standard errors ========== 1. Using any optimization code you like, maximize the likelihood of the gamma distribution on the cats’ hearts. Start the optimization at the estimate you get from the method of moments. (a) What command do you use to maximize the log-likelihood? Explain its arguments. (b) What is the estimate? (c) What is the log-likelihood there? The gradient? We need standard errors for the estimated parameters. If we believe the model is accurate, we can get standard errors by simulating from the fitted model, and re-estimating on the simulation output. 2. Write a function, `make.gamma.loglike`, which takes in a data vector `x` and returns a log-likelihood function. 3. Write a function, `gamma.mle`, which takes in a data vector `x`, and returns a shape and a scale parameter, estimated by maximizing the log-likelihood of the gamma distribution. It should use your `make.gamma.loglike` function from the previous part. Check that if `x` is `cats$Hwt`, then `gamma.mle` matches the answer in problem 1. 4. Modify the code from homework 4 to use your `gamma.mle` function, rather than the method-of-moments estimator. In addition to giving the modified code, explain in words what you had to change, and why. 5. What standard errors do you get from running $10e4$ simulations? 6. An alternative to using simulation is to use the jack-knife. Calculate jack-knife standard errors for the MLE of the gamma distribution. Your code should be able to work with an arbitrary data vector, not just `cats$Hwt`, and you will want to use functions from problems 1 and 2. 7. What are the jackknife standard errors for the MLE? (If you do not have two, one for the shape and one for the scale parameters, something is wrong.) 8. Do your jackknife standard errors for the MLE match those you got in problem 5? Should they? Part II - Newton's method ========== Consider the density $f(x) = \left[ 1 - \cos\{x-\theta\}\right] / 2 \pi$ on $0 \le x \le 2 \pi$, where $\theta$ is a parameter between $-\pi$ and $\pi$. The following i.i.d. data arise from this density: 3.91, 4.85, 2.28, 4.06, 3.70, 4.04, 5.46, 3.53, 2.28, 1.96, 2.53, 3.88, 2.22, 3.47, 4.82, 2.46, 2.99, 2.54, 0.52, 2.50. We wish to estimate $\theta$. 9. Graph the log-likelihood function between $-\pi$ and $\pi$. 10. Find the method of moments estimator of $\theta$. 11. Find the MLE for $\theta$ using Newton's method, using the result from 10 as a starting value. What solutions do you find when you start at -2.7 and 2.7? 12. Repeat problem 11 using 200 equally spaced starting values between $-\pi$ and $\pi$. The partition the interval into sets of attraction. That is, divide the starting values into separate groups corresponding to the different local modes. Discuss your results. 13. Find two starting values as close together as you can that converge to different solution using Newton's method.