Skip to content

Commit

Permalink
updated for Stan 2.18 and ggplot2 3.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
MatsuuraKentaro committed Nov 2, 2018
1 parent 8238d00 commit fcfb395
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 30 deletions.
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,18 @@ source('ex1.R')
| ソフトやパッケージ名 | 執筆時点 | サポートページ内の現状 |
|:-----------|:------------|:------------|
| OS | Windows 7 SP1 (64bit) | Windows 7 SP1 (64bit) |
| R | 3.3.1 | 3.3.1 |
| Rtools | Rtools34 | Rtools34 |
| Stan | 2.11 | 2.14 |
| rstan | 2.11.1 | 2.14.2 |
| ggplot | 2.1.0 | 2.2.1 |
| R | 3.3.1 | 3.5.1 |
| Rtools | Rtools34 | Rtools35 |
| Stan | 2.11 | 2.18 |
| rstan | 2.11.1 | 2.18.1 |
| ggplot | 2.1.0 | 3.1.0 |
| ggmcmc | 1.1 | 1.1 |
| GGally | 1.1.0 | 1.3.0 |
| ellipse | 0.3.8 | 0.3.8 |
| hexbin | 1.27.1 | 1.27.1 |
| ggtern | 2.1.1 | 2.2.0 |
| mvtnorm | 1.0.5 | 1.0.5 |
| bda | 5.1.6 | 5.1.6 |
| gtools | 3.5.0 | 3.5.0 |
| Nippon | 0.6.3.1 | 0.6.3.1 |
| ggrepel | 0.5 | 0.6.5 |
| GGally | 1.1.0 | 1.4.0 |
| ellipse | 0.3.8 | 0.4.1 |
| hexbin | 1.27.1 | 1.27.2 |
| ggtern | 2.1.1 | 3.0.0 |
| mvtnorm | 1.0.5 | 1.0.8 |
| bda | 5.1.6 | 10.1.9 |
| gtools | 3.5.0 | 3.8.1 |
| Nippon | 0.6.3.1 | 0.7.1 |
| ggrepel | 0.5 | 0.8.0 |
4 changes: 2 additions & 2 deletions chap04/fig4-7.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ g1 <- cbind(g_x, g_emp, size='first')
g2 <- cbind(g_xy, g_y, size='first')
g <- rbind(g1, g2, size='first')
g$widths[1:3] <- grid::unit.pmax(g1$widths[1:3], g2$widths[1:3])
g$heights[7:12] <- g$widths[5:10] <- rep(unit(0.5,'mm'), 6)
g$heights[6] <- g$widths[11] <- unit(3,'cm')
g$heights[8:13] <- g$widths[6:11] <- rep(unit(0.5,'mm'), 6)
g$heights[7] <- g$widths[14] <- unit(3,'cm')

