In [1]:
list_pkgs <- c("plyr", "dplyr", "tidyr", "readr", "car", "lme4", "lmerTest", "ggplot2", "cowplot")
new_pkgs <- list_pkgs[!(list_pkgs %in% installed.packages()[,"Package"])]
if(length(new_pkgs) > 0){ install.packages(new_pkgs) }

library(plyr)
library(dplyr)
library(tidyr)
library(readr)
library(car)
library(lme4)
library(lmerTest)
library(ggplot2)
library(cowplot)


Attaching package: ‘dplyr’

The following objects are masked from ‘package:plyr’:

    arrange, count, desc, failwith, id, mutate, rename, summarise,
    summarize

The following objects are masked from ‘package:stats’:

    filter, lag

The following objects are masked from ‘package:base’:

    intersect, setdiff, setequal, union


Attaching package: ‘car’

The following object is masked from ‘package:dplyr’:

    recode

Loading required package: Matrix

Attaching package: ‘Matrix’

The following object is masked from ‘package:tidyr’:

    expand


Attaching package: ‘lmerTest’

The following object is masked from ‘package:lme4’:

    lmer

The following object is masked from ‘package:stats’:

    step


Attaching package: ‘cowplot’

The following object is masked from ‘package:ggplot2’:

    ggsave

Outline

Move on to an F3 population and look at the importance of population stratification.

An F3 is created by random mating of F2 individuals. F2 individuals are genetically different from each other, so the F3 generation typically has family structure (sets of siblings sharing the same parents). This phenomenon is generally called population stratification. It is important because individuals with correlated phenotypes have correlated genotypes due to relatedness. Treating them as independent leads to a form of pseudoreplication.

We can start by running the null model for a set of simulated markers to see how the analysis performs with a true null hypothesis. Do we get the right number of false positives?

We can also try to run this model by randomizing either genotypes and phenotypes, while ignoring the structure of the population (so we ignore family). Do we get the same significance results?

We can account for the influence of population stratification by including a random effect term that accounts for family. This is basically the same as running the variance component model, so we are fitting the family variance component as a random effect while fitting the fixed effect of a locus. This same approach could be done in a more complex population by using an animal model to fit the family variance component.

We can now go back and run the null model with simulated markers and look at how including the family covariance parameter changes the behaviour of the model.

We can also use this mixed model to simultaneously estimate QTL effects and family variance components, which is a simple version of the structure of a model that is now widely used for mapping loci in natural populations (including for human association studies)

We can also look at whether a locus is pleiotropic and affects multiple traits.

Population stratification

An F3 population has more recombination, which means you get higher resolution, but your model is more complex

Reading and plotting data


In [2]:
f3_data = read_csv("./F3 geno pheno with QTL effect.csv")
f3_data


