測量遺傳率
記住,皮爾森相關係數是兩個資料集之間的共變異數,除以兩者變異數的幾何平均的比值。它衡量的是親代與子代之間的相關性,但可能不是遺傳率的最佳估計。如果仔細思考,更合理的遺傳率定義是:親代與子代之間性狀的共變異數,除以「僅親代性狀的變異數」。在這個練習中,你會估計遺傳率,並以配對自助法(pairs bootstrap)計算 95% 信賴區間。
這個練習凸顯了一個非常重要的觀念。統計推論(以及一般的資料分析)不是套公式就能搞定的。你需要仔細思考想用資料回答的問題,並以合適的方法分析。如果你關心性狀的可遺傳程度,我們所定義的遺傳率,比起現成的統計量——皮爾森相關係數——更貼切。
請記住,資料分別存於 bd_parent_scandens、bd_offspring_scandens、bd_parent_fortis 與 bd_offspring_fortis。
本練習屬於課程
Statistical Thinking in Python(第 2 部分)
練習說明
- 撰寫函式
heritability(parents, offspring),計算遺傳率,其定義為:親代與子代之間性狀的共變異數,除以親代性狀的變異數。提示:回想本課程前集介紹過的np.cov()函式。 - 使用此函式計算 G. scandens 與 G. fortis 的遺傳率。
- 使用配對自助法(pairs bootstrap)為 G. scandens 與 G. fortis 取得 1000 個遺傳率重抽樣複本。
- 使用重抽樣結果計算兩者的 95% 信賴區間。
- 印出結果。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
def heritability(parents, offspring):
"""Compute the heritability from parent and offspring samples."""
covariance_matrix = np.cov(parents, offspring)
return ____ / ____
# Compute the heritability
heritability_scandens = ____
heritability_fortis = ____
# Acquire 1000 bootstrap replicates of heritability
replicates_scandens = draw_bs_pairs(
____, ____, ____, size=____)
replicates_fortis = draw_bs_pairs(
____, ____, ____, size=____)
# Compute 95% confidence intervals
conf_int_scandens = ____
conf_int_fortis = ____
# Print results
print('G. scandens:', heritability_scandens, conf_int_scandens)
print('G. fortis:', heritability_fortis, conf_int_fortis)