René J.V. Bertin
2006-Aug-02 14:41 UTC
[R] best way to calculate per-parameter differences in across-subject means
Hello, I have some data in a data.frame where for each of a number of subjects, I have scores for all of a number of symptoms. Subjects are subdivided in a number of groups, which have unequal sizes. I'd like to plot between-group differences in the scores on the various symptoms. Ideally, that would be in a form as would be produced by> bwplot( Score~Symptom )but I'm not sure one can say anything about the distribution of differences when the sample sizes differ as much as they do. So I will start plotting the per-group differences in the per-symptom mean scores. Is there a better way (rather than using loops) to get a table of those per-symptom means, something like> with( subset(dat, group==1, drop=FALSE), Score~Symptom )Thanks in advance, Ren? Bertin
Dieter Menne
2006-Aug-02 16:04 UTC
[R] best way to calculate per-parameter differences in across-subject means
Ren? J.V. Bertin <rjvbertin <at> gmail.com> writes:> I have some data in a data.frame where for each of a number of > subjects, I have scores for all of a number of symptoms. > > Subjects are subdivided in a number of groups, which have unequal sizes. > > I'd like to plot between-group differences in the scores on the > various symptoms. Ideally, that would be in a form as would be > produced by.... Maybe it's a bit more than you want, but possibly you are happy with it: see the example under TukeyHSD. summary(fm1 <- aov(breaks ~ wool + tension, data = warpbreaks)) TukeyHSD(fm1, "tension", ordered = TRUE) plot(TukeyHSD(fm1, "tension")) Dieter
René J.V. Bertin
2006-Aug-03 10:34 UTC
[R] best way to calculate per-parameter differences in across-subject means
Thanks, I'll look at that. In the meantime, the code below is what I came up with myself. It does what I want # SelectCases(dat,crit) == subset(dat, crit, drop=FALSE) SENSICK.AvScores<- function( dat=SENSICK.items.tr ) { n<-nlevels(dat$Symptom) data.frame( Patient=c( rep(1,n), rep(0, 3*n)), WasSick=c( rep(1,2*n), rep(NA,2*n)), StrictSick=c( rep(NA,2*n), rep(-1,n), rep(1,n)), Symptom=rep(levels(dat$Symptom),4), AvScore=c( with( SelectCases(dat, 'Patient==1 & WasSick==1'), tapply(Score, Symptom , mean) ), with( SelectCases(dat, 'Patient==0 & WasSick==1'), tapply(Score, Symptom , mean) ), with( SelectCases(dat, 'Patient==0 & StrictSick==-1'), tapply(Score, Symptom , mean) ), with( SelectCases(dat, 'Patient==0 & StrictSick==1'), tapply(Score, Symptom , mean) ) ) ) } AvScores<-SENSICK.AvScores with( AvScores, (barchart( AvScore[Patient==1] - AvScore[Patient==0 & WasSick==1]) ~ Symptom, scales=list( rot=c(45,0)) ) ------ Dieter wrote: Maybe it's a bit more than you want, but possibly you are happy with it: see the example under TukeyHSD. summary(fm1 <- aov(breaks ~ wool + tension, data = warpbreaks)) TukeyHSD(fm1, "tension", ordered = TRUE) plot(TukeyHSD(fm1, "tension")) Dieter