Skip to main content

f-test

Open In Colab

In [1]:
import numpy as np
import pandas as pd
import scipy.stats as stats

# Create synthetic data for testing.
group1 = np.random.normal(0.0, 1.0, size=9)
group2 = np.random.normal(10.0, 2.0, size=30)

# Calculate the F-statistic.
variance1 = np.var(group1, ddof=1)
variance2 = np.var(group2, ddof=1)
f_value = variance1 / variance2

# Calculate the p-value.
df1 = len(group1) - 1
df2 = len(group2) - 1
p_value = stats.f.cdf(f_value, df1, df2)

# Collect results.
scores = {
    "Degree of freedom 1": df1,
    "Degree of freedom 2": df2,
    "F-statistic": f_value,
    "p-value": p_value,
}
pd.DataFrame(scores, index=[0])
Out[1]:
Degree of freedom 1 Degree of freedom 2 F-statistic p-value
0 8 29 0.251063 0.023463

Comments

Comments powered by Disqus