[R] weird question about lm() and data.frame
Guojun Zhu
shmilylemon at yahoo.com
Sat May 6 04:43:23 CEST 2006
--- Prof Brian Ripley <ripley at stats.ox.ac.uk> wrote:
> On Thu, 4 May 2006, Guojun Zhu wrote:
>
> > I am still battling with my project :(
> >
> > I have a line like this
> >
> >
>
lm(month.model$next.ret~.,month.model,na.action=na.omit)
>
>
Yourexamplesmightactuallybereeadableifyouusedyourspacebar.
What do you mean here?
>
> next.ret ~ . would suffice here.
>
> > month.model is a data frame with lots of columns.
> One
> > of them is "Oth", a dummy variable. I checked
> > month.model, there are two rows with number 1 and
> > others are either 0 or NA. the two rows with
> Oth==1
> > have no NA. I have totally about 900 rows. But
> after
> > the regression, the Oth's coefficient is NA. I do
> not
> > understand.
>
> You don't show us how you reach that conclusion, but
> probably aliasing is
> the cause. See ?alias.
I edit my data frame. And check all the month.model.
I see two 1 in that column, hundreds of 0 and a few
NA. I have about 900 rows with 13 normal variables
and 20 dummy variables. "Oth" is one of the dummy
variables.
I do not quite understand alias. The help is not
clear. But I will try to read it again.
>
> > Another issue is also about NA. I offen use
> something
> > like "model[model$Oth==1,]", but it will not only
> > gives rows with oth==1, but also gives some rows
> with
> > all item as NA. I then changed this into "
> >
>
month.model[(month.model$Oth==1)&(!is.na(month.model$next.ret)),]"
> > and it gives the same result. Finally I change it
> > into
> > "
> >
>
month.model[(month.model$Oth==1)&(!is.na(month.model$Oth)),]"
> > and it works. next.ret is a column for sure. Can
> > anyone explain this to me?
>
> You want month.model$Oth %in% 1
>
> Such things are covered with detailed examples in
> chapter 2 of MASS4 (see
> the FAQ).
Is there any online materials available? I start R
because it is free and would much rather to keep in
that way. Thanks.
>
>
> --
> 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
>
More information about the R-help
mailing list