From han at enfor.dk  Tue Jan 26 11:05:13 2010
From: han at enfor.dk (han at enfor.dk)
Date: Tue, 26 Jan 2010 11:05:13 +0100 (CET)
Subject: [Rd] Residual DF of NLS models (PR#14194)
Message-ID: <20100126100513.1E8F0282EFFB@mail.pubhealth.ku.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



[Rd] Residual DF of NLS models (PR#14194)
han at enfor.dk