Skip to content

Instantly share code, notes, and snippets.

@Deleetdk
Created January 9, 2023 20:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Deleetdk/21c189567fa80d149a5e27d574998014 to your computer and use it in GitHub Desktop.
Save Deleetdk/21c189567fa80d149a5e27d574998014 to your computer and use it in GitHub Desktop.
sibling SD
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