IDFAMILYSexSireDamNURSELSBLSWTrait1Trait2G25G26G27G28G29G30G31Trait2aTrait3aTrait3b
492 11 F 82 173 173 8 8 0.0873266212.511166 1 1 1 1 1 1 1 12.004366 25.99122 26.66904
493 11 F 82 173 173 8 8 0.0973266210.522276 1 1 1 1 1 1 1 10.522276 22.88304 22.88304
494 14 F 85 114 173 7 8 0.0937115613.818946 -1 -1 -1 -1 -1 -1 -1 13.312146 26.25022 27.42804
495 14 M 85 114 173 7 8 0.1589737312.384913 0 0 0 0 0 1 1 12.891713 30.75996 30.75996
496 11 F 82 173 173 8 8 0.0258700013.101166 1 1 1 1 1 1 1 13.607966 31.49486 30.31704
497 14 M 85 114 173 7 8 0.1298774913.744913 -1 -1 -1 -1 -1 -1 -1 13.238113 33.92932 35.10714
498 14 M 85 114 173 7 8 0.1024080313.376023 -1 -1 0 0 0 0 0 12.869223 33.27632 34.45414
499 11 F 82 173 173 8 8 0.0949182513.953386 -1 -1 -1 -1 -1 0 0 13.446586 28.12822 29.30604
500 11 F 82 173 114 8 7 0.0993828110.617069 -1 -1 -1 -1 -1 0 0 10.110269 28.59073 29.76855
501 11 M 82 173 114 8 7 0.0922951810.383046 0 0 0 0 0 0 0 10.383046 28.14965 28.14965
502 11 M 82 173 114 8 7 0.0931403612.258596 1 1 0 0 0 0 0 11.751796 27.56783 26.39001
503 14 F 85 114 114 7 7 0.12787820 9.839289 -1 -1 0 0 0 0 0 9.332489 30.13873 31.31655
504 14 M 85 114 114 7 7 0.1331403610.613046 0 0 0 0 0 0 0 11.119846 25.71247 25.71247
505 14 F 85 114 114 7 7 0.10787820 9.033736 0 0 0 0 0 1 1 9.033736 27.63955 27.63955
506 11 F 82 173 114 8 7 0.0978782010.922629 -1 -1 -1 -1 -1 0 0 10.415829 28.71473 29.89255
507 24 F 122 103 103 7 7 0.0978782011.814849 0 0 1 1 1 1 1 11.814849 26.83955 28.01737
508 12 F 83 102 103 11 7 0.1278782011.182619 1 1 0 0 0 0 0 11.182619 29.10755 28.60755
509 12 M 83 102 103 11 7 0.1619336711.535266 0 0 -1 -1 -1 0 0 11.028466 29.07283 29.07283
510 24 F 122 103 103 7 7 0.0902865711.680399 -1 -1 -1 -1 -1 0 0 11.173599 28.63373 29.81155
511 24 F 122 103 103 7 7 0.0878782011.301509 -1 -1 -1 -1 -1 0 0 10.794709 24.25273 25.43055
512 12 M 83 102 103 11 7 0.09193367 8.949709 1 1 0 0 0 0 0 8.949709 22.97965 22.47965
513 24 F 122 103 103 7 7 0.0978782011.933739 -1 -1 -1 -1 -1 0 0 11.426939 26.24273 27.42055
514 12 F 83 102 102 11 11 0.0983061810.444278 0 0 0 0 0 0 0 10.444278 26.38775 26.38775
515 24 F 122 103 102 7 11 0.1021020010.954277 0 0 1 1 0 0 -1 11.461077 29.17557 29.17557
516 24 F 122 103 102 7 11 0.06878986 9.877611 0 0 0 0 0 0 -1 10.384411 26.29057 26.29057
517 24 M 122 103 102 7 11 0.1049557810.288029 0 0 1 1 1 1 1 10.794829 22.21567 22.21567
518 12 F 83 102 102 11 11 0.0887898610.440944 -1 -1 0 0 0 0 0 9.934144 25.07293 26.25075
519 24 M 122 103 102 7 11 0.1337491011.310252 0 0 0 0 0 -1 -1 11.310252 27.19985 27.19985
520 12 M 83 102 102 11 11 0.09718341 8.835807 0 0 0 0 0 -1 0 8.835807 23.16585 23.16585
521 12 F 83 102 102 11 11 0.0987898610.115389 0 0 0 0 0 0 0 10.115389 25.90775 25.90775
3138 192 M 1443 1173 1171 8 11 0.0698745014.290840 0 0 1 1 1 1 1 14.290840 38.01906 38.01906
3139 192 F 1443 1173 1171 8 11 0.1058003514.343533 -1 0 1 1 1 0 0 13.836733 31.11215 32.28997
3140 192 F 1443 1173 1171 8 11 0.1258003514.382533 -1 0 0 0 0 1 1 14.382533 33.01197 33.01197
3141 192 F 1443 1173 1173 8 8 0.0959256413.282172 -1 0 0 0 0 -1 -1 12.775372 19.37653 20.55435
3142 192 M 1443 1173 1173 8 8 0.0771909115.008172 0 -1 -1 -1 0 0 0 15.008172 37.08435 37.08435
3143 192 F 1443 1173 1173 8 8 0.1159256413.896172 0 -1 -1 -1 0 0 0 13.896172 23.68835 23.68835
3144 192 M 1443 1173 1173 8 8 0.0859256414.587172 0 -1 -1 -1 -1 -1 -1 14.587172 31.95735 31.95735
3145 202 M 1441 1171 1173 11 8 0.1359256414.418172 0 0 0 -1 -1 0 0 14.924972 36.78817 36.78817
3146 202 F 1441 1171 1173 11 8 0.0987540015.251172 0 0 0 -1 -1 0 0 15.757972 34.83217 34.83217
3147 202 M 1441 1171 1173 11 8 0.1071909115.030172 0 0 0 -1 -1 0 0 15.536972 38.14017 36.96235
3148 202 F 1441 1171 1173 11 8 0.1559256415.106172 1 1 1 1 1 1 1 15.612972 28.53117 27.35335
3265 187 M 1169 1437 1437 4 4 0.1146336810.813225 1 1 1 0 0 0 0 10.813225 24.53626 24.03626
3266 187 F 1169 1437 1437 4 4 0.1291907711.443919 -1 -1 -1 -1 -1 -1 -1 10.937119 25.50135 26.67917
3267 187 F 1169 1437 1437 4 4 0.1897240010.962919 -1 -1 -1 -1 -1 -1 0 10.456119 21.20335 22.38117
3268 187 F 1169 1437 1437 4 4 0.10919077 9.872919 -1 -1 -1 -1 0 -1 -1 9.366119 18.87635 20.05417
3305 190 M 1297 1438 1438 9 8 0.1277331710.972172 0 0 -1 -1 -1 -1 -1 10.972172 33.71235 33.71235
3306 190 F 1297 1438 1438 9 8 0.1122902510.228865 0 0 0 0 0 0 0 10.735665 32.84908 31.67126
3307 190 M 1297 1438 1438 9 8 0.08773317 9.642172 0 0 0 0 0 0 0 9.642172 23.83635 23.83635
3308 190 F 1297 1438 1438 9 8 0.10229025 9.859865 -1 -1 -1 -1 -1 -1 -1 9.353065 25.37444 26.55226
3309 190 F 1297 1438 1438 9 8 0.1222902510.483865 0 -1 -1 -1 -1 0 0 10.483865 31.15626 31.15626
3311 190 M 1297 1438 1438 9 8 0.11773317 9.742172 1 1 0 0 0 0 0 10.248972 26.88117 25.70335
3312 190 F 1297 1438 1438 9 8 0.10229025 8.851865 -1 -1 -1 -1 -1 0 0 8.345065 26.66644 27.84426
3842 188 M 1172 1299 1299 8 8 0.1189984410.197172 -1 -1 -1 -1 -1 -1 0 10.197172 23.14235 23.64235
3843 188 F 1172 1299 1299 8 8 0.0835555210.212865 0 0 0 0 0 0 0 10.212865 25.35926 25.35926
3844 188 F 1172 1299 1299 8 8 0.05355552 9.371865 0 0 0 0 0 0 0 9.371865 22.02126 22.02126
3845 188 F 1172 1299 1299 8 8 0.1435555210.696865 0 1 1 1 1 1 1 10.696865 23.11626 23.11626
3846 188 M 1172 1299 1299 8 8 0.08899844 9.180172 0 0 0 0 0 0 0 9.180172 23.55035 23.55035
3847 188 M 1172 1299 1299 8 8 0.0989984410.396172 0 0 0 0 0 0 0 10.396172 22.93835 22.93835
3848 188 F 1172 1299 1299 8 8 0.1235555210.214865 0 0 0 0 0 0 0 10.214865 24.95126 24.95126
3849 188 M 1172 1299 1299 8 8 0.0889984410.963172 0 0 0 0 0 -1 0 10.963172 23.26835 23.26835

