习题9.5

点击查看代码
import numpy as np
import statsmodels.api as sm
data = np.loadtxt('F:\python数学建模与算法\源程序\《Python数学建模算法与应用》程序和数据\第9章  数据的描述性统计方法/ti9_5.txt')
x1 = np.vstack([np.ones((4, 4)), np.ones((4, 4))*2, np.ones((4, 4))*3])
x2 = np.tile(np.array([[1, 1, 2, 2]]).T, (3, 4))
x3 = np.tile(np.array([[1, 2]]).T, (6, 4))
model_dic = {
    'x1': x1.flatten(),
    'x2': x2.flatten(),
    'x3': x3.flatten(),
    'y': data.flatten()
}
model = sm.formula.ols('y~C(x1)+C(x2)+C(x3)', model_dic).fit()
sm.stats.anova_lm(model)


posted @ 2024-12-03 18:02  等我刷把宗师  阅读(3)  评论(0编辑  收藏  举报