For 1c
(1c) In seeking to derive the MLE (which I'm trying to do by finding
the value(s) of pi where the slope of the likelihood function is
zero), in taking the derivative of the logs (produced by taking the
log of the function), I keep getting pi in the denominator, and when I
set the first derivative to zero, I then can't find a critical point
for pi. Can anyone help me see where I'm going wrong? Should I be
getting y/n as the answer?
Pi hat = (Sum(Y)/n) / N - that is the mean of Y over the number of tasks
(since for the binomial, E(Y) = Mean = N*pi, where pi is probability)
You should be able to reduce the derivative of the log likelihood to match the Pi hat you
would expect
Remember some log rules as they are helpful for this problem set:
Log(x) - Log(y) = Log(x / y)
Log(x) + Log(y) = Log(x*y)
d/dx Log(x/(x+1)) = 1/(x*(x+1))
From: gov2001-l-bounces at
lists.fas.harvard.edu [mailto:gov2001-l-bounces at
lists.fas.harvard.edu] On Behalf Of Bernard L. Fraga
Sent: Tuesday, March 03, 2009 12:29 PM
To: gov2001-l at
lists.fas.harvard.edu
Subject: Re: [gov2001-l] many problems with PS4
Yeah, i think Gary King gave an example very, very close to what we have to do on the
problem set in the lecture (he also mentions the optim() one parameter fix). It might be
good to look over the lecture video as well.
-Bernard
-----------------------
Bernard L. Fraga
Ph.D. Student, Harvard University
Government and Social Policy
bfraga at fas.harvard.edu<mailto:bfraga at fas.harvard.edu>
-----------------------
On Mar 3, 2009, at 12:23 PM, sparsha saha wrote:
oh you have the equation wrng i thing...or at least that is part of the problem. You
don't need to do factorial(x)...that gets crossed of during the simplification
process(?) because it doesn't have the parameter in it. Also remember optim can only
deal with one input at a time, so you need to figure out a way of doing that...it think
some emails were sent out about this in the past, or just go to like help(optim) that also
tells you how you need to go about doing it i think
On Tue, Mar 3, 2009 at 9:14 AM, Malcolm Fairbrother <m.fairbrother at
bristol.ac.uk<mailto:m.fairbrother at bristol.ac.uk>> wrote:
Dear all,
After cruising through the earlier problem sets with relative ease, I
can't even get started with this one. Can anyone help me with some
embarrassing basics?
(1c) In seeking to derive the MLE (which I'm trying to do by finding
the value(s) of pi where the slope of the likelihood function is
zero), in taking the derivative of the logs (produced by taking the
log of the function), I keep getting pi in the denominator, and when I
set the first derivative to zero, I then can't find a critical point
for pi. Can anyone help me see where I'm going wrong? Should I be
getting y/n as the answer?
(1d) Setting aside the above problem, I've tried to figure out how to
do this in R. However, I've gotten nowhere. My code and the error term
I'm getting are below. Again, can anyone give me a hint about what I'm
doing wrong? I tried to do this by mimicking what Patrick did in the
section for the Poisson distribution, but clearly I'm not getting the
differences between the Poisson and the Binomial.
Thanks in advance,
Malcolm
ps4.binomial <- function(pi, x) {
+ xe <-
factorial(x)
+ ne <- factorial(10)
+ out <- (ne/xe*factorial(10-x))*(pi^x)*((1-pi)^(10-x))
+ return(out)
+ }
data <- rbinom(1000, 10, 0.75)
opt <- optim(par = 0.5, fn = ps4.binomial, method = "BFGS", control
=
list(fnscale = -1),x = data)$par
Error in optim(par = 0.5, fn = ps4.binomial, method = "BFGS", control
= list(fnscale = -1), :
objective function in optim evaluates to length 1000 not 1
_______________________________________________
gov2001-l mailing list
gov2001-l at lists.fas.harvard.edu<mailto:gov2001-l at lists.fas.harvard.edu>
http://lists.fas.harvard.edu/mailman/listinfo/gov2001-l
_______________________________________________
gov2001-l mailing list
gov2001-l at lists.fas.harvard.edu<mailto:gov2001-l at lists.fas.harvard.edu>
http://lists.fas.harvard.edu/mailman/listinfo/gov2001-l