Skip to content

Commit

Permalink
v1.59 - patch for rstan 2.10.1
Browse files Browse the repository at this point in the history
- Brings map2stan up to date with syntax changes in rstan 2.10.1. Now
requires rstan 2.10.0 or greater. See changes to R/map2stan-templates.r
if curious about internal syntax changes. Older Stan code will still
function, but will throw deprecation warnings.
- A book errata file is now included: ERRATA.md
- A few documentation fixes
- Adjusted namespace and added manually constructed generics
(R/aa_generics.r) to hopefully fix the odd issues with plot methods
that some people have had. I still can’t repeat the issue myself, so
flying blind. Sorry.
- fixed an unusual variable name bug with glimmer()
- fixed an issue with negative bounds in uniform densities and map2stan.
  • Loading branch information
Richard McElreath committed Jun 27, 2016
1 parent e71dbc1 commit a309712
Show file tree
Hide file tree
Showing 14 changed files with 3,863 additions and 43 deletions.
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
Package: rethinking
Type: Package
Title: Statistical Rethinking book package
Version: 1.58
Date: 2015-12-24
Version: 1.59
Date: 2016-6-24
Author: Richard McElreath
Maintainer: Richard McElreath <mcelreath@ucdavis.edu>
Imports: coda, MASS, mvtnorm, loo
Depends: rstan, parallel, methods
Depends: rstan (>= 2.10.0), parallel, methods, stats, graphics
Description: Utilities for fitting and comparing models
License: GPL (>= 3)
34 changes: 34 additions & 0 deletions ERRATA.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
Statistical Rethinking book Errata
==========

page 42: Just below R code box 2.6, the text says that map requires a list of start values. It does not, as long as priors are provided for each parameter. And indeed the example in box 2.6 does not contain a list of start values.

page 87: The marginal description of the model reads "mu ~ dnorm(156, 10)" but the model is Normal(178, 20). Same error on p 95 and in code 4.38. It is corrected in code 4.39.

page 95-96: dnorm(156,100) should be dnorm(178,100) in both model presentation and then R code on top of page 96.

page 103, R code 4.50: The ``post`` object implied here is the one from R code 4.46: ``post <- extract.samples(m4.3)``.

page 125: Below R code 5.4, "The posterior mean for age at marriage, ba, ..." 'ba' should be 'bA'.

page 156, near top: "In fact, if you try to include a dummy variable for apes, you'll up with..." Should be "you'll end up with".

page 196-200: The data.frame d has 17 cases. However in the discussion of the four models (on e.g. page 200), the text repeatedly refers to 12 cases.

page 212, the next-to-last sentence on the page refers to "the Rethinking box at the end of this section." That box is not in the text.

