[R] lm/model.frame.default surgery: Am I doing something crazy?

Ritter, Christian C SRTCL-CTGAS Christian.C.Ritter at OPC.shell.com
Tue Jan 22 13:30:48 CET 2002


This message is for people who know the mechanics of model.frame within lm.

I am fitting lm models for different responses on a data frame which has (at
least some) factors.
As it happens, some of the responses are NA for some of the factor levels. 

Logically, lm creates an xlevels list for which the length of levels is
different from the original 
number of levels in the data frame (a consequence of na.action=na.omit). 

If I now call predict with the full data frame, error occurs in these cases
with the message
that there is a new factor level was encountered. 

This message originates from model.frame.default in the section:

                if (any(m <- is.na(match(nxl, xl)))) 
                  stop(paste("factor", nm, "has new level(s)", 
                    nxl[m]))

On first sight, this behavior is logical. Something is likely wrong if
someone submits newdata with factor levels which
did not contribute to the fitting. I

n my case, however, I would prefer as behavior that the program gives NA as
predicted
values for rows in newdata which correspond to "new" factor levels. This
behavior seems to occur if I simply change stop into
warning. (it then gives a warning message and there are in fact NA's where I
want).

Am I missing something?

Thanks in advance,
			Chris

platform i386-pc-mingw32
arch     x86            
os       Win32          
system   x86, Win32     
status                  
major    1              
minor    3.0            
year     2001           
month    06             
day      22             
language R              

> Kind Regards, 
> Christian Ritter, Statistical Services
> 
       Tel  +32 10 477349/ Fax +32 10 477219       
       email : Christian.C.Ritter at OPC.Shell.com

       Shell Coordination Centre
       Shell Research and Technology Centre 
       Avenue Jean Monnet 1
       B-1348 Ottignies Louvain-La-Neuve (Belgium)





-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list