From: s-news-owner@lists.biostat.wustl.edu
[mailto:s-news-owner@lists.biostat.wustl.edu]On Behalf Of Emil Coman
Sent: Monday, May 22, 2006 9:16 AM
To: s-news@lists.biostat.wustl.edu
Subject: [S] basic inquiry: "select if"
this is my first
question posted here, and I'm a beginner with S-Plus, so bear with me...
I am trying to run some analyses, any, say a
lm(Y~ X+ Z)
or
gee(formula = (formula = Y~ X+ Z), cluster = W, variance =
"glm.scale")
but only for a sub-group of my
dataset, say for males only; I know in SPSS there is a command "select if
(gender=1)" e.g., but does anyone know the S-Plus similar command? thanks
a lot,
From: "Barker,
Chris [SCIUS]" <cbarker1@scius.jnj.com>
To: "'Emil
Coman'" <emilcoman@yahoo.com>
Subject: RE:
[S] basic inquiry: "select if"
Date: Mon, 22 May
2006 12:25:24 -0400
Presumably you ?attached? the dataframe
Try ?gee for the syntax.
Otherwise, the syntax may be something like
lm(Y~ X+ Z, subset=Gender==1
or you can subset the dataframe
gender.dfr <- my.dataframe[gender==1 , ]; # notice the comma - its very important
then
lm(y ~ x + z , data="" )
Chris Barker
Associate Director, Biostatistics
Scios
Inc.
6500 Paseo Padre Parkway
Fremont, CA
94555
Tel 510 248 2439
Date: Mon, 22 May
2006 12:23:53 -0400
From: "Chuck
Cleland" <ccleland@optonline.net>
Subject: Re:
[S] basic inquiry: "select if"
To: "Emil
Coman" emilcoman@yahoo.com
Look at the subset argument to lm(). For example:
mydf <- data.frame(Y = Y, X = X, Z = Z, GENDER = GENDER)
lm(Y ~ X + Z, data = "" subset = (GENDER ==
"Male"))
There is most likely a subset argument to gee() as well.
hope this helps,
From: "Jim
Pratt" <JimP@sonuspharma.com>
To: "Emil
Coman" <emilcoman@yahoo.com>
Emil,
Many functions in S-Plus have a subset= option. Go to ?lm to see example.
You will likely want to use data= "" as well. It certainly helps make sure you are using
the correct variables.
My.df <- data.frame(X,Y,Z,Gender)
lm(Y~X+Z, data="" subset=Gender==1)
[Notice two equal
signs == in the Gender==1. This is
important. A single = is an assignment,
while == is a condition statement.]
Best of luck.
Date: Mon, 22 May
2006 09:36:16 -0700 (PDT)
From: "Bill
Dunlap" <bill@insightful.com>
To: "Emil
Coman" <emilcoman@yahoo.com>
Subject: Re:
[S] basic inquiry: "select if"
Add the argument subset=gender==1 (or gender="M"
opr gender="Male",
depending on how you encoded things). You may put arbitrarily
complicated expressions in the subset argument. E.g.,
subset=
gender=="Male" & PaternalAge-Age<20 & Stage %in%
c("I","II")
to use only males who were born of teenage fathers and are
in stage I
or II of some malady.
help(lm) and help(gee) tell about the subset= argument.
By the way
gee(formula =
(formula = Y~ X+ Z), cluster = W, variance = "glm.scale")
should probably be just
gee(formula = Y~ X+
Z, cluster = W, variance = "glm.scale")
The former saves a dataset called "formula"
(containing the formula
Y~X+Z) and then computes gee().
----------------------------------------------------------------------------
Bill Dunlap
Insightful Corporation
bill at insightful dot com
360-428-8146
"All statements in this message represent the opinions
of the author and do
not necessarily
reflect Insightful Corporation policy or position."