In [3]:
f3_data %>% 
    gather(trait, value, Trait2a:Trait3b) %>%
    ggplot(aes(trait, value)) + geom_violin() + geom_jitter(width = 0.1, alpha = 0.1)


Warning message:
“Removed 9 rows containing non-finite values (stat_ydensity).”Warning message:
“Removed 9 rows containing missing values (geom_point).”

Mapping gone wrong

Let's see what happens when we use the same model as in the F2 population, using the set of null markers with no effect.

Remeber, we expect no more than 5% of significant markers in this set.


In [4]:
simulated_genotypes = read_csv("sim genotypes.csv")
f3_data_null = inner_join(select(f3_data, ID:Trait3), simulated_genotypes, by = "ID")
#f3_data_null

In [5]:
n_markers = 675
null_marker_fits_trait3 = list()
for(i in seq(n_markers)){
    current_marker = paste0('G', i)
    f3_data_null[[paste0(current_marker, '_D')]] = ifelse(f3_data_null[[current_marker]], 0, 1)
    model_formula = paste0("Trait3 ~ Sex + LSB + LSW + ", current_marker, "+", current_marker, "_D")
    null_marker_fits_trait3[[i]] = lm(as.formula(model_formula), data = f3_data_null)
}

In [6]:
table(laply(null_marker_fits_trait3, function(x) summary(x)$coefficients[5, 'Pr(>|t|)']) < 0.05) / n_markers


    FALSE      TRUE 
