stan-dev / example-models

Example models for Stan
http://mc-stan.org/
772 stars 479 forks source link

Missing function in Introduction #145

Closed cfbeuchel closed 5 years ago

cfbeuchel commented 5 years ago

Hi!

I discovered the "bayes-stats-stan" documentation and started reading the Introduction on mc-stan.org (This one or the pdf-version on github).

I simply wanted to reproduce the first Hello World but stumbled upon an R-function used in the example that was not provided in the document. It's not a real issue but it might be confusing/discouraging to new readers trying to reproduce the provided example. I'm referring to the function extract_one_draw (Page 16 in the PDF version), or this chunk here:

y <- extract_one_draw(fake_data)$y
hello_data <- list(N=N, x=x, y=y)

The function extract_one_draw is not defined anywhere in the HTML/PDF version, but I found the chunk here and here and here:

options(htmltools.dir.version = FALSE)
options(digits = 2)
library(knitr)
knitr::opts_chunk$set(cache = TRUE)
knitr::opts_chunk$set(tidy = FALSE, cache.extra = packageVersion('tufte'))
knitr::opts_chunk$set(comment = "")
print_file <- function(file) {
  cat(paste(readLines(file), "\n", sep=""), sep="")
}
extract_one_draw <- function(stanfit, chain = 1, iter = 1) {
  x <- get_inits(stanfit, iter = iter)
  x[[chain]]
}
library("arm")
library("rstan")
options(mc.cores = parallel::detectCores())
rstan_options(auto_write = TRUE)

This file looks like the newest version of the introduction and also does not include the function definition, which is therefore not included in the respective HTML/PDF file. I guess it was moved here.

The knitr-options in all the .Rmd files are {r setup, include=FALSE, echo=FALSE} for the above chunk. I don't really know which exact file the PDF/HTML version on the mc-stan-website is based on but I guess this issue could be easily solved by defining the function in an include = T, echo = T chunk, like the one the function is called in (maybe this one).

I hope I didn't make any mistakes or reproduced an issue or overlook anything. Thank you for creating such accessible documentation for this great software!

Edit: I realize this issue should have been opened in the https://github.com/stan-dev/docs repository. I'll close and re-open it. I'm sorry for the mix-up.