Created
January 9, 2023 20:40
-
-
Save Deleetdk/21c189567fa80d149a5e27d574998014 to your computer and use it in GitHub Desktop.
sibling SD
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(tidyverse) | |
#simulate datasets | |
sibs = 20 | |
x = map_df(seq(0, 1, .01), function(r) { | |
#simulate sibling scores at correlation r | |
matrix = matrix(r, ncol = sibs, nrow = sibs) | |
diag(matrix) = 1 | |
mvrnorm(n = 1e4, | |
Sigma = matrix, | |
mu = rep(0, sibs) | |
) %>% | |
as_tibble() %>% | |
mutate( | |
r = r, | |
) | |
}) %>% | |
#change the scale to IQ norms | |
{ | |
.[1:sibs] = .[1:sibs] * 15 + 100 | |
. | |
} | |
#compute SDs | |
x_sds = plyr::alply(x, .margins = 1, function(dd) { | |
dd[1:sibs] %>% sd() | |
}) %>% unlist() | |
sibling_SDs = tibble( | |
r = x$r, | |
SD = x_sds | |
) %>% | |
group_by(r) %>% | |
summarise( | |
mean_SD = mean(SD) | |
) | |
sibling_SDs %>% | |
ggplot(aes(r, mean_SD)) + | |
geom_line() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment