RE: [R] Getting the same values of adjusted mean and standarderrors as SAS

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

From: John Fox (jfox@mcmaster.ca)
Date: Fri 28 May 2004 - 01:48:18 EST


Message-id: <20040527154819.BZEU9492.tomts16-srv.bellnexxia.net@JohnDesktop8300>

Dear David,

You might also take a look at the effects package, which can compute
"adjusted" means and a variety of other adjusted effects.

I hope this helps,
 John

> -----Original Message-----
> From: r-help-bounces@stat.math.ethz.ch
> [mailto:r-help-bounces@stat.math.ethz.ch] On Behalf Of Frank
> E Harrell Jr
> Sent: Thursday, May 27, 2004 1:45 AM
> To: David J. Netherway
> Cc: R-help@stat.math.ethz.ch
> Subject: Re: [R] Getting the same values of adjusted mean and
> standarderrors as SAS
>
> On Thu, 27 May 2004 16:34:58 +0930
> "David J. Netherway" <david.netherway@adelaide.edu.au> wrote:
>
> > Hello,
> >
> > I am trying to get the same values for the adjusted means
> and standard
> > errors using R that are given in SAS for the following
> data. The model
> > is Measurement ~ Age + Gender + Group. I can get the
> adusted means at
> > the mean age by using predict. I do not know how to get the
> > appropriate standard errors at the adjusted means for Gender using
> > values from predict. So I attempted to get them directly from the
> > residuals as follows. The data is at the end of the email.
> While there
> > is a match for the males there is a large difference for
> the females
> > indicating that what I am doing is wrong.
> >
> > #
> > meanAge <- mean(dd$Age)
> > meanAgeM <- mean(dd$Age[d$Gender=="M"]) meanAgeF <-
> > mean(dd$Age[d$Gender=="F"])
> . . . .
>
> By using sex-specific means of age you are not getting
> adjusted estimates
> in the usual sense.
>
> I prefer to think of effects as differences in predicted values rather
> than as complex SAS-like contrasts. The Design package's
> contrast function
> makes this easy (including SEs and confidence limits):
>
> library(Design) # also requires Hmisc
> d <- datadist(dd); options(datadist='d')
> f <- ols(y ~ age + sex + group, data=dd)
> contrast(f, list(sex='M'), list(sex='F')) # usual adjusted
> difference M
> vs F
> contrast(f, list(sex='M',age=mean(dd$age[dd$sex=='M']),
> list(sex='F',age=mean(dd$age[dd$sex=='F')) # M vs F not
> holding age constant
>
> You can also experiment with specifying age=tapply(age, sex, mean,
> na.rm=TRUE) using some of the contrast.Design options.
> ---
> Frank E Harrell Jr Professor and Chair School of Medicine
> Department of Biostatistics Vanderbilt
> University
>
> ______________________________________________
> 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

______________________________________________
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:13 EST