0.8059259 0.1940741 

Almost four times what we should be getting!

Mixed models for stratification

We can take stratification into account using a random effect for family structure. The lme4 and lmerTest packages allow us to fit the model and extract the relevant p-value. The only difference is the (1|FAMILY) term in the model formula.


In [7]:
n_markers = 675
null_marker_mixed_fits_trait3 = list()
for(i in seq(n_markers)){
    current_marker = paste0('G', i)
    f3_data_null[[paste0(current_marker, '_D')]] = ifelse(f3_data_null[[current_marker]], 0, 1)  
    model_formula = paste0("Trait3 ~ (1|FAMILY) + Sex + LSB + LSW + ", current_marker, "+", current_marker, "_D")
    null_marker_mixed_fits_trait3[[i]] = lmer(as.formula(model_formula), data = f3_data_null)
}

In [8]:
table(laply(null_marker_mixed_fits_trait3, function(x) summary(x)$coefficients[5, 'Pr(>|t|)']) < 0.05) / n_markers


     FALSE       TRUE 
0.94222222 0.05777778 

Much better!

Mapping pleiotropic QTLs

For more than 1 trait we can fit the models separetly for each trait or run them in a single model.


In [9]:
n_markers = 31
interval = 6 # Play around with this value. 
fl_marker_fits_trait2a = list()
for(i in seq(n_markers)) f3_data[[paste0(paste0('G', i), '_D')]] = ifelse(f3_data[[paste0('G', i)]], 0, 1)
for(i in seq(n_markers)){
    current_marker = paste0('G', i)
    model_formula = paste0("Trait2a ~ (1|FAMILY) + Sex + LSB + LSW + ", current_marker, "+", current_marker, "_D")
    if((i - interval) >= 1)
        model_formula = paste0(model_formula, "+ G", paste0(i - interval), "+ G", paste0(i - interval), "_D")
    if((i + interval) <= n_markers)
        model_formula = paste0(model_formula, "+ G", paste0(i + interval), "+ G", paste0(i + interval), "_D")
    fl_marker_fits_trait2a[[i]] = lmer(as.formula(model_formula), data = f3_data)
}

In [10]:
ldply(fl_marker_fits_trait2a, function(x) summary(x)$coefficients[5, 'Pr(>|t|)']) %>%
    ggplot(aes(1:n_markers, -log10(V1))) + geom_line() + labs(x = "marker", y = "LPR") +
    scale_x_continuous(breaks = seq(1, n_markers, by = 2))



In [11]:
n_markers = 31
interval = 6 # Play around with this value. 
fl_marker_fits_trait3a = list()
for(i in seq(n_markers)){
    current_marker = paste0('G', i)
    model_formula = paste0("Trait3a ~ (1|FAMILY) + Sex + LSB + LSW + ", current_marker, "+", current_marker, "_D")
    if((i - interval) >= 1)
        model_formula = paste0(model_formula, "+ G", paste0(i - interval), "+ G", paste0(i - interval), "_D")
    if((i + interval) <= n_markers)
        model_formula = paste0(model_formula, "+ G", paste0(i + interval), "+ G", paste0(i + interval), "_D")
    fl_marker_fits_trait3a[[i]] = lmer(as.formula(model_formula), data = f3_data)
}

