I have used the following code to obtain a max likelihood estimator for
a logit regression. The final command invokes ‘optim’ to obtain the
parameter estimates. The code works OK but I want to use the ‘mle’
function in the ‘stats4’ package instead of directly calling ‘optim’.
Can someone please figure out the command to do this?

 

Thank you in advance.

 

Martin 

 

# mlelo.r - maximum likelihood estimation for logit regression

 

# log-likelihood function (returns negative to minimise)

log.lo.like <- function(beta,Y,X) {

  Fbetax   <- 1/(1+exp(-beta%*%t(X)))

  loglbeta <- -log(prod(Fbetax^Y*(1-Fbetax)^(1-Y)))

}

 

# data

Y <-  c(0,0,1,0,0,1,1,0,0,0,0,1,1,0,1,1,0,1,1,0,1)

X <-
cbind(matrix(1,21,1),matrix(c(-48.5,24.4,82.8,-24.6,-31.6,91.0,52.1,-87.
7,

 
-17.0,-51.5,-90.7,65.5,-44.0,-7.0,51.6,32.4,-61.8,34.0,27.9,-72.9,49.9),
21,1))

 

# maximum likelihood estimator

mle.res <- optim(c(0,0),log.lo.like,Y=Y, X=X)


-- 
Internal Virus Database is out-of-date.
Checked by AVG Free Edition.

20/01/2006
 

        [[alternative HTML version deleted]]

______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

Reply via email to