[R] Gamma MLE

Gavin Simpson gavin.simpson at ucl.ac.uk
Sun Jul 22 23:52:35 CEST 2007


On Sat, 2007-07-21 at 11:36 -0700, rach.s wrote:
> Hello,
> 
> I was asked to try the following code on R,
> 

I think, if you typed the code below *exactly* as you reproduced it in
your email, that you are missing the assignment operator "<-" between
gamma.mles and function(xx, shape0, rate0), i.e.:

gamma.mles <- function(xx, shape0, rate0)
{
   ##function body here
}

Does this help? Notice where the error occurs - immediately after the
line "gamma.mles", if you paste the code exactly as you reproduced.

G

> gamma.mles
> function (xx,shape0,rate0)
> {
> n<- length(xx)
> xbar<- mean(xx)
> logxbar<- mean(log(xx))
> theta<-c(shape0,rate0)
> repeat {
> theta0<- theta
> shape<- theta0[1]
> rate<- theta0[2]
> S<- n*matrix(c(log(rate)-digamma(shape)+logxbar,shape/rate-xbar),ncol=1)
> I<- n*matrix(c(trigamma(shape),-1/rate,-1/rate,shape/rate^2),ncol=2)
> theta<- theta0 + solve(I) %*% S
> if(max(abs(theta-theta0)) < 1e-08)
> break
> }
> list(estimates=theta, infmat=I)
> }
> 
> However, this appears: Error: object "gamma.mles" not found
> 
> I tried looking in the packages for gamma.mles, but I couldn't find it
> anywhere. Can someone tell me where can I load it?
> 
> Thanks
-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
 Gavin Simpson                 [t] +44 (0)20 7679 0522
 ECRC, UCL Geography,          [f] +44 (0)20 7679 0565
 Pearson Building,             [e] gavin.simpsonATNOSPAMucl.ac.uk
 Gower Street, London          [w] http://www.ucl.ac.uk/~ucfagls/
 UK. WC1E 6BT.                 [w] http://www.freshwaters.org.uk
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%



More information about the R-help mailing list