Re: [Rd] Residual DF of NLS models (PR#14194)

From: Henrik Aalborg Nielsen <han_at_enfor.dk>
Date: Tue, 26 Jan 2010 14:21:15 +0100

OK - I do think the bug is pretty obvious when looking at the code (and remembering that resid(object) may contain NA's). Anyway, I've attached a script and the output (from 'R CMD BATCH --vanilla').

BR
Henrik

On Tue, 2010-01-26 at 12:04 +0000, Prof Brian Ripley wrote:

> Can we please have a reproducible example (as we did ask in the
> FAQ, the posting guide ...).
>
> On Tue, 26 Jan 2010, han_at_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_at_r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-devel
> >
>



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Tue 26 Jan 2010 - 22:21:43 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 27 Jan 2010 - 10:10:17 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive