Bug 14194 - Residual DF of NLS models
Residual DF of NLS models
Status: CLOSED FIXED
Product: R
Classification: Unclassified
Component: Models
old
All Linux
: P5 normal
Assigned To: Jitterbug compatibility account
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2010-01-26 15:59 UTC by Jitterbug compatibility account
Modified: 2010-01-26 19:21 UTC (History)
0 users

See Also:


Attachments
(1.15 KB, application/x-extension-r)
2010-01-26 19:21 UTC, Jitterbug compatibility account
Details
(3.04 KB, text/plain)
2010-01-26 19:21 UTC, Jitterbug compatibility account
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jitterbug compatibility account 2010-01-26 15:59:59 UTC
From: han@enfor.dk
Full_Name: Henrik Aalborg Nielsen
Version: 2.10
OS: Linux (SLES 10 / openSUSE 11.1)
Submission from: (NULL) (77.66.63.89)


There seems to be a bug in df.residual.nls which is triggered when nls is called
with argument na.action = na.exclude; in that case 'resid(object)' will contain
NA-values which should be disregarded when counting the number of residuals:

df.residual.nls <- function(object, ...) {
    w <- object$weights
    n <- if(!is.null(w)) sum(w != 0) else length(resid(object))
    n - length(coef(object))
}

The bug cause the F-test of anova.nls to be wrong.

Replace 'length(resid(object))' with 'sum(!is.na(resid(object)))' ?

... and thank you for producing this fantastic software!

BR
Henrik

Comment 1 Jitterbug compatibility account 2010-01-26 18:04:23 UTC
From: Prof Brian Ripley <ripley@stats.ox.ac.uk>
Can we please have a reproducible example (as we did ask in the 
FAQ, the posting guide ...).

On Tue, 26 Jan 2010, han@enfor.dk wrote:

> Full_Name: Henrik Aalborg Nielsen
> Version: 2.10
> OS: Linux (SLES 10 / openSUSE 11.1)
> Submission from: (NULL) (77.66.63.89)
>
>
> There seems to be a bug in df.residual.nls which is triggered when nls is called
> with argument na.action = na.exclude; in that case 'resid(object)' will contain
> NA-values which should be disregarded when counting the number of residuals:
>
> df.residual.nls <- function(object, ...) {
>    w <- object$weights
>    n <- if(!is.null(w)) sum(w != 0) else length(resid(object))
>    n - length(coef(object))
> }
>
> The bug cause the F-test of anova.nls to be wrong.
>
> Replace 'length(resid(object))' with 'sum(!is.na(resid(object)))' ?
>
> ... and thank you for producing this fantastic software!
>
> BR
> Henrik
>
> ______________________________________________
> R-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

-- 
Brian D. Ripley,                  ripley@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

Comment 2 Jitterbug compatibility account 2010-01-26 19:21:15 UTC
From: Henrik Aalborg Nielsen <han@enfor.dk>
PARTS: 3
(Import NOTE: MIME parts are too deeply nested, ignoring)

(Attached 'nlsDFresid.R' of type 'application/x-extension-R')

(Attached 'nlsDFresid.Rout' of type 'text/plain')

**END
Comment 3 Jitterbug compatibility account 2010-01-26 19:21:15 UTC
Created attachment 1034 [details]
Comment 4 Jitterbug compatibility account 2010-01-26 19:21:15 UTC
Created attachment 1035 [details]
Comment 5 Jitterbug compatibility account 2010-01-28 13:29:00 UTC
NOTES:
 fixed in 2.10.1 patched
Comment 6 Jitterbug compatibility account 2010-01-28 13:29:10 UTC
Audit (from Jitterbug):
Thu Jan 28 07:29:10 2010	ripley	changed notes
Thu Jan 28 07:29:10 2010	ripley	moved from incoming to Models-fixed