[R] lm() silently drops NAs

peter dalgaard pdalgd at gmail.com
Tue Jul 26 23:30:31 CEST 2016


> On 26 Jul 2016, at 22:26 , Hadley Wickham <h.wickham at gmail.com> wrote:
> 
> On Tue, Jul 26, 2016 at 3:24 AM, Martin Maechler
> <maechler at stat.math.ethz.ch> wrote:
>> 
...
> To me, this would be the most sensible default behaviour, but I
> realise it's too late to change without breaking many existing
> expectations.

Probably. 

Re. the default choice, my recollection is that at the time the only choices available were na.omit and na.fail. S-PLUS was using na.fail for all the usual good reasons, but from a practical perspective, the consequence was that, since almost every data set has NA values,  you got an error unless you added na.action=na.omit to every single lm() call. And habitually typing na.action=na.omit doesn't really solve any of the issues with different models being fit to different subsets and all that. So the rationale for doing it differently in R was that it was better to get some probably meaningful output rather than to be certain of getting nothing. And, that was what the mainstream packages of the time were doing.

> On a related note, I've never really understood why it's called
> na.exclude - from my perspective it causes the _inclusion_ of missing
> values in the predictions/residuals.

I think the notion is that you exclude them from the analysis, but keep them around for the other purposes.

-pd

> 
> Thanks for the (as always!) informative response, Martin.
> 
> Hadley
> 
> -- 
> http://hadley.nz
> 
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: pd.mes at cbs.dk  Priv: PDalgd at gmail.com



More information about the R-help mailing list