From ripley at stats.ox.ac.uk  Wed Jan 19 13:06:52 2011
From: ripley at stats.ox.ac.uk (Prof Brian Ripley)
Date: Wed, 19 Jan 2011 12:06:52 +0000 (GMT)
Subject: [Rd] naresid.exclude query
In-Reply-To: <201101141452.09977.s.wood@bath.ac.uk>
References: <201101141452.09977.s.wood@bath.ac.uk>
Message-ID: <alpine.LFD.2.00.1101191132540.4595@gannet.stats.ox.ac.uk>

There was a reason for that line, as running 'make check' with your 
modification would have shown you.  Sometimes naresid() is called with 
x=NULL.   AFAICS replacing the test with is.null(x) suffices, and I'm 
testing that in R-devel.  If nothing else comes up I will port it to 
R-patched later.

Note that R's own code does not AFAIR call these functions when 
predicting with 'newdata', and a fit with all cases omitted would not 
be very interesting so it is unsurprising no one noticed for >8 years.

On Fri, 14 Jan 2011, Simon Wood wrote:

>  x <- NA
>  na.act <- na.action(na.exclude(x))
>  y <- rep(0,0)
>  naresid(na.act,y)
>
> ... currently produces the result...
>  numeric(0)
>
> ... whereas the documentation might lead you to expect
>  NA
>
> The behaviour is caused by the line
>  if (length(x) == 0L) return(x)
>
> in `stats:::naresid.exclude'. Removing this line results in the behaviour I'd
> expected in the above example (and in a test example where `x' is a zero row
> matrix).
>
> Is the coded behaviour necessary for some reason? Could it be changed (so that
> my example produces NA)? The reason I ask is that I use `napredict' in
> mgcv:predict.gam, and someone complained that if he predicts using newdata
> that is all NA, then he doesn't get what he expected (he has a pretty good
> reason for doing this). Part of the problem with predict.gam in this case was
> my code, but once I fixed that I ran up against the above problem.
>
> Actually, I just checked the source code and the line of naresid.exclude that
> causes the problem already has this comment after it....
>  # << FIXME? -- reconstructing all NA object
> ... so I guess I'm really asking if there is any chance of fixing this soon,
> or whether I should just code up a work-around for predict.gam?
>
> Simon
>
> -- 
>> Simon Wood, Mathematical Sciences, University of Bath, Bath, BA2 7AY UK
>> +44 1225 386603  www.maths.bath.ac.uk/~sw283
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

-- 
Brian D. Ripley,                  ripley at 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



[Rd] naresid.exclude query
Prof Brian Ripley