The non-finite thing means that you have a different number of
starting values than you have parameters. I would check the
number of columns in X vs the number of starting values. If you
have k columns in X, you should have k+1 starting values.
Also, in your log likelihood function, I think you need to
exp(gamma) -- I'm not sure one this because I didn't decipher
your math fully -- but the idea is that all the paremeters
should be optimized over an unbounded space. So for s and
sigma, you have to parameterize them so that the parameter
you're optimizing isn't bounded below at zero.
Hope this helps!
Olivia
----- Original Message -----
From: "Matthew Ryan Smith" <smith21(a)fas.harvard.edu>
To: <gov2001-l(a)lists.fas.harvard.edu>
Sent: Monday, November 08, 2004 11:24 AM
Subject: [gov2001-l] Another question re: #2
Every time I run my function for #2, I get this
message:
Error in optim(start, llike.t, method = "BFGS", control =
list(fnscale =
-1), : non-finite finite-difference value [4]
I can't figure out exactly what's going wrong in the function
(or even
what that means...). I've pasted the code below...anyone have
any ideas?
Thanks,
Matt
# (a) Log-likelihood function ##this definitely works for
given values of
the parameters
llike.t <- function(par,X,Y,nu){
xbeta <- t(X)%*%par[1:nrow(X)]
gam <- par[nrow(X) + 1]
nu <- nu
sum(log(gamma((nu+1)/2))-log(gamma(nu/2))-1/2*log(nu)-1/2*gam+(nu+1)/2*log(1
+ ((Y-xbeta)^2)/(nu*exp(gam))))
}
#(b) Numerical Optimization
start <- c(lm(Y ~ t(X) - 1)$coef, 1)
results <- matrix(0, nrow=98, ncol=6)
t.optim <- function(){
for (i in 3:100){
nu <- i
MLE <- optim(start, llike.t, method="BFGS",
control=list(fnscale =
-1), hessian = TRUE, X=X, Y=Y, nu=nu)
point.estimate <- c(MLE$par[1:4], exp(MLE$par[5]))
results[i-2,] <- c(point.estimate, MLE$value)
}
}
_______________________________________________
gov2001-l mailing list
gov2001-l(a)lists.fas.harvard.edu
http://lists.fas.harvard.edu/mailman/listinfo/gov2001-l