第四次作业

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

%matplotlib inline
%config InlineBackend.figure_format = 'retina'

mean = np.mean(100)
std = np.sqrt(100)/2

# -1.96 < ( (x-mean)/std ) < 1.96 
def comparefunx(x,mean,std):
    if ( ((x-mean)/std ) < 1.96 and (( x-mean)/std ) > (-1.96)):
        print("accept the hypothesis,%d is in confidence interval" %x)
        return x
    else:
        print("abondan the hypothesis!")       
        
n = comparefunx(100,mean,std)
accept the hypothesis,100 is in confidence interval


# 2
#总体均值为μ, 总体标准差为σ, 从中观测的n个数据x的样本均值X分布也是正态分布。X的分布平均值
#扔为a,标准差为σ/sqrt(n)(极简统计学P131)
# -1.96 < ( (x-mean)/(σ/sqrt(n)) ) < 1.96  95%置信区间 
# -2.58 < ( (x-mean)/(σ/sqrt(n)) ) < 2.58  99%置信区间


def rangefunx(mean,std,n,range,interval):
    low = mean - range * std / np.sqrt(n)
    high = mean + range * std / np.sqrt(n)
    print("%d percent confidence interval is : from %d to %d" %(interval,low,high))
    return low,high
    
low,high = rangefunx(1082,108,30,1.96,95)

low1,high1 = rangefunx(1082,108,30,2.58,99)
95 percent confidence interval is : from 1043 to 1120
99 percent confidence interval is : from 1031 to 1132

你可能感兴趣的:(第四次作业)