In [12]:
ldply(fl_marker_fits_trait3a, function(x) summary(x)$coefficients[5, 'Pr(>|t|)']) %>%
    ggplot(aes(1:n_markers, -log10(V1))) + geom_line() + labs(x = "marker", y = "LPR") +
    scale_x_continuous(breaks = seq(1, n_markers, by = 2))


Multiple traits at the same time

It's also possible to run both traits at the same time and get an estimate for the significance of the marker for all traits. This is more complicated, so we'll do it for a single marker which we already know there is an effect.

First we need to get the data in the apropriate "narrow" format, with a single column for the value of the traits and a column for the trait identity:


In [13]:
narrow_f3_data = gather(f3_data, variable, value, Trait2a, Trait3a)
narrow_f3_data


IDFAMILYSexSireDamNURSELSBLSWTrait1Trait2G24_DG25_DG26_DG27_DG28_DG29_DG30_DG31_Dvariablevalue
492 11 F 82 173 173 8 8 0.0873266212.511166 1 0 0 0 0 0 0 0 Trait2a 12.004366
493 11 F 82 173 173 8 8 0.0973266210.522276 0 0 0 0 0 0 0 0 Trait2a 10.522276
494 14 F 85 114 173 7 8 0.0937115613.818946 0 0 0 0 0 0 0 0 Trait2a 13.312146
495 14 M 85 114 173 7 8 0.1589737312.384913 1 1 1 1 1 1 0 0 Trait2a 12.891713
496 11 F 82 173 173 8 8 0.0258700013.101166 0 0 0 0 0 0 0 0 Trait2a 13.607966
497 14 M 85 114 173 7 8 0.1298774913.744913 0 0 0 0 0 0 0 0 Trait2a 13.238113
498 14 M 85 114 173 7 8 0.1024080313.376023 0 0 0 1 1 1 1 1 Trait2a 12.869223
499 11 F 82 173 173 8 8 0.0949182513.953386 0 0 0 0 0 0 1 1 Trait2a 13.446586
500 11 F 82 173 114 8 7 0.0993828110.617069 0 0 0 0 0 0 1 1 Trait2a 10.110269
501 11 M 82 173 114 8 7 0.0922951810.383046 1 1 1 1 1 1 1 1 Trait2a 10.383046
502 11 M 82 173 114 8 7 0.0931403612.258596 0 0 0 1 1 1 1 1 Trait2a 11.751796
503 14 F 85 114 114 7 7 0.12787820 9.839289 0 0 0 1 1 1 1 1 Trait2a 9.332489
504 14 M 85 114 114 7 7 0.1331403610.613046 1 1 1 1 1 1 1 1 Trait2a 11.119846
505 14 F 85 114 114 7 7 0.10787820 9.033736 1 1 1 1 1 1 0 0 Trait2a 9.033736
506 11 F 82 173 114 8 7 0.0978782010.922629 0 0 0 0 0 0 1 1 Trait2a 10.415829
507 24 F 122 103 103 7 7 0.0978782011.814849 1 1 1 0 0 0 0 0 Trait2a 11.814849
508 12 F 83 102 103 11 7 0.1278782011.182619 0 0 0 1 1 1 1 1 Trait2a 11.182619
509 12 M 83 102 103 11 7 0.1619336711.535266 1 1 1 0 0 0 1 1 Trait2a 11.028466
510 24 F 122 103 103 7 7 0.0902865711.680399 0 0 0 0 0 0 1 1 Trait2a 11.173599
511 24 F 122 103 103 7 7 0.0878782011.301509 0 0 0 0 0 0 1 1 Trait2a 10.794709
512 12 M 83 102 103 11 7 0.09193367 8.949709 0 0 0 1 1 1 1 1 Trait2a 8.949709
513 24 F 122 103 103 7 7 0.0978782011.933739 1 0 0 0 0 0 1 1 Trait2a 11.426939
514 12 F 83 102 102 11 11 0.0983061810.444278 1 1 1 1 1 1 1 1 Trait2a 10.444278
515 24 F 122 103 102 7 11 0.1021020010.954277 1 1 1 0 0 1 1 0 Trait2a 11.461077
516 24 F 122 103 102 7 11 0.06878986 9.877611 1 1 1 1 1 1 1 0 Trait2a 10.384411
517 24 M 122 103 102 7 11 0.1049557810.288029 1 1 1 0 0 0 0 0 Trait2a 10.794829
518 12 F 83 102 102 11 11 0.0887898610.440944 0 0 0 1 1 1 1 1 Trait2a 9.934144
519 24 M 122 103 102 7 11 0.1337491011.310252 1 1 1 1 1 1 0 0 Trait2a 11.310252
520 12 M 83 102 102 11 11 0.09718341 8.835807 1 1 1 1 1 1 0 1 Trait2a 8.835807
521 12 F 83 102 102 11 11 0.0987898610.115389 1 1 1 1 1 1 1 1 Trait2a 10.115389
3138 192 M 1443 1173 1171 8 11 0.0698745014.290840 1 1 1 0 0 0 0 0 Trait3a 38.01906
3139 192 F 1443 1173 1171 8 11 0.1058003514.343533 0 0 1 0 0 0 1 1 Trait3a 31.11215
3140 192 F 1443 1173 1171 8 11 0.1258003514.382533 0 0 1 1 1 1 0 0 Trait3a 33.01197
3141 192 F 1443 1173 1173 8 8 0.0959256413.282172 0 0 1 1 1 1 0 0 Trait3a 19.37653
3142 192 M 1443 1173 1173 8 8 0.0771909115.008172 1 1 0 0 0 1 1 1 Trait3a 37.08435
3143 192 F 1443 1173 1173 8 8 0.1159256413.896172 1 1 0 0 0 1 1 1 Trait3a 23.68835
3144 192 M 1443 1173 1173 8 8 0.0859256414.587172 1 1 0 0 0 0 0 0 Trait3a 31.95735
3145 202 M 1441 1171 1173 11 8 0.1359256414.418172 1 1 1 1 0 0 1 1 Trait3a 36.78817
3146 202 F 1441 1171 1173 11 8 0.0987540015.251172 1 1 1 1 0 0 1 1 Trait3a 34.83217
3147 202 M 1441 1171 1173 11 8 0.1071909115.030172 1 1 1 1 0 0 1 1 Trait3a 38.14017
3148 202 F 1441 1171 1173 11 8 0.1559256415.106172 0 0 0 0 0 0 0 0 Trait3a 28.53117
3265 187 M 1169 1437 1437 4 4 0.1146336810.813225 0 0 0 0 1 1 1 1 Trait3a 24.53626
3266 187 F 1169 1437 1437 4 4 0.1291907711.443919 0 0 0 0 0 0 0 0 Trait3a 25.50135
3267 187 F 1169 1437 1437 4 4 0.1897240010.962919 0 0 0 0 0 0 0 1 Trait3a 21.20335
3268 187 F 1169 1437 1437 4 4 0.10919077 9.872919 0 0 0 0 0 1 0 0 Trait3a 18.87635
3305 190 M 1297 1438 1438 9 8 0.1277331710.972172 1 1 1 0 0 0 0 0 Trait3a 33.71235
3306 190 F 1297 1438 1438 9 8 0.1122902510.228865 1 1 1 1 1 1 1 1 Trait3a 32.84908
3307 190 M 1297 1438 1438 9 8 0.08773317 9.642172 1 1 1 1 1 1 1 1 Trait3a 23.83635
3308 190 F 1297 1438 1438 9 8 0.10229025 9.859865 0 0 0 0 0 0 0 0 Trait3a 25.37444
3309 190 F 1297 1438 1438 9 8 0.1222902510.483865 1 1 0 0 0 0 1 1 Trait3a 31.15626
3311 190 M 1297 1438 1438 9 8 0.11773317 9.742172 0 0 0 1 1 1 1 1 Trait3a 26.88117
3312 190 F 1297 1438 1438 9 8 0.10229025 8.851865 0 0 0 0 0 0 1 1 Trait3a 26.66644
3842 188 M 1172 1299 1299 8 8 0.1189984410.197172 0 0 0 0 0 0 0 1 Trait3a 23.14235
3843 188 F 1172 1299 1299 8 8 0.0835555210.212865 1 1 1 1 1 1 1 1 Trait3a 25.35926
3844 188 F 1172 1299 1299 8 8 0.05355552 9.371865 1 1 1 1 1 1 1 1 Trait3a 22.02126
3845 188 F 1172 1299 1299 8 8 0.1435555210.696865 1 1 0 0 0 0 0 0 Trait3a 23.11626
3846 188 M 1172 1299 1299 8 8 0.08899844 9.180172 1 1 1 1 1 1 1 1 Trait3a 23.55035
3847 188 M 1172 1299 1299 8 8 0.0989984410.396172 1 1 1 1 1 1 1 1 Trait3a 22.93835
3848 188 F 1172 1299 1299 8 8 0.1235555210.214865 1 1 1 1 1 1 1 1 Trait3a 24.95126
3849 188 M 1172 1299 1299 8 8 0.0889984410.963172 1 1 1 1 1 1 0 1 Trait3a 23.26835

