You are on page 1of 1

The data frame provides the pre-therapy weight ( Prewt ) and post-therapy weight

( Postwt ) for each patient. What about the weight change? Can R calculate that for
each patient? Of course!
> anorexia$Postwt-anorexia$Prewt
[1] -0.5 -9.3 -5.4 12.3 -2.0 -10.2 -12.2 11.6 -7.1
[10] 6.2 -0.2 -9.2 8.3 3.3 11.3 0.0 -1.0 -10.6
[19] -4.6 -6.7 2.8 0.3 1.8 3.7 15.9 -10.2 1.7
[28] 0.7 -0.1 -0.7 -3.5 14.9 3.5 17.1 -7.6 1.6
[37] 11.7 6.1 1.1 -4.0 20.9 -9.1 2.1 -1.4 1.4
[46] -0.3 -3.7 -0.8 2.4 12.6 1.9 3.9 0.1 15.4
[55] -0.7 11.4 11.0 5.5 9.4 13.6 -2.9 -0.1 7.4
[64] 21.5 -5.3 -3.8 13.4 13.1 9.0 3.9 5.7 10.7
Hmmm. . . . Remember that t-test I showed you earlier in this chapter? I use it
here to see whether the pre-therapy/post-therapy weight change is different
from 0. You would hope that, on average, the change is positive. Here’s the t-test:
> t.test(anorexia$Postwt-anorexia$Prewt, mu=0)
One Sample t-test
data: anorexia$Postwt - anorexia$Prewt
t = 2.9376, df = 71, p-value = 0.004458
alternative hypothesis: true mean is not equal to 0
95 percent confidence interval:
0.8878354 4.6399424
sample estimates:
mean of x
2.763889
The t-test output shows that the average weight change was positive (2.763889
lbs). The high value of t ( 2.9376 ), along with the low value of p ( 0.004458 ),
indi-
cates that this change is statistically significant. (What does that mean?) If I
tell
you any more, I’ll be getting ahead of myself. (See Chapter 10 for the details.)
Here’s something else: I said that each patient completed one of three types of
therapy. Was one therapy more effective than the others? Or were they about the
same? Now I’d really be getting ahead of myself! (That explanation is in
Chapter 12,
but see the section “R Formulas,” a little later in this chapter.)

You might also like