**From:** Frank E Harrell Jr (*f.harrell@vanderbilt.edu*)

**Date:** Mon 31 May 2004 - 14:38:44 EST

**Next message:**Douglas Bates: "Re: [R] glmm?"**Previous message:**Petr Pikal: "Re: [R] bar plot patterns"**In reply to:**David J. Netherway: "Re: [R] Getting the same values of adjusted mean and standard errors as SAS"

Message-id: <40BAB6D4.1050205@vanderbilt.edu>

David J. Netherway wrote:

*> Thanks for the help.
*

*>
*

*> Both the "Design" package and the "effects" package look as though they are
*

*> what I need although it will probably take me a while to get on top of
*

*> both.
*

*>
*

*> I have had a brief go at the Design package and the contrast function
*

*> is particularly useful.
*

*>
*

*> A question on the Design package:
*

*>
*

*> There are 5 types for factor "group", one is the reference - call it "a".
*

*>
*

*> f <- ols(y ~ age + sex + group, data=dd)
*

*> contrast(f, list(group='a'), list(group='b'))
*

*>
*

*> I can use this to contrast pairs but can I use this to contrast b
*

*> against c,d, and e as a group.
*

*> Also "a" against the rest?
*

*>
*

Type ?contrast.Design. You'll see examples of 'vector' contrasts with

and without weighted/unweighted averaging of effects. E.g. contrast(f,

list(group='b'), list(group=c('c','d','e'))) will give 3 contrasts.

There is an option to average these.

Frank

*>
*

*> Thanks, David
*

*>
*

*> Frank E Harrell Jr wrote:
*

*>
*

*>> 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
*

*>
*

-- 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

**Next message:**Douglas Bates: "Re: [R] glmm?"**Previous message:**Petr Pikal: "Re: [R] bar plot patterns"**In reply to:**David J. Netherway: "Re: [R] Getting the same values of adjusted mean and standard errors as SAS"

*
This archive was generated by hypermail 2.1.3
: Mon 31 May 2004 - 23:05:14 EST
*