Now we set up a mixed model with a (variable|FAMILY) mixed effect, which will fit a genetic covariance matrix between the 2 traits.


In [14]:
null_2trait_fit = lmer(value ~ (variable|FAMILY) + variable + variable:Sex + variable:LSB + variable:LSW, data = narrow_f3_data)
summary(null_2trait_fit)


Linear mixed model fit by REML t-tests use Satterthwaite approximations to
  degrees of freedom [lmerMod]
Formula: 
value ~ (variable | FAMILY) + variable + variable:Sex + variable:LSB +  
    variable:LSW
   Data: narrow_f3_data

REML criterion at convergence: 14603

Scaled residuals: 
    Min      1Q  Median      3Q     Max 
-5.0311 -0.5061  0.0140  0.5120  3.8385 

Random effects:
 Groups   Name            Variance Std.Dev. Corr
 FAMILY   (Intercept)     0.8789   0.9375       
          variableTrait3a 3.1997   1.7888   0.56
 Residual                 4.9383   2.2222       
Number of obs: 3164, groups:  FAMILY, 198

Fixed effects:
                       Estimate Std. Error         df t value Pr(>|t|)    
(Intercept)            11.28022    0.36220  315.50000  31.143  < 2e-16 ***
variableTrait3a        16.47386    0.59643  289.00000  27.621  < 2e-16 ***
variableTrait2a:SexM   -0.02885    0.11472 2948.80000  -0.251  0.80145    
variableTrait3a:SexM    0.35535    0.11867 2874.60000   2.995  0.00277 ** 
variableTrait2a:LSB    -0.08234    0.04546  366.80000  -1.811  0.07093 .  
variableTrait3a:LSB     0.01709    0.08092  282.60000   0.211  0.83292    
variableTrait2a:LSW     0.06996    0.04008 1215.20000   1.745  0.08117 .  
variableTrait3a:LSW     0.03911    0.04823 2858.30000   0.811  0.41749    
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Correlation of Fixed Effects:
            (Intr) vrblT3 vT2:SM vT3:SM vT2:LSB vT3:LSB vT2:LSW