page 237 Exercise H1: "...index variable, as explained in Chapter 6.",
should be chapter 5 (at least that's their first appearance)

page 253 ("...the functions postcheck, link and sim work on map2stan
just as they do on map models...") postcheck appears somewhat out of thin air. Need a better introduction to it.

page 314: "Islands that are better network acquire or sustain more tool types.": network should be networked.

page 331, line 1: "a women" -> "a woman"

page 435: "FIGURE 14.4 display ... imputed neocortex values in blue ...
shown by the blue line segments". The imputed values are actually the
open black dots (and corresponding black line segments) as the caption
of the figure correctly states.

8 changes: 8 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
exportPattern("^[^x]")
importFrom(graphics, "plot")
importFrom(stats, "coef")
importFrom(stats, "vcov")
importFrom(stats, "nobs")
importFrom(stats, "logLik")
importFrom(stats, "deviance")
importFrom(stats, "AIC")
importFrom(graphics, "pairs")
importFrom(coda, HPDinterval)
importFrom(coda, as.mcmc)
importFrom(MASS, mvrnorm)
Expand Down
23 changes: 23 additions & 0 deletions R/aa_generics.r
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
if (!isGeneric("plot"))
setGeneric("plot", function(x, y, ...) standardGeneric("plot"))

if (!isGeneric("coef"))
setGeneric("coef", function(object, ...) standardGeneric("coef"))

if (!isGeneric("vcov"))
setGeneric("vcov", function(object, ...) standardGeneric("vcov"))

if (!isGeneric("nobs"))
setGeneric("nobs", function(object, ...) standardGeneric("nobs"))

if (!isGeneric("logLik"))
setGeneric("logLik", function(object, ...) standardGeneric("logLik"))

if (!isGeneric("deviance"))
setGeneric("deviance", function(object, ...) standardGeneric("deviance"))

if (!isGeneric("AIC"))
setGeneric("AIC", function(object, ..., k=2) standardGeneric("AIC"))

if (!isGeneric("pairs"))
setGeneric("pairs", function(x, ...) standardGeneric("pairs"))
1 change: 1 addition & 0 deletions R/glimmer.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ xparse_glimmer_formula <- function( formula , data ) {
if ( class(f_nobars)=="name" & length(f_nobars)==1 ) {
f_nobars <- nobars( as.formula( paste( deparse(formula) , "+ 1" ) ) )
}
#fixef <- make.names( colnames( model.matrix( f_nobars , data ) ) )
fixef <- colnames( model.matrix( f_nobars , data ) )

# convert to all fixed effects and build needed model matrix
Expand Down
2 changes: 1 addition & 1 deletion R/map.r
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ map <- function( flist , data , start , method="BFGS" , hessian=TRUE , debug=FAL
laplace = 'dlaplace'
)

idx_marker_string <- "_._"
idx_marker_string <- "___"

# function to sample from prior specified with density function
sample_from_prior <- function( f ) {
Expand Down
16 changes: 9 additions & 7 deletions R/map2stan-class.r
Original file line number Diff line number Diff line change
Expand Up @@ -295,20 +295,22 @@ setMethod("pairs" , "map2stan" , function(x, n=500 , alpha=0.7 , cex=0.7 , pch=1
rethink_palette <- c("#8080FF","#F98400","#F2AD00","#00A08A","#FF0000")
rethink_cmyk <- c(col.alpha("black",0.25),"cyan")
tracerplot <- function( object , pars , col=rethink_palette , alpha=1 , bg=col.alpha("black",0.15) , ask=TRUE , window , n_cols=3 , max_rows=5 , ... ) {
chain.cols <- col

if ( class(object)!="map2stan" ) stop( "requires map2stan fit" )
if ( !(class(object) %in% c("map2stan","stanfit")) ) stop( "requires map2stan or stanfit fit object" )

if ( class(object)=="map2stan" ) object <- object@stanfit

# get all chains, not mixed, from stanfit
if ( missing(pars) )
post <- extract(object@stanfit,permuted=FALSE,inc_warmup=TRUE)
post <- extract(object,permuted=FALSE,inc_warmup=TRUE)
else
post <- extract(object@stanfit,pars=pars,permuted=FALSE,inc_warmup=TRUE)
post <- extract(object,pars=pars,permuted=FALSE,inc_warmup=TRUE)

# names
dimnames <- attr(post,"dimnames")
chains <- dimnames$chains
pars <- dimnames$parameters
chain.cols <- rep_len(col,length(chains))
# cut out "dev" and "lp__"
wdev <- which(pars=="dev")
if ( length(wdev)>0 ) pars <- pars[-wdev]
Expand All @@ -326,8 +328,8 @@ tracerplot <- function( object , pars , col=rethink_palette , alpha=1 , bg=col.a
n_pages <- ceiling(n_pars/(n_cols*n_rows_per_page))
paging <- TRUE
}
n_iter <- object@stanfit@sim$iter
n_warm <- object@stanfit@sim$warmup
n_iter <- object@sim$iter
n_warm <- object@sim$warmup
wstart <- 1
wend <- n_iter
if ( !missing(window) ) {
Expand All @@ -351,7 +353,7 @@ tracerplot <- function( object , pars , col=rethink_palette , alpha=1 , bg=col.a
}

# fetch n_eff
n_eff <- summary(object@stanfit)$summary[,'n_eff']
n_eff <- summary(object)$summary[,'n_eff']

# make window
#set_nice_margins()
Expand Down
Loading

0 comments on commit a309712

Please sign in to comment.