Advertisement
elena1234

One-Way ANOVA in Python

Jul 20th, 2022
1,006
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.65 KB | None | 0 0
  1. import numpy as np
  2. import pandas as pd
  3. import statsmodels.api as sm
  4. from statsmodels.formula.api import ols
  5. import matplotlib.pyplot as plt
  6. import seaborn as sns
  7. import scipy.stats as stats
  8. import statsmodels.stats.oneway as oneway
  9.  
  10.  
  11. 1. Check data for normality with Shapiro Test;
  12. 2. Check for homogeneity of variances - Bartlet's Test(data is normal), Levene's Test(data is almost normal), Brown-Forsythe Test(data is sort of normal), Fligner-Killen Test(data is non-normal)
  13. If data is normal and there is homogeneity of variances:
  14.  
  15. model = ols("horsepower~C(cylinders)", data = data_new).fit()
  16. model
  17.  
  18. anova = sm.stats.anova_lm(model, type = 2)
  19. anova
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement