Message-ID: <608930.9580.qm@web32808.mail.mud.yahoo.com>
Date: 2008-03-17T13:45:32Z
From: John Kane
Subject: (no subject)
In-Reply-To: <2bb745800803161446y9fc8c6bkb81b61da14286ca3@mail.gmail.com>
Your loop assumes p has a length of 10 but length(p)
is 2.
--- Kathy Maher <jessiejames1124 at gmail.com> wrote:
> Hi,
>
> I am trying to use the Fisher scoring method with a
> geometric distribution,
> with p = .07, 100 observations from the geom
> distrib, and 10 iterations.
> I cannot quite get the code to work.
> Can anyone see the mistake?
>
> n <- 100
> p <- 0.07
> x <- rgeom(n, p)
>
> s <- sum(x)
> f <- function(x, p) p*(1-p)^x
> L <- function(p) p^n*(1-p)^s
> logL <- function(p) n*log(p)+s*(log(1-p))
> logLprime <- function(p) (n/p)-(s/(1-p))
> I <- n/p^2*(1-p)
> iter <- 10
> p[1] <- .06
> p[2] <- .11
>
> for (i in 1:10)
>
> {
> pnew <- p[i]+logLprime(p[i])/I*(p[i])
>
> }