Created
October 4, 2018 10:56
-
-
Save ymer/c129d419df88ff957513bc6e2fbda2b8 to your computer and use it in GitHub Desktop.
This file contains 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
using Distributions | |
using GLM | |
using RCall | |
using Random | |
Random.seed!(2) | |
n = 10000 | |
ses = collect(1:n) | |
pgs = rand(Normal(), n) | |
low_ses = collect(1:Int(n*0.2)) | |
medium_ses = collect(Int(n*0.2) + 1:Int(n*0.6)) | |
high_ses = collect(Int(n*0.6) +1:n) | |
divergence_low_ses = rand(Normal(0, 4), length(low_ses)) | |
divergence_middle_ses = rand(Normal(0, 2.6), length(medium_ses)) | |
divergence_high_ses = rand(Normal(0, 2), length(high_ses)) | |
divergence = vcat(divergence_low_ses, divergence_middle_ses, divergence_high_ses) | |
iq = pgs + divergence | |
scale(v) = (v .- mean(v)) / std(v) | |
iq_scaled = scale(iq) | |
ses_scaled = scale(ses) | |
show_cor(s, group) = println(s * ": ", cor(pgs[group], iq_scaled[group])) | |
show_cor("Overall correlation", ses) | |
show_cor("Low SES correlation", low_ses) | |
show_cor("Medium SES correlation", medium_ses) | |
show_cor("High SES correlation", high_ses) | |
iq_dot_pgs = iq_scaled .* pgs | |
@rput iq_dot_pgs | |
R"summary(lm(iq_dot_pgs ~ ses_scaled))" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment