In this exercise, we will see some basics in hypothesis testing and more specifically on t-tests. As an example, we will work with the captopril dataset that we already explored in the exercise on data exploration.

The goal is to answer these two research questions;

  1. Is the average systolic baseline blood pressure of the patients is higher than the treshold for hypertension of 140 mmHg?

  2. Is the average SBP before captopril treatment different from the average SBP after captopril treatment?

First, load the required R libraries:

1 Import the data

captopril <- ...

2 Data exploration

Note: you may copy the results from the data exploration tutorial.

Before we start with hypothesis testing, it is crucial to first explore the data.

We have 15 patients, for which we have measured the systolic blood pressure and diastolyic blood pressure, before and after treatment with the captopril drug.

Visualize the data in an informative way with respect to assessing both hypotheses

Interpret the plots!

3 Question 1

Is the average baseline systolic blood pressure (SBP) higher than the threshold for hypertension of 140 mmHg?

To test the effect of the captopril on subjects with hypertension (patients), we need to select patients with hypertension, hence they should have elevated SBP levels, that are on average higher than 140 mmHg. We can assess this hypothesis using a one sample t-test.

3.1 Assess the assumptions

Before we can perform a t-test, we must check that the required assumptions are met!

  1. The observations are independent
  2. The data (SBPb) must be normally distributed
... %>%
  ... +
  geom_qq() +
  geom_qq_line()

Interpret the qq-plot

If you feel comfortable with assuming normality based on the qq-plot, you may proceed with the analysis.

3.2 Hypothesis test

Here, we will test if mean systolic blood pressure at baseline is significantly higher than 140 mmHg. More specifically, we will test the null hypothesis;

\(H_0:\)

versus the alternative hypothesis;

\(H_1:\)

output1 <- t.test(...,mu=...,alternative = ...,conf.level = ...,data=...)
output1

3.3 Conclusion

When writing a conclusion on your research hypothesis, it is very important to be precise, concise, and complete. Try to formulate a good conclusion here.

4 Question 2

Is the average SBP before captopril treatment different from the average SBP after captopril treatment?

As the data are paired, there will be a strong correlation between the BP values before and after treatment of each individual patient. We can show this with a scatterplot.

# Create scatterplot

We clearly see that if a patient’s SBPb value is high, its SBPa value will be comparatively high as well.

We can immediately calculate the impact of the treatment for every patient by calculating the difference between the blood pressure after and before the treatment.

# mutate the dataset captopril to calculate the difference
# make an informative boxplot on the difference

As such, we will now need to perform a paired t-test. First, we must check the assumptions.

4.1 Check the assumptions

State the assumptions that you have to check and include the diagnostic plots to assess the assumption.

4.2 Hypothesis test

If all assumptions are met, we may continue with performing the paired two-sample t-test.

output2 <- t.test(...,..., paired = ...,data=)
output2

4.3 Conclusion

Formulate a conclusion based on the output.

5 Alternative solution: One-sample t-test on the difference

Performing a paired t-test is analogous to performing a one-sample t-test on the difference between both groups.

This can be easily seen from the output of the paired two-sample t-test. The alternative hypothesis \(HA\) there states that the “true difference in means is not equal to 0”. So internally, R will actually perform a one-sample t-test on the difference, and check whether or not the true mean difference is equal to 0. We can also set this up manually.

captopril %>%
  mutate(bp_diff = ...) %>%
  t.test(...,mu=...)

Indeed, the output is equivalent to that of the paired t-test.

LS0tCnRpdGxlOiAiRXhlcmNpc2UgNS4xOiBIeXBvdGhlc2lzIHRlc3Rpbmcgb24gdGhlIGNhcHRvcHJpbCBkYXRhc2V0IiAgIAphdXRob3I6ICJMaWV2ZW4gQ2xlbWVudCBhbmQgSmVyb2VuIEdpbGlzIgpkYXRlOiAic3RhdE9taWNzLCBHaGVudCBVbml2ZXJzaXR5IChodHRwczovL3N0YXRvbWljcy5naXRodWIuaW8pIiAgCm91dHB1dDoKICAgIGh0bWxfZG9jdW1lbnQ6CiAgICAgIGNvZGVfZG93bmxvYWQ6IHRydWUgICAgCiAgICAgIHRoZW1lOiBjb3NtbwogICAgICB0b2M6IHRydWUKICAgICAgdG9jX2Zsb2F0OiB0cnVlCiAgICAgIGhpZ2hsaWdodDogdGFuZ28KICAgICAgbnVtYmVyX3NlY3Rpb25zOiB0cnVlCi0tLQoKSW4gdGhpcyBleGVyY2lzZSwgd2Ugd2lsbCBzZWUgc29tZSBiYXNpY3MgaW4gaHlwb3RoZXNpcyB0ZXN0aW5nIGFuZCBtb3JlIApzcGVjaWZpY2FsbHkgb24gdC10ZXN0cy4gQXMgYW4gZXhhbXBsZSwgd2Ugd2lsbCB3b3JrIHdpdGggdGhlCmNhcHRvcHJpbCBkYXRhc2V0IHRoYXQgd2UgYWxyZWF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