diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..7da1da5 Binary files /dev/null and b/.DS_Store differ diff --git a/README.md b/README.md index b900ffa..46c9b77 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ Currently there are demos for BDA3 Chapters 2, 3, 4, 5, 6, 10, 11 and 12. Furthermore there are demos for [CmdStanR](https://github.com/stan-dev/cmdstanr), [RStan](https://github.com/stan-dev/rstan) -[RStanARM](https://github.com/stan-dev/rstanarm). +[RStanARM](https://github.com/stan-dev/rstanarm). When running the R-scripts from Aalto Jupyter notebook, please make sure to set the parent directory to "~/notebooks/BDA_R_demos". The initial demos were originally written for Matlab by [Aki Vehtari](http://users.aalto.fi/~ave/) and translated to R by [Markus diff --git a/demos_ch12/demo12_1.R b/demos_ch12/demo12_1.R index 55a0961..078c764 100644 --- a/demos_ch12/demo12_1.R +++ b/demos_ch12/demo12_1.R @@ -54,7 +54,7 @@ tt[1,] <- c(t1, t2) # Save starting point # For demonstration load pre-computed values # Replace this with your algorithm! # tt is a M x 2 array, with M samples of both theta_1 and theta_2 -load(root("demos_ch11","demo12_1b.RData")) +load(root("demos_ch12","demo12_1b.RData")) # Here we have intentionally used a very small step size for smooth # simulations, but for more efficient simulations larger step size # could be used diff --git a/demos_ch12/demo12_1.Rmd b/demos_ch12/demo12_1.Rmd index 72e0baf..3fb1041 100644 --- a/demos_ch12/demo12_1.Rmd +++ b/demos_ch12/demo12_1.Rmd @@ -69,7 +69,7 @@ tt[1,] <- c(t1, t2) # Save starting point # For demonstration load pre-computed values # Replace this with your algorithm! # tt is a M x 2 array, with M samples of both theta_1 and theta_2 -load(root("demos_ch11","demo12_1b.RData")) +load(root("demos_ch12","demo12_1b.RData")) # Here we have intentionally used a very small step size for smooth # simulations, but for more efficient simulations larger step size # could be used diff --git a/demos_ch5/demo5_2.R b/demos_ch5/demo5_2.R index 375dbe5..d5f5076 100644 --- a/demos_ch5/demo5_2.R +++ b/demos_ch5/demo5_2.R @@ -20,7 +20,7 @@ library(gridExtra) library(tidyr) library(latex2exp) library(rprojroot) -root<-has_file(".BDA_R_demos_root")$make_fix_file() +root<-has_file(".BDA_R_demos_root")$make_fix_file() # Make sure to set parent directory to ~/notebooks/BDA_R_demos #' Data y <- c(28,8,-3,7,-1,1,18,12) @@ -81,7 +81,7 @@ plot_margpost <- geom_line(aes(x = x, y = p), color='forestgreen') + labs(x = expression(tau), y = TeX('$p(\\tau | y)$'), title = title1) + scale_y_continuous(breaks = 0) + - xlim(c(0, 35)) + xlim(c(0, 40)) df_condmeans <- as.data.frame(t(tm)) %>% @@ -93,7 +93,7 @@ yl <- c(-5, 40) title2 <- TeX('Conditional means E\\[$\\theta_j | \\tau , y $\\]') plot_condmeans <- ggplot(data = df_condmeans) + geom_line(aes(x = x, y = p, color = (school=='A'), group = school)) + - coord_cartesian(ylim = yl, xlim = c(0, 35)) + + coord_cartesian(ylim = yl, xlim = c(0, 40)) + labs(x = expression(tau), y = TeX('E\\[$\\theta_j | \\tau , y $\\]'), title = title2, color = '') + scale_color_manual(values = c('blue','red'), labels = labs1) + theme(legend.background = element_blank(), legend.position = c(0.8,0.9)) @@ -107,7 +107,7 @@ yl <- c(0, 25) title3 <- TeX('Conditional standard deviations sd\\[$\\theta_j | \\tau , y $\\]') plot_condsds <- ggplot(data = df_condsds) + geom_line(aes(x = x, y = p, color = (school=='A'), group = school)) + - coord_cartesian(ylim = yl, xlim = c(0,35)) + + coord_cartesian(ylim = yl, xlim = c(0,40)) + labs(x = expression(tau), y = TeX('sd\\[$\\theta_j | \\tau , y $\\]'), title = title3, color = '') + scale_color_manual(values = c('blue','red'), labels = labs1) + theme(legend.background = element_blank(), legend.position = c(0.8,0.9)) diff --git a/demos_rstan/README.md b/demos_rstan/README.md index 22efce0..a4307f0 100644 --- a/demos_rstan/README.md +++ b/demos_rstan/README.md @@ -1,5 +1,7 @@ # Links to html versions of demos +If running the CMDStanR demos on Aalto Jupyter, please make sure to have specified the location for CMDStanR: set_cmdstan_path('/coursedata/cmdstan'). + - [rstan_demo: RStan demo](http://avehtari.github.io/BDA_R_demos/demos_rstan/rstan_demo.html) - [cmdstanr_demo: CmdStanR demo](http://avehtari.github.io/BDA_R_demos/demos_rstan/cmdstanr_demo.html) - [rstanarm_demo: RStanARM demo](http://avehtari.github.io/BDA_R_demos/demos_rstan/rstanarm_demo.html) diff --git a/demos_rstan/rstanarm_demo.R b/demos_rstan/rstanarm_demo.R index cc96292..8a393b7 100644 --- a/demos_rstan/rstanarm_demo.R +++ b/demos_rstan/rstanarm_demo.R @@ -194,7 +194,7 @@ mcmc_hist(draws_bin2, pars='oddsratio') #' # Linear Gaussian model #' #' The following file has Kilpisjärvi summer month temperatures 1952-2013: -data_kilpis <- read.delim('kilpisjarvi-summer-temp.csv', sep = ';') +data_kilpis <- read.delim('~/BDA_R_demos/demos_rstan/kilpisjarvi-summer-temp.csv', sep = ';') data_lin <-data.frame(year = data_kilpis$year, temp = data_kilpis[,5]) @@ -284,7 +284,7 @@ loo_compare(loo1, loo2) #' # Comparison of k groups with hierarchical models #' #' Let's compare the temperatures in three summer months. -data_kilpis <- read.delim('kilpisjarvi-summer-temp.csv', sep = ';') +data_kilpis <- read.delim('~/BDA_R_demos/demos_rstan/kilpisjarvi-summer-temp.csv', sep = ';') data_grp <- data.frame(month = rep(6:8, nrow(data_kilpis)), temp = c(t(data_kilpis[,2:4]))) diff --git a/demos_rstan/rstanarm_demo.Rmd b/demos_rstan/rstanarm_demo.Rmd index e090987..f54f173 100644 --- a/demos_rstan/rstanarm_demo.Rmd +++ b/demos_rstan/rstanarm_demo.Rmd @@ -239,7 +239,7 @@ mcmc_hist(draws_bin2, pars='oddsratio') The following file has Kilpisjärvi summer month temperatures 1952-2013: ```{r } -data_kilpis <- read.delim('kilpisjarvi-summer-temp.csv', sep = ';') +data_kilpis <- read.delim('~/BDA_R_demos/demos_rstan/kilpisjarvi-summer-temp.csv', sep = ';') data_lin <-data.frame(year = data_kilpis$year, temp = data_kilpis[,5]) ``` @@ -348,7 +348,7 @@ There is no practical difference between Gaussian and Student's t models. Let's compare the temperatures in three summer months. ```{r } -data_kilpis <- read.delim('kilpisjarvi-summer-temp.csv', sep = ';') +data_kilpis <- read.delim('~/BDA_R_demos/demos_rstan/kilpisjarvi-summer-temp.csv', sep = ';') data_grp <- data.frame(month = rep(6:8, nrow(data_kilpis)), temp = c(t(data_kilpis[,2:4]))) ```