# -*- coding: utf-8 -*-
"""
Created on Tue Jun 11 14:03:08 2019
@author: User
"""
# 《Python数据分析基础》中国统计出版社
#import numpy as np
from scipy import stats
import pandas as pd
import statsmodels.api as sm
moisture=pd.read_csv(u'data\\ch6\moisture.csv',encoding = "gbk")
print(moisture.head())
print("\n 对总体均值进行 置信度95% Z估计 statsmodels zconfint_mean(alpha=0.05)")
'''
zconfint_mean
参数:
alpha:置信区间的显着性水平
返回值:
lower,upper:浮点数或ndarray,置信区间的下限和上限
'''
zm=sm.stats.DescrStatsW(moisture['moisture']).zconfint_mean(alpha=0.05)
print(zm)
print("\n 对总体均值进行 置信度95% t分布估计 statsmodels tconfint_mean(alpha=0.05)")
tm=sm.stats.DescrStatsW(moisture['moisture']).tconfint_mean(alpha=0.05)
print(tm)
print("\n 对总体均值进行 置信度95% t分布估计 scipy bayes_mvs(alpha=0.05)")
moisture_mean,moisture_var,moisture_std=stats.bayes_mvs(moisture['moisture'],alpha=0.05)
print(moisture_mean)
print(moisture_var)
print(moisture_std)
运行:
对总体均值进行 置信度95% Z估计 statsmodels zconfint_mean(alpha=0.05)
(3.8561051908351796, 4.0910948091648205)
对总体均值进行 置信度95% t分布估计 statsmodels tconfint_mean(alpha=0.05)
(3.853131123764977, 4.094068876235023)
对总体均值进行 置信度95% t分布估计 scipy bayes_mvs(alpha=0.05)
Mean(statistic=3.9736000000000002, minmax=(3.9698215863920807, 3.9773784136079198))
Variance(statistic=0.18733089361702127, minmax=(0.17985571283091048, 0.18449764399286908))
Std_dev(statistic=0.43052145521911656, minmax=(0.4240939905621282, 0.4295318893782732))