Biostatistics and Hypothesis Testing with T-Tests
General Strategy for Hypothesis Testing
The process for conducting any hypothesis test follows a systematic seven-step strategy:
Specify the Hypotheses: Define the Null Hypothesis () and the Alternative Hypothesis ().
Select a Test Statistic: Choose the appropriate statistical tool based on the data and research question.
Specify Acceptable Error Thresholds: Determine the level of risk for errors.
False Positive (Alpha/): Commonly set to approximately .
False Negative (Beta/): Commonly set to approximately .
Test Assumptions: Verify that the data meets the requirements of the selected statistical test (e.g., normality, independence).
Calculate the Test Statistic: Sample the population and perform the calculation.
Compare to Distribution: Compare the calculated value to the test statistic distribution, assuming the null hypothesis is true.
Draw Conclusions: If the probability (-value) of obtaining that value (or something more extreme) is less than the chosen threshold (), reject in favor of . Otherwise, stands.
Factors for Selecting Statistical Tests
The choice of a statistical test depends on several critical factors:
Number of Independent Variables: How many factors are being manipulated or categorized.
Number of Dependent Variables: How many response measures are being collected.
Data Type: Whether the data is continuous, categorical, ordinal, etc.
Nature of the Research Question: What specifically is being asked of the data.
Assumptions:
Normality: Data should follow a normal distribution.
Homoscedasticity: Homogeneity of variance (equal variance across groups).
Linearity: Relationships between variables should be linear.
Sample Size: Whether the sample sizes are equal or sufficiently large.
One-Sample T-Tests and Continuous Variables
Usage Case: Used when there is one continuous variable and you want to compare its mean to a specific, known value.
Example Scenario: Does the mean weight of chickens fed linseed significantly exceed ?
Null Hypothesis (): The mean weight is equal to or less than .
Alpha (): Typically set to .
Exploratory Data Analysis (EDA): It is essential to graph the data before testing. Methods include:
Histogram
Boxplot
Scatterplot
Barplot
Violin plot
Directionality in Testing: One-Tailed vs. Two-Tailed
One-Tailed Test: Used when you only care about an effect in one direction, or you can reasonably assume the response in one group will be greater/less than the other but not both.
Example: Testing if a new medication works better than the current standard of care.
Statistical Power: One-tailed tests have higher power in the specified direction because the critical region () is concentrated in one tail ( for a one-tailed critical value vs. for a two-tailed critical value in some distributions).
Two-Tailed Test: Used when you want to detect a difference in either direction (greater or less than).
Checking Assumptions: Normality and Independence
Normality Assumptions:
Visual check: Histogram.
Statistical tests: Kolmogorov-Smirnov (KS) Test or Shapiro-Wilks Test.
Data Independence:
Determined by the experimental design. Data points must be independent of one another to meet the requirements of standard t-tests.
Example KS Test Results (Chicken Feed):
Meatmeal: . (High -value suggests no violation of normality).
Linseed: . (High -value suggests no violation of normality).
Independent Two-Sample T-Tests (Welch's T-Test)
Usage Case: Used when the independent variable consists of two categories and the dependent variable is continuous.
Example Scenario: Are there significant differences in mean weights between chickens fed 'linseed' and 'meatmeal'?
Welch's Two-Sample T-test: This version is preferred because it does not assume homoscedasticity (equal variance between groups).
R Programming Example:
weights_linseed <- chickwts |> filter(feed == "linseed") |> pull(weight)weights_meatmeal <- chickwts |> filter(feed == "meatmeal") |> pull(weight)twosample <- t.test(weights_meatmeal, weights_linseed)
Paired T-Tests
Usage Case: Used when measurements are taken from the same subjects under two different conditions (e.g., Before vs. After).
Example Scenario: Comparing Miles Per Gallon (MPG) in the
mtcarsdataset before and after a hypothetical engine modification.Hypotheses for Paired Test:
Null Hypothesis (): The mean difference in MPG ( for each car) is zero.
Mathematical Equivalence: A paired t-test between two groups is mathematically identical to a one-sample t-test performed on the calculated differences between those groups.
Example Code Comparison:
paired_test_result1 <- t.test(mpg_after, mpg_before, alternative = "greater", paired = TRUE)paired_test_result2 <- t.test(diff_column, mu = 0, alternative = "greater", paired = FALSE)Both tests yield identical results: .
Questions & Discussion
Question 1: Does the mean weight of chickens fed linseed significantly exceed based on the code provided?
Answer: Based on the test:
t.test(alternative = "greater", mu = 200), if the resulting -value is less than , the answer is Yes.
Question 2: Which statement represents the null hypothesis for a paired t-test on MPG modification?
Answer: The mean difference in MPG (before minus after for each car) is zero.
Question 3: You want to see if a new drug lowers blood pressure. Subjects are divided into placebo and experimental groups, and blood pressure is measured before and after for everyone. What test do you use?
Answer: D. We need to do more than one of these (likely a combination of paired tests for time and two-sample tests for treatment groups, often handled by an ANOVA or mixed-model, but in the context of t-tests, multiple steps are required).
Question 4: You want to compare the mean height of BILD 5 students (complete census) with the mean height of UCSD students (random sample of 300). What test do you use?
Answer: A. One sample t-test (comparing the sample mean of 300 UCSD students to the known population mean/fixed value of the BILD 5 students).