Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes and reminders #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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".
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should make this automatic


The initial demos were originally written for Matlab by [Aki
Vehtari](http://users.aalto.fi/~ave/) and translated to R by [Markus
Expand Down
2 changes: 1 addition & 1 deletion demos_ch12/demo12_1.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion demos_ch12/demo12_1.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions demos_ch5/demo5_2.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should make this automatic


#' Data
y <- c(28,8,-3,7,-1,1,18,12)
Expand Down Expand Up @@ -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))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why was this change needed?



df_condmeans <- as.data.frame(t(tm)) %>%
Expand All @@ -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))
Expand All @@ -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))
Expand Down
2 changes: 2 additions & 0 deletions demos_rstan/README.md
Original file line number Diff line number Diff line change
@@ -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').
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should work automatically as soon as IT has fixed it


- [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)
Expand Down
4 changes: 2 additions & 2 deletions demos_rstan/rstanarm_demo.R
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ';')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No fixed absolute paths!

data_lin <-data.frame(year = data_kilpis$year,
temp = data_kilpis[,5])

Expand Down Expand Up @@ -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 = ';')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No fixed absolute paths!

data_grp <- data.frame(month = rep(6:8, nrow(data_kilpis)),
temp = c(t(data_kilpis[,2:4])))

Expand Down
4 changes: 2 additions & 2 deletions demos_rstan/rstanarm_demo.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ';')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No fixed absolute paths!

data_lin <-data.frame(year = data_kilpis$year,
temp = data_kilpis[,5])
```
Expand Down Expand Up @@ -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 = ';')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No fixed absolute paths!

data_grp <- data.frame(month = rep(6:8, nrow(data_kilpis)),
temp = c(t(data_kilpis[,2:4])))
```
Expand Down