Bug 15960 - `confint` fails on nls objects created with `lower` or `upper`, due to bug on `profile[r].nls`
Summary: `confint` fails on nls objects created with `lower` or `upper`, due to bug on...
Alias: None
Product: R
Classification: Unclassified
Component: Language (show other bugs)
Version: R 3.1.1
Hardware: x86_64/x64/amd64 (64-bit) OS X Mavericks
: P5 normal
Assignee: R-core
Depends on:
Reported: 2014-09-03 18:16 UTC by Juan Sebastian Casallas
Modified: 2014-09-04 12:31 UTC (History)
1 user (show)

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description Juan Sebastian Casallas 2014-09-03 18:16:40 UTC

I've encountered an unexpected error when calling `confint` on nls objects created with `lower` or `upper` bounds.

Minimal example


DNase1 <- subset(DNase, Run == 1)

scal.min <- -Inf
scal.max <- Inf
fm3DNase1 <- nls(density ~ Asym/(1 + exp((xmid - log(conc))/scal)),
                data = DNase1,
                start = list(Asym = 3, xmid = 0, scal = 1), lower=list(Asym = -Inf, xmid = -Inf, scal = scal.min),
                upper = list(Asym = Inf, xmid = Inf, scal = scal.max))



Waiting for profiling to be done...
Error in rep_len(if (!is.null(lower)) as.double(lower) else Inf, length(defaultPars)) : 
  'pairlist' object cannot be coerced to type 'double'

I've traced the offending lines, which are within profiler.nls (src/library/stats/R/nls-profile.R):
lines 34-35, and lines 37-38

and profile.nls (src/library/stats/R/nls-profile.R):
line 140, and line 142

I've created a small patch that solves this, which successfully treats the above example. The patch is here: https://github.com/casallas/r-source/commit/fd220b0048f68a7b81ee967e26b2107f0715dd29.diff
(or with pretty highlighting here: https://github.com/casallas/r-source/commit/fd220b0048f68a7b81ee967e26b2107f0715dd29)

Juan Sebastian
Comment 1 Duncan Murdoch 2014-09-04 10:57:19 UTC
According to the documentation (and the nls code), the lower and upper bounds are ignored unless algorithm is "port".  So isn't the bug here that profiler() isn't ignoring the bounds?

It does handle the case of missing bounds properly, so perhaps the best patch is to remove the lower and upper bounds from the call in case the bounds will be ignored.
Comment 2 Duncan Murdoch 2014-09-04 12:31:22 UTC
I've fixed this by removing the limits in the nls result.  Committed in R-devel, soon in R-patched.