Attaching package: ‘coda’
The following object is masked from ‘package:rstan’:
traceplot
The following object is masked from ‘package:rstan’:
traceplot
Attaching package: ‘geiger’
The following object is masked from ‘package:bridgesampling’:
bf
The following object is masked from ‘package:brms’:
bf
Attaching package: ‘geiger’
The following object is masked from ‘package:bridgesampling’:
bf
The following object is masked from ‘package:brms’:
bf
Data Preparation
d <-read_csv("../data/soundpop.csv")head(d)
Rows: 1508 Columns: 7
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (3): Glottocode, Macroarea, Family
dbl (4): nSegments, population, Longitude, Latitude
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (3): Glottocode, Macroarea, Family
dbl (4): nSegments, population, Longitude, Latitude
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
A tibble: 6 × 7
Glottocode
nSegments
population
Macroarea
Longitude
Latitude
Family
<chr>
<dbl>
<dbl>
<chr>
<dbl>
<dbl>
<chr>
bafi1243
51
60000
Africa
11.17
5.00
Atlantic-Congo
nugu1242
35
35000
Africa
11.25
4.58
Atlantic-Congo
mmaa1238
34
8000
Africa
11.08
4.50
Atlantic-Congo
tuki1240
39
26000
Africa
11.50
4.58
Atlantic-Congo
ewon1239
34
578000
Africa
12.00
4.00
Atlantic-Congo
abar1238
36
1850
Africa
10.25
6.58
Atlantic-Congo
load tree and scale its height
tree <-read.tree("../data/soundpop.tre")tree$edge.length <- tree$edge.length /median(tree$edge.length)
arrange data in order of tree tip.labels
d <- d[match(tree$tip.label, d$Glottocode), ]
create normalized numerical versions of relevant features
# Load or fit the bivariate OU modelif (file.exists("../models_soundpop/fit_bivariate_ou.rds")) { fit_bivariate_ou <-readRDS("../models_soundpop/fit_bivariate_ou.rds")} else { bivariate_ou_model <-stan_model("OU_bivariate.stan") fit_bivariate_ou <-sampling( bivariate_ou_model,data = stan_data,iter =20000,chains =4,cores =4,control =list(adapt_delta =0.95),save_warmup =FALSE )saveRDS(fit_bivariate_ou, file ="../models_soundpop/fit_bivariate_ou.rds")}
# Print a summary of the fitsummary(fit_bivariate_ou, pars =c("sigma_x", "sigma_y", "lambda_x", "lambda_y", "mu_x", "mu_y", "rho", "rho_family"))$summary
A matrix: 8 × 10 of type dbl
mean
se_mean
sd
2.5%
25%
50%
75%
97.5%
n_eff
Rhat
sigma_x
0.80653933
0.0006815855
0.03740842
0.73864921
0.78052412
0.80454272
0.830611558
0.88513907
3012.298
1.001036
sigma_y
0.74036977
0.0005773613
0.03397798
0.67844843
0.71668248
0.73872234
0.761805481
0.81189833
3463.377
1.001219
lambda_x
0.64817606
0.0012465188
0.06797915
0.52661202
0.60072757
0.64384875
0.691080690
0.79414549
2974.088
1.001207
lambda_y
0.54889715
0.0009651324
0.05889606
0.44481907
0.50759247
0.54542172
0.585912229
0.67628866
3723.906
1.000973
mu_x
-0.58308574
0.0012629078
0.06504179
-0.71158658
-0.62679582
-0.58242744
-0.538968364
-0.45822509
2652.416
1.001979
mu_y
-0.33357811
0.0015447217
0.07593576
-0.48270394
-0.38478076
-0.33357869
-0.282422594
-0.18459376
2416.530
1.000614
rho
-0.01312946
0.0002037643
0.02754853
-0.06689844
-0.03168409
-0.01307791
0.005510488
0.04077955
18278.496
1.000248
rho_family
0.56612106
0.0008440469
0.08373925
0.38937578
0.51134013
0.57019730
0.625400949
0.71761905
9842.944
1.000151
# compute loo# Compute LOO for the bivariate OU modelif (file.exists("../models_soundpop/loo_bivariate_ou.rds")) { loo_bivariate_ou <-readRDS("../models_soundpop/loo_bivariate_ou.rds")} else { loo_bivariate_ou <-loo(fit_bivariate_ou)# Save the LOO result for the bivariate OU modelsaveRDS(loo_bivariate_ou, file ="../models_soundpop/loo_bivariate_ou.rds")}
Estimated log Bayes factor (based on medians of log marginal likelihood estimates)
in favor of x1 over x2: -1194.40055
Range of estimates: -1198.27927 to -1190.88134
Interquartile range: 3.94644
Estimated log Bayes factor (based on medians of log marginal likelihood estimates)
in favor of x1 over x2: -116.87466
Range of estimates: -122.04057 to -113.23186
Interquartile range: 5.10539