I am trying to do maximum likelihood for a spatio-temporal model. However, I think I should start with a simple model first before I go for the complicated one. I tried to run a simple maximum likelihood model and it gave me this error message: initial value in 'vmmin' is not finite
. I was looking at another post, and it suggested I change the starting value. I did try a couple of different values, and it still gave me this error message. What should I do? is there anything wrong with the function?
y <- matrix(low$SalePrice, ncol=1)
z <- as.matrix(cbind(1,low$Housesqft,low$lotacres))
OLS<-function(theta,y,z){
n <- nrow(z)
k <- ncol(z)
beta <- theta[1:k]
sigma2 <- theta[k+1]
e <- y-z%*%beta
logl<- -0.5*n*log(2*pi)-0.5*n*log(sigma2)-((t(e)%*%e)/(2*sigma2))
return(-logl)
}
p <- optim(c(1,1,1),OLS, method="BFGS", hessian=TRUE, y=y, z=z)
Error in optim(c(1, 1, 1), OLS, method = "BFGS", hessian = TRUE,
y = y, z = z) :
initial value in 'vmmin' is not finite