This chapter has been an introduction to the motivation, implementation, and interpretation of basic multilevel models. It focused on varying intercepts, which achieve better estimates of baseline differences among clusters in the data. They achieve better estimates, because they simultaneously model the population of clusters and use inferences about the population to pool information among parameters. From another perspective, varying intercepts are adaptively regularized parameters, relying upon a prior that is itself learned from the data.
Place each answer inside the code chunk (grey box). The code chunks should contain a text response or a code that completes/answers the question or activity requested. Make sure to include plots if the question requests them.
Finally, upon completion, name your final output .html
file as: YourName_ANLY505-Year-Semester.html and publish
the assignment to your R Pubs account and submit the link to Canvas.
Each question is worth 5 points.
13-1. Revisit the Reed frog survival data, data(reedfrogs), and add the predation and size treatment variables to the varying intercepts model. Consider models with either main effect alone, both main effects, as well as a model including both and their interaction. Instead of focusing on inferences about these two predictor variables, focus on the inferred variation across tanks. Explain why it changes as it does across models. Plot the sigma estimates.
library(rethinking)
library(rstan)
data(reedfrogs)
d <- reedfrogs
str(d)
## 'data.frame': 48 obs. of 5 variables:
## $ density : int 10 10 10 10 10 10 10 10 10 10 ...
## $ pred : Factor w/ 2 levels "no","pred": 1 1 1 1 1 1 1 1 2 2 ...
## $ size : Factor w/ 2 levels "big","small": 1 1 1 1 2 2 2 2 1 1 ...
## $ surv : int 9 10 7 10 9 9 10 9 4 9 ...
## $ propsurv: num 0.9 1 0.7 1 0.9 0.9 1 0.9 0.4 0.9 ...
# Make the tank cluster variable
d$tank <- 1:nrow(d)
dat <- list(
S = d$surv,
N = d$density,
tank = d$tank,
pred = ifelse(d$pred == "no", 0L, 1L),
size_ = ifelse(d$size == "small", 1L, 2L)
)
# Models
# 1. Tank model
m_tank <- ulam(
alist(
S ~ dbinom(N, p),
logit(p) <- a[tank],
a[tank] ~ dnorm(a_bar, sigma),
a_bar ~ dnorm(0, 1.5),
sigma ~ dexp(1)
),
data=dat, chains=4, cores=4, log_lik=TRUE, iter=2e3, refresh = 0
)
## Running /Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB foo.c
## clang -mmacosx-version-min=10.13 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/Rcpp/include/" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/unsupported" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/BH/include" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/src/" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppParallel/include/" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include" -DEIGEN_NO_DEBUG -DBOOST_DISABLE_ASSERTS -DBOOST_PENDING_INTEGER_LOG2_HPP -DSTAN_THREADS -DBOOST_NO_AUTO_PTR -include '/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp' -D_REENTRANT -DRCPP_PARALLEL_USE_TBB=1 -I/usr/local/include -fPIC -Wall -g -O2 -c foo.c -o foo.o
## In file included from <built-in>:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
## In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Core:88:
## /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/Macros.h:628:1: error: unknown type name 'namespace'
## namespace Eigen {
## ^
## /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/Macros.h:628:16: error: expected ';' after top level declarator
## namespace Eigen {
## ^
## ;
## In file included from <built-in>:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
## In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:1:
## /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Core:96:10: fatal error: 'complex' file not found
## #include <complex>
## ^~~~~~~~~
## 3 errors generated.
## make: *** [foo.o] Error 1
precis(m_tank, depth=2)
## mean sd 5.5% 94.5% n_eff Rhat4
## a[1] 2.148871452 0.8617406 0.83311171 3.600200177 6992.363 0.9992351
## a[2] 3.089910279 1.1201731 1.49286831 5.000925642 5312.154 1.0000248
## a[3] 0.996776790 0.6709333 -0.01919227 2.094832403 7874.264 0.9991720
## a[4] 3.068230660 1.0910271 1.45595537 4.947503243 5951.253 0.9995319
## a[5] 2.135990490 0.8852687 0.85249757 3.663925811 6381.474 1.0001051
## a[6] 2.145783453 0.8896404 0.83510179 3.670988003 6238.651 0.9991651
## a[7] 3.073453746 1.1004329 1.50633691 4.974780575 5651.099 0.9999045
## a[8] 2.140249708 0.8891801 0.83674470 3.663909620 6278.675 1.0007521
## a[9] -0.181006224 0.5947680 -1.13714578 0.751408980 8794.487 0.9992573
## a[10] 2.146231223 0.8730076 0.85268693 3.637394830 5999.589 0.9998447
## a[11] 0.992153574 0.7009721 -0.09357621 2.143065053 8566.212 0.9997689
## a[12] 0.570802506 0.6371833 -0.40999125 1.603548580 10438.357 0.9997798
## a[13] 0.998761398 0.6859693 -0.04075473 2.118824529 8085.245 0.9994319
## a[14] 0.196740145 0.6351798 -0.81337176 1.211848610 7237.434 1.0003107
## a[15] 2.143959296 0.9088245 0.85126647 3.683186597 5420.838 0.9991993
## a[16] 2.137080382 0.8725361 0.86062498 3.629187905 7371.944 0.9995083
## a[17] 2.917222912 0.7986651 1.78057076 4.262972385 5651.523 0.9997600
## a[18] 2.411420755 0.6673298 1.43461580 3.536404899 5389.844 1.0007754
## a[19] 2.009948570 0.5871052 1.12926988 3.016921415 8339.978 0.9994871
## a[20] 3.685183877 1.0465644 2.18356530 5.532745436 4305.763 1.0005991
## a[21] 2.398462091 0.6718880 1.39964326 3.530067819 6727.391 0.9996898
## a[22] 2.395959568 0.6649382 1.43589478 3.547383861 6215.023 0.9993783
## a[23] 2.411315255 0.6758494 1.41429986 3.571036918 6769.036 0.9994363
## a[24] 1.695975760 0.5149881 0.91360539 2.570689310 7109.346 0.9997106
## a[25] -1.001650639 0.4457328 -1.74439100 -0.300613072 9415.967 0.9995700
## a[26] 0.163167112 0.3969833 -0.46758803 0.792240784 8609.943 0.9991481
## a[27] -1.431905873 0.4848338 -2.23403596 -0.693449149 9063.415 0.9993960
## a[28] -0.472981825 0.4048880 -1.12399758 0.166537821 7717.373 0.9992897
## a[29] 0.161011351 0.3975752 -0.46414098 0.797395525 9538.296 0.9994411
## a[30] 1.452803533 0.4962813 0.71766342 2.273858586 6886.118 0.9993717
## a[31] -0.639864729 0.4211085 -1.33836760 0.008677954 8063.074 0.9998886
## a[32] -0.310480319 0.3992339 -0.93484469 0.305260008 7699.473 0.9994981
## a[33] 3.204825553 0.7612886 2.11312516 4.516505701 5550.200 0.9995173
## a[34] 2.713694253 0.6523520 1.73933891 3.815677870 6627.804 0.9994809
## a[35] 2.710619224 0.6285115 1.79569975 3.781636890 7819.212 0.9992481
## a[36] 2.067395205 0.5287535 1.27864127 2.958499507 7361.062 0.9991990
## a[37] 2.062819979 0.5188491 1.30386667 2.929836843 6516.839 0.9999487
## a[38] 3.904847118 0.9781488 2.54161768 5.577554077 5170.813 1.0001250
## a[39] 2.708223108 0.6590875 1.72488297 3.827058483 7777.216 0.9994668
## a[40] 2.357850102 0.5693013 1.50802771 3.325318365 7277.035 0.9998063
## a[41] -1.807398829 0.4667524 -2.58898591 -1.118666511 6622.123 0.9996034
## a[42] -0.574911008 0.3570955 -1.15742935 -0.017466005 8307.130 0.9991419
## a[43] -0.455037822 0.3417082 -1.00801659 0.087241369 9129.632 0.9995094
## a[44] -0.337114454 0.3462609 -0.89183769 0.218208313 8198.507 0.9995459
## a[45] 0.573081529 0.3500904 0.02699896 1.127605941 7817.591 0.9993737
## a[46] -0.572828761 0.3469280 -1.12529895 -0.019866766 7776.716 0.9993651
## a[47] 2.062662316 0.5037004 1.31428595 2.909081865 7494.443 0.9998281
## a[48] 0.005651987 0.3315155 -0.52487023 0.526914244 8395.157 0.9996468
## a_bar 1.349010804 0.2572899 0.95383885 1.765927457 5602.310 0.9992880
## sigma 1.623683567 0.2102284 1.32310718 1.977299906 2998.385 0.9999507
# 2. Predation model
m_pred <- ulam(
alist(
S ~ dbinom(N, p),
logit(p) <- a[tank] + bp * pred,
a[tank] ~ dnorm(a_bar, sigma),
bp ~ dnorm(-0.5, 1),
a_bar ~ dnorm(0, 1.5),
sigma ~ dexp(1)
),
data=dat, chains=4, cores=4, log_lik=TRUE, iter=2e3, refresh = 0
)
## Running /Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB foo.c
## clang -mmacosx-version-min=10.13 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/Rcpp/include/" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/unsupported" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/BH/include" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/src/" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppParallel/include/" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include" -DEIGEN_NO_DEBUG -DBOOST_DISABLE_ASSERTS -DBOOST_PENDING_INTEGER_LOG2_HPP -DSTAN_THREADS -DBOOST_NO_AUTO_PTR -include '/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp' -D_REENTRANT -DRCPP_PARALLEL_USE_TBB=1 -I/usr/local/include -fPIC -Wall -g -O2 -c foo.c -o foo.o
## In file included from <built-in>:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
## In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Core:88:
## /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/Macros.h:628:1: error: unknown type name 'namespace'
## namespace Eigen {
## ^
## /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/Macros.h:628:16: error: expected ';' after top level declarator
## namespace Eigen {
## ^
## ;
## In file included from <built-in>:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
## In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:1:
## /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Core:96:10: fatal error: 'complex' file not found
## #include <complex>
## ^~~~~~~~~
## 3 errors generated.
## make: *** [foo.o] Error 1
precis(m_pred, depth=2)
## mean sd 5.5% 94.5% n_eff Rhat4
## a[1] 2.4728561 0.6659877 1.45724524 3.569863 3395.6812 1.0004424
## a[2] 2.9775059 0.7413525 1.87766064 4.201598 2360.6402 1.0009472
## a[3] 1.6996419 0.6374600 0.68495175 2.714112 3802.8515 1.0016600
## a[4] 2.9708527 0.7715458 1.83156124 4.234369 2624.9637 1.0014036
## a[5] 2.4894658 0.6901904 1.42479581 3.616305 3728.1072 0.9992013
## a[6] 2.4875271 0.6865672 1.40841723 3.630858 3822.9471 1.0005105
## a[7] 2.9690254 0.7479589 1.83917235 4.205763 2962.4397 1.0001458
## a[8] 2.4880695 0.6669984 1.46164407 3.588884 2512.6366 1.0005925
## a[9] 2.2195217 0.5605564 1.31909914 3.094304 1377.1709 1.0039566
## a[10] 3.5907969 0.6471958 2.57416558 4.628674 1307.0327 1.0051156
## a[11] 3.0114543 0.5735080 2.10195683 3.952759 1779.1534 1.0068759
## a[12] 2.7277821 0.5660351 1.82301031 3.648079 1351.5982 1.0041091
## a[13] 3.0095451 0.5843479 2.09013363 3.934204 1739.9214 1.0037371
## a[14] 2.4780087 0.5590996 1.57102446 3.364053 1624.0811 1.0022113
## a[15] 3.5757777 0.6497855 2.58694735 4.664259 1656.6899 1.0041905
## a[16] 3.5611605 0.6138067 2.63212750 4.566075 1629.5504 1.0032640
## a[17] 2.8946173 0.6213694 1.96122949 3.939656 3485.1193 1.0016525
## a[18] 2.5507774 0.5597810 1.69836309 3.480057 3820.2880 1.0011641
## a[19] 2.2815427 0.5462464 1.44662523 3.191986 3140.1656 1.0008996
## a[20] 3.2855124 0.6790764 2.26549412 4.450059 2948.6900 1.0009032
## a[21] 2.5671612 0.5809260 1.70305390 3.577023 3295.9646 1.0014440
## a[22] 2.5742689 0.5767510 1.71765151 3.542349 3615.3589 0.9998966
## a[23] 2.5612535 0.5665076 1.69591374 3.492681 3311.6993 1.0003135
## a[24] 2.0072361 0.5009674 1.20932412 2.818176 3886.5774 1.0009951
## a[25] 1.5705960 0.4844762 0.78261096 2.330152 1064.5868 1.0041470
## a[26] 2.5218051 0.4576971 1.79483213 3.254851 1123.1005 1.0076566
## a[27] 1.2440458 0.5085924 0.38367828 2.020722 991.9206 1.0051943
## a[28] 1.9899853 0.4584770 1.25685180 2.710943 940.1597 1.0068624
## a[29] 2.5247054 0.4492945 1.82388427 3.229452 1093.5553 1.0071591
## a[30] 3.5147371 0.4801349 2.75268446 4.273301 1280.6133 1.0067284
## a[31] 1.8535200 0.4668200 1.08922912 2.582022 1103.3383 1.0069618
## a[32] 2.1273426 0.4475964 1.39282760 2.812728 906.2815 1.0062576
## a[33] 3.0655313 0.5891766 2.17486160 4.036458 2673.6028 0.9997049
## a[34] 2.7609245 0.5396842 1.95043035 3.659347 3922.5906 1.0001426
## a[35] 2.7555070 0.5356521 1.95094856 3.645378 3430.4878 0.9999829
## a[36] 2.2759161 0.4746046 1.54417472 3.083603 3921.4208 1.0005440
## a[37] 2.2506351 0.4675766 1.54112989 3.029615 3954.3828 1.0011137
## a[38] 3.4353571 0.6610592 2.46759899 4.571565 2331.2715 1.0015640
## a[39] 2.7550291 0.5483653 1.93427865 3.666791 3417.3862 1.0010742
## a[40] 2.4873410 0.4977355 1.72768488 3.307436 4154.6842 0.9997120
## a[41] 0.9126535 0.5114414 0.07155098 1.703894 1148.8110 1.0070418
## a[42] 1.8962464 0.4220836 1.22645695 2.562212 848.6282 1.0089857
## a[43] 2.0038611 0.4318821 1.30955213 2.683683 853.4930 1.0063289
## a[44] 2.1010316 0.4310796 1.39869329 2.785649 735.3119 1.0084199
## a[45] 2.8986830 0.4350499 2.20262708 3.593316 993.1972 1.0069235
## a[46] 1.8996463 0.4275981 1.20504357 2.581463 844.7798 1.0070967
## a[47] 4.0029469 0.4822345 3.24304717 4.789371 833.2959 1.0084215
## a[48] 2.4090888 0.4322590 1.72029683 3.099932 775.2056 1.0085026
## bp -2.4391114 0.2958277 -2.91295098 -1.945877 430.7393 1.0169142
## a_bar 2.5409080 0.2349337 2.17746359 2.919886 545.5829 1.0115571
## sigma 0.8255973 0.1463804 0.60942787 1.074299 1016.4462 1.0049123
# 3. Size model
m_size <- ulam(
alist(
S ~ dbinom(N, p),
logit(p) <- a[tank] + s[size_],
a[tank] ~ dnorm(a_bar, sigma),
s[size_] ~ dnorm(0, 0.5),
a_bar ~ dnorm(0, 1.5),
sigma ~ dexp(1)
),
data=dat, chains=4, cores=4, log_lik=TRUE, iter=2e3, refresh = 0
)
## Running /Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB foo.c
## clang -mmacosx-version-min=10.13 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/Rcpp/include/" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/unsupported" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/BH/include" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/src/" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppParallel/include/" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include" -DEIGEN_NO_DEBUG -DBOOST_DISABLE_ASSERTS -DBOOST_PENDING_INTEGER_LOG2_HPP -DSTAN_THREADS -DBOOST_NO_AUTO_PTR -include '/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp' -D_REENTRANT -DRCPP_PARALLEL_USE_TBB=1 -I/usr/local/include -fPIC -Wall -g -O2 -c foo.c -o foo.o
## In file included from <built-in>:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
## In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Core:88:
## /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/Macros.h:628:1: error: unknown type name 'namespace'
## namespace Eigen {
## ^
## /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/Macros.h:628:16: error: expected ';' after top level declarator
## namespace Eigen {
## ^
## ;
## In file included from <built-in>:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
## In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:1:
## /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Core:96:10: fatal error: 'complex' file not found
## #include <complex>
## ^~~~~~~~~
## 3 errors generated.
## make: *** [foo.o] Error 1
precis(m_size, depth=2)
## mean sd 5.5% 94.5% n_eff Rhat4
## a[1] 2.21300891 0.9563609 0.7719412 3.79857438 1332.7839 1.005214
## a[2] 3.14554454 1.1916246 1.4534066 5.18635195 1159.8897 1.003307
## a[3] 1.10024865 0.7802672 -0.1351779 2.37035344 1163.4161 1.005279
## a[4] 3.11822949 1.1550189 1.4351463 5.10947312 1602.6792 1.003758
## a[5] 2.00097185 0.9400700 0.5913188 3.54453899 1450.6584 1.001826
## a[6] 2.03107036 0.9618709 0.5999718 3.61293485 1288.8186 1.004247
## a[7] 3.02125253 1.2275963 1.2120785 5.09866484 1728.0029 1.002862
## a[8] 2.01822865 0.9820458 0.5743469 3.67837768 1355.3529 1.003694
## a[9] -0.08567207 0.7199628 -1.2319550 1.07442989 985.4416 1.006642
## a[10] 2.22732316 0.9636923 0.8031070 3.83773805 1515.3348 1.003785
## a[11] 1.08105127 0.7691888 -0.1270688 2.34671395 981.2639 1.007521
## a[12] 0.65074080 0.7408272 -0.5038800 1.83527895 973.9293 1.006644
## a[13] 0.85612087 0.7861780 -0.3622656 2.11864954 1121.4409 1.005454
## a[14] 0.04614178 0.7257846 -1.1056017 1.21972623 1126.7824 1.005460
## a[15] 2.00506606 0.9421421 0.5965184 3.61192980 1285.0457 1.003444
## a[16] 1.99743244 0.9404040 0.5738531 3.54779598 1195.6979 1.007896
## a[17] 2.97333298 0.8546893 1.7040738 4.39396853 1084.4038 1.005204
## a[18] 2.49597027 0.7793418 1.3132210 3.78890628 1041.7266 1.007315
## a[19] 2.10116259 0.7112814 1.0004993 3.29958799 895.1133 1.007095
## a[20] 3.75072004 1.0700199 2.1800420 5.58482273 1508.2086 1.004604
## a[21] 2.23830529 0.7890414 1.0633304 3.57426204 1025.7626 1.005811
## a[22] 2.25706179 0.7750064 1.1055161 3.56529086 1048.3392 1.004140
## a[23] 2.23277635 0.7575523 1.0864882 3.50500268 1119.6822 1.002695
## a[24] 1.54017450 0.6600783 0.5098010 2.61845707 797.6173 1.009586
## a[25] -0.90460134 0.6004955 -1.8742965 0.04103280 740.8268 1.011059
## a[26] 0.25447039 0.5635903 -0.6565652 1.16815332 608.5886 1.013846
## a[27] -1.34006502 0.6327033 -2.3964239 -0.35885680 826.4878 1.007040
## a[28] -0.37582218 0.5677545 -1.2763970 0.52692808 652.9149 1.011601
## a[29] -0.01013984 0.5487192 -0.8692771 0.85013679 720.9667 1.008794
## a[30] 1.28362673 0.6126426 0.3309698 2.26761408 844.6727 1.007581
## a[31] -0.79784608 0.5668395 -1.6967486 0.10331843 701.3084 1.010309
## a[32] -0.48332120 0.5516944 -1.3767989 0.39234951 716.6833 1.009900
## a[33] 3.26594920 0.8404338 1.9800297 4.64719808 1243.8020 1.008138
## a[34] 2.80337361 0.7639862 1.6612707 4.03938398 952.8820 1.007500
## a[35] 2.77563828 0.7389479 1.6249442 3.99438754 1060.9812 1.005942
## a[36] 2.14914015 0.6425306 1.1688267 3.20055715 768.9606 1.010162
## a[37] 1.90278726 0.6316011 0.9070037 2.92668498 835.9983 1.007081
## a[38] 3.80910087 1.0714594 2.2574333 5.70328108 1411.7051 1.002252
## a[39] 2.56136450 0.7710435 1.3878826 3.84001721 1007.7276 1.005154
## a[40] 2.19185375 0.6939286 1.1452716 3.35500376 966.1399 1.007404
## a[41] -1.72152671 0.6298377 -2.7714530 -0.73235388 793.6861 1.011768
## a[42] -0.47562281 0.5348634 -1.3367114 0.35078913 644.8067 1.010282
## a[43] -0.35153448 0.5318512 -1.2127672 0.49988647 611.0181 1.012414
## a[44] -0.23269148 0.5240500 -1.0693620 0.60825832 601.0391 1.014918
## a[45] 0.40159283 0.5200246 -0.3948393 1.23953924 618.5242 1.012795
## a[46] -0.74351589 0.5216349 -1.5762337 0.07905639 644.4419 1.009281
## a[47] 1.90629665 0.6302852 0.9455457 2.94018745 930.1805 1.008303
## a[48] -0.17147579 0.5173446 -1.0032108 0.67094830 629.4573 1.011406
## s[1] 0.18086267 0.3967978 -0.4474014 0.81354998 395.6856 1.017883
## s[2] -0.10596716 0.4064345 -0.7687853 0.55564999 386.7847 1.024366
## a_bar 1.31668129 0.4248385 0.6228731 2.00036700 428.0232 1.020751
## sigma 1.62721949 0.2223289 1.3064921 1.99103110 1768.9928 1.002646
# 4. Predation and Size model
m_pred_size <- ulam(
alist(
S ~ dbinom(N, p),
logit(p) <- a[tank] + bp * pred + s[size_],
a[tank] ~ dnorm(a_bar, sigma),
bp ~ dnorm(-0.5, 1),
s[size_] ~ dnorm(0, 0.5),
a_bar ~ dnorm(0, 1.5),
sigma ~ dexp(1)
),
data=dat, chains=4, cores=4, log_lik=TRUE, iter=2e3, refresh = 0
)
## Running /Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB foo.c
## clang -mmacosx-version-min=10.13 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/Rcpp/include/" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/unsupported" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/BH/include" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/src/" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppParallel/include/" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include" -DEIGEN_NO_DEBUG -DBOOST_DISABLE_ASSERTS -DBOOST_PENDING_INTEGER_LOG2_HPP -DSTAN_THREADS -DBOOST_NO_AUTO_PTR -include '/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp' -D_REENTRANT -DRCPP_PARALLEL_USE_TBB=1 -I/usr/local/include -fPIC -Wall -g -O2 -c foo.c -o foo.o
## In file included from <built-in>:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
## In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Core:88:
## /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/Macros.h:628:1: error: unknown type name 'namespace'
## namespace Eigen {
## ^
## /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/Macros.h:628:16: error: expected ';' after top level declarator
## namespace Eigen {
## ^
## ;
## In file included from <built-in>:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
## In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:1:
## /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Core:96:10: fatal error: 'complex' file not found
## #include <complex>
## ^~~~~~~~~
## 3 errors generated.
## make: *** [foo.o] Error 1
precis(m_pred_size, depth=2)
## mean sd 5.5% 94.5% n_eff Rhat4
## a[1] 2.39930187 0.7171058 1.26268458 3.5424597 953.0886 1.0012689
## a[2] 2.82264537 0.7676892 1.63799008 4.0644454 1295.9415 1.0010112
## a[3] 1.66735718 0.6722514 0.59715766 2.7334564 927.0921 1.0013400
## a[4] 2.82021380 0.7768045 1.60428623 4.0972437 1207.6886 1.0022523
## a[5] 2.26669543 0.7191222 1.11084424 3.4078487 1189.0606 1.0006164
## a[6] 2.26740024 0.7588547 1.09048726 3.4802494 1279.0955 0.9998585
## a[7] 2.72660025 0.7862782 1.53545020 4.0024390 1171.4371 1.0023022
## a[8] 2.26876127 0.7320917 1.12654452 3.4740281 1144.4908 1.0033790
## a[9] 2.20603091 0.6475185 1.16494358 3.2237227 799.4590 1.0015446
## a[10] 3.47237346 0.6804584 2.43955097 4.5655159 799.6859 1.0014979
## a[11] 2.94131267 0.6359145 1.94970498 3.9580399 775.1339 1.0017173
## a[12] 2.69940308 0.6480258 1.68019502 3.7428764 809.4523 1.0013395
## a[13] 2.70340017 0.6540827 1.68639560 3.7578322 798.2866 1.0012024
## a[14] 2.21059496 0.6424838 1.19697960 3.2447369 733.8843 1.0015936
## a[15] 3.25670573 0.6987996 2.14810118 4.3842765 864.6655 1.0017693
## a[16] 3.24250737 0.6958645 2.14476009 4.3615926 874.4901 1.0012853
## a[17] 2.80368661 0.6661857 1.75575346 3.9052714 990.6443 1.0024347
## a[18] 2.50776746 0.6315733 1.52832515 3.5409015 902.6363 1.0035007
## a[19] 2.25380949 0.6202767 1.28987202 3.2355518 948.6372 1.0029602
## a[20] 3.14234958 0.7147639 2.04241455 4.3144933 1140.1623 0.9999215
## a[21] 2.30638082 0.6540435 1.27682357 3.3511786 946.6193 1.0020782
## a[22] 2.29790902 0.6455293 1.29956891 3.3583315 894.4558 1.0011961
## a[23] 2.29671888 0.6663674 1.25562889 3.3556521 1144.9484 1.0015152
## a[24] 1.77562952 0.6129728 0.82488382 2.7618686 815.5706 1.0016485
## a[25] 1.60417425 0.5850884 0.64650320 2.5008872 581.6124 1.0016652
## a[26] 2.53580148 0.5619260 1.63071597 3.4211188 602.0904 1.0017531
## a[27] 1.28991920 0.6186919 0.26639161 2.2495144 661.9679 1.0013748
## a[28] 2.02065683 0.5743654 1.06952481 2.9425645 576.9256 1.0025787
## a[29] 2.21086154 0.5578772 1.32974061 3.0929411 568.1022 1.0022269
## a[30] 3.18035490 0.5744903 2.24954399 4.0889011 682.3107 1.0022925
## a[31] 1.57260217 0.5570708 0.65460180 2.4347073 570.9379 1.0029174
## a[32] 1.82662753 0.5634357 0.89252941 2.7016409 601.0269 1.0026320
## a[33] 2.98079106 0.6571302 1.98902983 4.0634194 947.4913 1.0028047
## a[34] 2.72513150 0.6213565 1.76364839 3.7574784 845.2654 1.0049081
## a[35] 2.71709594 0.6242978 1.73888395 3.7337492 964.0336 1.0019930
## a[36] 2.25722750 0.5681776 1.35256783 3.1817727 888.7762 1.0021060
## a[37] 1.98796757 0.5762381 1.07647259 2.9031772 835.7494 1.0037865
## a[38] 3.11719566 0.7214653 2.03771860 4.3218734 1214.2833 1.0005109
## a[39] 2.48052583 0.6288611 1.50129278 3.5264715 965.3618 1.0029048
## a[40] 2.21442027 0.5920117 1.27330226 3.1959116 910.9260 1.0022130
## a[41] 0.98116466 0.5968713 0.02396211 1.9082734 587.1556 1.0025937
## a[42] 1.93599981 0.5485674 1.04246236 2.7728550 515.7963 1.0024403
## a[43] 2.04615359 0.5406299 1.15810580 2.9111296 514.8473 1.0025585
## a[44] 2.14477571 0.5315364 1.26860229 2.9772847 503.1941 1.0020594
## a[45] 2.57278732 0.5316932 1.70449066 3.4078876 472.2591 1.0028111
## a[46] 1.59054585 0.5372821 0.71748763 2.4248268 511.2994 1.0031041
## a[47] 3.64960066 0.5833652 2.73584913 4.5835523 616.8710 1.0015671
## a[48] 2.07313961 0.5294737 1.21725318 2.9033600 520.0019 1.0026627
## bp -2.43691340 0.2853585 -2.88009631 -1.9715243 1272.6865 0.9996521
## s[1] 0.35805849 0.3572167 -0.20316653 0.9349007 461.6951 1.0056954
## s[2] -0.07228013 0.3599783 -0.64743544 0.5264165 456.3452 1.0067445
## a_bar 2.38194796 0.3896158 1.74903764 2.9978675 343.0247 1.0054778
## sigma 0.77552793 0.1468570 0.56004548 1.0210463 1090.1887 1.0018648
# 5. Predation and Size interaction model
m_pred_size_int <- ulam(
alist(
S ~ dbinom(N, p),
logit(p) <- a_bar + a[tank] * sigma + bp[size_] * pred + s[size_],
a[tank] ~ dnorm(0, 1),
bp[size_] ~ dnorm(-0.5, 1),
s[size_] ~ dnorm(0, 0.5),
a_bar ~ dnorm(0, 1.5),
sigma ~ dexp(1)
),
data=dat, chains=4, cores=4, log_lik=TRUE, iter=2e3, refresh = 0
)
## Running /Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB foo.c
## clang -mmacosx-version-min=10.13 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/Rcpp/include/" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/unsupported" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/BH/include" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/src/" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppParallel/include/" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include" -DEIGEN_NO_DEBUG -DBOOST_DISABLE_ASSERTS -DBOOST_PENDING_INTEGER_LOG2_HPP -DSTAN_THREADS -DBOOST_NO_AUTO_PTR -include '/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp' -D_REENTRANT -DRCPP_PARALLEL_USE_TBB=1 -I/usr/local/include -fPIC -Wall -g -O2 -c foo.c -o foo.o
## In file included from <built-in>:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
## In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Core:88:
## /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/Macros.h:628:1: error: unknown type name 'namespace'
## namespace Eigen {
## ^
## /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/Macros.h:628:16: error: expected ';' after top level declarator
## namespace Eigen {
## ^
## ;
## In file included from <built-in>:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
## In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:1:
## /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Core:96:10: fatal error: 'complex' file not found
## #include <complex>
## ^~~~~~~~~
## 3 errors generated.
## make: *** [foo.o] Error 1
precis(m_pred_size_int, depth=2)
## mean sd 5.5% 94.5% n_eff Rhat4
## a[1] -0.042482185 0.8404682 -1.33023316 1.3091939 5979.157 0.9996859
## a[2] 0.501297048 0.8976188 -0.90193228 2.0036635 6873.272 0.9995747
## a[3] -0.970952903 0.7860456 -2.20372788 0.2863023 5886.450 0.9992034
## a[4] 0.506000366 0.9036684 -0.92903515 1.9472582 6552.016 0.9999243
## a[5] -0.002894981 0.8202678 -1.29871285 1.3498136 5967.304 0.9996287
## a[6] -0.035279145 0.8290404 -1.32819567 1.3147672 6899.196 0.9999577
## a[7] 0.504709756 0.8465355 -0.83836437 1.8863309 6848.632 0.9997335
## a[8] -0.030414236 0.8240047 -1.34582117 1.3048518 6326.836 0.9998225
## a[9] -0.101981381 0.6805876 -1.16402435 1.0121166 4627.464 0.9997176
## a[10] 1.535290300 0.7046915 0.41178865 2.6929915 5536.754 0.9997004
## a[11] 0.857980291 0.7098387 -0.29248834 2.0026986 5850.465 0.9997394
## a[12] 0.541626362 0.6948613 -0.57169318 1.6474804 5254.284 1.0004719
## a[13] 0.245294053 0.7150421 -0.86193088 1.4152223 5814.540 0.9996612
## a[14] -0.402194452 0.6825456 -1.46844834 0.6885036 4888.442 0.9991954
## a[15] 0.977283355 0.7394187 -0.18531784 2.1763135 5491.593 1.0002415
## a[16] 0.970422205 0.7187021 -0.15160674 2.1213011 5980.282 1.0003118
## a[17] 0.475383952 0.7671217 -0.75239529 1.6908688 5721.531 0.9993872
## a[18] 0.076749203 0.7271106 -1.05914185 1.2926868 5934.607 0.9991743
## a[19] -0.287899585 0.7101777 -1.38029034 0.8518617 4824.982 1.0003438
## a[20] 0.894898218 0.8137050 -0.35824300 2.2278573 6844.415 0.9991160
## a[21] 0.105567473 0.7405079 -1.06298830 1.3076292 5357.078 0.9998493
## a[22] 0.093939370 0.7370127 -1.06985264 1.2924017 6725.659 0.9997735
## a[23] 0.090554682 0.7276614 -1.05285214 1.2565696 6358.442 0.9996958
## a[24] -0.568969729 0.6800594 -1.65726571 0.5266996 5684.110 0.9995762
## a[25] -0.858862476 0.5923206 -1.84179236 0.0662756 4759.317 0.9996386
## a[26] 0.397912201 0.5667141 -0.52169147 1.2963414 3761.097 0.9998032
## a[27] -1.274171275 0.6030186 -2.26962386 -0.3358199 4651.158 0.9992506
## a[28] -0.292334156 0.5585105 -1.18051304 0.5875295 3679.709 0.9997220
## a[29] -0.477407227 0.5566976 -1.39648292 0.3838138 3584.864 1.0002333
## a[30] 0.824407383 0.5981938 -0.11844448 1.7833190 4172.943 0.9997041
## a[31] -1.335038513 0.5692671 -2.26659032 -0.4529801 3750.890 0.9996164
## a[32] -0.990536092 0.5602977 -1.88998806 -0.1079744 4337.083 0.9996993
## a[33] 0.673755998 0.7428641 -0.47129566 1.8604992 5818.660 0.9994423
## a[34] 0.333870586 0.7031100 -0.74744979 1.4643542 5538.004 0.9998443
## a[35] 0.313485013 0.7044411 -0.79098173 1.4462161 5665.354 1.0000446
## a[36] -0.275997424 0.6513835 -1.27240648 0.7903050 4575.400 1.0005271
## a[37] -0.252825692 0.6486373 -1.26031278 0.7989438 4834.987 0.9993008
## a[38] 1.113891490 0.7835625 -0.09694434 2.3733636 6705.740 1.0000195
## a[39] 0.357422558 0.7152082 -0.77138820 1.5153223 5466.572 0.9994580
## a[40] 0.031320422 0.6878412 -1.05409119 1.1589866 5610.250 0.9997705
## a[41] -1.691049583 0.5745738 -2.62489956 -0.7908283 4527.785 0.9999821
## a[42] -0.398296824 0.5200752 -1.24394447 0.4293841 3911.364 0.9997287
## a[43] -0.255982421 0.5137423 -1.05197374 0.5875822 3697.186 0.9995671
## a[44] -0.127848332 0.5220315 -0.93790371 0.7184648 3811.996 0.9994110
## a[45] -0.012993660 0.5256059 -0.81263772 0.8430107 3313.141 1.0002755
## a[46] -1.334206092 0.5145108 -2.18539705 -0.5526125 4000.528 0.9995677
## a[47] 1.454291922 0.6204984 0.49718322 2.4828098 3801.440 1.0000736
## a[48] -0.669863029 0.5136933 -1.48066448 0.1295298 3530.197 0.9996486
## bp[1] -1.857463819 0.3759438 -2.44418101 -1.2533854 2258.271 1.0000326
## bp[2] -2.757414056 0.3802031 -3.35464315 -2.1474389 2109.922 1.0003094
## s[1] 0.113760482 0.3871300 -0.51402607 0.7287342 2728.398 1.0003191
## s[2] 0.154211943 0.3901330 -0.46188139 0.7907379 2672.911 0.9995643
## a_bar 2.304191585 0.3949467 1.68132143 2.9438310 2297.145 1.0004176
## sigma 0.752715708 0.1488774 0.53585111 1.0067017 1557.787 1.0034974
# There is a significant variation in tank between model that contains predation and model that does not. From this we can conclude that the predation variable explains a lot of the variation across tanks. Without the inclusion of predation, the model assign the unexplainable variation towards tank, hence the higher value of tank for the model without predation.
13-2. Compare the models you fit just above, using WAIC. Can you reconcile the differences in WAIC with the posterior distributions of the models? Show the WAIC table.
compare(m_tank, m_pred, m_size, m_pred_size, m_pred_size_int)
## WAIC SE dWAIC dSE pWAIC weight
## m_pred 198.9458 9.130291 0.0000000 NA 19.19206 0.3021027
## m_pred_size_int 199.7807 9.098142 0.8349134 3.163076 19.13583 0.1990011
## m_pred_size 199.8599 8.629018 0.9140302 1.969033 19.09684 0.1912826
## m_size 200.2834 7.189156 1.3375962 5.848942 21.06743 0.1547744
## m_tank 200.3086 7.238030 1.3627599 5.849261 20.95892 0.1528393
# The WAIC between the different models are quite similar. However, for the posterior (see results in Question 13-1), parameter estimate for s is closer to 0 than those of bp, therfore, model that contains bp significantly reduce sigma, even if the WAIC value is similar for the different models.
13-3. Re-estimate the basic Reed frog varying intercept model, but now using a Cauchy distribution in place of the Gaussian distribution for the varying intercepts. That is, fit this model: \[\begin{align} s_i ∼ Binomial(n_i, p_i) \\ logit(p_i) = α_{tank[i]} \\ α_{tank} ∼ Cauchy(α, σ) \\ α ∼ Normal(0, 1) \\ σ ∼ Exponential(1) \\ \end{align}\]
(You are likely to see many divergent transitions for this model. Can you figure out why? Can you fix them?) Plot and compare the posterior means of the intercepts, αtank, to the posterior means produced in the chapter, using the customary Gaussian prior. Can you explain the pattern of differences? Take note of any change in the mean α as well.
# Model Tank - Cauchy
m_tank_cauchy <- ulam(
alist(
S ~ dbinom(N, p),
logit(p) <- a[tank],
a[tank] ~ dcauchy(a_bar, sigma),
a_bar ~ dnorm(0, 1.5),
sigma ~ dexp(1)
),
data=dat, chains=4, cores=4, log_lik=TRUE, iter=2e3, refresh = 0
)
## Running /Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB foo.c
## clang -mmacosx-version-min=10.13 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/Rcpp/include/" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/unsupported" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/BH/include" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/src/" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppParallel/include/" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include" -DEIGEN_NO_DEBUG -DBOOST_DISABLE_ASSERTS -DBOOST_PENDING_INTEGER_LOG2_HPP -DSTAN_THREADS -DBOOST_NO_AUTO_PTR -include '/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp' -D_REENTRANT -DRCPP_PARALLEL_USE_TBB=1 -I/usr/local/include -fPIC -Wall -g -O2 -c foo.c -o foo.o
## In file included from <built-in>:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
## In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Core:88:
## /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/Macros.h:628:1: error: unknown type name 'namespace'
## namespace Eigen {
## ^
## /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/Macros.h:628:16: error: expected ';' after top level declarator
## namespace Eigen {
## ^
## ;
## In file included from <built-in>:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
## In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:1:
## /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Core:96:10: fatal error: 'complex' file not found
## #include <complex>
## ^~~~~~~~~
## 3 errors generated.
## make: *** [foo.o] Error 1
precis(m_tank_cauchy, depth=2)
## mean sd 5.5% 94.5% n_eff Rhat4
## a[1] 2.04344083 0.8776330 0.86872235 3.563649042 2589.2457 1.0007823
## a[2] 5.14895359 5.2854557 1.44102514 15.361546145 374.6478 1.0052640
## a[3] 1.11803504 0.6016321 0.14774819 2.075062783 4351.8620 0.9993143
## a[4] 5.21074738 5.0811665 1.52593724 14.859758439 532.9746 1.0099960
## a[5] 2.04686180 0.8503211 0.88536402 3.603373465 3250.7761 1.0000691
## a[6] 2.03730584 0.8409440 0.92798120 3.460184815 2109.8221 1.0001556
## a[7] 5.21035170 5.1669212 1.49587483 15.153617611 313.1150 1.0107437
## a[8] 2.04293176 0.8624731 0.90384550 3.518730064 2492.2187 0.9996375
## a[9] -0.06744424 0.6294440 -1.08250000 0.900499157 4549.4730 0.9996781
## a[10] 2.05731315 0.8679936 0.88909129 3.593260239 2946.5359 1.0009956
## a[11] 1.13271629 0.6066094 0.17483359 2.103288195 3666.7702 1.0006854
## a[12] 0.74877574 0.6069761 -0.22428381 1.710430453 4480.2071 0.9992988
## a[13] 1.12000127 0.6058097 0.14603888 2.077397771 4902.0925 0.9996653
## a[14] 0.33901750 0.6527641 -0.73435778 1.345898100 4528.5598 0.9994373
## a[15] 2.06499745 0.8639121 0.92218334 3.569065912 2432.3332 1.0027093
## a[16] 2.03257336 0.8472228 0.89359105 3.426745142 2649.1806 1.0008152
## a[17] 2.87190708 0.9454830 1.65030936 4.515353256 2510.9519 1.0002717
## a[18] 2.26395806 0.6490226 1.36317922 3.381123909 3215.0824 1.0005521
## a[19] 1.91856096 0.5415018 1.11312188 2.807723744 3907.2227 0.9994925
## a[20] 7.42987280 6.3393353 2.40073340 20.949004280 455.0857 1.0077172
## a[21] 2.28395993 0.6685675 1.36813586 3.446953914 2834.6827 1.0001015
## a[22] 2.28466438 0.6532649 1.37765208 3.445610128 2919.5832 1.0009297
## a[23] 2.27687334 0.6483983 1.37228262 3.395840017 3247.4548 0.9996306
## a[24] 1.66740437 0.5000493 0.92077864 2.498179578 4033.9513 0.9995967
## a[25] -1.06014290 0.4818246 -1.83077550 -0.318068614 4362.7118 0.9999725
## a[26] 0.22687854 0.4016970 -0.40972218 0.877709588 5546.1864 0.9996931
## a[27] -1.58696007 0.5570792 -2.51392687 -0.754667254 4395.6230 0.9995548
## a[28] -0.45548515 0.4269235 -1.15973685 0.212527533 5907.4232 0.9993676
## a[29] 0.23806973 0.4090341 -0.41093326 0.894729452 5111.7884 0.9993801
## a[30] 1.46049941 0.4490519 0.75785433 2.194046486 4625.8052 0.9998541
## a[31] -0.64014590 0.4354377 -1.34759877 0.035108404 5284.0210 0.9993528
## a[32] -0.27945700 0.4122927 -0.93645080 0.357416882 5060.4866 0.9997296
## a[33] 3.26381670 0.9954693 1.98925048 5.071056958 2495.6511 1.0002921
## a[34] 2.60597373 0.6868759 1.65093324 3.834857836 3432.2393 0.9993596
## a[35] 2.60871116 0.6778622 1.64983130 3.823253605 3218.7730 0.9998052
## a[36] 1.98395328 0.4754608 1.25508428 2.806555313 3792.3867 0.9999597
## a[37] 1.98667003 0.4887370 1.23867131 2.799409370 4107.2349 0.9996126
## a[38] 7.92242563 6.1048735 2.73051416 20.682507787 745.0197 1.0073987
## a[39] 2.60049087 0.6671630 1.66186461 3.753204168 3773.8974 1.0001974
## a[40] 2.25738041 0.5591396 1.46159828 3.225727757 3716.8138 1.0010772
## a[41] -1.99778856 0.5346004 -2.88791677 -1.216305060 3737.3415 1.0014385
## a[42] -0.57238597 0.3726476 -1.19713984 0.004959328 4601.4162 0.9995166
## a[43] -0.43474656 0.3483374 -1.00260011 0.106896172 5846.2720 0.9994467
## a[44] -0.31912971 0.3547282 -0.88339703 0.238600569 4631.4621 0.9993534
## a[45] 0.64974219 0.3613752 0.08086758 1.232047596 5595.4784 0.9997673
## a[46] -0.56646886 0.3608767 -1.15815585 -0.003202903 4938.1278 1.0001252
## a[47] 1.98334832 0.4929609 1.26589287 2.797881806 4153.7143 0.9991404
## a[48] 0.05245648 0.3484361 -0.50409405 0.601411479 5222.1013 1.0003405
## a_bar 1.48349531 0.2937372 0.99805797 1.942951409 2859.9673 1.0002126
## sigma 1.01252160 0.2240984 0.67861984 1.383059193 2494.2639 1.0004245
# Extract results
a_tank <- apply(extract.samples(m_tank)$a, 2, mean)
a_tank_cauchy <- apply(extract.samples(m_tank_cauchy)$a, 2, mean)
# Plot
plot(a_tank, a_tank_cauchy, pch=15, col=rangi2,
xlab="Intercept (Guassian Prior)", ylab="Intercept(Cauchy Prior)")
abline(a=0, b=1, lty=4)
# At higher level of αtank value, we see a higher divergent values between the Cauchy Prior and Gaussian Prior, with αtank values for Cauchy Prior being much higher than the Gaussian prior. This is likely due to the fact that Cauchy distribution has a much longer tail than the Gaussian prior. At normal αtank value, we see that the point falls on the straight line, which means that they are not divergent.
13-4. Now use a Student-t distribution with ν = 2 for the intercepts: \[\begin{align} α_{tank} ∼ Student(2, α, σ) \end{align}\]
Refer back to the Student-t example in Chapter 7 (page 234), if necessary. Plot and compare the resulting posterior to both the original model and the Cauchy model in 13-3. Can you explain the differences and similarities in shrinkage in terms of the properties of these distributions?
# Model Tank - Student t
m_tank_t <- ulam(
alist(
S ~ dbinom(N, p),
logit(p) <- a[tank],
a[tank] ~ dstudent(2, a_bar, sigma),
a_bar ~ dnorm(0, 1.5),
sigma ~ dexp(1)
),
data=dat, chains=4, cores=4, log_lik=TRUE, iter=2e3, refresh = 0
)
## Running /Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB foo.c
## clang -mmacosx-version-min=10.13 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/Rcpp/include/" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/unsupported" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/BH/include" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/src/" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppParallel/include/" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include" -DEIGEN_NO_DEBUG -DBOOST_DISABLE_ASSERTS -DBOOST_PENDING_INTEGER_LOG2_HPP -DSTAN_THREADS -DBOOST_NO_AUTO_PTR -include '/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp' -D_REENTRANT -DRCPP_PARALLEL_USE_TBB=1 -I/usr/local/include -fPIC -Wall -g -O2 -c foo.c -o foo.o
## In file included from <built-in>:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
## In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Core:88:
## /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/Macros.h:628:1: error: unknown type name 'namespace'
## namespace Eigen {
## ^
## /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/Macros.h:628:16: error: expected ';' after top level declarator
## namespace Eigen {
## ^
## ;
## In file included from <built-in>:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
## In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:1:
## /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Core:96:10: fatal error: 'complex' file not found
## #include <complex>
## ^~~~~~~~~
## 3 errors generated.
## make: *** [foo.o] Error 1
precis(m_tank_t, depth=2)
## mean sd 5.5% 94.5% n_eff Rhat4
## a[1] 2.08095679 0.8917094 0.84815897 3.59983263 4193.5093 0.9996273
## a[2] 3.83870439 2.5636279 1.48922764 8.27686114 1041.8761 1.0009230
## a[3] 1.04391498 0.6264521 0.04880518 2.05911990 7274.2721 0.9994165
## a[4] 3.97831690 2.9902771 1.42053622 8.94840463 772.3540 1.0019129
## a[5] 2.07377268 0.8741913 0.88735361 3.55695293 4533.3276 1.0008053
## a[6] 2.06144446 0.8525098 0.87325677 3.51606570 4677.0626 0.9996352
## a[7] 4.10711145 3.6100960 1.46166369 9.06872035 417.4205 1.0060647
## a[8] 2.05011486 0.8332496 0.87693533 3.47149099 4909.3365 1.0002296
## a[9] -0.10883227 0.6438603 -1.15054895 0.89810854 7980.2709 0.9994150
## a[10] 2.06107342 0.8472991 0.88491226 3.52817481 5501.0033 1.0005059
## a[11] 1.05924948 0.6491704 0.03833504 2.10475510 6698.7508 0.9994841
## a[12] 0.68060117 0.6329330 -0.31987124 1.68305522 9187.7998 0.9999055
## a[13] 1.06451562 0.6558861 0.02748635 2.12839436 8419.7587 0.9995344
## a[14] 0.28827392 0.6299429 -0.72015943 1.28699775 8374.0154 0.9995520
## a[15] 2.07234778 0.8864410 0.82903627 3.56162843 4394.3422 1.0005454
## a[16] 2.05417213 0.8393212 0.84664644 3.48905702 5852.3634 1.0000777
## a[17] 2.90773418 0.9206875 1.70698351 4.48363287 2978.7057 0.9995109
## a[18] 2.31166404 0.6327220 1.41020382 3.38986817 5622.8944 1.0002373
## a[19] 1.96019107 0.5580809 1.14274129 2.89802242 5017.5906 1.0009776
## a[20] 5.08513645 3.1542174 2.34326425 10.51081728 939.0673 1.0019622
## a[21] 2.33606169 0.6817664 1.38826687 3.51280543 5436.2476 0.9994165
## a[22] 2.35158097 0.6954700 1.35737392 3.54060186 5487.2076 0.9995598
## a[23] 2.31796077 0.6561863 1.37248241 3.41674516 5895.2919 0.9997936
## a[24] 1.68612955 0.5123457 0.91564466 2.54180486 5731.9600 0.9997204
## a[25] -1.03756279 0.4787299 -1.81564745 -0.31160391 8132.0561 0.9995911
## a[26] 0.20414727 0.3887035 -0.41143643 0.83672153 8012.4544 0.9998634
## a[27] -1.54653489 0.5572681 -2.47699184 -0.71269263 7535.9598 0.9993240
## a[28] -0.45029921 0.4184621 -1.12270337 0.20290368 8634.3077 0.9991867
## a[29] 0.21057737 0.3969333 -0.40541236 0.84082607 8983.8053 0.9992081
## a[30] 1.45129631 0.4735796 0.74973368 2.23021961 7502.5276 0.9994584
## a[31] -0.63170311 0.4201386 -1.32793283 0.03236480 9090.0689 0.9992727
## a[32] -0.29546089 0.4200111 -0.95819499 0.38039172 9829.0874 0.9994312
## a[33] 3.24825360 0.9162969 2.02233972 4.84926531 3424.1138 1.0001544
## a[34] 2.66458409 0.6775129 1.69992053 3.82739960 4305.6758 1.0009826
## a[35] 2.63971190 0.6493110 1.72682658 3.76702850 5712.2302 0.9999298
## a[36] 2.01011479 0.4927125 1.28931336 2.83552424 7889.7358 0.9991590
## a[37] 2.01864499 0.4880644 1.29493909 2.85663908 6967.9645 0.9995056
## a[38] 5.73496401 3.5847714 2.64675167 12.25133895 1109.2759 1.0014538
## a[39] 2.64642065 0.6776995 1.68680286 3.80005136 5359.1807 0.9992458
## a[40] 2.28720159 0.5588937 1.46330081 3.25604844 7713.5616 0.9999054
## a[41] -1.96921934 0.5307576 -2.85109468 -1.16127400 7437.6937 0.9995050
## a[42] -0.56300510 0.3580915 -1.14521455 0.00313047 9976.4652 0.9993010
## a[43] -0.44250946 0.3527218 -1.02126871 0.11812520 8199.8152 0.9992941
## a[44] -0.31666180 0.3365145 -0.84774051 0.22175996 8755.9006 0.9993588
## a[45] 0.61546707 0.3416797 0.08085960 1.16889896 9658.7333 0.9994635
## a[46] -0.57163700 0.3719125 -1.17384521 0.01437171 10325.8526 0.9997068
## a[47] 2.01655209 0.4896453 1.29949578 2.83757623 8090.4383 0.9999601
## a[48] 0.03089651 0.3303473 -0.49646062 0.55184397 7906.6447 0.9995980
## a_bar 1.40462687 0.2774835 0.95483870 1.84676074 6503.1225 0.9996669
## sigma 1.26210553 0.2229053 0.94312822 1.64250352 3865.6273 1.0001589
# Extract results
a_tank_t <- apply(extract.samples(m_tank_t)$a, 2, mean)
# Compare results
compare(m_tank, m_tank_cauchy, m_tank_t)
## WAIC SE dWAIC dSE pWAIC weight
## m_tank 200.3086 7.238030 0.000000 NA 20.95892 0.5200128
## m_tank_t 201.4737 7.785569 1.165099 1.474910 22.04423 0.2904130
## m_tank_cauchy 202.3267 8.350413 2.018146 2.191405 22.54737 0.1895742
# Plot
plot(a_tank, a_tank_t, pch=15, col=rangi2,
xlab="Intercept (Guassian Prior)", ylab="Intercept(Student T Prior)")
abline(a=0, b=1, lty=4)
# Comparing αtank value between Gaussian and Student T prior, we see some similarities to the αtank value between Gaussian and Cauchy prior. We see some drift at higher value of αtank. This means that the tail end of Student T distribution is longer than a Gaussian distribution However, comparing the αtank value between Cauchy and Student T we see that at higher αtank value the value of Student T is lower than the value of Cauchy. This indicates that while the Student T distribution has a longer tail than the Gaussian distribution, but the tail is shorter than that of the Cauchy distribution. Overall, WAIC is quite similar between the three models, with Gaussian distribution intercept prior having the lowest WAIC, hence the preferred model.
13-5. Sometimes the prior and the data (through the likelihood) are in conflict, because they concentrate around different regions of parameter space. What happens in these cases depends a lot upon the shape of the tails of the distributions. Likewise, the tails of distributions strongly influence can outliers are shrunk or not towards the mean. I want you to consider four different models to fit to one observation at y = 0, this is your data, do not use any other data set. The models differ only in the distributions assigned to the likelihood and prior. Here are the four models:
\[\begin{align} Model \;NN: y &∼ Normal(μ, 1) & Model \;TN: y &∼ Student(2, μ, 1) \\ μ &∼ Normal(10, 1) & μ &∼ Normal(10, 1) \\ Model \;NT: y &∼ Normal(μ, 1) & Model \;TT: y &∼ Student(2, μ, 1) \\ μ &∼ Student(2, 10, 1) & μ &∼ Student(2, 10, 1) \\ \end{align}\]Estimate and plot the posterior distributions against the likelihoods for these models and compare them. Can you explain the results, using the properties of the distributions?
# Model NN
m_nn <- ulam(
alist(
y ~ normal(mu, 1),
mu ~ normal(10, 1)
), data=list(N=1), chains=4
)
## Running /Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB foo.c
## clang -mmacosx-version-min=10.13 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/Rcpp/include/" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/unsupported" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/BH/include" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/src/" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppParallel/include/" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include" -DEIGEN_NO_DEBUG -DBOOST_DISABLE_ASSERTS -DBOOST_PENDING_INTEGER_LOG2_HPP -DSTAN_THREADS -DBOOST_NO_AUTO_PTR -include '/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp' -D_REENTRANT -DRCPP_PARALLEL_USE_TBB=1 -I/usr/local/include -fPIC -Wall -g -O2 -c foo.c -o foo.o
## In file included from <built-in>:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
## In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Core:88:
## /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/Macros.h:628:1: error: unknown type name 'namespace'
## namespace Eigen {
## ^
## /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/Macros.h:628:16: error: expected ';' after top level declarator
## namespace Eigen {
## ^
## ;
## In file included from <built-in>:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
## In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:1:
## /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Core:96:10: fatal error: 'complex' file not found
## #include <complex>
## ^~~~~~~~~
## 3 errors generated.
## make: *** [foo.o] Error 1
##
## SAMPLING FOR MODEL '112d01a38d18ebffd06431a2c363fdac' NOW (CHAIN 1).
## Chain 1:
## Chain 1: Gradient evaluation took 1.7e-05 seconds
## Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 0.17 seconds.
## Chain 1: Adjust your expectations accordingly!
## Chain 1:
## Chain 1:
## Chain 1: Iteration: 1 / 1000 [ 0%] (Warmup)
## Chain 1: Iteration: 100 / 1000 [ 10%] (Warmup)
## Chain 1: Iteration: 200 / 1000 [ 20%] (Warmup)
## Chain 1: Iteration: 300 / 1000 [ 30%] (Warmup)
## Chain 1: Iteration: 400 / 1000 [ 40%] (Warmup)
## Chain 1: Iteration: 500 / 1000 [ 50%] (Warmup)
## Chain 1: Iteration: 501 / 1000 [ 50%] (Sampling)
## Chain 1: Iteration: 600 / 1000 [ 60%] (Sampling)
## Chain 1: Iteration: 700 / 1000 [ 70%] (Sampling)
## Chain 1: Iteration: 800 / 1000 [ 80%] (Sampling)
## Chain 1: Iteration: 900 / 1000 [ 90%] (Sampling)
## Chain 1: Iteration: 1000 / 1000 [100%] (Sampling)
## Chain 1:
## Chain 1: Elapsed Time: 0.011439 seconds (Warm-up)
## Chain 1: 0.007338 seconds (Sampling)
## Chain 1: 0.018777 seconds (Total)
## Chain 1:
##
## SAMPLING FOR MODEL '112d01a38d18ebffd06431a2c363fdac' NOW (CHAIN 2).
## Chain 2:
## Chain 2: Gradient evaluation took 4e-06 seconds
## Chain 2: 1000 transitions using 10 leapfrog steps per transition would take 0.04 seconds.
## Chain 2: Adjust your expectations accordingly!
## Chain 2:
## Chain 2:
## Chain 2: Iteration: 1 / 1000 [ 0%] (Warmup)
## Chain 2: Iteration: 100 / 1000 [ 10%] (Warmup)
## Chain 2: Iteration: 200 / 1000 [ 20%] (Warmup)
## Chain 2: Iteration: 300 / 1000 [ 30%] (Warmup)
## Chain 2: Iteration: 400 / 1000 [ 40%] (Warmup)
## Chain 2: Iteration: 500 / 1000 [ 50%] (Warmup)
## Chain 2: Iteration: 501 / 1000 [ 50%] (Sampling)
## Chain 2: Iteration: 600 / 1000 [ 60%] (Sampling)
## Chain 2: Iteration: 700 / 1000 [ 70%] (Sampling)
## Chain 2: Iteration: 800 / 1000 [ 80%] (Sampling)
## Chain 2: Iteration: 900 / 1000 [ 90%] (Sampling)
## Chain 2: Iteration: 1000 / 1000 [100%] (Sampling)
## Chain 2:
## Chain 2: Elapsed Time: 0.009724 seconds (Warm-up)
## Chain 2: 0.009172 seconds (Sampling)
## Chain 2: 0.018896 seconds (Total)
## Chain 2:
##
## SAMPLING FOR MODEL '112d01a38d18ebffd06431a2c363fdac' NOW (CHAIN 3).
## Chain 3:
## Chain 3: Gradient evaluation took 4e-06 seconds
## Chain 3: 1000 transitions using 10 leapfrog steps per transition would take 0.04 seconds.
## Chain 3: Adjust your expectations accordingly!
## Chain 3:
## Chain 3:
## Chain 3: Iteration: 1 / 1000 [ 0%] (Warmup)
## Chain 3: Iteration: 100 / 1000 [ 10%] (Warmup)
## Chain 3: Iteration: 200 / 1000 [ 20%] (Warmup)
## Chain 3: Iteration: 300 / 1000 [ 30%] (Warmup)
## Chain 3: Iteration: 400 / 1000 [ 40%] (Warmup)
## Chain 3: Iteration: 500 / 1000 [ 50%] (Warmup)
## Chain 3: Iteration: 501 / 1000 [ 50%] (Sampling)
## Chain 3: Iteration: 600 / 1000 [ 60%] (Sampling)
## Chain 3: Iteration: 700 / 1000 [ 70%] (Sampling)
## Chain 3: Iteration: 800 / 1000 [ 80%] (Sampling)
## Chain 3: Iteration: 900 / 1000 [ 90%] (Sampling)
## Chain 3: Iteration: 1000 / 1000 [100%] (Sampling)
## Chain 3:
## Chain 3: Elapsed Time: 0.009387 seconds (Warm-up)
## Chain 3: 0.009996 seconds (Sampling)
## Chain 3: 0.019383 seconds (Total)
## Chain 3:
##
## SAMPLING FOR MODEL '112d01a38d18ebffd06431a2c363fdac' NOW (CHAIN 4).
## Chain 4:
## Chain 4: Gradient evaluation took 5e-06 seconds
## Chain 4: 1000 transitions using 10 leapfrog steps per transition would take 0.05 seconds.
## Chain 4: Adjust your expectations accordingly!
## Chain 4:
## Chain 4:
## Chain 4: Iteration: 1 / 1000 [ 0%] (Warmup)
## Chain 4: Iteration: 100 / 1000 [ 10%] (Warmup)
## Chain 4: Iteration: 200 / 1000 [ 20%] (Warmup)
## Chain 4: Iteration: 300 / 1000 [ 30%] (Warmup)
## Chain 4: Iteration: 400 / 1000 [ 40%] (Warmup)
## Chain 4: Iteration: 500 / 1000 [ 50%] (Warmup)
## Chain 4: Iteration: 501 / 1000 [ 50%] (Sampling)
## Chain 4: Iteration: 600 / 1000 [ 60%] (Sampling)
## Chain 4: Iteration: 700 / 1000 [ 70%] (Sampling)
## Chain 4: Iteration: 800 / 1000 [ 80%] (Sampling)
## Chain 4: Iteration: 900 / 1000 [ 90%] (Sampling)
## Chain 4: Iteration: 1000 / 1000 [100%] (Sampling)
## Chain 4:
## Chain 4: Elapsed Time: 0.01001 seconds (Warm-up)
## Chain 4: 0.010024 seconds (Sampling)
## Chain 4: 0.020034 seconds (Total)
## Chain 4:
precis(m_nn)
## mean sd 5.5% 94.5% n_eff Rhat4
## y 10.00208 1.447115 7.651893 12.22111 522.6327 1.005592
## mu 10.04285 1.036531 8.416847 11.75392 558.5558 1.002195
# Model NT
m_nt <- ulam(
alist(
y ~ normal(mu, 1),
mu ~ dstudent(2, 10, 1)
), data=list(N=1), chains=4
)
## Running /Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB foo.c
## clang -mmacosx-version-min=10.13 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/Rcpp/include/" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/unsupported" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/BH/include" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/src/" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppParallel/include/" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include" -DEIGEN_NO_DEBUG -DBOOST_DISABLE_ASSERTS -DBOOST_PENDING_INTEGER_LOG2_HPP -DSTAN_THREADS -DBOOST_NO_AUTO_PTR -include '/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp' -D_REENTRANT -DRCPP_PARALLEL_USE_TBB=1 -I/usr/local/include -fPIC -Wall -g -O2 -c foo.c -o foo.o
## In file included from <built-in>:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
## In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Core:88:
## /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/Macros.h:628:1: error: unknown type name 'namespace'
## namespace Eigen {
## ^
## /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/Macros.h:628:16: error: expected ';' after top level declarator
## namespace Eigen {
## ^
## ;
## In file included from <built-in>:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
## In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:1:
## /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Core:96:10: fatal error: 'complex' file not found
## #include <complex>
## ^~~~~~~~~
## 3 errors generated.
## make: *** [foo.o] Error 1
##
## SAMPLING FOR MODEL 'ed7d07e3adb68efaaf0a8ca2fa4adc14' NOW (CHAIN 1).
## Chain 1:
## Chain 1: Gradient evaluation took 1.9e-05 seconds
## Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 0.19 seconds.
## Chain 1: Adjust your expectations accordingly!
## Chain 1:
## Chain 1:
## Chain 1: Iteration: 1 / 1000 [ 0%] (Warmup)
## Chain 1: Iteration: 100 / 1000 [ 10%] (Warmup)
## Chain 1: Iteration: 200 / 1000 [ 20%] (Warmup)
## Chain 1: Iteration: 300 / 1000 [ 30%] (Warmup)
## Chain 1: Iteration: 400 / 1000 [ 40%] (Warmup)
## Chain 1: Iteration: 500 / 1000 [ 50%] (Warmup)
## Chain 1: Iteration: 501 / 1000 [ 50%] (Sampling)
## Chain 1: Iteration: 600 / 1000 [ 60%] (Sampling)
## Chain 1: Iteration: 700 / 1000 [ 70%] (Sampling)
## Chain 1: Iteration: 800 / 1000 [ 80%] (Sampling)
## Chain 1: Iteration: 900 / 1000 [ 90%] (Sampling)
## Chain 1: Iteration: 1000 / 1000 [100%] (Sampling)
## Chain 1:
## Chain 1: Elapsed Time: 0.010808 seconds (Warm-up)
## Chain 1: 0.010694 seconds (Sampling)
## Chain 1: 0.021502 seconds (Total)
## Chain 1:
##
## SAMPLING FOR MODEL 'ed7d07e3adb68efaaf0a8ca2fa4adc14' NOW (CHAIN 2).
## Chain 2:
## Chain 2: Gradient evaluation took 5e-06 seconds
## Chain 2: 1000 transitions using 10 leapfrog steps per transition would take 0.05 seconds.
## Chain 2: Adjust your expectations accordingly!
## Chain 2:
## Chain 2:
## Chain 2: Iteration: 1 / 1000 [ 0%] (Warmup)
## Chain 2: Iteration: 100 / 1000 [ 10%] (Warmup)
## Chain 2: Iteration: 200 / 1000 [ 20%] (Warmup)
## Chain 2: Iteration: 300 / 1000 [ 30%] (Warmup)
## Chain 2: Iteration: 400 / 1000 [ 40%] (Warmup)
## Chain 2: Iteration: 500 / 1000 [ 50%] (Warmup)
## Chain 2: Iteration: 501 / 1000 [ 50%] (Sampling)
## Chain 2: Iteration: 600 / 1000 [ 60%] (Sampling)
## Chain 2: Iteration: 700 / 1000 [ 70%] (Sampling)
## Chain 2: Iteration: 800 / 1000 [ 80%] (Sampling)
## Chain 2: Iteration: 900 / 1000 [ 90%] (Sampling)
## Chain 2: Iteration: 1000 / 1000 [100%] (Sampling)
## Chain 2:
## Chain 2: Elapsed Time: 0.012425 seconds (Warm-up)
## Chain 2: 0.010444 seconds (Sampling)
## Chain 2: 0.022869 seconds (Total)
## Chain 2:
##
## SAMPLING FOR MODEL 'ed7d07e3adb68efaaf0a8ca2fa4adc14' NOW (CHAIN 3).
## Chain 3:
## Chain 3: Gradient evaluation took 3e-06 seconds
## Chain 3: 1000 transitions using 10 leapfrog steps per transition would take 0.03 seconds.
## Chain 3: Adjust your expectations accordingly!
## Chain 3:
## Chain 3:
## Chain 3: Iteration: 1 / 1000 [ 0%] (Warmup)
## Chain 3: Iteration: 100 / 1000 [ 10%] (Warmup)
## Chain 3: Iteration: 200 / 1000 [ 20%] (Warmup)
## Chain 3: Iteration: 300 / 1000 [ 30%] (Warmup)
## Chain 3: Iteration: 400 / 1000 [ 40%] (Warmup)
## Chain 3: Iteration: 500 / 1000 [ 50%] (Warmup)
## Chain 3: Iteration: 501 / 1000 [ 50%] (Sampling)
## Chain 3: Iteration: 600 / 1000 [ 60%] (Sampling)
## Chain 3: Iteration: 700 / 1000 [ 70%] (Sampling)
## Chain 3: Iteration: 800 / 1000 [ 80%] (Sampling)
## Chain 3: Iteration: 900 / 1000 [ 90%] (Sampling)
## Chain 3: Iteration: 1000 / 1000 [100%] (Sampling)
## Chain 3:
## Chain 3: Elapsed Time: 0.011332 seconds (Warm-up)
## Chain 3: 0.009686 seconds (Sampling)
## Chain 3: 0.021018 seconds (Total)
## Chain 3:
##
## SAMPLING FOR MODEL 'ed7d07e3adb68efaaf0a8ca2fa4adc14' NOW (CHAIN 4).
## Chain 4:
## Chain 4: Gradient evaluation took 4e-06 seconds
## Chain 4: 1000 transitions using 10 leapfrog steps per transition would take 0.04 seconds.
## Chain 4: Adjust your expectations accordingly!
## Chain 4:
## Chain 4:
## Chain 4: Iteration: 1 / 1000 [ 0%] (Warmup)
## Chain 4: Iteration: 100 / 1000 [ 10%] (Warmup)
## Chain 4: Iteration: 200 / 1000 [ 20%] (Warmup)
## Chain 4: Iteration: 300 / 1000 [ 30%] (Warmup)
## Chain 4: Iteration: 400 / 1000 [ 40%] (Warmup)
## Chain 4: Iteration: 500 / 1000 [ 50%] (Warmup)
## Chain 4: Iteration: 501 / 1000 [ 50%] (Sampling)
## Chain 4: Iteration: 600 / 1000 [ 60%] (Sampling)
## Chain 4: Iteration: 700 / 1000 [ 70%] (Sampling)
## Chain 4: Iteration: 800 / 1000 [ 80%] (Sampling)
## Chain 4: Iteration: 900 / 1000 [ 90%] (Sampling)
## Chain 4: Iteration: 1000 / 1000 [100%] (Sampling)
## Chain 4:
## Chain 4: Elapsed Time: 0.014241 seconds (Warm-up)
## Chain 4: 0.010771 seconds (Sampling)
## Chain 4: 0.025012 seconds (Total)
## Chain 4:
# Model TN
m_tn <- ulam(
alist(
y ~ dstudent(2, mu, 1),
mu ~ normal(10, 1)
), data=list(N=1), chains=4
)
## Running /Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB foo.c
## clang -mmacosx-version-min=10.13 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/Rcpp/include/" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/unsupported" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/BH/include" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/src/" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppParallel/include/" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include" -DEIGEN_NO_DEBUG -DBOOST_DISABLE_ASSERTS -DBOOST_PENDING_INTEGER_LOG2_HPP -DSTAN_THREADS -DBOOST_NO_AUTO_PTR -include '/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp' -D_REENTRANT -DRCPP_PARALLEL_USE_TBB=1 -I/usr/local/include -fPIC -Wall -g -O2 -c foo.c -o foo.o
## In file included from <built-in>:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
## In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Core:88:
## /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/Macros.h:628:1: error: unknown type name 'namespace'
## namespace Eigen {
## ^
## /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/Macros.h:628:16: error: expected ';' after top level declarator
## namespace Eigen {
## ^
## ;
## In file included from <built-in>:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
## In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:1:
## /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Core:96:10: fatal error: 'complex' file not found
## #include <complex>
## ^~~~~~~~~
## 3 errors generated.
## make: *** [foo.o] Error 1
##
## SAMPLING FOR MODEL '9d84542d1c1b8ab5ec48d279b9de5446' NOW (CHAIN 1).
## Chain 1:
## Chain 1: Gradient evaluation took 1.8e-05 seconds
## Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 0.18 seconds.
## Chain 1: Adjust your expectations accordingly!
## Chain 1:
## Chain 1:
## Chain 1: Iteration: 1 / 1000 [ 0%] (Warmup)
## Chain 1: Iteration: 100 / 1000 [ 10%] (Warmup)
## Chain 1: Iteration: 200 / 1000 [ 20%] (Warmup)
## Chain 1: Iteration: 300 / 1000 [ 30%] (Warmup)
## Chain 1: Iteration: 400 / 1000 [ 40%] (Warmup)
## Chain 1: Iteration: 500 / 1000 [ 50%] (Warmup)
## Chain 1: Iteration: 501 / 1000 [ 50%] (Sampling)
## Chain 1: Iteration: 600 / 1000 [ 60%] (Sampling)
## Chain 1: Iteration: 700 / 1000 [ 70%] (Sampling)
## Chain 1: Iteration: 800 / 1000 [ 80%] (Sampling)
## Chain 1: Iteration: 900 / 1000 [ 90%] (Sampling)
## Chain 1: Iteration: 1000 / 1000 [100%] (Sampling)
## Chain 1:
## Chain 1: Elapsed Time: 0.011625 seconds (Warm-up)
## Chain 1: 0.010435 seconds (Sampling)
## Chain 1: 0.02206 seconds (Total)
## Chain 1:
##
## SAMPLING FOR MODEL '9d84542d1c1b8ab5ec48d279b9de5446' NOW (CHAIN 2).
## Chain 2:
## Chain 2: Gradient evaluation took 5e-06 seconds
## Chain 2: 1000 transitions using 10 leapfrog steps per transition would take 0.05 seconds.
## Chain 2: Adjust your expectations accordingly!
## Chain 2:
## Chain 2:
## Chain 2: Iteration: 1 / 1000 [ 0%] (Warmup)
## Chain 2: Iteration: 100 / 1000 [ 10%] (Warmup)
## Chain 2: Iteration: 200 / 1000 [ 20%] (Warmup)
## Chain 2: Iteration: 300 / 1000 [ 30%] (Warmup)
## Chain 2: Iteration: 400 / 1000 [ 40%] (Warmup)
## Chain 2: Iteration: 500 / 1000 [ 50%] (Warmup)
## Chain 2: Iteration: 501 / 1000 [ 50%] (Sampling)
## Chain 2: Iteration: 600 / 1000 [ 60%] (Sampling)
## Chain 2: Iteration: 700 / 1000 [ 70%] (Sampling)
## Chain 2: Iteration: 800 / 1000 [ 80%] (Sampling)
## Chain 2: Iteration: 900 / 1000 [ 90%] (Sampling)
## Chain 2: Iteration: 1000 / 1000 [100%] (Sampling)
## Chain 2:
## Chain 2: Elapsed Time: 0.010448 seconds (Warm-up)
## Chain 2: 0.00983 seconds (Sampling)
## Chain 2: 0.020278 seconds (Total)
## Chain 2:
##
## SAMPLING FOR MODEL '9d84542d1c1b8ab5ec48d279b9de5446' NOW (CHAIN 3).
## Chain 3:
## Chain 3: Gradient evaluation took 6e-06 seconds
## Chain 3: 1000 transitions using 10 leapfrog steps per transition would take 0.06 seconds.
## Chain 3: Adjust your expectations accordingly!
## Chain 3:
## Chain 3:
## Chain 3: Iteration: 1 / 1000 [ 0%] (Warmup)
## Chain 3: Iteration: 100 / 1000 [ 10%] (Warmup)
## Chain 3: Iteration: 200 / 1000 [ 20%] (Warmup)
## Chain 3: Iteration: 300 / 1000 [ 30%] (Warmup)
## Chain 3: Iteration: 400 / 1000 [ 40%] (Warmup)
## Chain 3: Iteration: 500 / 1000 [ 50%] (Warmup)
## Chain 3: Iteration: 501 / 1000 [ 50%] (Sampling)
## Chain 3: Iteration: 600 / 1000 [ 60%] (Sampling)
## Chain 3: Iteration: 700 / 1000 [ 70%] (Sampling)
## Chain 3: Iteration: 800 / 1000 [ 80%] (Sampling)
## Chain 3: Iteration: 900 / 1000 [ 90%] (Sampling)
## Chain 3: Iteration: 1000 / 1000 [100%] (Sampling)
## Chain 3:
## Chain 3: Elapsed Time: 0.011729 seconds (Warm-up)
## Chain 3: 0.009782 seconds (Sampling)
## Chain 3: 0.021511 seconds (Total)
## Chain 3:
##
## SAMPLING FOR MODEL '9d84542d1c1b8ab5ec48d279b9de5446' NOW (CHAIN 4).
## Chain 4:
## Chain 4: Gradient evaluation took 4e-06 seconds
## Chain 4: 1000 transitions using 10 leapfrog steps per transition would take 0.04 seconds.
## Chain 4: Adjust your expectations accordingly!
## Chain 4:
## Chain 4:
## Chain 4: Iteration: 1 / 1000 [ 0%] (Warmup)
## Chain 4: Iteration: 100 / 1000 [ 10%] (Warmup)
## Chain 4: Iteration: 200 / 1000 [ 20%] (Warmup)
## Chain 4: Iteration: 300 / 1000 [ 30%] (Warmup)
## Chain 4: Iteration: 400 / 1000 [ 40%] (Warmup)
## Chain 4: Iteration: 500 / 1000 [ 50%] (Warmup)
## Chain 4: Iteration: 501 / 1000 [ 50%] (Sampling)
## Chain 4: Iteration: 600 / 1000 [ 60%] (Sampling)
## Chain 4: Iteration: 700 / 1000 [ 70%] (Sampling)
## Chain 4: Iteration: 800 / 1000 [ 80%] (Sampling)
## Chain 4: Iteration: 900 / 1000 [ 90%] (Sampling)
## Chain 4: Iteration: 1000 / 1000 [100%] (Sampling)
## Chain 4:
## Chain 4: Elapsed Time: 0.010772 seconds (Warm-up)
## Chain 4: 0.012574 seconds (Sampling)
## Chain 4: 0.023346 seconds (Total)
## Chain 4:
# Model TT
m_tt <- ulam(
alist(
y ~ dstudent(2, mu, 1),
mu ~ dstudent(2, 10, 1)
), data=list(N=1), chains=4
)
## Running /Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB foo.c
## clang -mmacosx-version-min=10.13 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/Rcpp/include/" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/unsupported" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/BH/include" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/src/" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppParallel/include/" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include" -DEIGEN_NO_DEBUG -DBOOST_DISABLE_ASSERTS -DBOOST_PENDING_INTEGER_LOG2_HPP -DSTAN_THREADS -DBOOST_NO_AUTO_PTR -include '/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp' -D_REENTRANT -DRCPP_PARALLEL_USE_TBB=1 -I/usr/local/include -fPIC -Wall -g -O2 -c foo.c -o foo.o
## In file included from <built-in>:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
## In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Core:88:
## /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/Macros.h:628:1: error: unknown type name 'namespace'
## namespace Eigen {
## ^
## /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/Macros.h:628:16: error: expected ';' after top level declarator
## namespace Eigen {
## ^
## ;
## In file included from <built-in>:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
## In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:1:
## /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Core:96:10: fatal error: 'complex' file not found
## #include <complex>
## ^~~~~~~~~
## 3 errors generated.
## make: *** [foo.o] Error 1
##
## SAMPLING FOR MODEL '2e6abf303efaca258b6fe191488c05c4' NOW (CHAIN 1).
## Chain 1:
## Chain 1: Gradient evaluation took 1.8e-05 seconds
## Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 0.18 seconds.
## Chain 1: Adjust your expectations accordingly!
## Chain 1:
## Chain 1:
## Chain 1: Iteration: 1 / 1000 [ 0%] (Warmup)
## Chain 1: Iteration: 100 / 1000 [ 10%] (Warmup)
## Chain 1: Iteration: 200 / 1000 [ 20%] (Warmup)
## Chain 1: Iteration: 300 / 1000 [ 30%] (Warmup)
## Chain 1: Iteration: 400 / 1000 [ 40%] (Warmup)
## Chain 1: Iteration: 500 / 1000 [ 50%] (Warmup)
## Chain 1: Iteration: 501 / 1000 [ 50%] (Sampling)
## Chain 1: Iteration: 600 / 1000 [ 60%] (Sampling)
## Chain 1: Iteration: 700 / 1000 [ 70%] (Sampling)
## Chain 1: Iteration: 800 / 1000 [ 80%] (Sampling)
## Chain 1: Iteration: 900 / 1000 [ 90%] (Sampling)
## Chain 1: Iteration: 1000 / 1000 [100%] (Sampling)
## Chain 1:
## Chain 1: Elapsed Time: 0.013796 seconds (Warm-up)
## Chain 1: 0.012898 seconds (Sampling)
## Chain 1: 0.026694 seconds (Total)
## Chain 1:
##
## SAMPLING FOR MODEL '2e6abf303efaca258b6fe191488c05c4' NOW (CHAIN 2).
## Chain 2:
## Chain 2: Gradient evaluation took 5e-06 seconds
## Chain 2: 1000 transitions using 10 leapfrog steps per transition would take 0.05 seconds.
## Chain 2: Adjust your expectations accordingly!
## Chain 2:
## Chain 2:
## Chain 2: Iteration: 1 / 1000 [ 0%] (Warmup)
## Chain 2: Iteration: 100 / 1000 [ 10%] (Warmup)
## Chain 2: Iteration: 200 / 1000 [ 20%] (Warmup)
## Chain 2: Iteration: 300 / 1000 [ 30%] (Warmup)
## Chain 2: Iteration: 400 / 1000 [ 40%] (Warmup)
## Chain 2: Iteration: 500 / 1000 [ 50%] (Warmup)
## Chain 2: Iteration: 501 / 1000 [ 50%] (Sampling)
## Chain 2: Iteration: 600 / 1000 [ 60%] (Sampling)
## Chain 2: Iteration: 700 / 1000 [ 70%] (Sampling)
## Chain 2: Iteration: 800 / 1000 [ 80%] (Sampling)
## Chain 2: Iteration: 900 / 1000 [ 90%] (Sampling)
## Chain 2: Iteration: 1000 / 1000 [100%] (Sampling)
## Chain 2:
## Chain 2: Elapsed Time: 0.014266 seconds (Warm-up)
## Chain 2: 0.012335 seconds (Sampling)
## Chain 2: 0.026601 seconds (Total)
## Chain 2:
##
## SAMPLING FOR MODEL '2e6abf303efaca258b6fe191488c05c4' NOW (CHAIN 3).
## Chain 3:
## Chain 3: Gradient evaluation took 5e-06 seconds
## Chain 3: 1000 transitions using 10 leapfrog steps per transition would take 0.05 seconds.
## Chain 3: Adjust your expectations accordingly!
## Chain 3:
## Chain 3:
## Chain 3: Iteration: 1 / 1000 [ 0%] (Warmup)
## Chain 3: Iteration: 100 / 1000 [ 10%] (Warmup)
## Chain 3: Iteration: 200 / 1000 [ 20%] (Warmup)
## Chain 3: Iteration: 300 / 1000 [ 30%] (Warmup)
## Chain 3: Iteration: 400 / 1000 [ 40%] (Warmup)
## Chain 3: Iteration: 500 / 1000 [ 50%] (Warmup)
## Chain 3: Iteration: 501 / 1000 [ 50%] (Sampling)
## Chain 3: Iteration: 600 / 1000 [ 60%] (Sampling)
## Chain 3: Iteration: 700 / 1000 [ 70%] (Sampling)
## Chain 3: Iteration: 800 / 1000 [ 80%] (Sampling)
## Chain 3: Iteration: 900 / 1000 [ 90%] (Sampling)
## Chain 3: Iteration: 1000 / 1000 [100%] (Sampling)
## Chain 3:
## Chain 3: Elapsed Time: 0.014266 seconds (Warm-up)
## Chain 3: 0.010062 seconds (Sampling)
## Chain 3: 0.024328 seconds (Total)
## Chain 3:
##
## SAMPLING FOR MODEL '2e6abf303efaca258b6fe191488c05c4' NOW (CHAIN 4).
## Chain 4:
## Chain 4: Gradient evaluation took 5e-06 seconds
## Chain 4: 1000 transitions using 10 leapfrog steps per transition would take 0.05 seconds.
## Chain 4: Adjust your expectations accordingly!
## Chain 4:
## Chain 4:
## Chain 4: Iteration: 1 / 1000 [ 0%] (Warmup)
## Chain 4: Iteration: 100 / 1000 [ 10%] (Warmup)
## Chain 4: Iteration: 200 / 1000 [ 20%] (Warmup)
## Chain 4: Iteration: 300 / 1000 [ 30%] (Warmup)
## Chain 4: Iteration: 400 / 1000 [ 40%] (Warmup)
## Chain 4: Iteration: 500 / 1000 [ 50%] (Warmup)
## Chain 4: Iteration: 501 / 1000 [ 50%] (Sampling)
## Chain 4: Iteration: 600 / 1000 [ 60%] (Sampling)
## Chain 4: Iteration: 700 / 1000 [ 70%] (Sampling)
## Chain 4: Iteration: 800 / 1000 [ 80%] (Sampling)
## Chain 4: Iteration: 900 / 1000 [ 90%] (Sampling)
## Chain 4: Iteration: 1000 / 1000 [100%] (Sampling)
## Chain 4:
## Chain 4: Elapsed Time: 0.013087 seconds (Warm-up)
## Chain 4: 0.011249 seconds (Sampling)
## Chain 4: 0.024336 seconds (Total)
## Chain 4:
# Extract results
mu_nn <- extract.samples(m_nn)$mu
mu_nt <- extract.samples(m_nt)$mu
mu_tn <- extract.samples(m_tn)$mu
mu_tt <- extract.samples(m_tt)$mu
# Plot
dens(mu_nn, col="blue")
dens(mu_nt, col="purple", add=TRUE)
dens(mu_tn, col="red", add=TRUE)
dens(mu_tt, col="orange", add=TRUE)
legend("topright",
col=c("blue","purple", "red", "orange"),
pch=15,
legend=c("Model NN","Model NT", "Model TN", "Model TT"))