Let’s start by reviewing the lister dataset. Note that the “Rev” function is not entirely necessary, but it makes it a little more readable for our purposes.
# install.packages("DescTools")
library(DescTools)
lister <- read.delim("http://myweb.uiowa.edu/pbreheny/data/lister.txt")
lister.table <- Rev(table(lister))
print(lister.table)
## Outcome
## Group Survived Died
## Sterile 34 6
## Control 19 16
Alternatively, if we knew the counts of the data themselves, we could make a table like this:
lister_manual <- data.frame("Group" = c(rep("Control", 35), rep("Sterile", 40)),
"Outcome" = c(rep("Survived", 19), rep("Died", 16), rep("Survived", 34), rep("Died", 6)))
tab <- table(lister_manual)
tab
## Outcome
## Group Died Survived
## Control 16 19
## Sterile 6 34
Do not fret that this table is in reverse. We will be using the first table for the rest of the lab. However, the table being in reverse does not matter.
Remember that Fisher’s Exact Test can be performed using the fisher.test() function. In lab last week using the lister dataset, we saw that this function not only gives you the p-value but also the odds ratio and a 95% CI for the odds ratio.
fisher.test(lister.table)
##
## Fisher's Exact Test for Count Data
##
## data: lister.table
## p-value = 0.005018
## alternative hypothesis: true odds ratio is not equal to 1
## 95 percent confidence interval:
## 1.437621 17.166416
## sample estimates:
## odds ratio
## 4.666849
Note that this Fisher’s Exact Test odds ratio is calculated using the formula:
\(\frac{a/b}{c/d}=\frac{ad}{bc}\) , where a, b, c, and d are defined by their location according to the following table:
## Success Failure
## Option 1 a b
## Option 2 c d
The easiest way to think of this odds ratio is to say that the odds of Success are 100*(OR-1) percent higher if we do Option 1 than if we do Option 2.
Be careful when calculating the OR that you interpret what you calculated. For instance, if I were to switch my Success and Failure column names, I’d be calculating the OR for Failure given Option 1 instead of Success. If you switch both the rows and column simultaneously (like we did with the “Rev” function), the odds ratio will be unchanged.
Calculating a confidence interval for an odds ratio is slightly more complicated than what we’ve done so far because it’s on a different scale. Here are the steps:
Find the odds ratio: \(\frac{ad}{bc}\)
Find the log odds ratio (natural log): \(\log{(OR)}\)
Find the error term: \(SE_{logOR}=\sqrt{\frac{1}{a} + \frac{1}{b} + \frac{1}{c} + \frac{1}{d}}\)
Calculate the CI on this scale: \(CI_{logOR}=\log{(OR)} \pm z_{\alpha/2} * SE_{logOR}\)
Calculate the CI on the original scale: \(CI = \exp{(CI_{logOR})}\)
Let’s find a CI for the OR for survival given sterile procedure by hand.
## Outcome
## Group Survived Died
## Sterile 34 6
## Control 19 16
## Outcome
## Group Survived Died
## Sterile a b
## Control c d
OR <- (34*16)/(19*6)
OR
## [1] 4.77193
logOR <- log(OR) # the log function in R is the natural log
logOR
## [1] 1.562751
SElogOR<-sqrt((1/19)+(1/6)+(1/16)+(1/34))
SElogOR
## [1] 0.557862
logCI <- logOR + qnorm(c(.025,.975)) * SElogOR
logCI
## [1] 0.4693614 2.6561402
CI <- exp(logCI)
CI
## [1] 1.598973 14.241215
Interpretation: We can say with 95% confidence that the true odds ratio for survival with sterile procedure relative to the control procedure is (1.599, 14.241), indicating significantly increased odds of survival on the sterile procedure compared to the non-sterile procedure. (Significant because the CI does not include the value 1.)
Note that this is the same as the relative odds of dying with the control surgery. This happens because the OR is symmetric.
A flowchart for when to use each distribution:
Write out the values of \(n, \bar{x}, s\), etc. for everything given in the prompt.
What is the population we’re looking at? What kind of distributions can be used with the information given? Which is most appropriate in this situation? (see chart) Do we want a test or an interval? Most importantly, what is the question being asked?
If Defining Hypotheses: The null case is the one based on no change, difference, or improvement. The alternative is what we want to show or what we are looking to prove. Remember that the hypotheses describe and apply to a population parameter.
In this class, most test statistics will similar to the form: \(z=\frac{(\hat{X}-X_0)}{SE_{\hat{X}}}\), and most confidence intervals will look similar to this: \(\hat{X} \pm z^**SE_{\hat{X}}\),
where:
Calculate the statistic or interval using the given values. Find the p-value (if applicable). This means that if we’re conducting a test, compare the test statistic to the distribution we picked in step 2, and find the probability of being as or more extreme than the value we observed.
This might very well be the most important step. Our interpretation is dependent on our study, so it varies. Below are some examples.
Situation: Paired study looking at the effect of oat bran consumption compared to cornflakes levels where the calculated p-value was 0.005
Situation: Weights of U.S. Males (mean believed to be 172.2) where observed mean was 180, and the calculated p-value was 0.09.
Modifiers based on p-value:
p | Evidence against null |
---|---|
> .1 | not |
.1 | borderline |
.05 | moderately |
.01 | strongly |
.001 | overwhelmingly |
Recall the Nexium/Prilosec example. If we have a large enough n, we can find statistical significance in the smallest true difference in means. Here, the difference, while real, was only 3%. That’s effectively REALLY close to being the same. For practical purposes, this difference doesn’t matter, but the p-value doesn’t tell us that the actual difference is little, just that it is significant.
Paired data can be analyzed using the binomial distribution (proportion of patients that saw any improvement) or using continuous methods (using 1-sample methods on a set of the differences between the two).
Given that the null hypothesis is false, the power of a test is the probability that we will correctly reject the null.
Properties of power: