使用python/scipy/statsmodel进行协方差分析

z0qdvdin  于 5个月前  发布在  Python
关注(0)|答案(2)|浏览(98)

有没有人可以帮助提供一个例子,展示如何在scipy/statsmodel中使用python进行ANCOVA(协方差分析)?
我不知道我是否问得太多,但快速搜索显示我this这是不够的信息给我。
谢谢你,谢谢

olhwl3o2

olhwl3o21#

Statmodels使用线性模型OLS来估计ANOVA。因此,在ANCOVA中使用额外的连续回归变量不会改变分析。
这里有一些相关文档的链接
Anova辅助函数和ANCOVA交互的示例http://statsmodels.sourceforge.net/devel/examples/generated/example_interactions.html
使用公式创建设计矩阵http://statsmodels.sourceforge.net/devel/example_formulas.html
核心OLS型号http://statsmodels.sourceforge.net/devel/generated/statsmodels.regression.linear_model.OLS.html

gajydyqb

gajydyqb2#

on geeks

import pandas as pd
import statsmodels.api as sm
from statsmodels.formula.api import ols

# Define the data for the ANCOVA
df = pd.DataFrame({'dependent_variable' : [8, 7, 9, 11, 10, 12, 14, 13, 15, 16],
   'group' : ["A", "A", "A", "B", "B", "B", "C", "C", "C", "C"],
    'covariate' : [20, 30, 40, 30, 40, 50, 40, 50, 60, 70]})

# Perform the ANCOVA
model = ols('dependent_variable ~ group + covariate', data=df).fit()

# Print the summary of the model
print(model.summary())

字符串
assumptions for ANCOVA- N.B.属于一般线性模型(*vs广义线性模型 * -一般线性模型要求响应变量遵循正态分布,而广义线性模型是一般线性模型的扩展,允许指定响应变量遵循不同分布的模型。
ANOVA & ANCOVA differ
协方差分析(ANCOVA)是一种统计过程,允许您在单个模型中同时包括分类变量和连续变量。ANCOVA假设分类变量的回归系数是齐次的(相同的)。违反此假设可能导致错误的结论。
correct data for ANCOVA-居中
e.g. how to handle interactions of continuous & categorical vars
在ANCOVA中,检验回归假设的同质性是很重要的,如果违反了这个假设,我们就需要估计各组之间具有不同斜率的模型。

相关问题