开始使用免费开始使用

测量遗传率

请记住,皮尔逊相关系数等于协方差与两个数据集方差几何平均数之比。它衡量父代与子代之间的相关性,但未必是遗传率的最佳估计。如果我们停下来想一想,更合理的做法是将遗传率定义为「父代与子代之间的协方差」与「仅父代方差」之比。在本练习中,您将估计遗传率,并通过配对自举(pairs bootstrap)计算 95% 置信区间。

本练习强调一个非常重要的观点。统计推断(以及一般的数据分析)不是套公式即可的流程。您需要认真思考要用数据回答的问题,并选择恰当的分析方法。如果您关注的是性状的可遗传性,我们这里对遗传率的定义比现成的统计量(皮尔逊相关系数)更合适。

请记住,数据存储在 bd_parent_scandensbd_offspring_scandensbd_parent_fortisbd_offspring_fortis 中。

本练习是课程的一部分

Python 统计思维(第 2 部分)

查看课程

练习说明

  • 编写函数 heritability(parents, offspring),其计算方式为:父代与子代性状的协方差除以父代性状的方差。提示:回顾一下本课程前一部分介绍过的 np.cov() 函数。
  • 使用该函数计算 G. scandensG. fortis 的遗传率。
  • G. scandensG. 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)
编辑并运行代码