├── .gitignore ├── HW9_Q_googlegroup.R ├── README.md ├── _site.yml ├── _site ├── index.html ├── rethinkingINLA_HW2.html ├── rethinkingINLA_HW2_files │ └── figure-html │ │ ├── 4.12-1.png │ │ ├── 4.13-1.png │ │ ├── 4.15-1.png │ │ ├── 4.38-1.png │ │ ├── 4.41-1.png │ │ ├── 4.45-1.png │ │ ├── 4.46-1.png │ │ ├── 4.49-1.png │ │ ├── 4.50 dens-1.png │ │ ├── 4.50-1.png │ │ ├── 4.55-1.png │ │ ├── 4.56-1.png │ │ ├── 4.61-1.png │ │ ├── 4.63-1.png │ │ ├── hw2 2 re-1.png │ │ └── hw2.2 inla clinear-1.png ├── rethinkingINLA_HW3.html ├── rethinkingINLA_HW3.pdf ├── rethinkingINLA_HW3_files │ └── figure-html │ │ └── hw3 dag-1.png ├── rethinkingINLA_HW4.html ├── rethinkingINLA_HW4.log ├── rethinkingINLA_HW4.tex ├── rethinkingINLA_HW4_files │ └── figure-html │ │ ├── hw3 dag-1.png │ │ └── hw4.2 dag-1.png ├── rethinkingINLA_HW5.html ├── rethinkingINLA_HW5_files │ └── figure-html │ │ ├── HW5 2a INLA-1.png │ │ ├── HW5 2a re-1.png │ │ ├── hw5 2b-1.png │ │ ├── hw5 3.a plot-1.png │ │ ├── hw5.1 INLA-1.png │ │ ├── hw5.1 re-1.png │ │ ├── hw5.1 re-2.png │ │ └── hw5.1 re-3.png └── site_libs │ ├── bootstrap-3.3.5 │ ├── css │ │ ├── bootstrap-theme.css │ │ ├── bootstrap-theme.css.map │ │ ├── bootstrap-theme.min.css │ │ ├── bootstrap.css │ │ ├── bootstrap.css.map │ │ ├── bootstrap.min.css │ │ ├── cerulean.min.css │ │ ├── cosmo.min.css │ │ ├── darkly.min.css │ │ ├── flatly.min.css │ │ ├── fonts │ │ │ ├── Lato.ttf │ │ │ ├── LatoBold.ttf │ │ │ ├── LatoItalic.ttf │ │ │ ├── NewsCycle.ttf │ │ │ ├── NewsCycleBold.ttf │ │ │ ├── OpenSans.ttf │ │ │ ├── OpenSansBold.ttf │ │ │ ├── OpenSansBoldItalic.ttf │ │ │ ├── OpenSansItalic.ttf │ │ │ ├── OpenSansLight.ttf │ │ │ ├── OpenSansLightItalic.ttf │ │ │ ├── Raleway.ttf │ │ │ ├── RalewayBold.ttf │ │ │ ├── Roboto.ttf │ │ │ ├── RobotoBold.ttf │ │ │ ├── RobotoLight.ttf │ │ │ ├── RobotoMedium.ttf │ │ │ ├── SourceSansPro.ttf │ │ │ ├── SourceSansProBold.ttf │ │ │ ├── SourceSansProItalic.ttf │ │ │ ├── SourceSansProLight.ttf │ │ │ └── Ubuntu.ttf │ │ ├── journal.min.css │ │ ├── lumen.min.css │ │ ├── paper.min.css │ │ ├── readable.min.css │ │ ├── sandstone.min.css │ │ ├── simplex.min.css │ │ ├── spacelab.min.css │ │ ├── united.min.css │ │ └── yeti.min.css │ ├── fonts │ │ ├── glyphicons-halflings-regular.eot │ │ ├── glyphicons-halflings-regular.svg │ │ ├── glyphicons-halflings-regular.ttf │ │ ├── glyphicons-halflings-regular.woff │ │ └── glyphicons-halflings-regular.woff2 │ ├── js │ │ ├── bootstrap.js │ │ ├── bootstrap.min.js │ │ └── npm.js │ └── shim │ │ ├── html5shiv.min.js │ │ └── respond.min.js │ ├── highlightjs-9.12.0 │ ├── default.css │ ├── highlight.js │ └── textmate.css │ ├── jquery-1.11.3 │ └── jquery.min.js │ ├── jqueryui-1.11.4 │ ├── README │ ├── images │ │ ├── ui-icons_444444_256x240.png │ │ ├── ui-icons_555555_256x240.png │ │ ├── ui-icons_777620_256x240.png │ │ ├── ui-icons_777777_256x240.png │ │ ├── ui-icons_cc0000_256x240.png │ │ └── ui-icons_ffffff_256x240.png │ ├── index.html │ ├── jquery-ui.css │ ├── jquery-ui.js │ ├── jquery-ui.min.css │ ├── jquery-ui.min.js │ ├── jquery-ui.structure.css │ ├── jquery-ui.structure.min.css │ ├── jquery-ui.theme.css │ └── jquery-ui.theme.min.css │ ├── navigation-1.1 │ ├── codefolding.js │ ├── sourceembed.js │ └── tabsets.js │ └── tocify-1.9.1 │ ├── jquery.tocify.css │ └── jquery.tocify.js ├── google03e966e10bf03c1a.html ├── iid123d.pdf ├── index.Rmd ├── index.html ├── rethinkingINLA_HW10.Rmd ├── rethinkingINLA_HW10.html ├── rethinkingINLA_HW10.pdf ├── rethinkingINLA_HW10_files └── figure-html │ ├── 10.1 model-1.png │ ├── 10.2.4 plot inla-1.png │ ├── 10.2.4 re-1.png │ ├── 2.1 dag-1.png │ └── 2.1 plot-1.png ├── rethinkingINLA_HW2.Rmd ├── rethinkingINLA_HW2.html ├── rethinkingINLA_HW2_files └── figure-html │ ├── 4.12-1.png │ ├── 4.13-1.png │ ├── 4.15-1.png │ ├── 4.38-1.png │ ├── 4.41-1.png │ ├── 4.45-1.png │ ├── 4.46-1.png │ ├── 4.49-1.png │ ├── 4.50 dens-1.png │ ├── 4.50-1.png │ ├── 4.55-1.png │ ├── 4.56-1.png │ ├── 4.61-1.png │ ├── 4.63-1.png │ ├── hw2 2 re-1.png │ └── hw2.2 inla clinear-1.png ├── rethinkingINLA_HW3.Rmd ├── rethinkingINLA_HW3.html ├── rethinkingINLA_HW3.pdf ├── rethinkingINLA_HW3_files └── figure-html │ └── hw3 dag-1.png ├── rethinkingINLA_HW4.Rmd ├── rethinkingINLA_HW4.html ├── rethinkingINLA_HW4.log ├── rethinkingINLA_HW4.tex ├── rethinkingINLA_HW4_files └── figure-html │ ├── hw3 dag-1.png │ ├── hw4.2 dag-1.png │ └── inla waic diff plot-1.png ├── rethinkingINLA_HW5.Rmd ├── rethinkingINLA_HW5.html ├── rethinkingINLA_HW5_files └── figure-html │ ├── HW5 2a INLA-1.png │ ├── HW5 2a re-1.png │ ├── HW5 2a re-2.png │ ├── hw5 2b-1.png │ ├── hw5 3.a plot-1.png │ ├── hw5.1 INLA-1.png │ ├── hw5.1 re-1.png │ ├── hw5.1 re-2.png │ ├── hw5.1 re-3.png │ ├── hw5.3a inla-1.png │ ├── hw5.3b INLA-1.png │ ├── in ulam-1.png │ └── inla 3a-1.png ├── rethinkingINLA_HW6.Rmd ├── rethinkingINLA_HW6.html ├── rethinkingINLA_HW6_files └── figure-html │ ├── 6.1 dag-1.png │ ├── 6.1.b postcheck-1.png │ ├── 6.2 dag-1.png │ ├── 6.3.1 re-1.png │ ├── 6.3.1 re-2.png │ ├── 6.3.1 re-3.png │ ├── 6.3.2 rethinking-1.png │ ├── 6.3.2 rethinking-2.png │ ├── 6.3.2 rethinking-3.png │ ├── 6.3.3 dag-1.png │ ├── inla 6.3 waic compare-1.png │ └── inla 6.3.1 postcheck-1.png ├── rethinkingINLA_HW7.Rmd ├── rethinkingINLA_HW7.html ├── rethinkingINLA_HW8.Rmd ├── rethinkingINLA_HW8.html ├── rethinkingINLA_HW8.log ├── rethinkingINLA_HW8.tex ├── rethinkingINLA_HW8_files └── figure-html │ ├── 8.1 post re-1.png │ ├── 8.2.2 inla hyper sd-1.png │ ├── 8.2.3 plot inla-1.png │ ├── 8.2.3 plot rethinking-1.png │ ├── 8.3 data-1.png │ ├── sigma.8.1 plot-1.png │ └── unnamed-chunk-1-1.png ├── rethinkingINLA_HW9.Rmd ├── rethinkingINLA_HW9.html ├── rethinkingINLA_HW9_files └── figure-html │ ├── 9.1 inla-1.png │ ├── 9.1 re plot outcome-1.png │ ├── 9.1 re plot-1.png │ ├── 9.1.1 outcome plot inla-1.png │ ├── 9.1.1 plot inla-1.png │ ├── 9.2 dag-1.png │ ├── 9.2 inla mean-1.png │ ├── 9.2.1 inla-1.png │ └── 9.2.2 inla-1.png ├── site_libs ├── bootstrap-3.3.5 │ ├── css │ │ ├── bootstrap-theme.css │ │ ├── bootstrap-theme.css.map │ │ ├── bootstrap-theme.min.css │ │ ├── bootstrap.css │ │ ├── bootstrap.css.map │ │ ├── bootstrap.min.css │ │ ├── cerulean.min.css │ │ ├── cosmo.min.css │ │ ├── darkly.min.css │ │ ├── flatly.min.css │ │ ├── fonts │ │ │ ├── Lato.ttf │ │ │ ├── LatoBold.ttf │ │ │ ├── LatoItalic.ttf │ │ │ ├── NewsCycle.ttf │ │ │ ├── NewsCycleBold.ttf │ │ │ ├── OpenSans.ttf │ │ │ ├── OpenSansBold.ttf │ │ │ ├── OpenSansBoldItalic.ttf │ │ │ ├── OpenSansItalic.ttf │ │ │ ├── OpenSansLight.ttf │ │ │ ├── OpenSansLightItalic.ttf │ │ │ ├── Raleway.ttf │ │ │ ├── RalewayBold.ttf │ │ │ ├── Roboto.ttf │ │ │ ├── RobotoBold.ttf │ │ │ ├── RobotoLight.ttf │ │ │ ├── RobotoMedium.ttf │ │ │ ├── SourceSansPro.ttf │ │ │ ├── SourceSansProBold.ttf │ │ │ ├── SourceSansProItalic.ttf │ │ │ ├── SourceSansProLight.ttf │ │ │ └── Ubuntu.ttf │ │ ├── journal.min.css │ │ ├── lumen.min.css │ │ ├── paper.min.css │ │ ├── readable.min.css │ │ ├── sandstone.min.css │ │ ├── simplex.min.css │ │ ├── spacelab.min.css │ │ ├── united.min.css │ │ └── yeti.min.css │ ├── fonts │ │ ├── glyphicons-halflings-regular.eot │ │ ├── glyphicons-halflings-regular.svg │ │ ├── glyphicons-halflings-regular.ttf │ │ ├── glyphicons-halflings-regular.woff │ │ └── glyphicons-halflings-regular.woff2 │ ├── js │ │ ├── bootstrap.js │ │ ├── bootstrap.min.js │ │ └── npm.js │ └── shim │ │ ├── html5shiv.min.js │ │ └── respond.min.js ├── highlightjs-9.12.0 │ ├── default.css │ ├── highlight.js │ └── textmate.css ├── jquery-1.11.3 │ └── jquery.min.js ├── jqueryui-1.11.4 │ ├── README │ ├── images │ │ ├── ui-icons_444444_256x240.png │ │ ├── ui-icons_555555_256x240.png │ │ ├── ui-icons_777620_256x240.png │ │ ├── ui-icons_777777_256x240.png │ │ ├── ui-icons_cc0000_256x240.png │ │ └── ui-icons_ffffff_256x240.png │ ├── index.html │ ├── jquery-ui.css │ ├── jquery-ui.js │ ├── jquery-ui.min.css │ ├── jquery-ui.min.js │ ├── jquery-ui.structure.css │ ├── jquery-ui.structure.min.css │ ├── jquery-ui.theme.css │ └── jquery-ui.theme.min.css ├── navigation-1.1 │ ├── codefolding.js │ ├── sourceembed.js │ └── tabsets.js └── tocify-1.9.1 │ ├── jquery.tocify.css │ └── jquery.tocify.js └── statistical_rethinking_inla.Rproj /.gitignore: -------------------------------------------------------------------------------- 1 | .Rproj.user 2 | .Rhistory 3 | .RData 4 | .Ruserdata 5 | -------------------------------------------------------------------------------- /HW9_Q_googlegroup.R: -------------------------------------------------------------------------------- 1 | ### HW9.1 in rethinking 2 | 3 | library(rethinking) 4 | data(bangladesh) 5 | d <- bangladesh 6 | 7 | dat_list <- list( 8 | C = d$use.contraception, 9 | did = as.integer( as.factor(d$district) ), 10 | urban = d$urban 11 | ) 12 | 13 | m1.1 <- ulam( 14 | alist( 15 | C ~ bernoulli( p ), 16 | logit(p) <- a[did] + b[did]*urban, 17 | c(a,b)[did] ~ multi_normal( c(abar,bbar) , Rho , Sigma ), 18 | abar ~ normal(0,1), 19 | bbar ~ normal(0,0.5), 20 | Rho ~ lkj_corr(2), 21 | Sigma ~ exponential(1) 22 | ) , data=dat_list , chains=4 , cores=4 ) 23 | 24 | precis(m1.1) 25 | 26 | precis( m1.1 , depth=3 , pars=c("Rho","Sigma") ) 27 | 28 | ## plot individual effects in rethinking 29 | 30 | post <- extract.samples(m1.1) 31 | 32 | a <- apply( post$a , 2 , mean ) 33 | b <- apply( post$b , 2 , mean ) 34 | plot( a, b , xlab="a (intercept)" , ylab="b (urban slope)" ) 35 | abline( h=0 , lty=2 ) 36 | abline( v=0 , lty=2 ) 37 | 38 | ## plot in the outcome scale in rethinking 39 | 40 | u0 <- inv_logit( a ) 41 | u1 <- inv_logit( a + b ) 42 | plot( u0 , u1 , xlim=c(0,1) , ylim=c(0,1) , xlab="urban = 0" , ylab="urban = 1" ) 43 | abline( h=0.5 , lty=2 ) 44 | abline( v=0.5 , lty=2 ) 45 | 46 | 47 | ### HW9.1 in INLA 48 | 49 | library(INLA) 50 | library(brinla) 51 | library(tid) 52 | 53 | d1.i <- d %>% 54 | #make a new variable of district that is continuous 55 | mutate(C = use.contraception, 56 | did = as.integer( as.factor(d$district)), 57 | a.did= did, 58 | b.did= did + max(did) 59 | ) 60 | 61 | n.district= max(d1.i$did) # = 60 62 | 63 | 64 | m1.1.i <- inla(C ~ 1 + urban + f(a.did, model="iid2d", n= 2*n.district) + f(b.did, urban, copy= "a.did"), data= d1.i, family = "binomial", 65 | Ntrials = 1, 66 | control.fixed = list( 67 | mean= 0, 68 | prec= 1/(0.5^2), 69 | mean.intercept= 0, 70 | prec.intercept= 1), 71 | control.family = list(control.link=list(model="logit")), 72 | control.predictor=list(link=1, compute=T), 73 | control.compute=list(config=T, dic=TRUE, waic= TRUE)) 74 | summary(m1.1.i) 75 | 76 | 77 | 78 | ## plot individual effects in INLA 79 | 80 | #m1.1.i$summary.random has 2 elements: a.did and b.did but they are identical. 81 | 82 | #extract the means of the random effects with m1.1.i$summary.random[[1]][["mean"]] 83 | m1.1.i.mean <- bind_cols(did= 1:length(m1.1.i$summary.random[[1]][["mean"]]), mean= m1.1.i$summary.random[[1]][["mean"]]) %>% 84 | #assign first 60 rows to a.did and 61:120 to b.did in new variable "param" 85 | mutate(param= if_else(did <= n.district, "a.did", "b.did"), 86 | #new variable "district" assigns the district index 1:60 to both a.did and b.did estimates. 87 | district= rep(1:60,2)) %>% 88 | #split dataframe by param into a list of 2: a.did and b.did 89 | group_split(param) %>% 90 | #join the a.did and b.did elements of the list into a dataframe by "district" 91 | reduce(left_join, by= "district") %>% 92 | select(c( "district", "mean.x", "mean.y")) %>% 93 | rename("a.did"= "mean.x", "b.did"= "mean.y") %>% 94 | mutate(intercept= a.did + m1.1.i$summary.fixed[[1]][[1]], 95 | slope= b.did + m1.1.i$summary.fixed[[1]][[2]]) 96 | 97 | 98 | 99 | m1.1.i.mean.plot <- ggplot()+ 100 | geom_point(data= m1.1.i.mean, aes(x=intercept, y= slope))+ 101 | geom_hline(yintercept=0, linetype='longdash') + 102 | geom_vline(xintercept = 0)+ 103 | labs(x= "a (intercept)", y = "b (urban slope)")+ 104 | theme_bw() 105 | 106 | m1.1.i.mean.plot 107 | 108 | ## plot in the outcome scale in INLA 109 | 110 | inverse_logit <- function (x){ 111 | p <- 1/(1 + exp(-x)) 112 | p <- ifelse(x == Inf, 1, p) 113 | p } 114 | 115 | 116 | m1.1.i.outcome <- m1.1.i.mean %>% 117 | mutate(u0.i = inverse_logit(a.did + m1.1.i$summary.fixed[[1]][[1]]), 118 | u1.i= inverse_logit(a.did + m1.1.i$summary.fixed[[1]][[1]] + 119 | b.did + m1.1.i$summary.fixed[[1]][[2]]) 120 | ) 121 | 122 | 123 | m1.1.i.outcome.plot <- ggplot()+ 124 | geom_point(data= m1.1.i.outcome, aes(x=u0.i, y= u1.i))+ 125 | geom_hline(yintercept=0.5, linetype='longdash') + 126 | geom_vline(xintercept = 0.5)+ 127 | labs(x= "urban = 0", y = "urban = 1")+ 128 | xlim(0,1) + 129 | ylim(0,1)+ 130 | theme_bw() 131 | 132 | m1.1.i.outcome.plot 133 | 134 | 135 | m1.1.i$summary.fixed 136 | 137 | a.did 138 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # statistical_rethinking_inla 2 | homework problems from the 2nd edition of Statistical Rethinking by Richard McElreath worked in R-INLA 3 | -------------------------------------------------------------------------------- /_site.yml: -------------------------------------------------------------------------------- 1 | name: "Statistical Rethinking homeworks in INLA" 2 | output_dir: "." 3 | navbar: 4 | title: "Home" 5 | left: 6 | - text: "Homework 2" 7 | href: rethinkingINLA_HW2.html 8 | - text: "Homework 3" 9 | href: rethinkingINLA_HW3.html 10 | - text: "Homework 4" 11 | href: rethinkingINLA_HW4.html 12 | - text: "Homework 5" 13 | href: rethinkingINLA_HW5.html 14 | - text: "Homework 6" 15 | href: rethinkingINLA_HW6.html 16 | - text: "Homework 8" 17 | href: rethinkingINLA_HW8.html 18 | - text: "Homework 9" 19 | href: rethinkingINLA_HW9.html 20 | - text: "Homework 10" 21 | href: rethinkingINLA_HW10.html 22 | 23 | 24 | output: 25 | html_document: 26 | theme: yeti 27 | highlight: textmate 28 | -------------------------------------------------------------------------------- /_site/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | Statistical Rethinking homeworks reworked in R-INLA 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 33 | 42 | 43 | 44 | 45 | 71 | 72 | 73 | 74 | 75 | 101 | 102 | 103 | 172 | 173 | 190 | 191 | 192 | 193 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 |
259 | 260 | 261 | 262 | 263 | 291 | 292 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 |
309 | 310 | 322 | 323 | 324 | 325 | 336 | 337 | 338 | 339 | 340 | 341 | 349 | 350 | 351 | 352 | -------------------------------------------------------------------------------- /_site/rethinkingINLA_HW2_files/figure-html/4.12-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/_site/rethinkingINLA_HW2_files/figure-html/4.12-1.png -------------------------------------------------------------------------------- /_site/rethinkingINLA_HW2_files/figure-html/4.13-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/_site/rethinkingINLA_HW2_files/figure-html/4.13-1.png -------------------------------------------------------------------------------- /_site/rethinkingINLA_HW2_files/figure-html/4.15-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/_site/rethinkingINLA_HW2_files/figure-html/4.15-1.png -------------------------------------------------------------------------------- /_site/rethinkingINLA_HW2_files/figure-html/4.38-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/_site/rethinkingINLA_HW2_files/figure-html/4.38-1.png -------------------------------------------------------------------------------- /_site/rethinkingINLA_HW2_files/figure-html/4.41-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/_site/rethinkingINLA_HW2_files/figure-html/4.41-1.png -------------------------------------------------------------------------------- /_site/rethinkingINLA_HW2_files/figure-html/4.45-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/_site/rethinkingINLA_HW2_files/figure-html/4.45-1.png -------------------------------------------------------------------------------- /_site/rethinkingINLA_HW2_files/figure-html/4.46-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/_site/rethinkingINLA_HW2_files/figure-html/4.46-1.png -------------------------------------------------------------------------------- /_site/rethinkingINLA_HW2_files/figure-html/4.49-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/_site/rethinkingINLA_HW2_files/figure-html/4.49-1.png -------------------------------------------------------------------------------- /_site/rethinkingINLA_HW2_files/figure-html/4.50 dens-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/_site/rethinkingINLA_HW2_files/figure-html/4.50 dens-1.png -------------------------------------------------------------------------------- /_site/rethinkingINLA_HW2_files/figure-html/4.50-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/_site/rethinkingINLA_HW2_files/figure-html/4.50-1.png -------------------------------------------------------------------------------- /_site/rethinkingINLA_HW2_files/figure-html/4.55-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/_site/rethinkingINLA_HW2_files/figure-html/4.55-1.png -------------------------------------------------------------------------------- /_site/rethinkingINLA_HW2_files/figure-html/4.56-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/_site/rethinkingINLA_HW2_files/figure-html/4.56-1.png -------------------------------------------------------------------------------- /_site/rethinkingINLA_HW2_files/figure-html/4.61-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/_site/rethinkingINLA_HW2_files/figure-html/4.61-1.png -------------------------------------------------------------------------------- /_site/rethinkingINLA_HW2_files/figure-html/4.63-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/_site/rethinkingINLA_HW2_files/figure-html/4.63-1.png -------------------------------------------------------------------------------- /_site/rethinkingINLA_HW2_files/figure-html/hw2 2 re-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/_site/rethinkingINLA_HW2_files/figure-html/hw2 2 re-1.png -------------------------------------------------------------------------------- /_site/rethinkingINLA_HW2_files/figure-html/hw2.2 inla clinear-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/_site/rethinkingINLA_HW2_files/figure-html/hw2.2 inla clinear-1.png -------------------------------------------------------------------------------- /_site/rethinkingINLA_HW3.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/_site/rethinkingINLA_HW3.pdf -------------------------------------------------------------------------------- /_site/rethinkingINLA_HW3_files/figure-html/hw3 dag-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/_site/rethinkingINLA_HW3_files/figure-html/hw3 dag-1.png -------------------------------------------------------------------------------- /_site/rethinkingINLA_HW4_files/figure-html/hw3 dag-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/_site/rethinkingINLA_HW4_files/figure-html/hw3 dag-1.png -------------------------------------------------------------------------------- /_site/rethinkingINLA_HW4_files/figure-html/hw4.2 dag-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/_site/rethinkingINLA_HW4_files/figure-html/hw4.2 dag-1.png -------------------------------------------------------------------------------- /_site/rethinkingINLA_HW5_files/figure-html/HW5 2a INLA-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/_site/rethinkingINLA_HW5_files/figure-html/HW5 2a INLA-1.png -------------------------------------------------------------------------------- /_site/rethinkingINLA_HW5_files/figure-html/HW5 2a re-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/_site/rethinkingINLA_HW5_files/figure-html/HW5 2a re-1.png -------------------------------------------------------------------------------- /_site/rethinkingINLA_HW5_files/figure-html/hw5 2b-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/_site/rethinkingINLA_HW5_files/figure-html/hw5 2b-1.png -------------------------------------------------------------------------------- /_site/rethinkingINLA_HW5_files/figure-html/hw5 3.a plot-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/_site/rethinkingINLA_HW5_files/figure-html/hw5 3.a plot-1.png -------------------------------------------------------------------------------- /_site/rethinkingINLA_HW5_files/figure-html/hw5.1 INLA-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/_site/rethinkingINLA_HW5_files/figure-html/hw5.1 INLA-1.png -------------------------------------------------------------------------------- /_site/rethinkingINLA_HW5_files/figure-html/hw5.1 re-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/_site/rethinkingINLA_HW5_files/figure-html/hw5.1 re-1.png -------------------------------------------------------------------------------- /_site/rethinkingINLA_HW5_files/figure-html/hw5.1 re-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/_site/rethinkingINLA_HW5_files/figure-html/hw5.1 re-2.png -------------------------------------------------------------------------------- /_site/rethinkingINLA_HW5_files/figure-html/hw5.1 re-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/_site/rethinkingINLA_HW5_files/figure-html/hw5.1 re-3.png -------------------------------------------------------------------------------- /_site/site_libs/bootstrap-3.3.5/css/fonts/Lato.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/_site/site_libs/bootstrap-3.3.5/css/fonts/Lato.ttf -------------------------------------------------------------------------------- /_site/site_libs/bootstrap-3.3.5/css/fonts/LatoBold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/_site/site_libs/bootstrap-3.3.5/css/fonts/LatoBold.ttf -------------------------------------------------------------------------------- /_site/site_libs/bootstrap-3.3.5/css/fonts/LatoItalic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/_site/site_libs/bootstrap-3.3.5/css/fonts/LatoItalic.ttf -------------------------------------------------------------------------------- /_site/site_libs/bootstrap-3.3.5/css/fonts/NewsCycle.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/_site/site_libs/bootstrap-3.3.5/css/fonts/NewsCycle.ttf -------------------------------------------------------------------------------- /_site/site_libs/bootstrap-3.3.5/css/fonts/NewsCycleBold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/_site/site_libs/bootstrap-3.3.5/css/fonts/NewsCycleBold.ttf -------------------------------------------------------------------------------- /_site/site_libs/bootstrap-3.3.5/css/fonts/OpenSans.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/_site/site_libs/bootstrap-3.3.5/css/fonts/OpenSans.ttf -------------------------------------------------------------------------------- /_site/site_libs/bootstrap-3.3.5/css/fonts/OpenSansBold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/_site/site_libs/bootstrap-3.3.5/css/fonts/OpenSansBold.ttf -------------------------------------------------------------------------------- /_site/site_libs/bootstrap-3.3.5/css/fonts/OpenSansBoldItalic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/_site/site_libs/bootstrap-3.3.5/css/fonts/OpenSansBoldItalic.ttf -------------------------------------------------------------------------------- /_site/site_libs/bootstrap-3.3.5/css/fonts/OpenSansItalic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/_site/site_libs/bootstrap-3.3.5/css/fonts/OpenSansItalic.ttf -------------------------------------------------------------------------------- /_site/site_libs/bootstrap-3.3.5/css/fonts/OpenSansLight.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/_site/site_libs/bootstrap-3.3.5/css/fonts/OpenSansLight.ttf -------------------------------------------------------------------------------- /_site/site_libs/bootstrap-3.3.5/css/fonts/OpenSansLightItalic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/_site/site_libs/bootstrap-3.3.5/css/fonts/OpenSansLightItalic.ttf -------------------------------------------------------------------------------- /_site/site_libs/bootstrap-3.3.5/css/fonts/Raleway.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/_site/site_libs/bootstrap-3.3.5/css/fonts/Raleway.ttf -------------------------------------------------------------------------------- /_site/site_libs/bootstrap-3.3.5/css/fonts/RalewayBold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/_site/site_libs/bootstrap-3.3.5/css/fonts/RalewayBold.ttf -------------------------------------------------------------------------------- /_site/site_libs/bootstrap-3.3.5/css/fonts/Roboto.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/_site/site_libs/bootstrap-3.3.5/css/fonts/Roboto.ttf -------------------------------------------------------------------------------- /_site/site_libs/bootstrap-3.3.5/css/fonts/RobotoBold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/_site/site_libs/bootstrap-3.3.5/css/fonts/RobotoBold.ttf -------------------------------------------------------------------------------- /_site/site_libs/bootstrap-3.3.5/css/fonts/RobotoLight.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/_site/site_libs/bootstrap-3.3.5/css/fonts/RobotoLight.ttf -------------------------------------------------------------------------------- /_site/site_libs/bootstrap-3.3.5/css/fonts/RobotoMedium.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/_site/site_libs/bootstrap-3.3.5/css/fonts/RobotoMedium.ttf -------------------------------------------------------------------------------- /_site/site_libs/bootstrap-3.3.5/css/fonts/SourceSansPro.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/_site/site_libs/bootstrap-3.3.5/css/fonts/SourceSansPro.ttf -------------------------------------------------------------------------------- /_site/site_libs/bootstrap-3.3.5/css/fonts/SourceSansProBold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/_site/site_libs/bootstrap-3.3.5/css/fonts/SourceSansProBold.ttf -------------------------------------------------------------------------------- /_site/site_libs/bootstrap-3.3.5/css/fonts/SourceSansProItalic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/_site/site_libs/bootstrap-3.3.5/css/fonts/SourceSansProItalic.ttf -------------------------------------------------------------------------------- /_site/site_libs/bootstrap-3.3.5/css/fonts/SourceSansProLight.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/_site/site_libs/bootstrap-3.3.5/css/fonts/SourceSansProLight.ttf -------------------------------------------------------------------------------- /_site/site_libs/bootstrap-3.3.5/css/fonts/Ubuntu.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/_site/site_libs/bootstrap-3.3.5/css/fonts/Ubuntu.ttf -------------------------------------------------------------------------------- /_site/site_libs/bootstrap-3.3.5/fonts/glyphicons-halflings-regular.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/_site/site_libs/bootstrap-3.3.5/fonts/glyphicons-halflings-regular.eot -------------------------------------------------------------------------------- /_site/site_libs/bootstrap-3.3.5/fonts/glyphicons-halflings-regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/_site/site_libs/bootstrap-3.3.5/fonts/glyphicons-halflings-regular.ttf -------------------------------------------------------------------------------- /_site/site_libs/bootstrap-3.3.5/fonts/glyphicons-halflings-regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/_site/site_libs/bootstrap-3.3.5/fonts/glyphicons-halflings-regular.woff -------------------------------------------------------------------------------- /_site/site_libs/bootstrap-3.3.5/fonts/glyphicons-halflings-regular.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/_site/site_libs/bootstrap-3.3.5/fonts/glyphicons-halflings-regular.woff2 -------------------------------------------------------------------------------- /_site/site_libs/bootstrap-3.3.5/js/npm.js: -------------------------------------------------------------------------------- 1 | // This file is autogenerated via the `commonjs` Grunt task. You can require() this file in a CommonJS environment. 2 | require('../../js/transition.js') 3 | require('../../js/alert.js') 4 | require('../../js/button.js') 5 | require('../../js/carousel.js') 6 | require('../../js/collapse.js') 7 | require('../../js/dropdown.js') 8 | require('../../js/modal.js') 9 | require('../../js/tooltip.js') 10 | require('../../js/popover.js') 11 | require('../../js/scrollspy.js') 12 | require('../../js/tab.js') 13 | require('../../js/affix.js') -------------------------------------------------------------------------------- /_site/site_libs/bootstrap-3.3.5/shim/html5shiv.min.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @preserve HTML5 Shiv 3.7.2 | @afarkas @jdalton @jon_neal @rem | MIT/GPL2 Licensed 3 | */ 4 | // Only run this code in IE 8 5 | if (!!window.navigator.userAgent.match("MSIE 8")) { 6 | !function(a,b){function c(a,b){var c=a.createElement("p"),d=a.getElementsByTagName("head")[0]||a.documentElement;return c.innerHTML="x",d.insertBefore(c.lastChild,d.firstChild)}function d(){var a=t.elements;return"string"==typeof a?a.split(" "):a}function e(a,b){var c=t.elements;"string"!=typeof c&&(c=c.join(" ")),"string"!=typeof a&&(a=a.join(" ")),t.elements=c+" "+a,j(b)}function f(a){var b=s[a[q]];return b||(b={},r++,a[q]=r,s[r]=b),b}function g(a,c,d){if(c||(c=b),l)return c.createElement(a);d||(d=f(c));var e;return e=d.cache[a]?d.cache[a].cloneNode():p.test(a)?(d.cache[a]=d.createElem(a)).cloneNode():d.createElem(a),!e.canHaveChildren||o.test(a)||e.tagUrn?e:d.frag.appendChild(e)}function h(a,c){if(a||(a=b),l)return a.createDocumentFragment();c=c||f(a);for(var e=c.frag.cloneNode(),g=0,h=d(),i=h.length;i>g;g++)e.createElement(h[g]);return e}function i(a,b){b.cache||(b.cache={},b.createElem=a.createElement,b.createFrag=a.createDocumentFragment,b.frag=b.createFrag()),a.createElement=function(c){return t.shivMethods?g(c,a,b):b.createElem(c)},a.createDocumentFragment=Function("h,f","return function(){var n=f.cloneNode(),c=n.createElement;h.shivMethods&&("+d().join().replace(/[\w\-:]+/g,function(a){return b.createElem(a),b.frag.createElement(a),'c("'+a+'")'})+");return n}")(t,b.frag)}function j(a){a||(a=b);var d=f(a);return!t.shivCSS||k||d.hasCSS||(d.hasCSS=!!c(a,"article,aside,dialog,figcaption,figure,footer,header,hgroup,main,nav,section{display:block}mark{background:#FF0;color:#000}template{display:none}")),l||i(a,d),a}var k,l,m="3.7.2",n=a.html5||{},o=/^<|^(?:button|map|select|textarea|object|iframe|option|optgroup)$/i,p=/^(?:a|b|code|div|fieldset|h1|h2|h3|h4|h5|h6|i|label|li|ol|p|q|span|strong|style|table|tbody|td|th|tr|ul)$/i,q="_html5shiv",r=0,s={};!function(){try{var a=b.createElement("a");a.innerHTML="",k="hidden"in a,l=1==a.childNodes.length||function(){b.createElement("a");var a=b.createDocumentFragment();return"undefined"==typeof a.cloneNode||"undefined"==typeof a.createDocumentFragment||"undefined"==typeof a.createElement}()}catch(c){k=!0,l=!0}}();var t={elements:n.elements||"abbr article aside audio bdi canvas data datalist details dialog figcaption figure footer header hgroup main mark meter nav output picture progress section summary template time video",version:m,shivCSS:n.shivCSS!==!1,supportsUnknownElements:l,shivMethods:n.shivMethods!==!1,type:"default",shivDocument:j,createElement:g,createDocumentFragment:h,addElements:e};a.html5=t,j(b)}(this,document); 7 | }; 8 | -------------------------------------------------------------------------------- /_site/site_libs/bootstrap-3.3.5/shim/respond.min.js: -------------------------------------------------------------------------------- 1 | /*! Respond.js v1.4.2: min/max-width media query polyfill * Copyright 2013 Scott Jehl 2 | * Licensed under https://github.com/scottjehl/Respond/blob/master/LICENSE-MIT 3 | * */ 4 | 5 | // Only run this code in IE 8 6 | if (!!window.navigator.userAgent.match("MSIE 8")) { 7 | !function(a){"use strict";a.matchMedia=a.matchMedia||function(a){var b,c=a.documentElement,d=c.firstElementChild||c.firstChild,e=a.createElement("body"),f=a.createElement("div");return f.id="mq-test-1",f.style.cssText="position:absolute;top:-100em",e.style.background="none",e.appendChild(f),function(a){return f.innerHTML='­',c.insertBefore(e,d),b=42===f.offsetWidth,c.removeChild(e),{matches:b,media:a}}}(a.document)}(this),function(a){"use strict";function b(){u(!0)}var c={};a.respond=c,c.update=function(){};var d=[],e=function(){var b=!1;try{b=new a.XMLHttpRequest}catch(c){b=new a.ActiveXObject("Microsoft.XMLHTTP")}return function(){return b}}(),f=function(a,b){var c=e();c&&(c.open("GET",a,!0),c.onreadystatechange=function(){4!==c.readyState||200!==c.status&&304!==c.status||b(c.responseText)},4!==c.readyState&&c.send(null))};if(c.ajax=f,c.queue=d,c.regex={media:/@media[^\{]+\{([^\{\}]*\{[^\}\{]*\})+/gi,keyframes:/@(?:\-(?:o|moz|webkit)\-)?keyframes[^\{]+\{(?:[^\{\}]*\{[^\}\{]*\})+[^\}]*\}/gi,urls:/(url\()['"]?([^\/\)'"][^:\)'"]+)['"]?(\))/g,findStyles:/@media *([^\{]+)\{([\S\s]+?)$/,only:/(only\s+)?([a-zA-Z]+)\s?/,minw:/\([\s]*min\-width\s*:[\s]*([\s]*[0-9\.]+)(px|em)[\s]*\)/,maxw:/\([\s]*max\-width\s*:[\s]*([\s]*[0-9\.]+)(px|em)[\s]*\)/},c.mediaQueriesSupported=a.matchMedia&&null!==a.matchMedia("only all")&&a.matchMedia("only all").matches,!c.mediaQueriesSupported){var g,h,i,j=a.document,k=j.documentElement,l=[],m=[],n=[],o={},p=30,q=j.getElementsByTagName("head")[0]||k,r=j.getElementsByTagName("base")[0],s=q.getElementsByTagName("link"),t=function(){var a,b=j.createElement("div"),c=j.body,d=k.style.fontSize,e=c&&c.style.fontSize,f=!1;return b.style.cssText="position:absolute;font-size:1em;width:1em",c||(c=f=j.createElement("body"),c.style.background="none"),k.style.fontSize="100%",c.style.fontSize="100%",c.appendChild(b),f&&k.insertBefore(c,k.firstChild),a=b.offsetWidth,f?k.removeChild(c):c.removeChild(b),k.style.fontSize=d,e&&(c.style.fontSize=e),a=i=parseFloat(a)},u=function(b){var c="clientWidth",d=k[c],e="CSS1Compat"===j.compatMode&&d||j.body[c]||d,f={},o=s[s.length-1],r=(new Date).getTime();if(b&&g&&p>r-g)return a.clearTimeout(h),h=a.setTimeout(u,p),void 0;g=r;for(var v in l)if(l.hasOwnProperty(v)){var w=l[v],x=w.minw,y=w.maxw,z=null===x,A=null===y,B="em";x&&(x=parseFloat(x)*(x.indexOf(B)>-1?i||t():1)),y&&(y=parseFloat(y)*(y.indexOf(B)>-1?i||t():1)),w.hasquery&&(z&&A||!(z||e>=x)||!(A||y>=e))||(f[w.media]||(f[w.media]=[]),f[w.media].push(m[w.rules]))}for(var C in n)n.hasOwnProperty(C)&&n[C]&&n[C].parentNode===q&&q.removeChild(n[C]);n.length=0;for(var D in f)if(f.hasOwnProperty(D)){var E=j.createElement("style"),F=f[D].join("\n");E.type="text/css",E.media=D,q.insertBefore(E,o.nextSibling),E.styleSheet?E.styleSheet.cssText=F:E.appendChild(j.createTextNode(F)),n.push(E)}},v=function(a,b,d){var e=a.replace(c.regex.keyframes,"").match(c.regex.media),f=e&&e.length||0;b=b.substring(0,b.lastIndexOf("/"));var g=function(a){return a.replace(c.regex.urls,"$1"+b+"$2$3")},h=!f&&d;b.length&&(b+="/"),h&&(f=1);for(var i=0;f>i;i++){var j,k,n,o;h?(j=d,m.push(g(a))):(j=e[i].match(c.regex.findStyles)&&RegExp.$1,m.push(RegExp.$2&&g(RegExp.$2))),n=j.split(","),o=n.length;for(var p=0;o>p;p++)k=n[p],l.push({media:k.split("(")[0].match(c.regex.only)&&RegExp.$2||"all",rules:m.length-1,hasquery:k.indexOf("(")>-1,minw:k.match(c.regex.minw)&&parseFloat(RegExp.$1)+(RegExp.$2||""),maxw:k.match(c.regex.maxw)&&parseFloat(RegExp.$1)+(RegExp.$2||"")})}u()},w=function(){if(d.length){var b=d.shift();f(b.href,function(c){v(c,b.href,b.media),o[b.href]=!0,a.setTimeout(function(){w()},0)})}},x=function(){for(var b=0;b'); 25 | show = (show || $(this).hasClass('fold-show')) && !$(this).hasClass('fold-hide'); 26 | if (show) div.addClass('in'); 27 | var id = 'rcode-643E0F36' + currentIndex++; 28 | div.attr('id', id); 29 | $(this).before(div); 30 | $(this).detach().appendTo(div); 31 | 32 | // add a show code button right above 33 | var showCodeText = $('' + (show ? 'Hide' : 'Code') + ''); 34 | var showCodeButton = $(''); 35 | showCodeButton.append(showCodeText); 36 | showCodeButton 37 | .attr('data-toggle', 'collapse') 38 | .attr('data-target', '#' + id) 39 | .attr('aria-expanded', show) 40 | .attr('aria-controls', id); 41 | 42 | var buttonRow = $('
'); 43 | var buttonCol = $('
'); 44 | 45 | buttonCol.append(showCodeButton); 46 | buttonRow.append(buttonCol); 47 | 48 | div.before(buttonRow); 49 | 50 | // update state of button on show/hide 51 | div.on('hidden.bs.collapse', function () { 52 | showCodeText.text('Code'); 53 | }); 54 | div.on('show.bs.collapse', function () { 55 | showCodeText.text('Hide'); 56 | }); 57 | }); 58 | 59 | } 60 | -------------------------------------------------------------------------------- /_site/site_libs/navigation-1.1/sourceembed.js: -------------------------------------------------------------------------------- 1 | 2 | window.initializeSourceEmbed = function(filename) { 3 | $("#rmd-download-source").click(function() { 4 | var src = $("#rmd-source-code").html(); 5 | var a = document.createElement('a'); 6 | a.href = "data:text/x-r-markdown;base64," + src; 7 | a.download = filename; 8 | document.body.appendChild(a); 9 | a.click(); 10 | document.body.removeChild(a); 11 | }); 12 | }; 13 | -------------------------------------------------------------------------------- /_site/site_libs/navigation-1.1/tabsets.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | /** 4 | * jQuery Plugin: Sticky Tabs 5 | * 6 | * @author Aidan Lister 7 | * adapted by Ruben Arslan to activate parent tabs too 8 | * http://www.aidanlister.com/2014/03/persisting-the-tab-state-in-bootstrap/ 9 | */ 10 | (function($) { 11 | "use strict"; 12 | $.fn.rmarkdownStickyTabs = function() { 13 | var context = this; 14 | // Show the tab corresponding with the hash in the URL, or the first tab 15 | var showStuffFromHash = function() { 16 | var hash = window.location.hash; 17 | var selector = hash ? 'a[href="' + hash + '"]' : 'li.active > a'; 18 | var $selector = $(selector, context); 19 | if($selector.data('toggle') === "tab") { 20 | $selector.tab('show'); 21 | // walk up the ancestors of this element, show any hidden tabs 22 | $selector.parents('.section.tabset').each(function(i, elm) { 23 | var link = $('a[href="#' + $(elm).attr('id') + '"]'); 24 | if(link.data('toggle') === "tab") { 25 | link.tab("show"); 26 | } 27 | }); 28 | } 29 | }; 30 | 31 | 32 | // Set the correct tab when the page loads 33 | showStuffFromHash(context); 34 | 35 | // Set the correct tab when a user uses their back/forward button 36 | $(window).on('hashchange', function() { 37 | showStuffFromHash(context); 38 | }); 39 | 40 | // Change the URL when tabs are clicked 41 | $('a', context).on('click', function(e) { 42 | history.pushState(null, null, this.href); 43 | showStuffFromHash(context); 44 | }); 45 | 46 | return this; 47 | }; 48 | }(jQuery)); 49 | 50 | window.buildTabsets = function(tocID) { 51 | 52 | // build a tabset from a section div with the .tabset class 53 | function buildTabset(tabset) { 54 | 55 | // check for fade and pills options 56 | var fade = tabset.hasClass("tabset-fade"); 57 | var pills = tabset.hasClass("tabset-pills"); 58 | var navClass = pills ? "nav-pills" : "nav-tabs"; 59 | 60 | // determine the heading level of the tabset and tabs 61 | var match = tabset.attr('class').match(/level(\d) /); 62 | if (match === null) 63 | return; 64 | var tabsetLevel = Number(match[1]); 65 | var tabLevel = tabsetLevel + 1; 66 | 67 | // find all subheadings immediately below 68 | var tabs = tabset.find("div.section.level" + tabLevel); 69 | if (!tabs.length) 70 | return; 71 | 72 | // create tablist and tab-content elements 73 | var tabList = $(''); 74 | $(tabs[0]).before(tabList); 75 | var tabContent = $('
'); 76 | $(tabs[0]).before(tabContent); 77 | 78 | // build the tabset 79 | var activeTab = 0; 80 | tabs.each(function(i) { 81 | 82 | // get the tab div 83 | var tab = $(tabs[i]); 84 | 85 | // get the id then sanitize it for use with bootstrap tabs 86 | var id = tab.attr('id'); 87 | 88 | // see if this is marked as the active tab 89 | if (tab.hasClass('active')) 90 | activeTab = i; 91 | 92 | // remove any table of contents entries associated with 93 | // this ID (since we'll be removing the heading element) 94 | $("div#" + tocID + " li a[href='#" + id + "']").parent().remove(); 95 | 96 | // sanitize the id for use with bootstrap tabs 97 | id = id.replace(/[.\/?&!#<>]/g, '').replace(/\s/g, '_'); 98 | tab.attr('id', id); 99 | 100 | // get the heading element within it, grab it's text, then remove it 101 | var heading = tab.find('h' + tabLevel + ':first'); 102 | var headingText = heading.html(); 103 | heading.remove(); 104 | 105 | // build and append the tab list item 106 | var a = $('' + headingText + ''); 107 | a.attr('href', '#' + id); 108 | a.attr('aria-controls', id); 109 | var li = $('
  • '); 110 | li.append(a); 111 | tabList.append(li); 112 | 113 | // set it's attributes 114 | tab.attr('role', 'tabpanel'); 115 | tab.addClass('tab-pane'); 116 | tab.addClass('tabbed-pane'); 117 | if (fade) 118 | tab.addClass('fade'); 119 | 120 | // move it into the tab content div 121 | tab.detach().appendTo(tabContent); 122 | }); 123 | 124 | // set active tab 125 | $(tabList.children('li')[activeTab]).addClass('active'); 126 | var active = $(tabContent.children('div.section')[activeTab]); 127 | active.addClass('active'); 128 | if (fade) 129 | active.addClass('in'); 130 | 131 | if (tabset.hasClass("tabset-sticky")) 132 | tabset.rmarkdownStickyTabs(); 133 | } 134 | 135 | // convert section divs with the .tabset class to tabsets 136 | var tabsets = $("div.section.tabset"); 137 | tabsets.each(function(i) { 138 | buildTabset($(tabsets[i])); 139 | }); 140 | }; 141 | 142 | -------------------------------------------------------------------------------- /_site/site_libs/tocify-1.9.1/jquery.tocify.css: -------------------------------------------------------------------------------- 1 | /* 2 | * jquery.tocify.css 1.9.1 3 | * Author: @gregfranko 4 | */ 5 | 6 | /* The Table of Contents container element */ 7 | .tocify { 8 | width: 20%; 9 | max-height: 90%; 10 | overflow: auto; 11 | margin-left: 2%; 12 | position: fixed; 13 | border: 1px solid #ccc; 14 | border-radius: 6px; 15 | } 16 | 17 | /* The Table of Contents is composed of multiple nested unordered lists. These styles remove the default styling of an unordered list because it is ugly. */ 18 | .tocify ul, .tocify li { 19 | list-style: none; 20 | margin: 0; 21 | padding: 0; 22 | border: none; 23 | line-height: 30px; 24 | } 25 | 26 | /* Top level header elements */ 27 | .tocify-header { 28 | text-indent: 10px; 29 | } 30 | 31 | /* Top level subheader elements. These are the first nested items underneath a header element. */ 32 | .tocify-subheader { 33 | text-indent: 20px; 34 | display: none; 35 | } 36 | 37 | /* Makes the font smaller for all subheader elements. */ 38 | .tocify-subheader li { 39 | font-size: 12px; 40 | } 41 | 42 | /* Further indents second level subheader elements. */ 43 | .tocify-subheader .tocify-subheader { 44 | text-indent: 30px; 45 | } 46 | .tocify-subheader .tocify-subheader .tocify-subheader { 47 | text-indent: 40px; 48 | } 49 | .tocify-subheader .tocify-subheader .tocify-subheader .tocify-subheader { 50 | text-indent: 50px; 51 | } 52 | .tocify-subheader .tocify-subheader .tocify-subheader .tocify-subheader .tocify-subheader { 53 | text-indent: 60px; 54 | } 55 | 56 | /* Twitter Bootstrap Override Style */ 57 | .tocify .tocify-item > a, .tocify .nav-list .nav-header { 58 | margin: 0px; 59 | } 60 | 61 | /* Twitter Bootstrap Override Styles */ 62 | .tocify .tocify-item a, .tocify .list-group-item { 63 | padding: 5px; 64 | } 65 | 66 | .tocify .nav-pills > li { 67 | float: none; 68 | } 69 | 70 | /* We don't override the bootstrap colors because this gives us the 71 | wrong selection colors when using bootstrap themes 72 | 73 | .tocify .list-group-item:hover, .tocify .list-group-item:focus { 74 | background-color: #f5f5f5; 75 | } 76 | 77 | .tocify .list-group-item.active:hover, .tocify .list-group-item.active:focus { 78 | background-color: #428bca; 79 | } 80 | */ 81 | 82 | /* End Twitter Bootstrap Override Styles */ 83 | -------------------------------------------------------------------------------- /google03e966e10bf03c1a.html: -------------------------------------------------------------------------------- 1 | google-site-verification: google03e966e10bf03c1a.html -------------------------------------------------------------------------------- /iid123d.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/iid123d.pdf -------------------------------------------------------------------------------- /index.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Statistical Rethinking 2nd edition homework reworked in R-INLA and the tidyverse" 3 | author: "Anna B. Kawiecki" 4 | output: 5 | html_document: 6 | fig_width: 1 7 | --- 8 | 9 | This is an attempt to re-code the homework from the 2nd edition of Statistical Rethinking by Richard McElreath using R-INLA. 10 | 11 | Solutions to the homework exercises using the rethinking package are provided for comparison. 12 | 13 | **Resources used for this work:** 14 | 15 | [Statistical Rethinking: A Bayesian Course with Examples in R and Stan. Second edition by Richard McElreath](http://xcelab.net/rm/statistical-rethinking/) 16 | 17 | [Homework Solutions of Statistical Rethinking by Richard McElreath](https://github.com/rmcelreath/statrethinking_winter2019/tree/master/homework) 18 | 19 | [Bayesian inference with INLA by Virgilio Gómez-Rubio](https://becarioprecario.bitbucket.io/inla-gitbook/) 20 | 21 | * INLA linear regression examples: 22 | 23 | https://people.bath.ac.uk/jjf23/brinla/chicago.html 24 | 25 | https://haakonbakka.bitbucket.io/btopic112.html 26 | 27 | * INLA binomial examples: 28 | 29 | https://rpubs.com/corey_sparks/431920 30 | 31 | * INLA poisson examples: 32 | 33 | https://www.flutterbys.com.au/stats/tut/tut12.10.html#h2_16 34 | 35 | * INLA single random effect examples: 36 | 37 | https://people.bath.ac.uk/jjf23/inla/oneway.html 38 | 39 | https://people.bath.ac.uk/jjf23/brinla/reeds.html 40 | 41 | * INLA correlated slope and intercept examples: 42 | 43 | https://rpubs.com/corey_sparks/431920 44 | 45 | https://groups.google.com/g/r-inla-discussion-group/c/iQELaQF8M9Q 46 | 47 | * INLA missing data and imputation examples: 48 | 49 | https://becarioprecario.bitbucket.io/inla-gitbook/ch-missing.html#sec:missresp 50 | 51 | * INLA measurement error examples: 52 | 53 | http://www.biometrische-gesellschaft.de/fileadmin/AG_Daten/BayesMethodik/workshops_etc/2016-12_Mainz/Muff2016-slides.pdf 54 | 55 | http://www.r-inla.org/models/tools#TOC-Copying-a-model 56 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | Statistical Rethinking 2nd edition homework reworked in R-INLA and the tidyverse 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 35 | 36 | 37 | 42 | 51 | 52 | 53 | 54 | 80 | 81 | 82 | 83 | 84 | 85 | 111 | 112 | 113 | 182 | 183 | 200 | 201 | 202 | 203 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 |
    269 | 270 | 271 | 272 | 273 | 316 | 317 | 325 | 326 | 327 |

    This is an attempt to re-code the homework from the 2nd edition of Statistical Rethinking by Richard McElreath using R-INLA.

    328 |

    Solutions to the homework exercises using the rethinking package are provided for comparison.

    329 |

    Resources used for this work:

    330 |

    Statistical Rethinking: A Bayesian Course with Examples in R and Stan. Second edition by Richard McElreath

    331 |

    Homework Solutions of Statistical Rethinking by Richard McElreath

    332 |

    Bayesian inference with INLA by Virgilio Gómez-Rubio

    333 |
      334 |
    • INLA linear regression examples:
    • 335 |
    336 |

    https://people.bath.ac.uk/jjf23/brinla/chicago.html

    337 |

    https://haakonbakka.bitbucket.io/btopic112.html

    338 |
      339 |
    • INLA binomial examples:
    • 340 |
    341 |

    https://rpubs.com/corey_sparks/431920

    342 |
      343 |
    • INLA poisson examples:
    • 344 |
    345 |

    https://www.flutterbys.com.au/stats/tut/tut12.10.html#h2_16

    346 |
      347 |
    • INLA single random effect examples:
    • 348 |
    349 |

    https://people.bath.ac.uk/jjf23/inla/oneway.html

    350 |

    https://people.bath.ac.uk/jjf23/brinla/reeds.html

    351 |
      352 |
    • INLA correlated slope and intercept examples:
    • 353 |
    354 |

    https://rpubs.com/corey_sparks/431920

    355 |

    https://groups.google.com/g/r-inla-discussion-group/c/iQELaQF8M9Q

    356 |
      357 |
    • INLA missing data and imputation examples:
    • 358 |
    359 |

    https://becarioprecario.bitbucket.io/inla-gitbook/ch-missing.html#sec:missresp

    360 |
      361 |
    • INLA measurement error examples:
    • 362 |
    363 |

    http://www.biometrische-gesellschaft.de/fileadmin/AG_Daten/BayesMethodik/workshops_etc/2016-12_Mainz/Muff2016-slides.pdf

    364 |

    http://www.r-inla.org/models/tools#TOC-Copying-a-model

    365 | 366 | 367 | 368 | 369 |
    370 | 371 | 383 | 384 | 385 | 386 | 397 | 398 | 399 | 400 | 401 | 402 | 410 | 411 | 412 | 413 | -------------------------------------------------------------------------------- /rethinkingINLA_HW10.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Statistical Rethinking 2nd edition Homework 9 in INLA" 3 | output: 4 | html_document: 5 | toc: true 6 | toc_float: true 7 | --- 8 | 9 | ```{r global_options, include=FALSE} 10 | knitr::opts_chunk$set(message=FALSE) 11 | ``` 12 | 13 | ```{r libraries, message= FALSE} 14 | 15 | library(tidyverse) 16 | library(rethinking) 17 | library(dagitty) 18 | library(INLA) 19 | library(knitr) 20 | library(stringr) 21 | ``` 22 | 23 | # 1. data(Primates301) measurement error: INCOMPLETE 24 | 25 | Consider the relationship between brain volume (brain) and bodymass (body) in the data (Primates301). These values are presented as single values for each species. However, there is always a range of sizes in a species, and some of these measurements are taken from very small samples. So these values are measured with some unknown error. 26 | 27 | We don’t have the raw measurements to work with—that would be best. But we can imagine what might happen if we had them. Suppose error is proportional to the measurement. This makes sense, because larger animals have larger variation. As a consequence, the uncertainty is not uniform across the values and this could mean trouble. 28 | 29 | Let’s make up some standard errors for these measurements, to see what might happen. Load the data and scale the the measurements so the maximum is 1 in both cases: 30 | 31 | ```{r 10.1 } 32 | 33 | library(rethinking) 34 | data(Primates301) 35 | d <- Primates301 36 | cc <- complete.cases( d$brain , d$body ) 37 | B <- d$brain[cc] 38 | M <- d$body[cc] 39 | B <- B / max(B) 40 | M <- M / max(M) 41 | ``` 42 | 43 | 44 | Now I’ll make up some standard errors for B and M, assuming error is 10% of the measurement. 45 | 46 | ```{r 10.1 error} 47 | Bse <- B*0.1 48 | Mse <- M*0.1 49 | ``` 50 | 51 | Let’s model these variables with this relationship: 52 | Bi ∼ Log-Normal(μi, σ) 53 | μi =α+βlogMi 54 | 55 | 56 | This says that brain volume is a log-normal variable, and the mean on the log scale is given by μ. What this model implies is that the expected value of B is: 57 | E(Bi|Mi) = exp(α)Mi^β 58 | 59 | 60 | So this is a standard allometric scaling relationship—incredibly common in biology. 61 | 62 | Ignoring measurement error, the corresponding ulam model is: 63 | 64 | 65 | ```{r 10.1 model} 66 | dat_list <- list( B = B, 67 | M=M) 68 | m1.1 <- ulam( 69 | alist( 70 | B ~ dlnorm( mu , sigma ), 71 | mu <- a + b*log(M), 72 | a ~ normal(0,1), 73 | b ~ normal(0,1), 74 | sigma ~ exponential(1) 75 | ) , data=dat_list ) 76 | 77 | precis( m1.1 ) 78 | ``` 79 | 80 | Your job is to add the measurement errors to this model. Use the divorce/marriage example in the chapter as a guide. It might help to initialize the unobserved true values of B and M using the observed values, by adding a list like this to ulam: 81 | 82 | ```{r 10.1 list} 83 | start=list( M_true=dat_list$M , B_true=dat_list$B ) 84 | ``` 85 | 86 | 87 | Compare the inference of the measurement error model to those of m1.1 above. Has anything changed? Why or why not? 88 | 89 | ## 1.1 model with measurement error 90 | 91 | To build the measurement error model, all we really need to do is add the observation process. This means that the observed values arise from their own distribution, each having a true value as the mean. We use these unknown true values in the regression. 92 | 93 | ### 1.1 rethinking 94 | 95 | The top chunk is the model for the B values. The first line is the measurement process. Then the next two lines are the same regression as before, but with B_true replacing the observed B values. Likewise M_true replaces the observed M in the linear model. 96 | The second chunk is the measurement model for M. The prior for M_true covers the entire range of the normalize variable—it ranges from 0 to 1 now, recall, because we scaled it that way to start by dividing by the maximum observed value. 97 | The last chunk holds the same priors as before. 98 | 99 | Note the control list at the bottom. If you run this model without that, it will work, but be inefficient and warn about exceeding maximum “treedepth.” This is not a concern for the validity of the chains, just how well they run. Treedepth is a control parameter for NUTS algorithm. The Stan manual contains more detail, if you want it. 100 | 101 | ```{r 10.1 error model re, eval= FALSE} 102 | 103 | d.complete <- d[which(cc ==TRUE),] 104 | 105 | N_spp <- nrow(d.complete) 106 | 107 | m1.2 <- ulam( alist( 108 | # B model 109 | B ~ normal( B_true , Bse ), 110 | vector[N_spp]:B_true ~ dlnorm( mu , sigma ), 111 | mu <- a + b*log( M_true[i] ), 112 | # M model 113 | M ~ normal( M_true , Mse ), 114 | vector[N_spp]:M_true ~ normal( 0.5 , 1 ), 115 | # priors 116 | a ~ normal(0,1), 117 | b ~ normal(0,1), 118 | sigma ~ exponential(1) ), 119 | data=dat_list , 120 | start=list( M_true=dat_list$M , B_true=dat_list$B ) , 121 | chains=4 , cores=4 , 122 | control=list(max_treedepth=15) ) 123 | 124 | precis( m1.2 ) 125 | 126 | ``` 127 | 128 | Those 364 hidden parameters are the estimated true values. We can look at those later on. For now, notice that the posterior distributions of a and b are nearly identical to m1.1. Adding measurement error hasn’t changed a thing! 129 | 130 | 131 | Plotting the regression against the observed values: 132 | 133 | 134 | ```{r 10.1 measurement error obs value plot re, eval= FALSE} 135 | plot( B ~ M , xlab="body mass" , ylab="brain volume" , col=rangi2 , pch=16 ) 136 | post <- extract.samples(m1.2) 137 | for ( i in 1:50 ) curve( exp(post$a[i])*x^(post$b[i]) , add=TRUE , col=grau(0.2) ) 138 | 139 | ``` 140 | 141 | The two points in the upper right are gorillas. Most primates are small, and obviously gorillas have something special going on. Now let’s plot the estimated values on this: 142 | 143 | 144 | ```{r 10.1 measurement error est value plot re, eval= FALSE} 145 | B_est <- apply( post$B_true , 2 , mean ) 146 | M_est <- apply( post$M_true , 2 , mean ) 147 | plot( B ~ M , xlab="body mass" , ylab="brain volume" , col=rangi2 , pch=16 ) points( M_est , B_est , pch=1 , lwd=1.5 ) 148 | x_seq <- seq( from=0 , to=1 , length.out=100 ) 149 | EB <- sapply( x_seq , function(x) mean( exp(post$a)*x^(post$b) ) ) lines( x_seq , EB ) 150 | ``` 151 | 152 | The open points are the posterior mean estimates. Notice that they have moved towards the regression line, as you’d expect. But even the outlier gorillas haven’t moved much. The assumed error just isn’t big enough to get them any closer. 153 | If you increase the amount of error, you can get all of the species to fall right on the regression line. Try for example 30% error. The model will mix poorly, but take a look at the inferred true values. 154 | The truth of this example is that there are just so many small primates that they dominate the relationship. And their measurement errors are also smaller (in abso- lute terms). So adding plausible amounts of measurement error here doesn’t make a big difference. We still don’t have a good explanation for gorillas. 155 | 156 | 157 | Before moving on, I’ll also plot the estimated species values with 50% compati- bility ellipses. 158 | 159 | 160 | ```{r 10.1 ellipse plot re, eval= FALSE} 161 | library(ellipse) 162 | plot( B_est ~ M_est , xlab="body mass" , ylab="brain volume" , lwd=1.5 , 163 | col=grau() , xlim=c(0,1.2) , ylim=c(0,1.2) ) 164 | 165 | for ( i in 1:length(B_est) ) { 166 | SIGMA <- cov( cbind( post$M_true[,i] , post$B_true[,i] ) ) 167 | el <- ellipse( SIGMA , centre=c(M_est[i],B_est[i]) , level=0.5 ) lines( el , col=grau(0.3) ) 168 | } 169 | ``` 170 | 171 | 172 | ### 1.1 INLA 173 | 174 | good resource for this: 175 | http://www.biometrische-gesellschaft.de/fileadmin/AG_Daten/BayesMethodik/workshops_etc/2016-12_Mainz/Muff2016-slides.pdf 176 | 177 | http://www.r-inla.org/models/tools#TOC-Copying-a-model 178 | 179 | **But i can't wrap my head around it right now.** 180 | ```{r 10.1 INLA} 181 | 182 | d1.i <- d %>% 183 | filter(!is.na(brain) &!is.na(body) ) %>% 184 | mutate(B= brain/max(brain), 185 | M= body/max(body), 186 | Bse= B*0.1, 187 | Mse= M*0.1) 188 | 189 | n.spp <- nrow(d1.i) # 182 190 | 191 | M_true= rnorm(n.spp, d1.i$M, d1.i$Mse) 192 | ``` 193 | 194 | 195 | # 2. data(Primates301) impute missing values for brain size 196 | 197 | Now consider missing values—this data set is lousy with them. You can ignore measurement error in this problem. Let’s get a quick idea of the missing values by counting them in each variable: 198 | 199 | ```{r 10.2 data} 200 | 201 | library(rethinking) 202 | data(Primates301) 203 | d <- Primates301 204 | colSums( is.na(d) ) 205 | 206 | ``` 207 | 208 | We’ll continue to focus on just brain and body, to stave off insanity. Consider only those species with measured body masses: 209 | 210 | 211 | ```{r 10.2 data filter} 212 | 213 | cc <- complete.cases( d$body ) 214 | M <- d$body[cc] 215 | M <- M / max(M) 216 | B <- d$brain[cc] 217 | B <- B / max( B , na.rm=TRUE ) 218 | ``` 219 | 220 | You should end up with 238 species and 56 missing brain values among them. 221 | 222 | 223 | **First, consider whether there is a pattern to the missing values. Does it look like missing values are associated with particular values of body mass? Draw a DAG that represents how missingness works in this case. Which type (MCAR, MAR, MNAR) is this?** 224 | 225 | **Second, impute missing values for brain size.** 226 | 227 | It might help to initialize the 56 imputed variables to a valid value: 228 | 229 | 230 | ```{r 10.2 imputed} 231 | start=list( B_impute=rep(0.5,56) ) 232 | ``` 233 | 234 | 235 | This just helps the chain get started. 236 | 237 | **Compare the inferences to an analysis that drops all the missing values**. Has anything changed? Why or why not? Hint: Consider the density of data in the ranges where there are missing values. You might want to plot the imputed brain sizes together with the observed values. 238 | 239 | ## 2.1 pattern of the missing values 240 | 241 | 242 | First,let’s see where the missing values are,to get some idea about the missingness mechanism. If missing brain sizes are associated with certain ranges of body sizes, then it isn’t plausibly MCAR (dog eats any homework). Let’s plot body size against missingness: 243 | ```{r 2.1 plot } 244 | 245 | Bna <- is.na(d$brain[cc]) 246 | plot( Bna ~ M , ylab="B is NA" ) 247 | 248 | ``` 249 | Looks like the missing brain values are almost all for small bodied species. This implies at least a MAR (dog eats students’ homework) mechanism. Let’s try a DAG to express it: 250 | 251 | ```{r 2.1 dag} 252 | library(dagitty) 253 | 254 | hw10.2.1.dag <- dagitty('dag{ 255 | M -> R_B -> "B*" <- B 256 | M -> B }') 257 | 258 | plot(hw10.2.1.dag) 259 | 260 | 261 | ``` 262 | M here is body mass, B (unobserved) is brain size, R_B is the missingness mechanism, and B* is the observed brain sizes (with missing values). The arrow from M to R_B indicates that body size influences missingness. In this case, it would imply that small body size makes a missing brain value more likely. 263 | 264 | ## 2.2 impute missing values for brain size 265 | 266 | Now let’s do some imputation. Remember that the model for imputation is really no different than an ordinary model. It just needs a prior for any variable with missing values. In this case, the missing values are in the outcome, so the likelihood is the prior we need. So the model doesn’t change at all. 267 | 268 | ### 2.2 rethinking 269 | 270 | In ulam: 271 | 272 | ```{r 10.2.2 m2.2a re} 273 | dat_list <- list( 274 | B = B, 275 | M=M) 276 | 277 | 278 | m2.2 <- ulam( alist( 279 | B ~ dlnorm( mu , sigma ), 280 | mu <- a + b*log(M), 281 | a ~ normal(0,1), 282 | b ~ normal(0,1), 283 | sigma ~ exponential(1) ), 284 | data=dat_list , chains=4 , cores=4 , start=list( B_impute = rep(0.5,56) ) ) 285 | 286 | 287 | 288 | ``` 289 | 290 | ulam figures out how to do the imputation. But an equivalent model that is more explicit would be: 291 | 292 | ```{r 10.2.2 m2.1b re } 293 | 294 | m2.2b <- ulam( alist( 295 | B_merge ~ dlnorm( mu , sigma ), 296 | mu <- a + b*log(M), 297 | B_merge <- merge_missing( B , B_impute ), 298 | a ~ normal(0,1), 299 | b ~ normal(0,1), 300 | sigma ~ exponential(1) ), 301 | data=dat_list , chains=4 , cores=4 , start=list( B_impute = rep(0.5,56) ) ) 302 | 303 | precis( m2.2b ) 304 | 305 | ``` 306 | 307 | It’s a little more obvious now what ulam is doing. It constructs the merged vector of observed and imputed values, B_merge, and then uses that merged vector as the outcome. The outcome distribution at the top of the model is the prior for each B_impute parameter. That prior is adaptive—it has parameters inside it. Hence, shrinkage happens. 308 | 309 | ### 2.2 INLA 310 | 311 | ```{r 10.2.2 m2.1 inla} 312 | 313 | 314 | d2.i <- d %>% 315 | #only cases with complete body masses 316 | filter(!is.na(body)) %>% 317 | mutate(M = body / max(body), 318 | B= brain / max(brain, na.rm=TRUE), 319 | logM= log(M)) 320 | 321 | m2.2.i <- inla(B ~ logM, family ="lognormal", data=d2.i, 322 | control.fixed = list( 323 | mean= 0, 324 | prec= 1, 325 | mean.intercept= 0, 326 | prec.intercept= 1), 327 | control.predictor=list(compute=TRUE) 328 | ) 329 | summary(m2.2.i ) 330 | 331 | ``` 332 | 333 | 334 | ## 2.3 compare to the analysis with complete cases 335 | 336 | ### 2.3 rethinking 337 | 338 | 339 | ```{r 10.2.3 m2.1b re } 340 | 341 | cc2 <- complete.cases( B ) 342 | dat_list2 <- list( B = B[cc2], 343 | M = M[cc2] ) 344 | m2.3 <- ulam( alist( 345 | B ~ dlnorm( mu , sigma ), 346 | mu <- a + b*log(M), 347 | a ~ normal(0,1), 348 | b ~ normal(0,1), 349 | sigma ~ exponential(1) ), 350 | data=dat_list2 , chains=4 , cores=4 ) 351 | 352 | precis( m2.3 ) 353 | 354 | ``` 355 | Really no difference from before. 356 | 357 | 358 | 359 | ### 2.3 INLA 360 | 361 | ```{r 10.2.3 m2.1 inla} 362 | 363 | d3.i <- d2.i %>% 364 | filter(!is.na(brain)) 365 | 366 | m2.3.i <- inla(B ~ logM, family ="lognormal", data=d3.i, 367 | control.fixed = list( 368 | mean= 0, 369 | prec= 1, 370 | mean.intercept= 0, 371 | prec.intercept= 1), 372 | control.compute = list(config= TRUE), 373 | control.predictor=list(compute=TRUE) 374 | ) 375 | summary(m2.3.i ) 376 | 377 | ``` 378 | 379 | 380 | ## 2.4 plot the imputed brain sizes together with the observed values. 381 | 382 | ### 2.4 rethinking 383 | 384 | ```{r 10.2.4 re} 385 | library(rethinking) 386 | post <- rethinking::extract.samples(m2.2) 387 | Bi <- apply( post$B_impute , 2 , mean ) 388 | miss_idx <- which( is.na(B) ) 389 | plot( M[-miss_idx] , B[-miss_idx] , col=rangi2 , pch=16 , xlab="body mass M" , ylab="brain size B" ) 390 | points( M[miss_idx] , Bi ) 391 | Bi_ci <- apply( post$B_impute , 2 , PI , 0.5 ) 392 | for ( i in 1:length(Bi) ) lines( rep(M[miss_idx][i],2) , Bi_ci[,i] ) 393 | ``` 394 | 395 | 396 | 397 | Black open points are the imputed values, with 50% compatibility intervals. Imputation hasn’t done much, apparently because all but one of the missing values are in a very dense region of the body size range. So almost no information was lost—the missing info is redundant. 398 | 399 | ### 2.4 INLA 400 | 401 | ```{r 10.2.4 plot inla} 402 | 403 | #indices of the weights with missing values of brain 404 | d2.i.na <- which(is.na(d2.i$B)) 405 | 406 | #cases with response data 407 | d2.i.cc <- d2.i %>% 408 | filter(!is.na(brain)) 409 | 410 | #cases with no response data 411 | d2.i.nobrain <- d2.i %>% 412 | filter(is.na(brain)) 413 | 414 | #imputed values of the response variable in the response scale exp(brain) 415 | Bi.i <- exp(m2.2.i$summary.fitted.values[d2.i.na,]) 416 | 417 | #imputed values df 418 | 419 | d2.i.imp <- bind_cols(d2.i.nobrain, Bi.i) %>% 420 | rename("LCI"= "0.025quant", "UCI"= "0.975quant") 421 | 422 | 423 | m2.2.i.plot <- ggplot() + 424 | geom_point(data= d2.i.cc, aes(M,B), color= "blue", alpha= 0.8)+ 425 | geom_pointrange(data= d2.i.imp , aes(x= M, y= mean, ymin= LCI, ymax= UCI))+ 426 | theme_bw() 427 | 428 | m2.2.i.plot 429 | 430 | ``` 431 | 432 | 433 | -------------------------------------------------------------------------------- /rethinkingINLA_HW10.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/rethinkingINLA_HW10.pdf -------------------------------------------------------------------------------- /rethinkingINLA_HW10_files/figure-html/10.1 model-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/rethinkingINLA_HW10_files/figure-html/10.1 model-1.png -------------------------------------------------------------------------------- /rethinkingINLA_HW10_files/figure-html/10.2.4 plot inla-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/rethinkingINLA_HW10_files/figure-html/10.2.4 plot inla-1.png -------------------------------------------------------------------------------- /rethinkingINLA_HW10_files/figure-html/10.2.4 re-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/rethinkingINLA_HW10_files/figure-html/10.2.4 re-1.png -------------------------------------------------------------------------------- /rethinkingINLA_HW10_files/figure-html/2.1 dag-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/rethinkingINLA_HW10_files/figure-html/2.1 dag-1.png -------------------------------------------------------------------------------- /rethinkingINLA_HW10_files/figure-html/2.1 plot-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/rethinkingINLA_HW10_files/figure-html/2.1 plot-1.png -------------------------------------------------------------------------------- /rethinkingINLA_HW2_files/figure-html/4.12-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/rethinkingINLA_HW2_files/figure-html/4.12-1.png -------------------------------------------------------------------------------- /rethinkingINLA_HW2_files/figure-html/4.13-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/rethinkingINLA_HW2_files/figure-html/4.13-1.png -------------------------------------------------------------------------------- /rethinkingINLA_HW2_files/figure-html/4.15-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/rethinkingINLA_HW2_files/figure-html/4.15-1.png -------------------------------------------------------------------------------- /rethinkingINLA_HW2_files/figure-html/4.38-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/rethinkingINLA_HW2_files/figure-html/4.38-1.png -------------------------------------------------------------------------------- /rethinkingINLA_HW2_files/figure-html/4.41-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/rethinkingINLA_HW2_files/figure-html/4.41-1.png -------------------------------------------------------------------------------- /rethinkingINLA_HW2_files/figure-html/4.45-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/rethinkingINLA_HW2_files/figure-html/4.45-1.png -------------------------------------------------------------------------------- /rethinkingINLA_HW2_files/figure-html/4.46-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/rethinkingINLA_HW2_files/figure-html/4.46-1.png -------------------------------------------------------------------------------- /rethinkingINLA_HW2_files/figure-html/4.49-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/rethinkingINLA_HW2_files/figure-html/4.49-1.png -------------------------------------------------------------------------------- /rethinkingINLA_HW2_files/figure-html/4.50 dens-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/rethinkingINLA_HW2_files/figure-html/4.50 dens-1.png -------------------------------------------------------------------------------- /rethinkingINLA_HW2_files/figure-html/4.50-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/rethinkingINLA_HW2_files/figure-html/4.50-1.png -------------------------------------------------------------------------------- /rethinkingINLA_HW2_files/figure-html/4.55-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/rethinkingINLA_HW2_files/figure-html/4.55-1.png -------------------------------------------------------------------------------- /rethinkingINLA_HW2_files/figure-html/4.56-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/rethinkingINLA_HW2_files/figure-html/4.56-1.png -------------------------------------------------------------------------------- /rethinkingINLA_HW2_files/figure-html/4.61-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/rethinkingINLA_HW2_files/figure-html/4.61-1.png -------------------------------------------------------------------------------- /rethinkingINLA_HW2_files/figure-html/4.63-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/rethinkingINLA_HW2_files/figure-html/4.63-1.png -------------------------------------------------------------------------------- /rethinkingINLA_HW2_files/figure-html/hw2 2 re-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/rethinkingINLA_HW2_files/figure-html/hw2 2 re-1.png -------------------------------------------------------------------------------- /rethinkingINLA_HW2_files/figure-html/hw2.2 inla clinear-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/rethinkingINLA_HW2_files/figure-html/hw2.2 inla clinear-1.png -------------------------------------------------------------------------------- /rethinkingINLA_HW3.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Statistical Rethinking 2nd edition Homework 3 in INLA" 3 | output: 4 | html_document: 5 | toc: true 6 | toc_float: true 7 | --- 8 | 9 | ```{r setup, include=FALSE} 10 | knitr::opts_chunk$set(echo = TRUE) 11 | ``` 12 | 13 | ```{r libraries, message= FALSE} 14 | library(tidyverse) 15 | library(rethinking) 16 | library(dagitty) 17 | library(INLA) 18 | 19 | ``` 20 | 21 | 22 | All three problems below are based on the same data. The data in data(foxes) are 116 foxes from 30 different urban groups in England. These foxes are like street gangs. Group size varies from 2 to 8 individuals. Each group maintains its own (almost exclusive) urban territory. Some territories are larger than others. The area variable encodes this information. Some territories also have more avgfood than others. We want to model the weight of each fox. For the problems below, assume this DAG: 23 | 24 | ```{r hw3 dag} 25 | 26 | hw3dag <- dagitty("dag{ 27 | avgfood <- area 28 | weight <- avgfood 29 | weight <- groupsize 30 | groupsize <- avgfood 31 | }") 32 | 33 | plot(hw3dag) 34 | 35 | 36 | ``` 37 | 38 | # 1. data(foxes) infer the total causal influence of area on weight 39 | 40 | **Use a model to infer the total causal influence of area on weight. Would increasing the area available to each fox make it heavier (healthier)? You might want to standardize the variables. Regardless, use prior predictive simulation to show that your model’s prior predictions stay within the possible outcome range.** 41 | 42 | 43 | ## 1. rethinking 44 | Because there are no back-door paths from area to weight,we only need to include area. No other variables are needed. 45 | Territory size seems to have no total causal influence on weight, at least not in this sample. 46 | 47 | 48 | ```{r hw3 1 rethinking} 49 | 50 | data(foxes) 51 | f <- foxes 52 | 53 | f$A <- scale( f$area ) 54 | f$F <- scale( f$avgfood ) 55 | f$G <- scale( f$groupsize ) 56 | f$W <- scale( f$weight) 57 | 58 | m1 <- quap( 59 | alist( 60 | W ~ dnorm( mu , sigma ) , 61 | mu <- a + bA*A , 62 | a ~ dnorm( 0 , 0.2 ) , 63 | bA ~ dnorm( 0 , 0.5 ) , 64 | sigma ~ dexp( 1 ) 65 | ) , data=f ) 66 | 67 | precis(m1) 68 | 69 | ``` 70 | 71 | ## 1. INLA 72 | 73 | **default priors** 74 | 75 | By default, the intercept has a Gaussian prior with mean and precision equal to zero. Coefficients of the fixed effects also have a Gaussian prior by default with zero mean and precision equal to 76 | 0.001. The prior on the precision of the error term is, by default, a Gamma distribution with parameters 1 and 0.00005 (shape and rate, respectively) ( so this is different from the statistical rethinking book's prior on the variance which is exp(1)) 77 | 78 | ```{r hw3 1 INLA default priors} 79 | 80 | #using default priors 81 | 82 | m1.inla <- inla(W~A, data= f) 83 | summary(m1.inla) 84 | 85 | ``` 86 | 87 | The precision is the inverse of the variance. If we want to set the sd to 0.5, we have to set the precision to 1/(0.5^2) 88 | 89 | ```{r hw3 1 INLA custom priors} 90 | 91 | m1.inla.prior <- inla(W~A, data= f, control.fixed = list( 92 | mean= 0, 93 | prec= 1/(0.5^2), # sd = 0.5 --> precision =1/variance --> 1/(sd^2) 94 | mean.intercept= 0, 95 | prec.intercept= 1/(0.2^2) 96 | )) 97 | 98 | summary(m1.inla.prior) 99 | ``` 100 | 101 | # 2. data(foxes) infer the causal impact of adding food to a territory 102 | 103 | **Now infer the causal impact of adding food to a territory. Would this make foxes heavier? Which covariates do you need to adjust for to estimate the total causal influence of food?** 104 | 105 | ## 2.rethinking 106 | 107 | To infer the causal influence of avg food on weight,we need to close any back-door paths. There are no back-door paths in the DAG. So again, just use a model with a single predictor. If you include groupsize, to block the indirect path, then you won’t get the total causal influence of food. You’ll just get the direct influence. But I asked for the effect of adding food, and that would mean through all forward paths. 108 | 109 | Again nothing. Adding food does not change weight. This shouldn’t surprise you, if the DAG is correct, because area is upstream of avgfood. 110 | 111 | 112 | ```{r hw3 2 rethinking} 113 | 114 | # food on weight 115 | m2 <- quap( 116 | alist( 117 | W ~ dnorm( mu , sigma ) , 118 | mu <- a + bF*F, 119 | a ~ dnorm( 0 , 0.2 ) , 120 | bF ~ dnorm( 0 , 0.5 ) , 121 | sigma ~ dexp( 1 ) 122 | ) , data=f ) 123 | 124 | precis(m2) 125 | 126 | 127 | ``` 128 | 129 | 130 | ## 2.INLA 131 | 132 | **INLA default priors** 133 | 134 | ```{r hw3 2 INLA default priors} 135 | 136 | #using default priors 137 | 138 | m2.inla <- inla(W~F, data= f) 139 | summary(m2.inla) 140 | 141 | ``` 142 | 143 | 144 | **INLA custom priors** 145 | ```{r hw3 2 INLA custom priors} 146 | #using custom priors 147 | 148 | m2.prec.prior <- 149 | 150 | m2.inla.prior <- inla(W~F, data= f, control.fixed = list( 151 | mean= 0, 152 | prec= 1/(0.5^2), 153 | mean.intercept= 0, 154 | prec.intercept= 1/(0.2^2) 155 | )) 156 | summary(m2.inla.prior) 157 | 158 | ``` 159 | 160 | # 3. data(foxes) infer the causal impact of groupsize 161 | 162 | **Now infer the causal impact of groupsize. Which covariates do you need to adjust for? Looking at the posterior distribution of the resulting model, what do you think explains these data? That is, can you explain the estimates for all three problems? How do they go together?** 163 | 164 | 165 | ## 3. rethinking 166 | The variable groupsize does have a back-door path, passing through avgfood. So to infer the causal influence of groupsize, we need to close that path. This implies a model with both groupsize and avgfood as predictors. 167 | 168 | It looks like group size is negatively associated with weight, controlling for food. Similarly, food is positively associated with weight, controlling for group size. So the causal influence of group size is to reduce weight—less food for each fox. And the direct causal influence of food is positive, of course. But the total causal influence of food is still nothing, since it causes larger groups. This is a masking effect, like in the milk energy example. But the causal explanation here is that more foxes move into a territory until the food available to each is no better than the food in a neighboring territory. Every territory ends up equally good/bad on average. This is known in be- havioral ecology as an ideal free distribution. 169 | 170 | 171 | ```{r hw3 3 rethinking} 172 | 173 | # groupsize on weight 174 | #need to include avgfood 175 | m3 <- quap( 176 | alist( 177 | W ~ dnorm( mu , sigma ) , 178 | mu <- a + bF*F + bG*G, 179 | a ~ dnorm( 0 , 0.2 ) , 180 | bF ~ dnorm( 0 , 0.5 ) , 181 | bG ~ dnorm( 0 , 0.5 ) , 182 | sigma ~ dexp( 1 ) 183 | ) , data=f ) 184 | 185 | precis(m3) 186 | 187 | 188 | 189 | ``` 190 | 191 | ## 3. INLA 192 | 193 | **INLA default priors** 194 | ```{r hw3 3 INLA default priors} 195 | 196 | #using default priors 197 | 198 | m3.inla <- inla(W~ F + G,family = c("gaussian"), data= f) 199 | summary(m3.inla) 200 | 201 | ``` 202 | 203 | **INLA custom priors** 204 | 205 | Prior mean for all fixed effects except the intercept. Alternatively, a named list with specific means where name=default applies to unmatched names. For example control.fixed=list(mean=list(a=1, b=2, default=0)) assign 'mean=1' to fixed effect 'a' , 'mean=2' to effect 'b' and 'mean=0' to all others. (default 0.0) 206 | 207 | ```{r hw3 3 INLA priors} 208 | 209 | #using custom priors 210 | m3.inla.prior <- inla(W~F+G, data= f, control.fixed = list( 211 | mean= list(F=0, G=0), 212 | prec= list(F=1/(0.5^2), G=1/(0.5^2)), 213 | mean.intercept= 0, 214 | prec.intercept= 1/(0.2^2) 215 | )) 216 | summary(m3.inla.prior) 217 | 218 | 219 | ``` 220 | 221 | -------------------------------------------------------------------------------- /rethinkingINLA_HW3.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/rethinkingINLA_HW3.pdf -------------------------------------------------------------------------------- /rethinkingINLA_HW3_files/figure-html/hw3 dag-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/rethinkingINLA_HW3_files/figure-html/hw3 dag-1.png -------------------------------------------------------------------------------- /rethinkingINLA_HW4_files/figure-html/hw3 dag-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/rethinkingINLA_HW4_files/figure-html/hw3 dag-1.png -------------------------------------------------------------------------------- /rethinkingINLA_HW4_files/figure-html/hw4.2 dag-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/rethinkingINLA_HW4_files/figure-html/hw4.2 dag-1.png -------------------------------------------------------------------------------- /rethinkingINLA_HW4_files/figure-html/inla waic diff plot-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/rethinkingINLA_HW4_files/figure-html/inla waic diff plot-1.png -------------------------------------------------------------------------------- /rethinkingINLA_HW5_files/figure-html/HW5 2a INLA-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/rethinkingINLA_HW5_files/figure-html/HW5 2a INLA-1.png -------------------------------------------------------------------------------- /rethinkingINLA_HW5_files/figure-html/HW5 2a re-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/rethinkingINLA_HW5_files/figure-html/HW5 2a re-1.png -------------------------------------------------------------------------------- /rethinkingINLA_HW5_files/figure-html/HW5 2a re-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/rethinkingINLA_HW5_files/figure-html/HW5 2a re-2.png -------------------------------------------------------------------------------- /rethinkingINLA_HW5_files/figure-html/hw5 2b-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/rethinkingINLA_HW5_files/figure-html/hw5 2b-1.png -------------------------------------------------------------------------------- /rethinkingINLA_HW5_files/figure-html/hw5 3.a plot-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/rethinkingINLA_HW5_files/figure-html/hw5 3.a plot-1.png -------------------------------------------------------------------------------- /rethinkingINLA_HW5_files/figure-html/hw5.1 INLA-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/rethinkingINLA_HW5_files/figure-html/hw5.1 INLA-1.png -------------------------------------------------------------------------------- /rethinkingINLA_HW5_files/figure-html/hw5.1 re-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/rethinkingINLA_HW5_files/figure-html/hw5.1 re-1.png -------------------------------------------------------------------------------- /rethinkingINLA_HW5_files/figure-html/hw5.1 re-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/rethinkingINLA_HW5_files/figure-html/hw5.1 re-2.png -------------------------------------------------------------------------------- /rethinkingINLA_HW5_files/figure-html/hw5.1 re-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/rethinkingINLA_HW5_files/figure-html/hw5.1 re-3.png -------------------------------------------------------------------------------- /rethinkingINLA_HW5_files/figure-html/hw5.3a inla-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/rethinkingINLA_HW5_files/figure-html/hw5.3a inla-1.png -------------------------------------------------------------------------------- /rethinkingINLA_HW5_files/figure-html/hw5.3b INLA-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/rethinkingINLA_HW5_files/figure-html/hw5.3b INLA-1.png -------------------------------------------------------------------------------- /rethinkingINLA_HW5_files/figure-html/in ulam-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/rethinkingINLA_HW5_files/figure-html/in ulam-1.png -------------------------------------------------------------------------------- /rethinkingINLA_HW5_files/figure-html/inla 3a-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/rethinkingINLA_HW5_files/figure-html/inla 3a-1.png -------------------------------------------------------------------------------- /rethinkingINLA_HW6_files/figure-html/6.1 dag-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/rethinkingINLA_HW6_files/figure-html/6.1 dag-1.png -------------------------------------------------------------------------------- /rethinkingINLA_HW6_files/figure-html/6.1.b postcheck-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/rethinkingINLA_HW6_files/figure-html/6.1.b postcheck-1.png -------------------------------------------------------------------------------- /rethinkingINLA_HW6_files/figure-html/6.2 dag-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/rethinkingINLA_HW6_files/figure-html/6.2 dag-1.png -------------------------------------------------------------------------------- /rethinkingINLA_HW6_files/figure-html/6.3.1 re-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/rethinkingINLA_HW6_files/figure-html/6.3.1 re-1.png -------------------------------------------------------------------------------- /rethinkingINLA_HW6_files/figure-html/6.3.1 re-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/rethinkingINLA_HW6_files/figure-html/6.3.1 re-2.png -------------------------------------------------------------------------------- /rethinkingINLA_HW6_files/figure-html/6.3.1 re-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/rethinkingINLA_HW6_files/figure-html/6.3.1 re-3.png -------------------------------------------------------------------------------- /rethinkingINLA_HW6_files/figure-html/6.3.2 rethinking-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/rethinkingINLA_HW6_files/figure-html/6.3.2 rethinking-1.png -------------------------------------------------------------------------------- /rethinkingINLA_HW6_files/figure-html/6.3.2 rethinking-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/rethinkingINLA_HW6_files/figure-html/6.3.2 rethinking-2.png -------------------------------------------------------------------------------- /rethinkingINLA_HW6_files/figure-html/6.3.2 rethinking-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/rethinkingINLA_HW6_files/figure-html/6.3.2 rethinking-3.png -------------------------------------------------------------------------------- /rethinkingINLA_HW6_files/figure-html/6.3.3 dag-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/rethinkingINLA_HW6_files/figure-html/6.3.3 dag-1.png -------------------------------------------------------------------------------- /rethinkingINLA_HW6_files/figure-html/inla 6.3 waic compare-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/rethinkingINLA_HW6_files/figure-html/inla 6.3 waic compare-1.png -------------------------------------------------------------------------------- /rethinkingINLA_HW6_files/figure-html/inla 6.3.1 postcheck-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/rethinkingINLA_HW6_files/figure-html/inla 6.3.1 postcheck-1.png -------------------------------------------------------------------------------- /rethinkingINLA_HW7.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Statistical Rethinking 2nd edition Homework 7 in INLA" 3 | output: 4 | html_document: 5 | toc: true 6 | toc_float: true 7 | --- 8 | 9 | ```{r libraries, message= FALSE} 10 | library(tidyverse) 11 | library(rethinking) 12 | library(dagitty) 13 | library(INLA) 14 | library(knitr) 15 | library(stringr) 16 | ``` 17 | 18 | # 1. data(Trolley) 19 | 20 | **In the Trolley data —data(Trolley)—we saw how education level (modeled as an ordered category) is associated with responses. Is this association causal? One plausible confound is that education is also associated with age, through a causal process: People are older when they finish school than when they begin it. 21 | Reconsider the Trolley data in this light. Draw a DAG that represents hypothetical causal relationships among response, education, and age. Which statical model or models do you need to evaluate the causal influence of education on responses? Fit these models to the trolley data. What do you conclude about the causal relationships among these three variables?** 22 | 23 | 24 | 25 | 26 | 27 | 28 | # 2. 29 | **Consider one more variable in the Trolley data: Gender. Suppose that gender might influence education as well as response directly. Draw the DAG now that includes response, education, age, and gender. 30 | Using only the DAG, is it possible that the inferences from Problem 1 are con- founded by gender? If so, define any additional models you need to infer the causal influence of education on response. What do you conclude?** 31 | 32 | -------------------------------------------------------------------------------- /rethinkingINLA_HW7.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | Statistical Rethinking 2nd edition Homework 7 in INLA 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 35 | 44 | 45 | 46 | 47 | 73 | 74 | 75 | 76 | 77 | 103 | 104 | 105 | 174 | 175 | 192 | 193 | 194 | 195 | 249 | 250 | 251 | 252 | 253 | 254 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 |
    324 | 325 | 326 | 327 |
    328 |
    329 |
    330 |
    331 |
    332 | 333 |
    334 | 335 | 336 | 337 | 338 | 381 | 382 | 389 | 390 | 391 |
    library(tidyverse)
    392 | library(rethinking)
    393 | library(dagitty)
    394 | library(INLA)
    395 | library(knitr)
    396 | library(stringr)
    397 |
    398 |

    1. data(Trolley)

    399 |

    In the Trolley data —data(Trolley)—we saw how education level (modeled as an ordered category) is associated with responses. Is this association causal? One plausible confound is that education is also associated with age, through a causal process: People are older when they finish school than when they begin it. Reconsider the Trolley data in this light. Draw a DAG that represents hypothetical causal relationships among response, education, and age. Which statical model or models do you need to evaluate the causal influence of education on responses? Fit these models to the trolley data. What do you conclude about the causal relationships among these three variables?

    400 |
    401 |
    402 |

    2.

    403 |

    Consider one more variable in the Trolley data: Gender. Suppose that gender might influence education as well as response directly. Draw the DAG now that includes response, education, age, and gender. Using only the DAG, is it possible that the inferences from Problem 1 are con- founded by gender? If so, define any additional models you need to infer the causal influence of education on response. What do you conclude?

    404 |
    405 | 406 | 407 | 408 |
    409 |
    410 | 411 |
    412 | 413 | 425 | 426 | 427 | 428 | 439 | 440 | 441 | 442 | 468 | 469 | 470 | 478 | 479 | 480 | 481 | -------------------------------------------------------------------------------- /rethinkingINLA_HW8_files/figure-html/8.1 post re-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/rethinkingINLA_HW8_files/figure-html/8.1 post re-1.png -------------------------------------------------------------------------------- /rethinkingINLA_HW8_files/figure-html/8.2.2 inla hyper sd-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/rethinkingINLA_HW8_files/figure-html/8.2.2 inla hyper sd-1.png -------------------------------------------------------------------------------- /rethinkingINLA_HW8_files/figure-html/8.2.3 plot inla-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/rethinkingINLA_HW8_files/figure-html/8.2.3 plot inla-1.png -------------------------------------------------------------------------------- /rethinkingINLA_HW8_files/figure-html/8.2.3 plot rethinking-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/rethinkingINLA_HW8_files/figure-html/8.2.3 plot rethinking-1.png -------------------------------------------------------------------------------- /rethinkingINLA_HW8_files/figure-html/8.3 data-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/rethinkingINLA_HW8_files/figure-html/8.3 data-1.png -------------------------------------------------------------------------------- /rethinkingINLA_HW8_files/figure-html/sigma.8.1 plot-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/rethinkingINLA_HW8_files/figure-html/sigma.8.1 plot-1.png -------------------------------------------------------------------------------- /rethinkingINLA_HW8_files/figure-html/unnamed-chunk-1-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/rethinkingINLA_HW8_files/figure-html/unnamed-chunk-1-1.png -------------------------------------------------------------------------------- /rethinkingINLA_HW9.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Statistical Rethinking 2nd edition Homework 9 in INLA" 3 | output: 4 | html_document: 5 | toc: true 6 | toc_float: true 7 | --- 8 | 9 | ```{r global_options, include=FALSE} 10 | knitr::opts_chunk$set(message=FALSE) 11 | ``` 12 | 13 | ```{r libraries, message= FALSE} 14 | 15 | library(tidyverse) 16 | library(rethinking) 17 | library(dagitty) 18 | library(INLA) 19 | library(knitr) 20 | library(stringr) 21 | ``` 22 | 23 | # 1. data(bangladesh) model with both varying intercepts by district_id and varying slopes of urban (as a 0/1 indicator variable) by district_id and correlation between the intercepts and slopes 24 | 25 | **Revisit the Bangladesh fertility data, data(bangladesh).Fit a model with both varying intercepts by district_id and varying slopes of urban (as a 0/1 indicator variable) by district_id. You are still predicting use.contraception. Inspect the correlation between the intercepts and slopes. Can you interpret this correlation, in terms of what it tells you about the pattern of contraceptive use in the sample? It might help to plot the varying effect estimates for both the intercepts and slopes, by district. Then you can visualize the correlation and maybe more easily think through what it means to have a particular correlation. Plotting predicted proportion of women using contraception, in each district, with urban women on one axis and rural on the other, might also help.** 26 | 27 | ## 1.1 model varying slopes of urban 28 | 29 | $C_{did} \sim Bernoulli(p_{did})$ 30 | 31 | $logit(p_{did}) = \alpha_{did} + \beta_{did}*urban_{did}$ 32 | 33 | $\begin{pmatrix}a_{did}\\b_{did}\end{pmatrix}= MVNormal \begin{pmatrix}\left[\begin{array}{ccc}\bar{a}\\\bar{b}\end{array}\right] , & Sigma ,& Rho\end{pmatrix}$ 34 | 35 | 36 | ### 1.1 rethinking 37 | 38 | ```{r 9.1 re mean} 39 | library(rethinking) 40 | data(bangladesh) 41 | d <- bangladesh 42 | 43 | dat_list <- list( 44 | C = d$use.contraception, 45 | did = as.integer( as.factor(d$district) ), 46 | urban = d$urban 47 | ) 48 | 49 | m1.1 <- ulam( 50 | alist( 51 | C ~ bernoulli( p ), 52 | logit(p) <- a[did] + b[did]*urban, 53 | c(a,b)[did] ~ multi_normal( c(abar,bbar) , Rho , Sigma ), 54 | abar ~ normal(0,1), 55 | bbar ~ normal(0,0.5), 56 | Rho ~ lkj_corr(2), 57 | Sigma ~ exponential(1) 58 | ) , data=dat_list , chains=4 , cores=4 ) 59 | 60 | precis(m1.1) 61 | ``` 62 | 63 | This is a conventional varying slopes model, with a centered parameterization. No surprises. If you peek at the posterior distributions for the average effects, you’ll see that the average slope is positive. This implies that urban areas use contraception more. Not surprising. 64 | 65 | Now consider the distribution of varying effects: 66 | 67 | ```{r 9.1 re rho } 68 | precis( m1.1 , depth=3 , pars=c("Rho","Sigma") ) 69 | ``` 70 | 71 | The correlation between the intercepts and slopes is quite negative. 72 | 73 | 74 | Let’s plot the individual effects to appreciate this. 75 | 76 | ```{r 9.1 re plot } 77 | 78 | post <- extract.samples(m1.1) 79 | 80 | a <- apply( post$a , 2 , mean ) 81 | b <- apply( post$b , 2 , mean ) 82 | plot( a, b , xlab="a (intercept)" , ylab="b (urban slope)" ) 83 | abline( h=0 , lty=2 ) 84 | abline( v=0 , lty=2 ) 85 | library(ellipse) 86 | R <- apply( post$Rho , 2:3 , mean ) 87 | s <- apply( post$Sigma , 2 , mean ) 88 | S <- diag(s) %*% R %*% diag(s) 89 | ll <- c( 0.5 , 0.67 , 0.89 , 0.97 ) 90 | for ( l in ll ) { 91 | el <- ellipse( S , centre=c( mean(post$abar) , mean(post$bbar) ) , level=l ) 92 | lines( el , col="black" , lwd=0.5 ) } 93 | 94 | ``` 95 | 96 | 97 | There’s the negative correlation — districts with higher use outside urban areas (a values) have smaller slopes. Since the slope is the difference between urban and non-urban areas, you can see this as saying that districts with high use in rural areas have urban areas that aren’t as different. 98 | 99 | 100 | On the outcome scale, what this ends up meaning is that urban places are much the same in all districts, but rural areas vary a lot. Plotting now in the outcome scale: 101 | 102 | ```{r 9.1 re plot outcome} 103 | u0 <- inv_logit( a ) 104 | u1 <- inv_logit( a + b ) 105 | plot( u0 , u1 , xlim=c(0,1) , ylim=c(0,1) , xlab="urban = 0" , ylab="urban = 1" ) 106 | abline( h=0.5 , lty=2 ) 107 | abline( v=0.5 , lty=2 ) 108 | 109 | ``` 110 | 111 | 112 | This plot is on the probability scale. The horizontal axis is probability of contraceptive use in rural area of a district. The vertical is the probability in urban area of same district. The urban areas all straddle 0.5. Most the of the rural areas are below 0.5. The negative correlation between the intercepts and slopes is necessary to encode this pattern. 113 | 114 | ### 1.1. inla 115 | 116 | 117 | ```{r 9.1 inla} 118 | library(INLA) 119 | library(brinla) 120 | 121 | d1.i <- d %>% 122 | #make a new variable of district that is continuous 123 | mutate(C = use.contraception, 124 | did = as.integer( as.factor(d$district)), 125 | a.did= did, 126 | b.did= did + max(did) 127 | ) 128 | 129 | n.district= max(d1.i$did) ## = 60 130 | 131 | 132 | m1.1.i <- inla(C ~ 1 + urban + f(a.did, model="iid2d", n= 2*n.district) + f(b.did, urban, copy= "a.did"), data= d1.i, family = "binomial", 133 | Ntrials = 1, 134 | control.fixed = list( 135 | mean= 0, 136 | prec= 1/(0.5^2), 137 | mean.intercept= 0, 138 | prec.intercept= 1), 139 | control.family = list(control.link=list(model="logit")), 140 | control.predictor=list(link=1, compute=T), 141 | control.compute=list(config=T, dic=TRUE, waic= TRUE)) 142 | summary(m1.1.i) 143 | 144 | bri.hyperpar.summary(m1.1.i) 145 | 146 | bri.hyperpar.plot(m1.1.i) 147 | 148 | ``` 149 | 150 | 151 | ```{r 9.1.1 plot inla} 152 | 153 | #m1.1.i$summary.random has 2 elements: a.did and b.did but they are identical. 154 | 155 | #extract the means of the random effects with m1.1.i$summary.random[[1]][["mean"]] 156 | m1.1.i.mean <- bind_cols(did= 1:length(m1.1.i$summary.random[[1]][["mean"]]), mean= m1.1.i$summary.random[[1]][["mean"]]) %>% 157 | #assign first 60 rows to a.did and 61:120 to b.did in new variable "param" 158 | mutate(param= if_else(did <= n.district, "a.did", "b.did"), 159 | #new variable "district" assigns the district index 1:60 to both a.did and b.did estimates. 160 | district= rep(1:60,2)) %>% 161 | #split dataframe by param into a list of 2: a.did and b.did 162 | group_split(param) %>% 163 | #join the a.did and b.did elements of the list into a dataframe by "district" 164 | reduce(left_join, by= "district") %>% 165 | select(c( "district", "mean.x", "mean.y")) %>% 166 | rename("a.did"= "mean.x", "b.did"= "mean.y") %>% 167 | mutate(intercept= a.did + m1.1.i$summary.fixed[[1]][[1]], 168 | slope= b.did + m1.1.i$summary.fixed[[1]][[2]]) 169 | 170 | 171 | 172 | m1.1.i.mean.plot <- ggplot()+ 173 | geom_point(data= m1.1.i.mean, aes(x=intercept, y= slope))+ 174 | geom_hline(yintercept=0, linetype='longdash') + 175 | geom_vline(xintercept = 0)+ 176 | labs(x= "a (intercept)", y = "b (urban slope)")+ 177 | theme_bw() 178 | 179 | m1.1.i.mean.plot 180 | 181 | 182 | ``` 183 | 184 | 185 | 186 | ```{r 9.1.1 outcome plot inla} 187 | 188 | inverse_logit <- function (x){ 189 | p <- 1/(1 + exp(-x)) 190 | p <- ifelse(x == Inf, 1, p) 191 | p } 192 | 193 | 194 | m1.1.i.outcome <- m1.1.i.mean %>% 195 | mutate(u0.i = inverse_logit(a.did + m1.1.i$summary.fixed[[1]][[1]]), 196 | u1.i= inverse_logit(a.did + m1.1.i$summary.fixed[[1]][[1]] + 197 | b.did + m1.1.i$summary.fixed[[1]][[2]]) 198 | ) 199 | 200 | 201 | m1.1.i.outcome.plot <- ggplot()+ 202 | geom_point(data= m1.1.i.outcome, aes(x=u0.i, y= u1.i))+ 203 | geom_hline(yintercept=0.5, linetype='longdash') + 204 | geom_vline(xintercept = 0.5)+ 205 | labs(x= "urban = 0", y = "urban = 1")+ 206 | xlim(0,1) + 207 | ylim(0,1)+ 208 | theme_bw() 209 | 210 | m1.1.i.outcome.plot 211 | 212 | ``` 213 | 214 | ### **Difference between the rethinking and INLA model parametrization** 215 | 216 | The rethinking random effects are parameterized like N[ (a, b); Sigma ], while the INLA random effects are parameterized like (a, b) + N[ (0, 0); Sigma ]. From INLA's perspective, (a, b) are fixed effects that define the center of the random effect. The INLA plot is centered at (0,0), while in this case, the rethinking plot is centered at (-0.68, 0.65). That's why, when we want to replicate the rethinking model in INLA, we have to add the the fixed effects, which are the center of the distribution, to the random effects, which are deviations from that center. 217 | 218 | Example: 219 | 220 | m1.1.i$summary.fixed[[1]][[1]] is the fixed effect of the intercept 221 | a.did is the deviation from the intercept by district 222 | 223 | a.did + m1.1.i$summary.fixed[[1]][[1]] in INLA is the equivalent of a in the rethinking model. 224 | 225 | 226 | 227 | ## 1.2 model urban index intercepts. 228 | 229 | $C_{did} \sim Bernoulli(p_{i})$ 230 | 231 | $logit(p_{i}) = \alpha_{district[i],urban[j]}$ 232 | 233 | $\begin{pmatrix}a_{urban1,i}\\b_{urban0,i}\end{pmatrix}= MVNormal \begin{pmatrix}\left[\begin{array}{ccc}\bar{a}\\\bar{b}\end{array}\right] , & Sigma ,& Rho\end{pmatrix}$ 234 | 235 | ### 1.2 rethinking 236 | 237 | In fact, if we fit the model so it instead has two intercepts, one for rural and one for urban, there is no strong correlation between those intercepts. Here’s such a model: 238 | 239 | ```{r 9.1.2 re, eval= FALSE} 240 | 241 | # version with matrix instead of slopes 242 | dat_list$uid <- dat_list$urban + 1L 243 | 244 | 245 | m1.2 <- ulam( alist( 246 | C ~ bernoulli( p ), 247 | logit(p) <- a[did,uid], 248 | vector[2]:a[did] ~ multi_normal( c(abar,bbar) , Rho , Sigma ), 249 | abar ~ normal(0,1), 250 | bbar ~ normal(0,1), 251 | Rho ~ lkj_corr(2), 252 | Sigma ~ exponential(1) 253 | ) , data=dat_list ) 254 | 255 | precis( m1.2 , depth=3 , pars="Rho" ) 256 | precis(m1.2) 257 | ``` 258 | 259 | Correlation all gone. 260 | 261 | ### 1.2 INLA 262 | ```{r 9.2 inla mean} 263 | library(INLA) 264 | library(brinla) 265 | 266 | d1.2.i <- d %>% 267 | #make a new variable of district that is continuous 268 | mutate(C = use.contraception, 269 | did = as.integer(as.factor(d$district)), 270 | a.did= did, 271 | b.did= did + max(did), 272 | urban= as.factor(urban) 273 | ) 274 | 275 | n.district= max(d1.i$did) ## = 60 276 | 277 | 278 | m1.2.i <- inla(C ~ 0 + urban + f(did, model="iid2d", n= 2*n.district), data= d1.2.i, family = "binomial", 279 | Ntrials = 1, 280 | control.fixed = list( 281 | mean= 0, 282 | prec= 1), 283 | control.family = list(control.link=list(model="logit")), 284 | control.predictor=list(link=1, compute=T), 285 | control.compute=list(config=T, dic=TRUE, waic= TRUE)) 286 | summary(m1.2.i) 287 | 288 | bri.hyperpar.summary(m1.2.i) 289 | 290 | bri.hyperpar.plot(m1.2.i) 291 | 292 | ``` 293 | 294 | 295 | # 2. data(bangladesh) evaluate the influences on contraceptive use (changing attitudes) of age and number of children 296 | 297 | **Now consider the predictor variables age.centered and living.children, also contained in data(bangladesh). Suppose that age influences contraceptive use (changing attitudes) and number of children (older people have had more time to have kids). Number of children may also directly influence contraceptive use. Draw a DAG that reflects these hypothetical relationships. Then build models needed to evaluate the DAG. You will need at least two models. Retain district and ur- ban, as in Problem 1. What do you conclude about the causal influence of age and children?** 298 | 299 | ```{r 9.2 dag} 300 | 301 | library(dagitty) 302 | 303 | hw9.2dag <- dagitty("dag{ 304 | C <- A 305 | K <- A 306 | C <- K 307 | }") 308 | plot(hw9.2dag) 309 | 310 | ``` 311 | A is age, K is number of children, and C is contraception use. 312 | 313 | To study this DAG, we should estimate both the total causal influence of A and then condition also on K and see if the direct influence of A is smaller. 314 | 315 | ## 2.1 model for the total influence of A 316 | 317 | ### 2.1 rethinking 318 | 319 | ```{r 9.2.1 rethinking} 320 | 321 | dat_list$children <- standardize( d$living.children ) 322 | dat_list$age <- standardize( d$age.centered ) 323 | 324 | m2.1 <- ulam( alist( 325 | C ~ bernoulli( p ), 326 | logit(p) <- a[did] + b[did]*urban + bA*age, 327 | c(a,b)[did] ~ multi_normal( c(abar,bbar) , Rho , Sigma ), 328 | abar ~ normal(0,1), 329 | c(bbar,bA) ~ normal(0,0.5), 330 | Rho ~ lkj_corr(2), 331 | Sigma ~ exponential(1) 332 | ) , data=dat_list , chains=4 , cores=4 ) 333 | 334 | precis(m2.1) 335 | 336 | precis( m2.1 , depth=3 , pars=c("Rho","Sigma") ) 337 | ``` 338 | In this model, the total causal effect of age is positive and very small. Older individuals use slightly more contraception. 339 | 340 | ### 2.1 inla 341 | 342 | ```{r 9.2.1 inla} 343 | library(INLA) 344 | library(brinla) 345 | 346 | 347 | dat_list$children <- standardize( d$living.children ) 348 | dat_list$age <- standardize( d$age.centered ) 349 | 350 | 351 | d2.i <- d %>% 352 | #make a new variable of district that is continuous 353 | mutate(C = use.contraception, 354 | did = as.integer( as.factor(d$district)), 355 | a.did= did, 356 | b.did= did + max(did), 357 | children= standardize( living.children ) , 358 | age = standardize( age.centered ) 359 | ) 360 | 361 | n.district= max(d1.i$did) ## = 60 362 | 363 | 364 | m2.1.i <- inla(C ~ 1+ urban + age + f(a.did, model="iid2d", n= 2*n.district) + f(b.did, urban, copy= "a.did"), data= d2.i, family = "binomial", 365 | Ntrials = 1, 366 | control.fixed = list( 367 | mean= 0, 368 | prec= 1/(0.5^2), 369 | mean.intercept= 0, 370 | prec.intercept= 1 371 | ), 372 | control.family = list(control.link=list(model="logit")), 373 | control.predictor=list(link=1, compute=T), 374 | control.compute=list(config=T, dic=TRUE, waic= TRUE)) 375 | summary(m2.1.i) 376 | 377 | bri.hyperpar.summary(m2.1.i) 378 | 379 | bri.hyperpar.plot(m2.1.i) 380 | 381 | ``` 382 | 383 | the intercept is abar 384 | 385 | 386 | *why didn't it work using did as an intercept instead of 1?* 387 | 388 | 389 | ## 2.2 model for the direct influence of A (with both K and A) 390 | 391 | ### 2.2 rethinking 392 | 393 | ```{r 9.2.2 rethinking} 394 | 395 | m2.2 <- ulam( alist( 396 | C ~ bernoulli( p ), 397 | logit(p) <- a[did] + b[did]*urban + bK*children + bA*age, 398 | c(a,b)[did] ~ multi_normal( c(abar,bbar) , Rho , Sigma ), 399 | abar ~ normal(0,1), 400 | c(bbar,bK,bA) ~ normal(0,0.5), 401 | Rho ~ lkj_corr(2), 402 | Sigma ~ exponential(1) 403 | ) , data=dat_list , chains=4 , cores=4 ) 404 | 405 | precis(m2.2) 406 | 407 | precis( m2.2 , depth=3 , pars=c("Rho","Sigma") ) 408 | ``` 409 | 410 | In this model, the direct effect of age is negative, and much farther from zero than before. The effect of number of children is strong and positive. These results are consistent with the DAG, because they imply that the reason the total effect of age, from m2.1, is positive is that older individuals also have more kids. Having more kids increases contraception. Being older, controlling for kids, actually makes con- traception less likely. 411 | 412 | ### 2.2 inla 413 | 414 | ```{r 9.2.2 inla} 415 | library(INLA) 416 | library(brinla) 417 | 418 | 419 | m2.2.i <- inla(C ~ 1+ urban + age + children + f(a.did, model="iid2d", n= 2*n.district) + f(b.did, urban, copy= "a.did"), data= d2.i, family = "binomial", 420 | Ntrials = 1, 421 | control.fixed = list( 422 | mean= 0, 423 | prec= 1/(0.5^2), 424 | mean.intercept= 0, 425 | prec.intercept= 1 426 | ), 427 | control.family = list(control.link=list(model="logit")), 428 | control.predictor=list(link=1, compute=T), 429 | control.compute=list(config=T, dic=TRUE, waic= TRUE)) 430 | summary(m2.2.i) 431 | 432 | bri.hyperpar.summary(m2.2.i) 433 | 434 | bri.hyperpar.plot(m2.2.i) 435 | 436 | ``` 437 | 438 | 439 | # 3. data(bangladesh) monotonic ordered category - INCOMPLETE 440 | 441 | **Modify any models from Problem 2 that contained that children variable and model the variable now as a monotonic ordered category, like education from the week we did ordered categories. Education in that example had 8 categories. Children here will have fewer (no one in the sample had 8 children). So modify the code appropriately. What do you conclude about the causal influence of each additional child on use of contraception?** 442 | 443 | 444 | nope, not doing ordered categories -------------------------------------------------------------------------------- /rethinkingINLA_HW9_files/figure-html/9.1 inla-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/rethinkingINLA_HW9_files/figure-html/9.1 inla-1.png -------------------------------------------------------------------------------- /rethinkingINLA_HW9_files/figure-html/9.1 re plot outcome-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/rethinkingINLA_HW9_files/figure-html/9.1 re plot outcome-1.png -------------------------------------------------------------------------------- /rethinkingINLA_HW9_files/figure-html/9.1 re plot-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/rethinkingINLA_HW9_files/figure-html/9.1 re plot-1.png -------------------------------------------------------------------------------- /rethinkingINLA_HW9_files/figure-html/9.1.1 outcome plot inla-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/rethinkingINLA_HW9_files/figure-html/9.1.1 outcome plot inla-1.png -------------------------------------------------------------------------------- /rethinkingINLA_HW9_files/figure-html/9.1.1 plot inla-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/rethinkingINLA_HW9_files/figure-html/9.1.1 plot inla-1.png -------------------------------------------------------------------------------- /rethinkingINLA_HW9_files/figure-html/9.2 dag-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/rethinkingINLA_HW9_files/figure-html/9.2 dag-1.png -------------------------------------------------------------------------------- /rethinkingINLA_HW9_files/figure-html/9.2 inla mean-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/rethinkingINLA_HW9_files/figure-html/9.2 inla mean-1.png -------------------------------------------------------------------------------- /rethinkingINLA_HW9_files/figure-html/9.2.1 inla-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/rethinkingINLA_HW9_files/figure-html/9.2.1 inla-1.png -------------------------------------------------------------------------------- /rethinkingINLA_HW9_files/figure-html/9.2.2 inla-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/rethinkingINLA_HW9_files/figure-html/9.2.2 inla-1.png -------------------------------------------------------------------------------- /site_libs/bootstrap-3.3.5/css/fonts/Lato.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/site_libs/bootstrap-3.3.5/css/fonts/Lato.ttf -------------------------------------------------------------------------------- /site_libs/bootstrap-3.3.5/css/fonts/LatoBold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/site_libs/bootstrap-3.3.5/css/fonts/LatoBold.ttf -------------------------------------------------------------------------------- /site_libs/bootstrap-3.3.5/css/fonts/LatoItalic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/site_libs/bootstrap-3.3.5/css/fonts/LatoItalic.ttf -------------------------------------------------------------------------------- /site_libs/bootstrap-3.3.5/css/fonts/NewsCycle.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/site_libs/bootstrap-3.3.5/css/fonts/NewsCycle.ttf -------------------------------------------------------------------------------- /site_libs/bootstrap-3.3.5/css/fonts/NewsCycleBold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/site_libs/bootstrap-3.3.5/css/fonts/NewsCycleBold.ttf -------------------------------------------------------------------------------- /site_libs/bootstrap-3.3.5/css/fonts/OpenSans.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/site_libs/bootstrap-3.3.5/css/fonts/OpenSans.ttf -------------------------------------------------------------------------------- /site_libs/bootstrap-3.3.5/css/fonts/OpenSansBold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/site_libs/bootstrap-3.3.5/css/fonts/OpenSansBold.ttf -------------------------------------------------------------------------------- /site_libs/bootstrap-3.3.5/css/fonts/OpenSansBoldItalic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/site_libs/bootstrap-3.3.5/css/fonts/OpenSansBoldItalic.ttf -------------------------------------------------------------------------------- /site_libs/bootstrap-3.3.5/css/fonts/OpenSansItalic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/site_libs/bootstrap-3.3.5/css/fonts/OpenSansItalic.ttf -------------------------------------------------------------------------------- /site_libs/bootstrap-3.3.5/css/fonts/OpenSansLight.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/site_libs/bootstrap-3.3.5/css/fonts/OpenSansLight.ttf -------------------------------------------------------------------------------- /site_libs/bootstrap-3.3.5/css/fonts/OpenSansLightItalic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/site_libs/bootstrap-3.3.5/css/fonts/OpenSansLightItalic.ttf -------------------------------------------------------------------------------- /site_libs/bootstrap-3.3.5/css/fonts/Raleway.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/site_libs/bootstrap-3.3.5/css/fonts/Raleway.ttf -------------------------------------------------------------------------------- /site_libs/bootstrap-3.3.5/css/fonts/RalewayBold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/site_libs/bootstrap-3.3.5/css/fonts/RalewayBold.ttf -------------------------------------------------------------------------------- /site_libs/bootstrap-3.3.5/css/fonts/Roboto.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/site_libs/bootstrap-3.3.5/css/fonts/Roboto.ttf -------------------------------------------------------------------------------- /site_libs/bootstrap-3.3.5/css/fonts/RobotoBold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/site_libs/bootstrap-3.3.5/css/fonts/RobotoBold.ttf -------------------------------------------------------------------------------- /site_libs/bootstrap-3.3.5/css/fonts/RobotoLight.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/site_libs/bootstrap-3.3.5/css/fonts/RobotoLight.ttf -------------------------------------------------------------------------------- /site_libs/bootstrap-3.3.5/css/fonts/RobotoMedium.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/site_libs/bootstrap-3.3.5/css/fonts/RobotoMedium.ttf -------------------------------------------------------------------------------- /site_libs/bootstrap-3.3.5/css/fonts/SourceSansPro.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/site_libs/bootstrap-3.3.5/css/fonts/SourceSansPro.ttf -------------------------------------------------------------------------------- /site_libs/bootstrap-3.3.5/css/fonts/SourceSansProBold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/site_libs/bootstrap-3.3.5/css/fonts/SourceSansProBold.ttf -------------------------------------------------------------------------------- /site_libs/bootstrap-3.3.5/css/fonts/SourceSansProItalic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/site_libs/bootstrap-3.3.5/css/fonts/SourceSansProItalic.ttf -------------------------------------------------------------------------------- /site_libs/bootstrap-3.3.5/css/fonts/SourceSansProLight.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/site_libs/bootstrap-3.3.5/css/fonts/SourceSansProLight.ttf -------------------------------------------------------------------------------- /site_libs/bootstrap-3.3.5/css/fonts/Ubuntu.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/site_libs/bootstrap-3.3.5/css/fonts/Ubuntu.ttf -------------------------------------------------------------------------------- /site_libs/bootstrap-3.3.5/fonts/glyphicons-halflings-regular.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/site_libs/bootstrap-3.3.5/fonts/glyphicons-halflings-regular.eot -------------------------------------------------------------------------------- /site_libs/bootstrap-3.3.5/fonts/glyphicons-halflings-regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/site_libs/bootstrap-3.3.5/fonts/glyphicons-halflings-regular.ttf -------------------------------------------------------------------------------- /site_libs/bootstrap-3.3.5/fonts/glyphicons-halflings-regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/site_libs/bootstrap-3.3.5/fonts/glyphicons-halflings-regular.woff -------------------------------------------------------------------------------- /site_libs/bootstrap-3.3.5/fonts/glyphicons-halflings-regular.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akawiecki/statistical_rethinking_inla/1d2dae9bbb766b9d4e235aa2181ac0deaaca706b/site_libs/bootstrap-3.3.5/fonts/glyphicons-halflings-regular.woff2 -------------------------------------------------------------------------------- /site_libs/bootstrap-3.3.5/js/npm.js: -------------------------------------------------------------------------------- 1 | // This file is autogenerated via the `commonjs` Grunt task. You can require() this file in a CommonJS environment. 2 | require('../../js/transition.js') 3 | require('../../js/alert.js') 4 | require('../../js/button.js') 5 | require('../../js/carousel.js') 6 | require('../../js/collapse.js') 7 | require('../../js/dropdown.js') 8 | require('../../js/modal.js') 9 | require('../../js/tooltip.js') 10 | require('../../js/popover.js') 11 | require('../../js/scrollspy.js') 12 | require('../../js/tab.js') 13 | require('../../js/affix.js') -------------------------------------------------------------------------------- /site_libs/bootstrap-3.3.5/shim/html5shiv.min.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @preserve HTML5 Shiv 3.7.2 | @afarkas @jdalton @jon_neal @rem | MIT/GPL2 Licensed 3 | */ 4 | // Only run this code in IE 8 5 | if (!!window.navigator.userAgent.match("MSIE 8")) { 6 | !function(a,b){function c(a,b){var c=a.createElement("p"),d=a.getElementsByTagName("head")[0]||a.documentElement;return c.innerHTML="x",d.insertBefore(c.lastChild,d.firstChild)}function d(){var a=t.elements;return"string"==typeof a?a.split(" "):a}function e(a,b){var c=t.elements;"string"!=typeof c&&(c=c.join(" ")),"string"!=typeof a&&(a=a.join(" ")),t.elements=c+" "+a,j(b)}function f(a){var b=s[a[q]];return b||(b={},r++,a[q]=r,s[r]=b),b}function g(a,c,d){if(c||(c=b),l)return c.createElement(a);d||(d=f(c));var e;return e=d.cache[a]?d.cache[a].cloneNode():p.test(a)?(d.cache[a]=d.createElem(a)).cloneNode():d.createElem(a),!e.canHaveChildren||o.test(a)||e.tagUrn?e:d.frag.appendChild(e)}function h(a,c){if(a||(a=b),l)return a.createDocumentFragment();c=c||f(a);for(var e=c.frag.cloneNode(),g=0,h=d(),i=h.length;i>g;g++)e.createElement(h[g]);return e}function i(a,b){b.cache||(b.cache={},b.createElem=a.createElement,b.createFrag=a.createDocumentFragment,b.frag=b.createFrag()),a.createElement=function(c){return t.shivMethods?g(c,a,b):b.createElem(c)},a.createDocumentFragment=Function("h,f","return function(){var n=f.cloneNode(),c=n.createElement;h.shivMethods&&("+d().join().replace(/[\w\-:]+/g,function(a){return b.createElem(a),b.frag.createElement(a),'c("'+a+'")'})+");return n}")(t,b.frag)}function j(a){a||(a=b);var d=f(a);return!t.shivCSS||k||d.hasCSS||(d.hasCSS=!!c(a,"article,aside,dialog,figcaption,figure,footer,header,hgroup,main,nav,section{display:block}mark{background:#FF0;color:#000}template{display:none}")),l||i(a,d),a}var k,l,m="3.7.2",n=a.html5||{},o=/^<|^(?:button|map|select|textarea|object|iframe|option|optgroup)$/i,p=/^(?:a|b|code|div|fieldset|h1|h2|h3|h4|h5|h6|i|label|li|ol|p|q|span|strong|style|table|tbody|td|th|tr|ul)$/i,q="_html5shiv",r=0,s={};!function(){try{var a=b.createElement("a");a.innerHTML="",k="hidden"in a,l=1==a.childNodes.length||function(){b.createElement("a");var a=b.createDocumentFragment();return"undefined"==typeof a.cloneNode||"undefined"==typeof a.createDocumentFragment||"undefined"==typeof a.createElement}()}catch(c){k=!0,l=!0}}();var t={elements:n.elements||"abbr article aside audio bdi canvas data datalist details dialog figcaption figure footer header hgroup main mark meter nav output picture progress section summary template time video",version:m,shivCSS:n.shivCSS!==!1,supportsUnknownElements:l,shivMethods:n.shivMethods!==!1,type:"default",shivDocument:j,createElement:g,createDocumentFragment:h,addElements:e};a.html5=t,j(b)}(this,document); 7 | }; 8 | -------------------------------------------------------------------------------- /site_libs/bootstrap-3.3.5/shim/respond.min.js: -------------------------------------------------------------------------------- 1 | /*! Respond.js v1.4.2: min/max-width media query polyfill * Copyright 2013 Scott Jehl 2 | * Licensed under https://github.com/scottjehl/Respond/blob/master/LICENSE-MIT 3 | * */ 4 | 5 | // Only run this code in IE 8 6 | if (!!window.navigator.userAgent.match("MSIE 8")) { 7 | !function(a){"use strict";a.matchMedia=a.matchMedia||function(a){var b,c=a.documentElement,d=c.firstElementChild||c.firstChild,e=a.createElement("body"),f=a.createElement("div");return f.id="mq-test-1",f.style.cssText="position:absolute;top:-100em",e.style.background="none",e.appendChild(f),function(a){return f.innerHTML='­',c.insertBefore(e,d),b=42===f.offsetWidth,c.removeChild(e),{matches:b,media:a}}}(a.document)}(this),function(a){"use strict";function b(){u(!0)}var c={};a.respond=c,c.update=function(){};var d=[],e=function(){var b=!1;try{b=new a.XMLHttpRequest}catch(c){b=new a.ActiveXObject("Microsoft.XMLHTTP")}return function(){return b}}(),f=function(a,b){var c=e();c&&(c.open("GET",a,!0),c.onreadystatechange=function(){4!==c.readyState||200!==c.status&&304!==c.status||b(c.responseText)},4!==c.readyState&&c.send(null))};if(c.ajax=f,c.queue=d,c.regex={media:/@media[^\{]+\{([^\{\}]*\{[^\}\{]*\})+/gi,keyframes:/@(?:\-(?:o|moz|webkit)\-)?keyframes[^\{]+\{(?:[^\{\}]*\{[^\}\{]*\})+[^\}]*\}/gi,urls:/(url\()['"]?([^\/\)'"][^:\)'"]+)['"]?(\))/g,findStyles:/@media *([^\{]+)\{([\S\s]+?)$/,only:/(only\s+)?([a-zA-Z]+)\s?/,minw:/\([\s]*min\-width\s*:[\s]*([\s]*[0-9\.]+)(px|em)[\s]*\)/,maxw:/\([\s]*max\-width\s*:[\s]*([\s]*[0-9\.]+)(px|em)[\s]*\)/},c.mediaQueriesSupported=a.matchMedia&&null!==a.matchMedia("only all")&&a.matchMedia("only all").matches,!c.mediaQueriesSupported){var g,h,i,j=a.document,k=j.documentElement,l=[],m=[],n=[],o={},p=30,q=j.getElementsByTagName("head")[0]||k,r=j.getElementsByTagName("base")[0],s=q.getElementsByTagName("link"),t=function(){var a,b=j.createElement("div"),c=j.body,d=k.style.fontSize,e=c&&c.style.fontSize,f=!1;return b.style.cssText="position:absolute;font-size:1em;width:1em",c||(c=f=j.createElement("body"),c.style.background="none"),k.style.fontSize="100%",c.style.fontSize="100%",c.appendChild(b),f&&k.insertBefore(c,k.firstChild),a=b.offsetWidth,f?k.removeChild(c):c.removeChild(b),k.style.fontSize=d,e&&(c.style.fontSize=e),a=i=parseFloat(a)},u=function(b){var c="clientWidth",d=k[c],e="CSS1Compat"===j.compatMode&&d||j.body[c]||d,f={},o=s[s.length-1],r=(new Date).getTime();if(b&&g&&p>r-g)return a.clearTimeout(h),h=a.setTimeout(u,p),void 0;g=r;for(var v in l)if(l.hasOwnProperty(v)){var w=l[v],x=w.minw,y=w.maxw,z=null===x,A=null===y,B="em";x&&(x=parseFloat(x)*(x.indexOf(B)>-1?i||t():1)),y&&(y=parseFloat(y)*(y.indexOf(B)>-1?i||t():1)),w.hasquery&&(z&&A||!(z||e>=x)||!(A||y>=e))||(f[w.media]||(f[w.media]=[]),f[w.media].push(m[w.rules]))}for(var C in n)n.hasOwnProperty(C)&&n[C]&&n[C].parentNode===q&&q.removeChild(n[C]);n.length=0;for(var D in f)if(f.hasOwnProperty(D)){var E=j.createElement("style"),F=f[D].join("\n");E.type="text/css",E.media=D,q.insertBefore(E,o.nextSibling),E.styleSheet?E.styleSheet.cssText=F:E.appendChild(j.createTextNode(F)),n.push(E)}},v=function(a,b,d){var e=a.replace(c.regex.keyframes,"").match(c.regex.media),f=e&&e.length||0;b=b.substring(0,b.lastIndexOf("/"));var g=function(a){return a.replace(c.regex.urls,"$1"+b+"$2$3")},h=!f&&d;b.length&&(b+="/"),h&&(f=1);for(var i=0;f>i;i++){var j,k,n,o;h?(j=d,m.push(g(a))):(j=e[i].match(c.regex.findStyles)&&RegExp.$1,m.push(RegExp.$2&&g(RegExp.$2))),n=j.split(","),o=n.length;for(var p=0;o>p;p++)k=n[p],l.push({media:k.split("(")[0].match(c.regex.only)&&RegExp.$2||"all",rules:m.length-1,hasquery:k.indexOf("(")>-1,minw:k.match(c.regex.minw)&&parseFloat(RegExp.$1)+(RegExp.$2||""),maxw:k.match(c.regex.maxw)&&parseFloat(RegExp.$1)+(RegExp.$2||"")})}u()},w=function(){if(d.length){var b=d.shift();f(b.href,function(c){v(c,b.href,b.media),o[b.href]=!0,a.setTimeout(function(){w()},0)})}},x=function(){for(var b=0;b'); 25 | var showThis = (show || $(this).hasClass('fold-show')) && !$(this).hasClass('fold-hide'); 26 | if (showThis) div.addClass('in'); 27 | var id = 'rcode-643E0F36' + currentIndex++; 28 | div.attr('id', id); 29 | $(this).before(div); 30 | $(this).detach().appendTo(div); 31 | 32 | // add a show code button right above 33 | var showCodeText = $('' + (showThis ? 'Hide' : 'Code') + ''); 34 | var showCodeButton = $(''); 35 | showCodeButton.append(showCodeText); 36 | showCodeButton 37 | .attr('data-toggle', 'collapse') 38 | .attr('data-target', '#' + id) 39 | .attr('aria-expanded', showThis) 40 | .attr('aria-controls', id); 41 | 42 | var buttonRow = $('
    '); 43 | var buttonCol = $('
    '); 44 | 45 | buttonCol.append(showCodeButton); 46 | buttonRow.append(buttonCol); 47 | 48 | div.before(buttonRow); 49 | 50 | // update state of button on show/hide 51 | div.on('hidden.bs.collapse', function () { 52 | showCodeText.text('Code'); 53 | }); 54 | div.on('show.bs.collapse', function () { 55 | showCodeText.text('Hide'); 56 | }); 57 | }); 58 | 59 | } 60 | -------------------------------------------------------------------------------- /site_libs/navigation-1.1/sourceembed.js: -------------------------------------------------------------------------------- 1 | 2 | window.initializeSourceEmbed = function(filename) { 3 | $("#rmd-download-source").click(function() { 4 | var src = $("#rmd-source-code").html(); 5 | var a = document.createElement('a'); 6 | a.href = "data:text/x-r-markdown;base64," + src; 7 | a.download = filename; 8 | document.body.appendChild(a); 9 | a.click(); 10 | document.body.removeChild(a); 11 | }); 12 | }; 13 | -------------------------------------------------------------------------------- /site_libs/navigation-1.1/tabsets.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | /** 4 | * jQuery Plugin: Sticky Tabs 5 | * 6 | * @author Aidan Lister 7 | * adapted by Ruben Arslan to activate parent tabs too 8 | * http://www.aidanlister.com/2014/03/persisting-the-tab-state-in-bootstrap/ 9 | */ 10 | (function($) { 11 | "use strict"; 12 | $.fn.rmarkdownStickyTabs = function() { 13 | var context = this; 14 | // Show the tab corresponding with the hash in the URL, or the first tab 15 | var showStuffFromHash = function() { 16 | var hash = window.location.hash; 17 | var selector = hash ? 'a[href="' + hash + '"]' : 'li.active > a'; 18 | var $selector = $(selector, context); 19 | if($selector.data('toggle') === "tab") { 20 | $selector.tab('show'); 21 | // walk up the ancestors of this element, show any hidden tabs 22 | $selector.parents('.section.tabset').each(function(i, elm) { 23 | var link = $('a[href="#' + $(elm).attr('id') + '"]'); 24 | if(link.data('toggle') === "tab") { 25 | link.tab("show"); 26 | } 27 | }); 28 | } 29 | }; 30 | 31 | 32 | // Set the correct tab when the page loads 33 | showStuffFromHash(context); 34 | 35 | // Set the correct tab when a user uses their back/forward button 36 | $(window).on('hashchange', function() { 37 | showStuffFromHash(context); 38 | }); 39 | 40 | // Change the URL when tabs are clicked 41 | $('a', context).on('click', function(e) { 42 | history.pushState(null, null, this.href); 43 | showStuffFromHash(context); 44 | }); 45 | 46 | return this; 47 | }; 48 | }(jQuery)); 49 | 50 | window.buildTabsets = function(tocID) { 51 | 52 | // build a tabset from a section div with the .tabset class 53 | function buildTabset(tabset) { 54 | 55 | // check for fade and pills options 56 | var fade = tabset.hasClass("tabset-fade"); 57 | var pills = tabset.hasClass("tabset-pills"); 58 | var navClass = pills ? "nav-pills" : "nav-tabs"; 59 | 60 | // determine the heading level of the tabset and tabs 61 | var match = tabset.attr('class').match(/level(\d) /); 62 | if (match === null) 63 | return; 64 | var tabsetLevel = Number(match[1]); 65 | var tabLevel = tabsetLevel + 1; 66 | 67 | // find all subheadings immediately below 68 | var tabs = tabset.find("div.section.level" + tabLevel); 69 | if (!tabs.length) 70 | return; 71 | 72 | // create tablist and tab-content elements 73 | var tabList = $(''); 74 | $(tabs[0]).before(tabList); 75 | var tabContent = $('
    '); 76 | $(tabs[0]).before(tabContent); 77 | 78 | // build the tabset 79 | var activeTab = 0; 80 | tabs.each(function(i) { 81 | 82 | // get the tab div 83 | var tab = $(tabs[i]); 84 | 85 | // get the id then sanitize it for use with bootstrap tabs 86 | var id = tab.attr('id'); 87 | 88 | // see if this is marked as the active tab 89 | if (tab.hasClass('active')) 90 | activeTab = i; 91 | 92 | // remove any table of contents entries associated with 93 | // this ID (since we'll be removing the heading element) 94 | $("div#" + tocID + " li a[href='#" + id + "']").parent().remove(); 95 | 96 | // sanitize the id for use with bootstrap tabs 97 | id = id.replace(/[.\/?&!#<>]/g, '').replace(/\s/g, '_'); 98 | tab.attr('id', id); 99 | 100 | // get the heading element within it, grab it's text, then remove it 101 | var heading = tab.find('h' + tabLevel + ':first'); 102 | var headingText = heading.html(); 103 | heading.remove(); 104 | 105 | // build and append the tab list item 106 | var a = $('' + headingText + ''); 107 | a.attr('href', '#' + id); 108 | a.attr('aria-controls', id); 109 | var li = $('
  • '); 110 | li.append(a); 111 | tabList.append(li); 112 | 113 | // set it's attributes 114 | tab.attr('role', 'tabpanel'); 115 | tab.addClass('tab-pane'); 116 | tab.addClass('tabbed-pane'); 117 | if (fade) 118 | tab.addClass('fade'); 119 | 120 | // move it into the tab content div 121 | tab.detach().appendTo(tabContent); 122 | }); 123 | 124 | // set active tab 125 | $(tabList.children('li')[activeTab]).addClass('active'); 126 | var active = $(tabContent.children('div.section')[activeTab]); 127 | active.addClass('active'); 128 | if (fade) 129 | active.addClass('in'); 130 | 131 | if (tabset.hasClass("tabset-sticky")) 132 | tabset.rmarkdownStickyTabs(); 133 | } 134 | 135 | // convert section divs with the .tabset class to tabsets 136 | var tabsets = $("div.section.tabset"); 137 | tabsets.each(function(i) { 138 | buildTabset($(tabsets[i])); 139 | }); 140 | }; 141 | 142 | -------------------------------------------------------------------------------- /site_libs/tocify-1.9.1/jquery.tocify.css: -------------------------------------------------------------------------------- 1 | /* 2 | * jquery.tocify.css 1.9.1 3 | * Author: @gregfranko 4 | */ 5 | 6 | /* The Table of Contents container element */ 7 | .tocify { 8 | width: 20%; 9 | max-height: 90%; 10 | overflow: auto; 11 | margin-left: 2%; 12 | position: fixed; 13 | border: 1px solid #ccc; 14 | border-radius: 6px; 15 | } 16 | 17 | /* The Table of Contents is composed of multiple nested unordered lists. These styles remove the default styling of an unordered list because it is ugly. */ 18 | .tocify ul, .tocify li { 19 | list-style: none; 20 | margin: 0; 21 | padding: 0; 22 | border: none; 23 | line-height: 30px; 24 | } 25 | 26 | /* Top level header elements */ 27 | .tocify-header { 28 | text-indent: 10px; 29 | } 30 | 31 | /* Top level subheader elements. These are the first nested items underneath a header element. */ 32 | .tocify-subheader { 33 | text-indent: 20px; 34 | display: none; 35 | } 36 | 37 | /* Makes the font smaller for all subheader elements. */ 38 | .tocify-subheader li { 39 | font-size: 12px; 40 | } 41 | 42 | /* Further indents second level subheader elements. */ 43 | .tocify-subheader .tocify-subheader { 44 | text-indent: 30px; 45 | } 46 | .tocify-subheader .tocify-subheader .tocify-subheader { 47 | text-indent: 40px; 48 | } 49 | .tocify-subheader .tocify-subheader .tocify-subheader .tocify-subheader { 50 | text-indent: 50px; 51 | } 52 | .tocify-subheader .tocify-subheader .tocify-subheader .tocify-subheader .tocify-subheader { 53 | text-indent: 60px; 54 | } 55 | 56 | /* Twitter Bootstrap Override Style */ 57 | .tocify .tocify-item > a, .tocify .nav-list .nav-header { 58 | margin: 0px; 59 | } 60 | 61 | /* Twitter Bootstrap Override Styles */ 62 | .tocify .tocify-item a, .tocify .list-group-item { 63 | padding: 5px; 64 | } 65 | 66 | .tocify .nav-pills > li { 67 | float: none; 68 | } 69 | 70 | /* We don't override the bootstrap colors because this gives us the 71 | wrong selection colors when using bootstrap themes 72 | 73 | .tocify .list-group-item:hover, .tocify .list-group-item:focus { 74 | background-color: #f5f5f5; 75 | } 76 | 77 | .tocify .list-group-item.active:hover, .tocify .list-group-item.active:focus { 78 | background-color: #428bca; 79 | } 80 | */ 81 | 82 | /* End Twitter Bootstrap Override Styles */ 83 | -------------------------------------------------------------------------------- /statistical_rethinking_inla.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: Default 4 | SaveWorkspace: Default 5 | AlwaysSaveHistory: Default 6 | 7 | EnableCodeIndexing: Yes 8 | UseSpacesForTab: Yes 9 | NumSpacesForTab: 2 10 | Encoding: UTF-8 11 | 12 | RnwWeave: Sweave 13 | LaTeX: pdfLaTeX 14 | 15 | BuildType: Website 16 | --------------------------------------------------------------------------------