Dear list, I have a simple question. If I need to run linear regression on a subset of the dataset, will the following two commands give the same output: lm(y ~ as.factor(x1) + as.factor(x2), data, subset = z==Z[1]) and lm(y ~ as.factor(x1) + as.factor(x2), data[data$z==Z[1],] ) I have got different results running the two commands. Am I missing something here, or it there a bug on the option subset? Thanks for the help! - Jackie -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Hi,> I have a simple question. If I need to run linear regression on a subset of > the dataset, will > the following two commands give the same output: > > lm(y ~ as.factor(x1) + as.factor(x2), data, subset = z==Z[1]) > > and > > lm(y ~ as.factor(x1) + as.factor(x2), data[data$z==Z[1],] ) > > > I have got different results running the two commands. Am I missing > something here, or it > there a bug on the option subset? >I tried the same thing at my computer and everything works fine. Maybe you have variable z, which is not the same as in your data frame. That is data$z!=z, Try do something like zz_z rm(z) and then repeat your two lm calls. Then I think the results should be the same. Vaidotas Zemlys -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Ngayee J Law wrote:> > Dear list, > > I have a simple question. If I need to run linear regression on a subset of > the dataset, will > the following two commands give the same output: > > lm(y ~ as.factor(x1) + as.factor(x2), data, subset = z==Z[1]) > > and > > lm(y ~ as.factor(x1) + as.factor(x2), data[data$z==Z[1],] ) > > I have got different results running the two commands. Am I missing > something here, or it > there a bug on the option subset?Works for me on R-1.5.1, NT4.0. Do you have z defined anywhere else? If not and your version is recent: Can you provide an example? Please, tell us your version of R and your OS as well. Uwe Ligges -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
I've found out that I have defined z elsewhere. If I remove z, the problem
is gone. Thanks!
- Jackie
Uwe Ligges
<ligges at statistik.uni-do To: Ngayee J Law
<Ngayee.Law at celeradiagnostics.com>
rtmund.de> cc: r-help at
stat.math.ethz.ch
Subject: Re: [R] subset
09/13/2002 01:56 AM
Ngayee J Law wrote:>
> Dear list,
>
> I have a simple question. If I need to run linear regression on a subset
of> the dataset, will
> the following two commands give the same output:
>
> lm(y ~ as.factor(x1) + as.factor(x2), data, subset = z==Z[1])
>
> and
>
> lm(y ~ as.factor(x1) + as.factor(x2), data[data$z==Z[1],] )
>
> I have got different results running the two commands. Am I missing
> something here, or it
> there a bug on the option subset?
Works for me on R-1.5.1, NT4.0.
Do you have z defined anywhere else?
If not and your version is recent: Can you provide an example?
Please, tell us your version of R and your OS as well.
Uwe Ligges
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._