[R] How to solve "nlm() non-finite value supplied by 'nlm'" and how to constrain parameters to (0, 1)?

mviljamaa mviljamaa at kapsi.fi
Sun Apr 2 14:19:32 CEST 2017


So I'm getting:

Error in nlm(neglikhood, p = c(0.1, 0.1), hessian = T, x = elinajat) :
   non-finite value supplied by 'nlm'
In addition: There were 50 or more warnings (use warnings() to see the 
first 50)

with the following (neglikelihood of 1-param. Weibull):

neglikhood <- function(theta,x) {
   n <- length(x)
   
-(n*log(theta[2])+n*log(theta[1])+(theta[1]-1)*sum(log(x))-theta[2]*sum(x^theta[1]))
}

> elinajat
  [1]  17.88  28.92  33.00  41.52  42.12  45.60  48.48  51.84  51.96  
54.12  55.56  67.80
[13]  68.64  68.64  68.88  84.12  93.12  98.64 105.12 105.84 127.92 
128.04 173.40

I read somewhere that I might need to constrain my parameters to the 
range (0,1). Is this correct?

For example:

> neglikhood(c(0.1,0.1),elinajat)
[1] 195.3213



More information about the R-help mailing list