[R] best way to calculate per-parameter differences in across-subject means

René J.V. Bertin rjvbertin at gmail.com
Thu Aug 3 12:34:07 CEST 2006


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



More information about the R-help mailing list