variablTrt3 -0.064                                             
vrblTrt2:SM -0.187  0.111                                      
vrblTrt3:SM -0.004 -0.114  0.024                               
vrblTr2:LSB -0.563 -0.107  0.012 -0.001                        
vrblTr3:LSB -0.415 -0.644 -0.001  0.004  0.436                 
vrblTr2:LSW -0.306  0.161  0.008  0.001 -0.578  -0.055         
vrblTr3:LSW -0.034 -0.191  0.001  0.010 -0.081  -0.397   0.133 

Now we add the marker term to this model


In [15]:
marker17_2trait_fit = update(null_2trait_fit, . ~ . + variable:G17 + variable:G17_D)
summary(marker17_2trait_fit)


Linear mixed model fit by REML ['lmerMod']
Formula: 
value ~ (variable | FAMILY) + variable + variable:Sex + variable:LSB +  
    variable:LSW + variable:G17 + variable:G17_D
   Data: narrow_f3_data

REML criterion at convergence: 14468.7

Scaled residuals: 
    Min      1Q  Median      3Q     Max 
-4.8006 -0.4938  0.0186  0.5035  4.2250 

Random effects:
 Groups   Name            Variance Std.Dev. Corr
 FAMILY   (Intercept)     0.8748   0.9353       
          variableTrait3a 3.1755   1.7820   0.51
 Residual                 4.7047   2.1690       
