question again. here is part of my original code for my research question. originally I used a loop with matrix form to do the work and it works (though looks ugly). I have tried the methods mentioned in the above posts and thought I did the same thing. but the new code does not work. the error message is:
Error in optim(guess, myfunc, data = mydata, method = "BFGS") : initial value in 'vmmin' is not finite which is the same error message if I have set up wrong numbers of estimated parameters. but I have changed nothing but just this part. the command I use is optim() with a self-writen function for maximum likelihood estimation. here is the part of my originall code. n is the number of observations: for(j in 1:n) { if (edu[j,i]==1) lia[j,i]=1/v8[j,i] if (wrk[j,i]==1) lia[j,i]=exp(vbar2[j,i])/v8[j,i] } and I have tried: lia[,i]<-ifelse(edu[,i]==1,1/v8[,i],0) lia[,i]<-ifelse(wrk[,i]==1,exp(vbar2[,i])/v8[,i],0) any suggestions? thanks a lot for every of them. Nan from Montreal ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.