[R] more on lm(y~x) question: removing NA´s

Adaikalavan Ramasamy ramasamy at cancer.org.uk
Tue May 4 16:25:03 CEST 2004


1. There should have been warning or error when using "_" as it is
depreceated. Use "<-" instead.
2. There is an extra "]"
3. Could it be that after removing all the cases with NA, you do not
have sufficient observations. Example :

> j <- c(NA, 2, NA,  4, NA)
> k <- c(1, NA,  3, NA,  5)
> lm(j~k,na.action=na.exclude)
Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) :
        0 (non-NA) cases

4. I would suggest you put a 'cat(i, "before", "\n") or something
similar before and after the problematic syntax to find out which values
of i is causing the problem.



On Tue, 2004-05-04 at 14:55, Christoph Scherber wrote:
> actually, the situation is much more complicated. I am producing 
> multiple graphs within a "for" loop. For some strange reason, the 
> plotting routine always stops once lm(y~x) encounters more than one 
> missing value (I have marked the important bit with "***********"):
> 
> par(mfrow=c(5,5))
> p_seq(3,122,2)
> i_0
> k_0
> number_0
> for (i in p) {
>    j_foranalysis[93:174,i+1]
>    k_foranalysis[93:174,i]  
>    df_data.frame(j,k)
>    mainlab1_substring(names(foranalysis[i]),2,8)
>    mainlab2_"; corr.:"
>    mainlab3_round(cor(j,k,na.method="available"),4)
>    mainlab4_"; excl.Mono:"
>    mainlab5_round(cor(j[j<0.9],k[j<0.9],na.method="available"),4)
>    mainlab_paste(mainlab1,mainlab2,mainlab3,mainlab4,mainlab5)
>    plot(k,j,main=mainlab,xlab="% of total biomass",ylab="% of total 
> cover",pch="n")
>    for (k in 1:length(foranalysis[93:174,i])) 
> number[k]_substring(plotcode[foranalysis[k,1]],1,5)
>    text(foranalysis[93:174,i],foranalysis[93:174,i+1],number)
> **********************************
>    model_lm(j~k,na.action=na.exclude])
> **********************************
>    abline(model)
>    abline(0,1,lty=2)
>     }
> 
> Does anyone have any suggestions on this?
> 
> Best regards
> Chris.,
> 
> 
> 
> 
> Liaw, Andy wrote:
> 
> >By (`factory') default that's done for you automagically, because
> >options("na.action") is `na.omit'.
> >
> >If you really want to do it `by hand', and have the data in a data frame,
> >you can use something like:
> >
> >lm(y ~ x, df[complete.cases(df),])
> >
> >HTH,
> >Andy
> >
> >  
> >
> >>From: Christoph Scherber
> >>
> >>Dear all,
> >>
> >>I have a data frame with different numbers of NAÂ´s in each 
> >>column, e.g.:
> >>
> >>x       y  
> >>1      2
> >>NA  3
> >>NA  4
> >>4     NA
> >>1     5
> >>NA NA
> >>
> >>
> >>I now want to do a linear regression on y~x with all the NAÂ´s 
> >>removed. 
> >>The problem now is that is.na(x) (and is.na(y) obviously 
> >>gives vectors 
> >>with different lengths. How could I solve this problem?
> >>
> >>Thank you very much for any help.
> >>
> >>Best regards
> >>Chris
> >>
> >>______________________________________________
> >>R-help at stat.math.ethz.ch mailing list
> >>https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> >>PLEASE do read the posting guide! 
> >>http://www.R-project.org/posting-guide.html
> >>
> >>
> >>    
> >>
> >
> >
> >------------------------------------------------------------------------------
> >Notice:  This e-mail message, together with any attachments, contains information of Merck & Co., Inc. (One Merck Drive, Whitehouse Station, New Jersey, USA 08889), and/or its affiliates (which may be known outside the United States as Merck Frosst, Merck Sharp & Dohme or MSD and in Japan as Banyu) that may be confidential, proprietary copyrighted and/or legally privileged. It is intended solely for the use of the individual or entity named on this message.  If you are not the intended recipient, and have received this message in error, please notify us immediately by reply e-mail and then delete it from your system.
> >------------------------------------------------------------------------------
> >
> >  
> >
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
--




More information about the R-help mailing list