Created
September 19, 2019 15:08
-
-
Save explodecomputer/c0b317e49cc136a585cf0e6e3ad3fb5f to your computer and use it in GitHub Desktop.
tetrachoric under different scenarios
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(mvtnorm) | |
library(psych) | |
n <- 100000 | |
dn <- rmvnorm(n, c(0,0), matrix(c(1,0.5, 0.5,1), 2)) | |
# 50% prevalence | |
d <- dn | |
d[,1] <- rbinom(n, 1, pnorm(d[,1])) | |
d[,2] <- rbinom(n, 1, pnorm(d[,2])) | |
tetrachoric(table(d[,1], d[,2])) | |
# Sample liability but 5% prevalence | |
d <- dn | |
d[,1] <- rbinom(n, 1, pnorm(d[,1])/10) | |
d[,2] <- rbinom(n, 1, pnorm(d[,2])/10) | |
tetrachoric(table(d[,1], d[,2])) | |
# Ascertain data - aim for sample size with 50% cases and controls for trait 1 | |
d <- dn | |
d[,1] <- rbinom(n, 1, pnorm(d[,1])/10) | |
d[,2] <- rbinom(n, 1, pnorm(d[,2])/10) | |
d <- rbind( | |
d[d[,1] == 1,], | |
d[d[,1] == 0, ][1:sum(d[,1] == 1),] | |
) | |
tetrachoric(table(d[,1], d[,2])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment