Bootstrap

python笔记:8.2.2 非参数检验的基本问题_分布的检验

 

# -*- coding: utf-8 -*-
"""
Created on Sun Jul 21 14:26:22 2019

@author: User
"""

# 《Python数据分析基础》中国统计出版社

import numpy as np
from scipy import stats
import pandas as pd
import statsmodels.api as sm
#import statsmodels.formula.api as smf
#import matplotlib.pyplot as plt
#from statsmodels.stats.multicomp import pairwise_tukeyhsd
#from statsmodels.graphics.api import interaction_plot
from matplotlib.font_manager import FontProperties
myfont=FontProperties(fname='data\msyh.ttc')

ks = pd.read_csv(u'data/ch8/ks.csv',encoding = "gbk")

print(ks)

print("\n sm.stats.diagnostic.kstest_normal(ks['observation']):")
print(sm.stats.diagnostic.kstest_normal(ks['observation']))

print("\n sm.stats.diagnostic.lilliefors(ks['observation']):")
print(sm.stats.diagnostic.lilliefors(ks['observation']))

st = stats.kstest(ks['observation'], 'norm', 
                  args=(ks['observation'].mean(),
                        ks['observation'].std()))
print("\n stats.kstest:")
print(st)

print("\n stats.shapiro(ks['observation']):")
print(stats.shapiro(ks['observation']))

print("\n stats.anderson(ks['observation'],dist='norm'):")
print(stats.anderson(ks['observation'],dist='norm'))

运行:

 sm.stats.diagnostic.kstest_normal(ks['observation']):
(0.11085609021293796, 0.021718830360242317)

 sm.stats.diagnostic.lilliefors(ks['observation']):
(0.11085609021293796, 0.021718830360242317)

 stats.kstest:
KstestResult(statistic=0.11085609021293796, pvalue=0.2869341737555461)

 stats.shapiro(ks['observation']):
(0.9556435346603394, 0.009623649530112743)

 stats.anderson(ks['observation'],dist='norm'):
AndersonResult(statistic=0.9221944197643097, critical_values=array([0.549, 0.626, 0.751, 0.876, 1.042]), significance_level=array([15. , 10. ,  5. ,  2.5,  1. ]))
 

;