set.seed(17)
n <- 60
DT <- data.frame(id = factor(rep(seq_len(n), each = 3)))
u <- matrix(rnorm(n * 2), n)
DT$trait_a <- u[DT$id, 1] + rnorm(nrow(DT), sd = 0.7)
DT$trait_b <- u[DT$id, 2] + rnorm(nrow(DT), sd = 1)
DTL <- stackTraits(DT, traits = c("trait_a", "trait_b"), keep = "id")
head(DTL)
table(DTL$trait)
# bivariate model with the residual paired through the record key
fit <- mmes(value ~ trait,
random = ~ vsm(usm(trait), ism(id)),
rcov = ~ vsm(usm(trait), ism(record)),
data = DTL,
control = mmes_control(diagnostics = list(verbose = FALSE)))
covmatrix_mmes(fit, 1)$correlation # genetic correlation
Run the code above in your browser using DataLab