Line 49: |
Line 49: |
| | | |
| The p-value in this example, <code>0.24</code>, is above <code>0.05</code> and therefore we will assume that any difference in sleep between the nights is due to pure chance. | | The p-value in this example, <code>0.24</code>, is above <code>0.05</code> and therefore we will assume that any difference in sleep between the nights is due to pure chance. |
| + | |
| + | === t-tests in R === |
| + | You can do the same t-test in the statistical programming language [[R]], using the same example: |
| + | |
| + | <pre> |
| + | melatonin <- c(8.53,7.64,7.26,7.53,7.85) # load intervention data |
| + | no_melatonin <- c(7.91,7.7,7.7,7.13,7.62,7.51) # load control data |
| + | |
| + | t.test(melatonin,no_melatonin,alternative='greater',paired=FALSE) # run the t-test |
| + | </pre> |
| + | |
| + | First we load both data series into R and then run the actual t-test. With <code>alternative='greater'</code> we specify a one-sided t-test in which we test whether the values of the intervention data are larger than those of the control. Alternatively we could have chosen <code>alternative='less'</code> or <code>alternative='two.sided'</code>. With <code>paired=FALSE</code> we specify that these are independent, non-paired samples. |
| + | |
| + | Running our test results in the following output: |
| + | |
| + | <pre> |
| + | Welch Two Sample t-test |
| + | |
| + | data: melatonin and no_melatonin |
| + | t = 0.69689, df = 5.9576, p-value = 0.2561 |
| + | alternative hypothesis: true difference in means is greater than 0 |
| + | 95 percent confidence interval: |
| + | -0.2992509 Inf |
| + | sample estimates: |
| + | mean of x mean of y |
| + | 7.762 7.595 |
| + | </pre> |
| + | |
| + | We see that <code>p-value = 0.2561</code>, indicating that the sleep-duration when taking melatonin is not substantially larger compared to the control and that any differences are likely just by chance. |
| + | |
| | | |
| == Limitations == | | == Limitations == |