简体   繁体   English

Statsmodels 均值差异的置信区间

[英]Statsmodels Confidence Interval for Difference in Means

I wanted to find the confidence interval for the difference between two means (Male vs Female).我想找到两种平均值(男性与女性)之间差异的置信区间。 I browsed on the index for statsmodels and found the function below.我浏览了 statsmodels 的索引,在下面找到了 function。 However it didn't explain where should I specify the Male and Female series.但是它没有解释我应该在哪里指定男性和女性系列。 Please advise.请指教。

在此处输入图像描述

Function: Function:

CompareMeans.tconfint_diff(alpha=0.05, alternative='two-sided', usevar='pooled')

Documentation: https://www.statsmodels.org/stable/generated/statsmodels.stats.weightstats.CompareMeans.tconfint_diff.html文档: https://www.statsmodels.org/stable/generated/statsmodels.stats.weightstats.CompareMeans.tconfint_diff.html

The descriptive statistics of the two series should be passed to the CompareMeans class in DescrStatsW format.两个系列的描述性统计应以DescrStatsW格式传递给CompareMeans class。 After that you can use the tconfint_diff method of the CompareMeans class to obtain the confidence interval for the difference in means.之后,您可以使用CompareMeans class 的tconfint_diff方法来获取均值差异的置信区间。

import pandas as pd
import numpy as np
from statsmodels.stats.weightstats import DescrStatsW, CompareMeans

df = pd.DataFrame({
    'Male': np.random.normal(loc=50, scale=5, size=100),
    'Female': np.random.normal(loc=50, scale=25, size=100),
})

cm = CompareMeans(d1=DescrStatsW(data=df['Male']), d2=DescrStatsW(data=df['Female']))

lower, upper = cm.tconfint_diff(alpha=0.05, alternative='two-sided', usevar='unequal')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM