用python进行方差分析

用python进行方差分析,第1张

用python进行方差分析
# -*- coding: utf-8 -*-
"""
Created on Sun Nov 14 11:09:44 2021

@author: Machi
"""

import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
from statsmodels.formula.api import ols
from statsmodels.stats.anova import anova_lm
from statsmodels.stats.multicomp import pairwise_tukeyhsd


df  = {'x':list(np.random.normal(10, 5, 20)),
       'y':list(np.random.normal(20, 5, 20))}

data = pd.Dataframe(df)

%config InlineBackend.figure_format = 'retina'
data_melt = data.melt()
data_melt.columns = ['Treat', 'value']
print(data_melt)
sns.boxplot(x = 'Treat', y = 'value', data = data_melt)


model = ols('value ~C(Treat)', data = data_melt).fit()
anova_table = anova_lm(model, type = 2)
result = pd.Dataframe(anova_table)
print(result)

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5491038.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-12
下一篇 2022-12-12

发表评论

登录后才能评论

评论列表(0条)

保存