Number of obs: 3164, groups:  FAMILY, 198

Fixed effects:
                      Estimate Std. Error t value
(Intercept)           11.24523    0.36124  31.129
variableTrait3a       16.49093    0.59445  27.741
variableTrait2a:SexM  -0.05688    0.11232  -0.506
variableTrait3a:SexM   0.30881    0.11602   2.662
variableTrait2a:LSB   -0.07765    0.04490  -1.729
variableTrait3a:LSB    0.02412    0.07942   0.304
variableTrait2a:LSW    0.06532    0.03949   1.654
variableTrait3a:LSW    0.03545    0.04714   0.752
variableTrait2a:G17    0.50112    0.08197   6.113
variableTrait3a:G17    0.97041    0.08932  10.865
variableTrait2a:G17_D  0.10428    0.11406   0.914
variableTrait3a:G17_D  0.03604    0.12031   0.300

Correlation of Fixed Effects:
            (Intr) vrblT3 vT2:SM vT3:SM vT2:LSB vT3:LSB vT2:LSW vT3:LSW
variablTrt3 -0.088                                                     
vrblTrt2:SM -0.178  0.106                                              
vrblTrt3:SM -0.003 -0.108  0.023                                       
vrblTr2:LSB -0.560 -0.093  0.010 -0.001                                
vrblTr3:LSB -0.403 -0.640 -0.001  0.004  0.425                         
vrblTr2:LSW -0.299  0.159  0.009  0.001 -0.577  -0.052                 
vrblTr3:LSW -0.032 -0.187  0.001  0.010 -0.076  -0.395   0.126         
vrblTr2:G17  0.017 -0.013 -0.026 -0.005  0.025  -0.002  -0.039   0.008 
vrblTr3:G17 -0.004  0.004 -0.004 -0.035 -0.003   0.009   0.008  -0.010 
vrbT2:G17_D -0.143  0.081 -0.042  0.000  0.007   0.001  -0.013   0.001 
vrbT3:G17_D -0.009 -0.093  0.000 -0.038  0.002   0.007   0.001  -0.009 
            vrT2:G17 vrT3:G17 vT2:G17_
variablTrt3                           
vrblTrt2:SM                           
vrblTrt3:SM                           
vrblTr2:LSB                           
vrblTr3:LSB                           
vrblTr2:LSW                           
vrblTr3:LSW                           
vrblTr2:G17                           
vrblTr3:G17  0.061                    
vrbT2:G17_D -0.007    0.001           
vrbT3:G17_D  0.001   -0.004    0.038  

Now we can compare the two models (with and without the marker) using a likelihood ratio test. As expected the marker term is highly significant.


In [16]:
anova(null_2trait_fit, marker17_2trait_fit)


refitting model(s) with ML (instead of REML)
DfAICBIClogLikdevianceChisqChi DfPr(>Chisq)
object12 14599.81 14672.53 -7287.906 14575.81 NA NA NA
..116 14462.14 14559.10 -7215.072 14430.14 145.6686 4 1.724715e-30

We can also extract the vectors of additive and dominance effects.


In [17]:
additive = summary(marker17_2trait_fit)$coefficients[9:10, 1]
dominance = summary(marker17_2trait_fit)$coefficients[11:12, 1]
additive
dominance


variableTrait2a:G17
0.501115637371015
variableTrait3a:G17
0.970412234260567
variableTrait2a:G17_D
0.104277696859758
variableTrait3a:G17_D
0.0360377496843756