Two sample continuous data and how to test them

In todays lab we are going to learn how to analyze a study in which there are two groups that both have continuous outcomes. We will focus on the use of a two-sample t-test, the confidence intervals for the difference between the two means, and other ways to look test them.

Infant Diarrhea Study

Diarrhea is a major public health problem in underdeveloped countries, especially for babies. Diarrhea leads to dehydration, which results in millions of deaths each year worldwide. Bismuth salicylate (the active ingredient in Pepto Bismol) has been shown to reduce diarrhea in adults.

Researchers in Peru conducted a double-blind randomized controlled trial, published in The New England Journal of Medicine, to determine whether it would do so in infants suffering from diarrhea as well. In their study, all infants received the standard therapy for diarrhea: oral rehydration. In addition to the rehydration, 85 babies received bismuth salicylate, while 84 babies received a placebo. The total stool volumes for all infants over the course of their illness was measured. To adjust for body size, the researchers divided by body weight to obtain their outcome of interest: stool output per kilogram of body weight. The results of their study are available on the course website.

If we upload the dataset and look at a table we will see the number of babies in the control group and treatment group.

DiaData <- read.delim("http://myweb.uiowa.edu/pbreheny/data/diarrhea.txt")
table(DiaData$Group)
## 
##   Control Treatment 
##        84        85

Explore the data

To begin to explore the data we can look at a boxplot of the data with the code below:

boxplot(DiaData$Stool ~ DiaData$Group, col = "grey", main = "Effect of bismuth salicylate")

A histogram can also be helpful:

require(lattice)
## Loading required package: lattice
histogram(~DiaData$Stool|DiaData$Group)

Looking at these two depictions of the data is can be seen that it looks like the bismuth salicylate does in fact help! However, looking at a histogram and boxplot does not tell us whether or not this difference could happen randomly. So how do we test to see if this is a statistically significant difference?

Two-Sample t-tests

Student’s two-sample t-tests

To do a students two-sample t-test we must be able to find the standard deviation using a pooled variance, standard error, and the t statistic. These three can be found using the equations below (which are also in your lecture slides).

\(SD_(pooled) = \sqrt{ \frac{(n_1 - 1)S_1^2 + (n_2 - 1)S_2^2}{n_1 + n_2 -2} }\)

\(SE_d = SD_(pooled) \sqrt{ \frac{1}{n_1} + \frac{1}{n_2}}\)

\(t = \frac{\bar{x_1} - \bar{x_2}}{SE_d} ~ T\) with \(n_1 + n_2 - 2\) degrees of freedom

So as you can tell we need to compute several statistics from the data in order to do this t-test. We need to compute the mean of continuous outcomes for both groups and those will be out \(\bar{x_1}\) and \(\bar{x_2}\) as well as the standard error above.

If you were asked this on a test it would look like:

There are 85 infants in the treatment group, and 84 infants in the control group. The sample mean for the treatment group is 181.8706, the sample mean for the control group is 260.2976. The pooled standard deviation is 227.07. Perform a 2-sample t-test testing whether or not bismuth salicylate significantly improves the condition of infants.

So lets do this by hand first as a class then we can check it with R.

done with R

#To do a Student's 2-sample t-test

t.test(DiaData$Stool~DiaData$Group, var.equal = TRUE)
## 
##  Two Sample t-test
## 
## data:  DiaData$Stool by DiaData$Group
## t = 2.245, df = 167, p-value = 0.02608
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##    9.457362 147.396700
## sample estimates:
##   mean in group Control mean in group Treatment 
##                260.2976                181.8706

So the conclusion to this testis that infants in the treatment group had significantly less diarrhea than infants in the control group with a p value of .0261.

Welch’s 2-sample t-test

In calculating the pooled variance, we found that the standard deviation in the treatment group was 197, and the standard deviation in the control group was 253.6. These are different by a little bit, so if I was worried about my assumption of equal variance that we made in doing the Student’s t-test (recall we told R var.equal = TRUE), we can just omit that line from the code and R will by default run the Welch t-test.

In the student’s t-test we pool the standard deviations which if they are far apart can have a massive impact on the outcome of the test.

To do this test by hand is quite computational so for matter of time we will just do it in R in today’s lab to compare to the students t-test.

t.test(DiaData$Stool~DiaData$Group, var.equal = FALSE)
## 
##  Welch Two Sample t-test
## 
## data:  DiaData$Stool by DiaData$Group
## t = 2.2417, df = 156.64, p-value = 0.02638
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##    9.323083 147.530979
## sample estimates:
##   mean in group Control mean in group Treatment 
##                260.2976                181.8706

Here our p-value is very close to the one we obtained using the Student’s test. This will generally be the case when the variances are so close.

Practice Problems

Some infants are born with congenital heart defects and require surgery very early in life. One approach to performing this surgery is known as “circulatory arrest.” A downside of this procedure, however, is that it cuts off the flow of blood to the brain, possibly resulting in brain damage. An alternative procedure, “low-flow bypass” maintains circulation to the brain, but does so with an external pump that potentially causes other sorts of injuries to the brain.

To investigate the treatments, surgeons at Harvard Medical School conducted a randomized controlled trial. In the trial, 70 infants received low-flow bypass surgery and 73 received the circulatory arrest approach. The researchers looked at two outcomes: the Psychomotor Development Index (PDI), which measures physiological development, and the Mental Development Index (MDI), which measures mental development. For both indices, higher scores indicate greater levels of development. The results of their study are on the course website.

use

Data4 <- read.delim("http://myweb.uiowa.edu/pbreheny/data/infant-heart.txt")
  1. Calculate the standard deviations of PDI and MDI for each group. Based on these values, should we do a Students test or a Welch test?

  2. Conduct a t-test (whichever one you decided was most appropriate) to determine whether the difference in physiological development between the infants in the circulatory arrest group and the low-flow bypass group is statistically significant.

  3. Conduct a t-test (whichever one you decided was most appropriate) to determine whether the difference in mental development between the infants in the circulatory arrest group and the low-flow bypass group is statistically significant.

  4. Calculate the 95% confidence intervals for these two tests. Interpret these in terms of the context of the study. What does the confidence interval mean? Which group did better?

  5. If your child had to have open-heart surgery as an infant, which treatment option would you prefer? Why?

answers

attach(Data4)

#part A

sd(PDI[Treatment == "Circulatory arrest"])
## [1] 16.488
sd(PDI[Treatment == "Low-flow bypass"])
## [1] 14.68527
sd(MDI[Treatment == "Circulatory arrest"])
## [1] 16.56448
sd(MDI[Treatment == "Low-flow bypass"])
## [1] 14.57256
#part B

t.test(PDI ~ Treatment, var.equal = T)
## 
##  Two Sample t-test
## 
## data:  PDI by Treatment
## t = -2.2385, df = 141, p-value = 0.02676
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -11.0232390  -0.6840017
## sample estimates:
## mean in group Circulatory arrest    mean in group Low-flow bypass 
##                         91.91781                         97.77143
#part C

t.test(MDI ~ Treatment, var.equal = T)
## 
##  Two Sample t-test
## 
## data:  MDI by Treatment
## t = -1.2696, df = 141, p-value = 0.2063
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -8.484009  1.848393
## sample estimates:
## mean in group Circulatory arrest    mean in group Low-flow bypass 
##                         103.0822                         106.4000
#part D 

#found in the t.test output

#part E