[R] Catching NaNs from pweibull()

Ben Bolker bolker at ufl.edu
Fri Feb 8 17:46:06 CET 2008


  That's odd, it works just fine for me
(R 2.6.1, i486-pc-linux-gnu)

  Can you send the results of sessionInfo() ?
 
# Observed data
Prepens.caughtintraps = c(94,45,71,64,71,31,16,19,27,16,113)  

# Numbers of seeds released
Prepens.released = 1250  

distances = c(2,3,4,5,7.5,10,12.5,15,17.5,20,25)
totalseedscaught = sum(Prepens.caughtintraps)
Pcatch = totalseedscaught/Prepens.released

## minor tweak: this is more efficient, gives same answer
cumsumcaught <- rev(cumsum(rev(Prepens.caughtintraps)))

res.nls <- nls(cumsumcaught ~
               Pcatch*Prepens.released*(1-pweibull(distances,k,l)),
               start = list(k=1,l=12), trace=TRUE)

## slightly more accurate -- use lower.tail instead of 1-pweibull()
## but makes no difference in this case
res.nls <- nls(cumsumcaught ~
               Pcatch*Prepens.released*
               pweibull(distances,k,l,lower.tail=FALSE),
               start = list(k=1,l=12), trace=TRUE)


13122.82 :   1 12 
11783.76 :   1.045207 12.668148 
11774.70 :   1.035480 12.676250 
11774.54 :   1.036564 12.679938 
11774.54 :   1.036398 12.679737 
11774.54 :   1.036420 12.679783 
11774.54 :   1.036417 12.679778 

Nonlinear regression model
  model:  cumsumcaught ~ Pcatch * Prepens.released * pweibull(distances,      k,
l, lower.tail = FALSE) 
   data:  parent.frame() 
     k      l 
 1.036 12.680 
 residual sum-of-squares: 11775

Number of iterations to convergence: 6 
Achieved convergence tolerance: 1.388e-06



More information about the R-help mailing list