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

John Fox jfox at mcmaster.ca
Thu May 27 17:48:18 CEST 2004


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 at stat.math.ethz.ch 
> [mailto:r-help-bounces at 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 at 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 at 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 at 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




More information about the R-help mailing list