R Tutorial : Basic statistical analysis

Learn how to run t-tests, Wilcoxon rank-sum tests, and chi-squared tests in R using a bone mineral density study. The tutorial covers null hypotheses, p-values, confidence intervals, and when each test applies based on whether your data is normally distributed.
Chapters
Here we will go through some basic statistical analyses for these endpoints. When a trial is conducted there is a target population, typically patients with a disease. We cannot include all those patients, so a sample is taken to test the study hypotheses and make inferences back to the target population. Consider a placebo controlled trial evaluating the effects of a drug on bone mineral density. Our endpoint is the change from baseline at one year. We would state for our null hypothesis that the mean changes in the drug and placebo groups are equal, no treatment difference. The alternative hypothesis could be that the group means are not equal. In this case we allow for the possibility that the mean change in active drug group could be higher or lower by than in the placebo group. A two sided test In a one sided test. Our alternative hypothesis could be that the increase in the drug group is greater than in the placebo. We then conduct an appropriate statistical test on the sample data to provide evidence against the null hypothesis. We estimate the treatment effect and its confidence interval, I.e. the range of values for this estimate that has a specified probability of containing the true population treatment effect. A test statistic is compared to a distribution in order to determine the P value, that is the probability of observing our data or something more extreme. If the null hypothesis is true, if this p value is less than a pre specified significance level, then we reject the null hypothesis. Commonly this is set to 0.05, that is we allow a 5% chance of incorrectly rejecting the null hypothesis when it is in fact true. In our example, bone mineral density change is a continuous measure. If we find that the changes from baseline within the groups are normally distributed, we can test whether the means are equal using a two sample t test. For the t test function we specify the outcome variable, treatment group and dataset. We also use the VAR equal argument to specify whether we are assuming that the two variances or standard deviations are equal. Here we see that the p value provides evidence against the null hypothesis of no treatment difference at the 5% level and that the 95% confidence interval excludes zero. So if there really is no treatment difference in the population, the probability of observing this sample or something even more favourable towards the active drug is 0.0018 very low. If we have a non normal distribution, presenting means is not appropriate as they are affected by skewness. Here we can use the Wilcoxon rank sum test. The null hypothesis is that the distributions of the two populations are the same and the alternative hypothesis is that there is a left or right translation shift. Finally, with binary outcomes. We can test the null hypothesis of equal group proportions with the chi squared test. We use the PROP testandtable functions specifying the treatment group and response. This produces a test statistic that is compared to the chi squared distribution. Here, the p value is significant at the 5% level, and the 95% confidence interval for the difference in proportions excludes zero, providing evidence against the null hypothesis. For these tests, we assume that the observations in the treatment groups are independent and that the randomization achieved. Similar patient characteristics also, although not covered in this course, many trials collect outcomes over several visits or have more than two groups. These require different statistical methods.
More from Richie

#359 My Best Friend is AI with Valerie Tiberius, Professor of Philosophy at University of Minnesota

How AI Agents Will Work While You Sleep | Ruslan Salakhutdinov, Professor at Carnegie Mellon

#358 How AI Agents Will Work While You Sleep | Ruslan Salakhutdinov, Professor at Carnegie Mellon







