Created
July 12, 2025 17:44
-
-
Save sashagusev/e7ff4eddbf3201eb1566abbfa7e9324e to your computer and use it in GitHub Desktop.
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
| # Fixed parameters | |
| N = 10e6 | |
| AM_cor = 0.50 | |
| for ( Cultural_cor in c(sqrt(0.15),0.51) ) { | |
| cat("\nSimulating cultural transmission of" , Cultural_cor , '\n' ) | |
| # Simulate two parental traits | |
| y_mother = rnorm(N,0,1) | |
| y_father = rnorm(N,0,1) | |
| # Mate assortatively | |
| ord1 = order(y_mother) | |
| ord2 = order(AM_cor * scale(y_father) + rnorm(N,0,sqrt(1-AM_cor^2))) | |
| y_mother = y_mother[ord1] | |
| y_father = y_father[ord2] | |
| # Cultural transmission to the offspring | |
| y_sib1 = scale((y_mother + y_father)/2) * Cultural_cor + rnorm(N,0,sqrt(1-Cultural_cor^2)) | |
| y_sib2 = scale((y_mother + y_father)/2) * Cultural_cor + rnorm(N,0,sqrt(1-Cultural_cor^2)) | |
| # Observed adopted sibling correlation : 0.15 | |
| cat( "Adopted sibling correlation:" , cor(y_sib1,y_sib2) , '\n' ) | |
| # Generate partners for the siblings | |
| y_sib1_partner = scale(y_sib1) * AM_cor + rnorm(N,0,sqrt(1-AM_cor^2)) | |
| y_sib2_partner = scale(y_sib2) * AM_cor + rnorm(N,0,sqrt(1-AM_cor^2)) | |
| y_sib1_offspring = scale((y_sib1 + y_sib1_partner)/2) * Cultural_cor + rnorm(N,0,sqrt(1-Cultural_cor^2)) | |
| y_sib2_offspring = scale((y_sib2 + y_sib2_partner)/2) * Cultural_cor + rnorm(N,0,sqrt(1-Cultural_cor^2)) | |
| # Observed adopted 1st cousin : 0.045 | |
| cat( "Adopted 1st cousing correlation:" , cor(y_sib1_offspring,y_sib2_offspring) , '\n' ) | |
| } | |
| # Output: | |
| # ------- | |
| # Simulating cultural transmission of 0.3872983 | |
| # Adopted sibling correlation: 0.1502106 | |
| # Adopted 1st cousing correlation: 0.016834 | |
| # Simulating cultural transmission of 0.51 | |
| # Adopted sibling correlation: 0.2600599 | |
| # Adopted 1st cousing correlation: 0.05077735 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment