So I am trying to use the mle command (from stats4 package) to estimate a number of parameters using data but it keeps throwing up this error message:
Error in solve.default(oout$hessian) : Lapack routine dgesv: system is exactly singular: U[1,1] = 0 This error sometimes indicates that the list of starting values is too far from optimum but this is unlikely since I picked values close to where the parameters usually end up. I have also tried switching these around a bit. Here is the code: xhat = c(statemw-(1-alpha)*rval) survivalf <- function(x) {(1-plnorm(statemw,mean=mu,sd=logalpha))} wagefn <- function(lam, eta, alpha, xhat, mu, logalpha) { n=nrow(cpsdata2) wagevec = matrix(nrow=n,ncol=1) for (i in 1:n) { if (cpsdata2[i,2] > 0){ wagevec[i,] <- c(eta*lam*survivalf(statemw)*exp(-lam*survivalf(statemw)*cpsdata2[i,2,])) } else if (cpsdata2[i,1,]==statemw) { wagevec[i,] <- c(lam*(survivalf(statemw)-survivalf((statemw-(1-alpha)*xhat)/alpha))/(eta+lam*survivalf(statemw))) } else if (cpsdata2[i,1,]>statemw) { wagevec[i,] <- c(lam*plnorm((cpsdata2[i,1,]-(1-alpha)*xhat)/alpha,mean=mu,sd=logalpha)/(alpha*(eta+lam*survivalf(statemw)))) } else { wagevec[i,] <- NA } } lnwagevec <- log(wagevec) -sum(lnwagevec>-200 & ln2wagevec<200, na.rm=TRUE) } fit <- mle(wagefn, start=listmat, method= "L-BFGS-B",lower= c(-Inf,0),upper=c(Inf,Inf) I know the likelihood function is a handful but it does return a reasonable looking vector of values. The "lnwagevec>-200" etc is an inelegant way of preventing values of Inf and -Inf from entering the sum, the actual values rarely go as high as 8 or low as -5. Thank you in advance to anyone responding! /Hugo [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.