模擬零假設

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

%matplotlib inline
np.random.seed(42)

full_data = pd.read_csv('coffee_dataset.csv')
sample_data = full_data.sample(200)
  1. If you were interested in if the average height for coffee drinkers is the same as for non-coffee drinkers, what would the null and alternative be? Place them in the cell below, and use your answer to answer the first quiz question below.

    Since there is no directional component associated with this statement, a not equal to seems most reasonable.

    ??0:?????????????????=0

    ??0:?????????????????≠0

    ?????????? and ?????? are the population mean values for coffee drinkers and non-coffee drinkers, respectivley.

  2. If you were interested in if the average height for coffee drinkers is less than non-coffee drinkers, what would the null and alternative be? Place them in the cell below, and use your answer to answer the second quiz question below.

    In this case, there is a question associated with a direction - that is the average height for coffee drinkers is less than non-coffee drinkers. Below is one of the ways you could write the null and alternative. Since the mean for coffee drinkers is listed first here, the alternative would suggest that this is negative.

    ??0:?????????????????≥0

    ??0:?????????????????<0

    ?????????? and ?????? are the population mean values for coffee drinkers and non-coffee drinkers, respectivley.

  3. For 10,000 iterations: bootstrap the sample data, calculate the mean height for coffee drinkers and non-coffee drinkers, and calculate the difference in means for each sample. You will want to have three arrays at the end of the iterations - one for each mean and one for the difference in means. Use the results of your sampling distribution, to answer the third quiz question below.

nocoff_means, coff_means, diffs = [], [], []

for _ in range(10000):
    bootsamp = sample_data.sample(200, replace = True)
    coff_mean = bootsamp[bootsamp['drinks_coffee'] == True]['height'].mean()
    nocoff_mean = bootsamp[bootsamp['drinks_coffee'] == False]['height'].mean()
    # append the info 
    coff_means.append(coff_mean)
    nocoff_means.append(nocoff_mean)
    diffs.append(coff_mean - nocoff_mean)   
np.std(nocoff_means) # the standard deviation of the sampling distribution for nocoff
np.std(coff_means) # the standard deviation of the sampling distribution for coff
np.std(diffs) # the standard deviation for the sampling distribution for difference in means
plt.hist(nocoff_means, alpha = 0.5);
plt.hist(coff_means, alpha = 0.5); # They look pretty normal to me!
plt.hist(diffs, alpha = 0.5); # again normal - this is by the central limit theorem
null_vals = np.random.normal(0, np.std(diffs), 10000) # Here are 10000 draws from the sampling distribution under the null
plt.hist(null_vals); #Here is the sampling distribution of the difference under the null
最后編輯于
?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市名船,隨后出現(xiàn)的幾起案子绰上,更是在濱河造成了極大的恐慌,老刑警劉巖渠驼,帶你破解...
    沈念sama閱讀 212,383評論 6 493
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件蜈块,死亡現(xiàn)場離奇詭異,居然都是意外死亡迷扇,警方通過查閱死者的電腦和手機百揭,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 90,522評論 3 385
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來蜓席,“玉大人器一,你說我怎么就攤上這事〕冢” “怎么了祈秕?”我有些...
    開封第一講書人閱讀 157,852評論 0 348
  • 文/不壞的土叔 我叫張陵,是天一觀的道長雏胃。 經(jīng)常有香客問我踢步,道長,這世上最難降的妖魔是什么丑掺? 我笑而不...
    開封第一講書人閱讀 56,621評論 1 284
  • 正文 為了忘掉前任,我火速辦了婚禮述雾,結果婚禮上街州,老公的妹妹穿的比我還像新娘。我一直安慰自己玻孟,他們只是感情好唆缴,可當我...
    茶點故事閱讀 65,741評論 6 386
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著黍翎,像睡著了一般面徽。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上匣掸,一...
    開封第一講書人閱讀 49,929評論 1 290
  • 那天趟紊,我揣著相機與錄音,去河邊找鬼碰酝。 笑死霎匈,一個胖子當著我的面吹牛,可吹牛的內(nèi)容都是我干的送爸。 我是一名探鬼主播铛嘱,決...
    沈念sama閱讀 39,076評論 3 410
  • 文/蒼蘭香墨 我猛地睜開眼暖释,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了墨吓?” 一聲冷哼從身側(cè)響起球匕,我...
    開封第一講書人閱讀 37,803評論 0 268
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎帖烘,沒想到半個月后亮曹,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 44,265評論 1 303
  • 正文 獨居荒郊野嶺守林人離奇死亡蚓让,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 36,582評論 2 327
  • 正文 我和宋清朗相戀三年乾忱,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片历极。...
    茶點故事閱讀 38,716評論 1 341
  • 序言:一個原本活蹦亂跳的男人離奇死亡窄瘟,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出趟卸,到底是詐尸還是另有隱情蹄葱,我是刑警寧澤,帶...
    沈念sama閱讀 34,395評論 4 333
  • 正文 年R本政府宣布锄列,位于F島的核電站图云,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏邻邮。R本人自食惡果不足惜竣况,卻給世界環(huán)境...
    茶點故事閱讀 40,039評論 3 316
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望筒严。 院中可真熱鬧丹泉,春花似錦、人聲如沸鸭蛙。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,798評論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽娶视。三九已至晒哄,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間肪获,已是汗流浹背寝凌。 一陣腳步聲響...
    開封第一講書人閱讀 32,027評論 1 266
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留孝赫,地道東北人硫兰。 一個月前我還...
    沈念sama閱讀 46,488評論 2 361
  • 正文 我出身青樓,卻偏偏與公主長得像寒锚,于是被迫代替她去往敵國和親劫映。 傳聞我的和親對象是個殘疾皇子违孝,可洞房花燭夜當晚...
    茶點故事閱讀 43,612評論 2 350

推薦閱讀更多精彩內(nèi)容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi閱讀 7,312評論 0 10
  • 好難啊……知道如何畫也畫不好
    fable花兒閱讀 391評論 0 1
  • 固定性思維和成長型思維模式造就不一樣的人生祖今! 你的某項專長校坑,并不是固定的先天能力決定的,而是通過有目的的鍛煉獲得千诬!...
    紙上芭蕾閱讀 94評論 0 0