Forum: help
Monitor Forum | Start New ThreadRE: MaxLik unused arguments [ Reply ] By: Arne Henningsen on 2018-08-13 08:11 | [forum:46215] |
Hi Chris The error occurs inside your loglik() function (in the call to dnorm()): > startPar <- c(0.1260504, -6.5373661, 1.0222147 ) > loglik( params = startPar, data = x ) Error in log(mean = mu, sd = sigma) : unused arguments (mean = -6.5373661, sd = 1.0222147) > traceback() 2: dnorm(data, log(mean = mu, sd = sigma)) at #9 1: loglik(params = startPar, data = x) Do you mean "dnorm(data, mean = mu, sd = sigma)" instead of "dnorm(data, log(mean = mu, sd = sigma))"? Best regards, Arne |
MaxLik unused arguments [ Reply ] By: Chris Jensen on 2018-05-13 17:50 | [forum:45947] |
I use maxLik to find parameters from a MLE to left-censored data, code is as follows; LOD <- (LODppb/1000)*0.4/70 x<- c(0.000260414, 0.001164827, 0.001077806, 0.000206215, 0.003244783, 0.001254606, 0.001298323, 0.000401082, 0.000947205, 0.003621713, 0.003054214, 0.008090681, 0.004951853, 0.001570994, 0.002745296) library(maxLik) require(fitdistrplus) loglik <- function(params,data){ p <- params[1] mu <- params[2] sigma <- params[3] Q <- pnorm(log(LOD), mean = mu, sd = sigma, lower.tail = TRUE, log.p = FALSE) # 212 t1 <- 15*log((1-p)+p*Q) t4 <- (119-15)*log(p)+sum(dnorm(data,log(mean = mu, sd = sigma))) ll <- t1+t4 return(ll)} newdistparameters <- maxLik(loglik,data = x, start=c(0.1260504, -6.5373661, 1.0222147)) summary( newdistparameters ) But I get an error due to unused arguments. SD value is (inf) and not an actual value, could it be caused by SD going below 0 ? if so, how do I stop that from happening ? Error in log(mean = mu, sd = sigma) : unused arguments (mean = -6.5373661, sd = 1.0222147) 8. dnorm(data, log(mean = mu, sd = sigma)) 7. fnOrig(theta, ...) 6. fn(start1, fixed = fixed, sumObs = TRUE, returnHessian = returnHessian, ...) 5. maxNRCompute(fn = function (theta, fnOrig, gradOrig = NULL, hessOrig = NULL, fixed, sumObs = FALSE, returnHessian = TRUE, ...) { nParam <- length(theta) ... 4. eval(as.call(cl)) 3. eval(as.call(cl)) 2. maxRoutine(fn = logLik, grad = grad, hess = hess, start = start, constraints = constraints, ...) 1. maxLik(loglik, data = x, start = c(0.1260504, -6.5373661, 1.0222147)) > summary( newdistparameters ) -------------------------------------------- Maximum Likelihood estimation Newton-Raphson maximisation, 17 iterations Return code 1: gradient close to zero Log-Likelihood: -45.07829 3 free parameters Estimates: Estimate Std. error t value Pr(> t) [1,] 0.8739496 Inf 0 1 [2,] -6.6636431 Inf 0 1 [3,] 0.0007371 Inf 0 1 I would appreciate any help. |