Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

profile confidence intervals in R: mle2

I am trying to use the command mle2, in the package bbmle. I am looking at p2 of "Maximum likelihood estimation and analysis with the bbmle package" by Bolker. Somehow I fail to enter the right start values. Here's the reproducible code:

l.lik.probit <-function(par, ivs, dv){
Y <- as.matrix(dv)
X <- as.matrix(ivs)
K <-ncol(X)
b <- as.matrix(par[1:K])
phi <- pnorm(X %*% b) 
sum(Y * log(phi) + (1 - Y) * log(1 - phi)) 
}

n=200

set.seed(1000)

x1 <- rnorm(n)
x2 <- rnorm(n)
x3 <- rnorm(n) 
x4 <- rnorm(n) 

latentz<- 1 + 2.0 * x1 + 3.0 * x2 + 5.0 * x3 + 8.0 * x4 + rnorm(n,0,5)

y <- latentz 
y[latentz < 1] <- 0 
y[latentz >=1] <- 1 
x <- cbind(1,x1,x2,x3,x4)
values.start <-c(1,1,1,1,1)   

foo2<-mle2(l.lik.probit, start=list(dv=0,ivs=values.start),method="BFGS",optimizer="optim", data=list(Y=y,X=x)) 

And this is the error I get:

Error in mle2(l.lik.probit, start = list(Y = 0, X = values.start), method = "BFGS",  : 
  some named arguments in 'start' are not arguments to the specified log-likelihood function

Any idea why? Thanks for your help!

like image 393
EOM Avatar asked May 15 '12 12:05

EOM


People also ask

What are Profile confidence intervals?

The idea of a profile likelihood confidence interval is to invert a likelihood-ratio test to obtain. a CI for the parameter in question. A 100(1 − α)% confidence interval for θ is the set of all values. θ0 such that a two-sided test of the null hypothesis H0 : θ = θ0 would not be rejected at the α level. of ...

What is profile likelihood?

Profile likelihood requires that the objective function is related to a statistical likelihood function, that is, the probability of generating the experimental data given the chosen model and a parameterization.


1 Answers

You've missed a couple of things, but the most important is that by default mle2 takes a list of parameters; you can make it take a parameter vector instead, but you have to work a little bit harder.

I have tweaked the code slightly in places. (I changed the log-likelihood function to a negative log-likelihood function, without which this would never work!)

l.lik.probit <-function(par, ivs, dv){
    K <- ncol(ivs)
    b <- as.matrix(par[1:K]) 
    phi <- pnorm(ivs %*% b)
    -sum(dv * log(phi) + (1 - dv) * log(1 - phi)) 
}

n <- 200

set.seed(1000)

dat <- data.frame(x1=rnorm(n),
                  x2=rnorm(n),
                  x3=rnorm(n),
                  x4=rnorm(n))

beta <- c(1,2,3,5,8)
mm <- model.matrix(~x1+x2+x3+x4,data=dat)
latentz<- rnorm(n,mean=mm%*%beta,sd=5)

y <- latentz 
y[latentz < 1] <- 0 
y[latentz >=1] <- 1
x <- mm
values.start <- rep(1,5)

Now we do the fit. The main thing is to specify vecpar=TRUE and to use parnames to let mle2 know the names of the elements in the parameter vector ...

library("bbmle")
names(values.start) <- parnames(l.lik.probit) <- paste0("b",0:4)
m1 <- mle2(l.lik.probit, start=values.start,
           vecpar=TRUE,
           method="BFGS",optimizer="optim",
           data=list(dv=y,ivs=x))

As pointed out above for this particular example you have just re-implemented the probit regression (although I understand that you now want to extend this to allow for heteroscedasticity in some way ...)

dat2 <- data.frame(dat,y)
m2 <- glm(y~x1+x2+x3+x4,family=binomial(link="probit"),
    data=dat2)

As a final note, I would say that you should check out the parameters argument, which allows you to specify a sub-linear model for any one of the parameters, and the formula interface:

m3 <- mle2(y~dbinom(prob=pnorm(eta),size=1),
           parameters=list(eta~x1+x2+x3+x4),
           start=list(eta=0),
           data=dat2)

PS confint(foo2) appears to work fine (giving profile CIs as requested) with this set-up.

ae <- function(x,y) all.equal(unname(coef(x)),unname(coef(y)),tol=5e-5)
ae(m1,m2) && ae(m2,m3)
like image 122
Ben Bolker Avatar answered Sep 30 '22 16:09

Ben Bolker