You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
All the requisite code to run this notebook can be found online, in the [planetary motion github repository](https://github.com/stan-dev/example-models/tree/case-study/planet/knitr/planetary_motion).
64
71
65
72
# Building the model
@@ -102,23 +109,20 @@ and we set $k = 1$.
102
109
mod <- cmdstan_model("model/planetary_motion_sim.stan")
@@ -426,10 +438,9 @@ fit <- mod$sample(data = list(n = n, q_obs = q_obs),
426
438
iter_sampling = 500,
427
439
seed = 123, save_warmup = TRUE, refresh = 0)
428
440
429
-
r_fit2 <- read_stan_csv(fit$output_files())
430
-
summary(r_fit2, pars = c("lp__", "k"), probs = c())[1]
441
+
fit$summary(c("lp__", "k"))[, c(1, 2, 4, 8, 9)]
431
442
432
-
traceplot(r_fit2, pars = c("lp__", "k"))
443
+
bayesplot::mcmc_trace(fit$draws(c("lp__", "k")))
433
444
```
434
445
435
446
Everything now looks good. The chains converge near $k = 1$, and simulate predictions that are consistent with the data.
@@ -514,7 +525,13 @@ Relaxing the above a little, we may roll with a prior such as $k \sim \mathrm{No
514
525
515
526
Let us fit the model, using the initial conditions we developed above, plus a broad range of values for the star's position, confined by the observations.
516
527
```{r }
517
-
model_name <- "planetary_motion_star2.stan"
528
+
mod <- cmdstan_model("model/planetary_motion_star.stan")
529
+
530
+
# Process data for new model (same data, different format)
531
+
n_select <- 40
532
+
time <- (1:n_select) / 10
533
+
stan_data <- list(n = n_select, q_obs = q_obs, time = time,
As commented before, we would've been wise not to run the algorithm for so many iterations... Stan returns several warning messages, including divergent transitions (for 343 out of 8,000 samples) and exceeded maximum treedepths (for 28 samples).
576
+
We can check the warning message report using `fit$cmdstan_diagnose()`.
577
+
As before, let's examine a few diagnostics:
560
578
```{r, message=FALSE}
561
579
pars <- c("lp__", "k", "q0", "p0", "star")
562
-
summary(r_fit, pars = pars, probs = c())[1]
563
-
traceplot(r_fit, pars = pars, inc_warmup = TRUE)
580
+
r_fit2$summary(pars)[, c(1, 2, 4, 8, 9)]
581
+
582
+
pars <- c("lp__", "k", "q0[1]", "q0[2]", "p0[1]", "p0[2]",
583
+
"star[1]", "star[2]")
584
+
bayesplot::mcmc_trace(r_fit2$draws(), pars = pars)
564
585
```
565
586
566
587
We have five well-behaved chains, which return consistent estimates, and three other chains which have with great effort ventured into other regions of the parameter space.
567
588
They take significantly longer to run without achieving the same log-posterior (what else is new?).
568
589
The posterior predictive checks confirm that these three chains don not produce output consistent with the observations.
0 commit comments