png(file='output/fig4-7.png', res=300, w=1800, h=1800)
grid::grid.draw(g)
Expand Down
6 changes: 3 additions & 3 deletions chap06/fig6-12.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ plot.multinormal <- function(file) {
g_xy <- ggplotGrob(p_xy)
g_x <- ggplotGrob(p_x)
g <- rbind(g_x, g_xy, size='first')
g$widths[1:3] <- grid::unit.pmax(g1$widths[1:3], g2$widths[1:3])
g$heights[7:12] <- rep(unit(0.3,'mm'), 6)
g$heights[6] <- unit(2,'cm')
g$widths[1:3] <- grid::unit.pmax(g_xy$widths[1:3], g_x$widths[1:3])
g$heights[8:13] <- rep(unit(0.3,'mm'), 6)
g$heights[7] <- unit(2,'cm')

png(file=file, res=300, w=1200, h=1400)
grid::grid.draw(g)
Expand Down
2 changes: 1 addition & 1 deletion chap06/fig6-6.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ lab_seq <- seq(from=0.2, to=1, by=0.2)

plot.tern <- function(d, file) {
p <- ggtern(data=d, aes(x=z, y=y, z=x))
p <- p + theme_bw(base_size=18, base_family='serif')
p <- p + theme_bw(base_size=18, base_family='serif') + theme_latex(value=TRUE)
p <- p + theme(
plot.margin=margin(-5,-5,-5,-5,'mm'),
tern.axis.line=element_line(color=gray(0.2)),
Expand Down
2 changes: 1 addition & 1 deletion chap08/run-model8-6.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ K <- 30
G <- 3
K2G <- unique(d[ , c('KID','GID')])$GID
data6 <- list(N=N, G=G, K=K, X=d$X, Y=d$Y, KID=d$KID, GID=d$GID, K2G=K2G)
fit6 <- stan(file='model/model8-6.stan', data=data6, seed=123)
fit6 <- stan(file='model/model8-6.stan', data=data6, seed=12345)

save.image('output/result-model8-6.RData')
3 changes: 2 additions & 1 deletion chap12/fig12-10-left.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
library(Nippon)
library(NipponMap)

d <- read.csv('input/data-map-temperature.txt')
d$Y[d$Y > 19] <- 19
Expand All @@ -7,5 +8,5 @@ cols <- lattice::level.colors(
col.regions=colorRampPalette(RColorBrewer::brewer.pal(9,'Greys'))(100)
)
png('output/fig12-10-left.png', w=800, h=600)
JapanPrefecturesMap(col=cols)
JapanPrefMap(col=cols)
dev.off()
3 changes: 2 additions & 1 deletion chap12/fig12-10-right.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
library(Nippon)
library(NipponMap)

load('output/result-model12-14.RData')
ms <- rstan::extract(fit)
Expand All @@ -9,5 +10,5 @@ cols <- lattice::level.colors(
col.regions=colorRampPalette(RColorBrewer::brewer.pal(9,'Greys'))(100)
)
png('output/fig12-10-right.png', w=800, h=600)
JapanPrefecturesMap(col=cols)
JapanPrefMap(col=cols)
dev.off()
4 changes: 2 additions & 2 deletions chap12/fig12-11.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ p <- ggplot.obspred(data=d_est, xylim=c(9, 24), size=0.8)
p <- p + geom_label_repel(
data=d_all[top3_diff, ], aes(label=name),
box.padding=grid::unit(2, 'lines'),
nudge_x=ifelse(d_all[top3_diff, ]$diff > 0, 2, -2),
nudge_y=ifelse(d_all[top3_diff, ]$diff > 0, -1, 1)
nudge_x=ifelse(d_all[top3_diff, ]$diff > 0, 4, -3),
nudge_y=ifelse(d_all[top3_diff, ]$diff > 0, -2, 3)
)
p <- p + labs(x='Observed', y='Predicted')
p <- p + scale_x_continuous(breaks=seq(0, 25, 5))
Expand Down
2 changes: 1 addition & 1 deletion chap12/run-model12-14.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ data <- list(N=N, Y=d$Y, I=nrow(d2), From=d2$From, To=d2$To)

stanmodel <- stan_model(file='model/model12-14.stan')
fit <- sampling(
stanmodel, data=data, seed=1234,
stanmodel, data=data, seed=1,
init=function() { list(r=d$Y, s_r=1, s_Y=0.1) }
)

Expand Down
2 changes: 1 addition & 1 deletion chap12/run-model12-2.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ T_pred <- 3
data <- list(T=T, T_pred=T_pred, Y=d$Y)
stanmodel <- stan_model(file='model/model12-2.stan')
fit <- sampling(stanmodel, data=data, pars=c('mu_all', 's_mu', 's_Y'),
iter=4000, thin=5, seed=1234)
iter=4000, thin=5, seed=123)

save.image('output/result-model12-2.RData')
4 changes: 2 additions & 2 deletions chap12/run-model12-6.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ d <- read.csv('input/data-ss2.txt')
T <- nrow(d)
data <- list(T=T, Y=d$Y)
stanmodel <- stan_model(file='model/model12-6.stan')
fit <- sampling(stanmodel, data=data, iter=4000, thin=5, seed=1234)
fit <- sampling(stanmodel, data=data, iter=4000, thin=5, seed=1)

save.image('output/result-model12-6.RData')

stanmodel_b <- stan_model(file='model/model12-6b.stan')
fit_b <- sampling(stanmodel_b, data=data,
pars=c('mu', 'season', 's_mu', 's_season', 's_Y', 'y_mean'), iter=4000, thin=5, seed=1234)
pars=c('mu', 'season', 's_mu', 's_season', 's_Y', 'y_mean'), iter=4000, thin=5, seed=123)
2 changes: 1 addition & 1 deletion update.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
### 2.15 → 2.17
### 2.15 → 2.18
特にありません.

### 2.14.2 → 2.15
Expand Down

0 comments on commit fcfb395

Please sign in to comment.