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?
Thanks, David
Frank E Harrell Jr wrote:
On Thu, 27 May 2004 16:34:58 +0930 "David J. Netherway" <[EMAIL PROTECTED]> 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
______________________________________________ [EMAIL PROTECTED] 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