💻Intro to Programming in R Unit 15 – Basic Statistical Tests

Statistical tests are essential tools in data analysis, helping researchers determine if observed differences or relationships are meaningful. These tests range from simple comparisons between two groups to complex analyses of multiple variables, allowing for robust conclusions from sample data. Understanding the types of data and selecting the appropriate test is crucial for accurate results. From t-tests and ANOVA for comparing means to correlation and chi-square tests for examining relationships, each method serves a specific purpose in uncovering patterns and significance in data.

What's the Deal with Statistical Tests?

  • Statistical tests assess whether observed differences between groups or relationships between variables are likely due to chance or represent real effects
  • Help researchers make inferences about populations based on sample data
  • Provide a systematic way to test hypotheses and draw conclusions from data
  • Different tests are used depending on the type of data, number of groups, and research question
  • Significance level (usually 0.05) is set to determine if results are statistically significant
  • P-values indicate the probability of observing the results if the null hypothesis is true
    • P-values less than the significance level suggest rejecting the null hypothesis
  • Statistical power is the ability to detect an effect when one exists and is influenced by sample size, effect size, and significance level

Types of Data: Know Your Numbers

  • Nominal data consists of categories without any order or hierarchy (colors, gender)
  • Ordinal data has categories with a specific order but no consistent scale (survey responses: strongly agree to strongly disagree)
  • Interval data has ordered categories with consistent intervals but no true zero point (temperature in Celsius)
  • Ratio data has ordered categories, consistent intervals, and a true zero point (height, weight)
  • Discrete data can only take on specific values, often integers (number of siblings)
  • Continuous data can take on any value within a range (time, length)
  • Knowing the data type is crucial for selecting the appropriate statistical test and interpreting results accurately

T-Tests: Comparing Two Groups

  • T-tests compare means between two groups to determine if they are significantly different
  • Independent samples t-test is used when the two groups are independent and unrelated
    • Example: comparing exam scores between students who attended a review session and those who did not
  • Paired samples t-test is used when the two groups are related or matched
    • Example: comparing blood pressure before and after a medication in the same patients
  • Assumptions include normal distribution of data, homogeneity of variances, and independence of observations
  • The test statistic (t) is calculated based on the difference between means, variability, and sample size
  • Degrees of freedom (df) are determined by sample size and used to find the critical value for the test
  • If the calculated t-value exceeds the critical value, the null hypothesis is rejected, indicating a significant difference between the groups

ANOVA: When Two's Not Enough

  • Analysis of Variance (ANOVA) is used to compare means across three or more groups
  • One-way ANOVA examines the effect of one independent variable (factor) on a dependent variable
    • Example: comparing job satisfaction scores among employees from different departments
  • Two-way ANOVA examines the effects of two independent variables and their interaction on a dependent variable
    • Example: comparing plant growth based on both fertilizer type and watering frequency
  • F-statistic is calculated to determine if there are significant differences among the group means
  • If the F-statistic exceeds the critical value, the null hypothesis is rejected, indicating significant differences among the groups
  • Post-hoc tests (Tukey, Bonferroni) are used to determine which specific groups differ significantly from each other
  • Assumptions include normal distribution, homogeneity of variances, and independence of observations

Correlation: Relationships Between Variables

  • Correlation measures the strength and direction of the linear relationship between two continuous variables
  • Pearson's correlation coefficient (r) ranges from -1 to +1
    • r = -1 indicates a perfect negative linear relationship
    • r = 0 indicates no linear relationship
    • r = +1 indicates a perfect positive linear relationship
  • Scatterplots are used to visualize the relationship between the variables
  • Correlation does not imply causation; other factors may influence the relationship
  • Spearman's rank correlation is used for ordinal data or when assumptions of Pearson's correlation are violated
  • Correlation can help identify variables that may be used in predictive models (regression analysis)

Chi-Square: Categorical Data's Best Friend

  • Chi-square tests are used to analyze relationships between categorical variables
  • Chi-square goodness of fit test compares observed frequencies to expected frequencies for a single categorical variable
    • Example: testing if the colors of M&Ms in a bag match the expected distribution
  • Chi-square test of independence examines the relationship between two categorical variables in a contingency table
    • Example: testing if there is a significant association between gender and preferred ice cream flavor
  • The test statistic (χ2\chi^2) is calculated based on the differences between observed and expected frequencies
  • Degrees of freedom are determined by the number of categories in the variables
  • If the calculated χ2\chi^2 value exceeds the critical value, the null hypothesis is rejected, indicating a significant relationship between the variables
  • Assumptions include independence of observations, adequate sample size, and expected frequencies greater than 5 in each cell

Implementing Tests in R: Code Time!

  • R provides built-in functions for conducting various statistical tests
  • t.test()
    function is used for t-tests
    • Specify the formula, data, and type of t-test (paired or independent)
  • aov()
    function is used for ANOVA
    • Specify the formula and data
    • Use
      summary()
      to view the ANOVA table and test results
  • cor()
    function is used for correlation
    • Specify the variables and method (Pearson or Spearman)
  • chisq.test()
    function is used for chi-square tests
    • Specify the observed frequencies or contingency table
  • Set the significance level using the
    conf.level
    argument (default is 0.95)
  • Extract p-values, test statistics, and other relevant information from the test objects
  • Use
    ggplot2
    package to create visualizations (scatterplots, boxplots, bar charts) to support test results

Interpreting Results: What Does It All Mean?

  • Statistical tests provide evidence for or against the null hypothesis
  • A significant result (p < 0.05) suggests that the observed differences or relationships are unlikely due to chance alone
    • Reject the null hypothesis and conclude that there is a significant effect or association
  • A non-significant result (p > 0.05) suggests that the observed differences or relationships could be due to chance
    • Fail to reject the null hypothesis and conclude that there is insufficient evidence for a significant effect or association
  • Effect sizes (Cohen's d, eta-squared, r-squared) quantify the magnitude of the difference or relationship
    • Interpret effect sizes in the context of the research question and field of study
  • Confidence intervals provide a range of plausible values for the population parameter
    • Narrower intervals indicate greater precision in the estimate
  • Consider the practical significance of the results in addition to statistical significance
  • Be cautious of type I (false positive) and type II (false negative) errors
    • Adjust significance levels or use multiple comparison corrections when conducting multiple tests
  • Interpret results in the context of the study design, limitations, and previous research findings


© 2024 Fiveable Inc. All rights reserved.
AP® and SAT® are trademarks registered by the College Board, which is not affiliated with, and does not endorse this website.

© 2024 Fiveable Inc. All rights reserved.
AP® and SAT® are trademarks registered by the College Board, which is not affiliated with, and does not endorse this website.
Glossary
Glossary