[R] RE: more on lm(y~x) question: removing NAs

About this list Date view Thread view Subject view Author view Attachment view

From: Liaw, Andy (andy_liaw@merck.com)
Date: Wed 05 May 2004 - 00:02:22 EST


Message-id: <3A822319EB35174CA3714066D590DCD504AF7CF8@usrymx25.merck.com>

1. If your code actually runs, you should upgrade R, and quit using `_' for
assignment... 8-)

2. You seem to have an extraneous `]' after the na.exclude. Could that be
the problem?

Andy

> From: Christoph Scherber
>
> 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 NAs 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 NAs
> >>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@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


About this list Date view Thread view Subject view Author view Attachment view

This archive was generated by hypermail 2.1.3 : Mon 31 May 2004 - 23:05:07 EST