Measuring heritability
Remember that the Pearson correlation coefficient is the ratio of the covariance to the geometric mean of the variances of the two data sets. This is a measure of the correlation between parents and offspring, but might not be the best estimate of heritability. If we stop and think, it makes more sense to define heritability as the ratio of the covariance between parent and offspring to the variance of the parents alone. In this exercise, you will estimate the heritability and perform a pairs bootstrap calculation to get the 95% confidence interval.
This exercise highlights a very important point. Statistical inference (and data analysis in general) is not a plug-n-chug enterprise. You need to think carefully about the questions you are seeking to answer with your data and analyze them appropriately. If you are interested in how heritable traits are, the quantity we defined as the heritability is more apt than the off-the-shelf statistic, the Pearson correlation coefficient.
Remember, the data are stored in bd_parent_scandens
, bd_offspring_scandens
, bd_parent_fortis
, and bd_offspring_fortis
.
Diese Übung ist Teil des Kurses
Statistical Thinking in Python (Part 2)
Anleitung zur Übung
- Write a function
heritability(parents, offspring)
that computes heritability defined as the ratio of the covariance of the trait in parents and offspring divided by the variance of the trait in the parents. Hint: Remind yourself of thenp.cov()
function we covered in the prequel to this course. - Use this function to compute the heritability for G. scandens and G. fortis.
- Acquire 1000 bootstrap replicates of the heritability using pairs bootstrap for G. scandens and G. fortis.
- Compute the 95% confidence interval for both using your bootstrap replicates.
- Print the results.
Interaktive Übung
Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.
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)