Model T-test ANOVA ANCOVA Chi-squared Test
Explanation Paired t-test: One Way: Blend of ANOVA and linear (For qualitative data, otherwise
Testing if the means of the same Similar to an independent T-test regression. evaluates whether the use T-test) Used to compare
group is different under two but can be used to test more than means of a dependent variable observed results with expected
different scenarios - the variance two groups. Doesn’t reveal how (DV) are equal across levels of results. The purpose of this test is
is assumed to not be equal. means differ. one or more categorical to determine if a difference
Independent (unpaired) t-test: Two Way: independent variables (IV) and between observed data and
Compares the means of two Uses two independent variables across one or more continuous expected data is due to chance,
unrelated groups - the variance (tests how both affect your variables. or if it is due to a relationship
between groups is assumed to be dependent variable). ANOVA that includes at least one between the variables you are
equal. (Also, Factorial ANOVA and covariate. studying.
MANOVA)
Assumption Normally distributed Normally distributed Normally distributed Data should be frequencies or
s Continuous data Continuous data Continuous data counts of cases rather than
Randomly sampled Randomly sampled Randomly sampled percentages or some other
Homogeneity of variance (for Homogeneity of variance Homogeneity of variance transformation.
unpaired) Roughly linear outcome Categories are mutually exclusive.
relationship Members can only belong to one
Imports import numpy as np import numpy as np import pandas as pd group.
from scipy import stats from scipy import stats import [Link] as sm
for two-way: from [Link]
from [Link] import ols
import ols
Code # Sample data # Sample data # Sample data
data1 = [2.3, 2.5, 3.1, 2.8, 3.3] group1 = [2.3, 2.5, 3.1, 2.8, 3.3] data = [Link]({
data2 = [3.2, 3.8, 2.7, 3.4, 3.1] group2 = [3.2, 3.8, 2.7, 3.4, 3.1] 'value': [2.3, 2.5, 3.1, 2.8, 3.3,
group3 = [2.8, 3.0, 2.9, 3.2, 2.7] 3.2, 3.8, 2.7, 3.4, 3.1, 2.8, 3.0,
# Perform the paired t-test # Perform the ANOVA test 2.9, 3.2, 2.7],
t_stat, p_value = f_stat, p_value = 'group': ['A', 'A', 'A', 'A', 'A', 'B',
stats.ttest_rel(data1, data2) stats.f_oneway(group1, group2, 'B', 'B', 'B', 'B', 'C', 'C', 'C', 'C', 'C'],
group3) 'covariate': [1.2, 1.3, 1.5, 1.1,
OR print(f"F-statistic: {f_stat}") 1.6, 2.3, 2.5, 2.7, 2.1, 2.2, 3.1,
print(f"P-value: {p_value}") 3.3, 3.0, 3.4, 3.2]
# Perform the unpaired t-test })
t_stat, p_value = # Sample data
stats.ttest_ind(data1, data2) data = [Link]({ # Define the model
'value': [2.3, 2.5, 3.1, 2.8, 3.3, model = ols('value ~ C(group) +
print(f"T-statistic: {t_stat}") 3.2, 3.8, 2.7, 3.4, 3.1, 2.8, 3.0, covariate', data=data).fit()
print(f"P-value: {p_value}") 2.9, 3.2, 2.7],
'group1': ['A', 'A', 'A', 'A', 'A', 'B', # Perform the ANCOVA
'B', 'B', 'B', 'B', 'C', 'C', 'C', 'C', 'C'], anova_table =
'group2': ['X', 'X', 'X', 'Y', 'Y', 'X', [Link].anova_lm(model, typ=2)
'X', 'Y', 'Y', 'Y', 'X', 'X', 'Y', 'Y', 'Y']})
# Define the model print(anova_table)
model = ols('value ~ C(group1) +
C(group2) +
C(group1):C(group2)',
data=data).fit()
# Perform the ANOVA
anova_table =
[Link].anova_lm(model, typ=2)
print(anova_table)
Examples: Paired T-Test Example One-Way ANOVA Example ANCOVA Example
An instructor wants to use two exams You can use a one-way ANOVA to For example, suppos
in her classes next year. This year, she determine whether exam performance know whether or not
gives both exams to the students. She differed based on test anxiety levels technique has an imp
wants to know if the exams are amongst students (i.e., your scores, but we want t
equally difficult and wants to check dependent variable would be "exam grade that the studen
this by looking at the differences performance", measured from 0-100, the class. We can use
between scores. If the mean and your independent variable would grade as a covariate
difference between scores for be "test anxiety levels", which has ANCOVA to determin
students is “close enough” to zero, three groups: "low stressed students", statistically significan
she will make a practical conclusion "medium stressed students, and "high between the mean e
that the exams are equally difficult. stressed students"). three groups.
Unpaired T-Test Example Two-Way ANOVA Example
Alarm signal difference between the You are researching which type of
Interceptor 8000 and Interceptor fertilizer and planting density
9000! produces the greatest crop yield in a
field experiment. You assign different
plots in a field to a combination of
fertilizer type (1, 2, or 3) and planting
density (1=low density, 2=high
density), and measure the final crop
yield in bushels per acre at harvest
time.