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:

    1. Specify the Hypotheses: Define the Null Hypothesis (H0H_0) and the Alternative Hypothesis (HAH_A).

    2. Select a Test Statistic: Choose the appropriate statistical tool based on the data and research question.

    3. Specify Acceptable Error Thresholds: Determine the level of risk for errors.

      • False Positive (Alpha/α\alpha): Commonly set to approximately 0.050.05.

      • False Negative (Beta/β\beta): Commonly set to approximately 0.200.20.

    4. Test Assumptions: Verify that the data meets the requirements of the selected statistical test (e.g., normality, independence).

    5. Calculate the Test Statistic: Sample the population and perform the calculation.

    6. Compare to Distribution: Compare the calculated value to the test statistic distribution, assuming the null hypothesis is true.

    7. Draw Conclusions: If the probability (pp-value) of obtaining that value (or something more extreme) is less than the chosen threshold (α=0.05\alpha = 0.05), reject H0H_0 in favor of HAH_A. Otherwise, H0H_0 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 200 g200\,g?

    • Null Hypothesis (H0H_0): The mean weight is equal to or less than 200 g200\,g.

    • Alpha (α\alpha): Typically set to 0.050.05.

  • 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 (α\alpha) is concentrated in one tail (1.671.67 for a one-tailed critical value vs. 2.002.00 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: D=0.1303,p-value=0.9801D = 0.1303, p\text{-value} = 0.9801. (High pp-value suggests no violation of normality).

    • Linseed: D=0.10226,p-value=0.9981D = 0.10226, p\text{-value} = 0.9981. (High pp-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 mtcars dataset before and after a hypothetical engine modification.

  • Hypotheses for Paired Test:

    • Null Hypothesis (H0H_0): The mean difference in MPG (Before−After\text{Before} - \text{After} 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: t=4.6151,df=31,p-value=3.226×10−05t = 4.6151, df = 31, p\text{-value} = 3.226 \times 10^{-05}.

Questions & Discussion

  • Question 1: Does the mean weight of chickens fed linseed significantly exceed 200 g200\,g based on the code provided?

    • Answer: Based on the test: t.test(alternative = "greater", mu = 200), if the resulting pp-value is less than 0.050.05, 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).