One thing jumps out...you seem to be missing a fourth "0" in your optim() line.
It should read:
optim.out <- optim(par = c(0,0,0,0), scobit.ll, y = y, X = X,
method="BFGS",control=list(fnscale = -1), hessian = T)
From: gov2001-l-bounces at
lists.fas.harvard.edu [mailto:gov2001-l-bounces at
lists.fas.harvard.edu] On Behalf Of Lauren Peritz
Sent: Tuesday, March 17, 2009 10:42 PM
To: gov2001-l at
lists.fas.harvard.edu
Subject: Re: [gov2001-l] 1.2 in pset
Hi All - Patrick suggested using 0's as starting values for the simulation in part
1.2. I did so but seem to be getting an error when I run optim:
"...initial value in 'vmmin' is not finite"
Has anyone else encountered this problem? My code is below - perhaps I am missing
something entirely obvious?
Thanks in advance,
Lauren
---------------
# "Scobit" log-likelihood
scobit.ll <- function(par, X, y){
#par=parameters
#X=matrix of covariates with intercept
#y=dependent variable
beta <- par[1:ncol(X)]
mu <- X %*% beta
a <- 0.01
outA <- sum(-y*log((1+exp(-mu))^a))
outB <- sum((1-y)*log(1-(1+exp(-mu))^a))
out<-outA+outB
return(out)
}
#### Problem 1.2 use "turnout" data and run model using ll.scobit
library(Zelig)
data(turnout)
# select indept variables from turnout data for X
X <- matrix(NA,2000,4)
X[,1] <- 1
X[,2] <- as.numeric(turnout[,"income"])
X[,3] <- as.numeric(turnout[,"educate"])
X[,4] <- as.numeric(turnout[,"age"])
colnames(X) <-
c("intercept","income","educate","age")
# select dept variable from turnout data
y <- as.numeric(turnout[,"vote"])
# Maximize the log likelihood for "Scobit"
optim.out <- optim(par = c(0,0,0), scobit.ll, y = y, X = X,
method="BFGS",control=list(fnscale = -1), hessian = T)
On Fri, Mar 13, 2009 at 2:13 PM, Patrick Lam <plam at fas.harvard.edu<mailto:plam at
fas.harvard.edu>> wrote:
Hi all,
Just a slight tip. To avoid numerical issues, use 0s as your starting values for 1.2 in
the problem set.
--
Patrick Lam
Department of Government and Institute for Quantitative Social Science, Harvard
University
http://www.people.fas.harvard.edu/~plam
_______________________________________________
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