Skip to content

Commit

Permalink
ensemble fix - release prep
Browse files Browse the repository at this point in the history
- fixed ensemble to work with new methods
- various pre-release housekeeping
  • Loading branch information
Richard McElreath committed Feb 22, 2020
1 parent 3b36bbe commit b17cb2a
Show file tree
Hide file tree
Showing 9 changed files with 3,741 additions and 16 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Package: rethinking
Type: Package
Title: Statistical Rethinking book package
Version: 1.95
Date: 2020-02-01
Date: 2020-02-11
Author: Richard McElreath
Maintainer: Richard McElreath <[email protected]>
Imports: coda, MASS, mvtnorm, loo, shape
Expand Down
4 changes: 3 additions & 1 deletion R/compare.r
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ compare <- function( ... , n=1e3 , sort="WAIC" , func=WAIC , WAIC=TRUE , refresh
mnames <- as.character(mnames)[2:(length(L)+1)]

# use substitute to deparse the func argument
the_func <- deparse(substitute(func))
the_func <- func
if ( class(the_func) != "character" )
the_func <- deparse(substitute(func))

# check class of fit models and warn when more than one class represented
classes <- as.character(sapply( L , class ))
Expand Down
10 changes: 5 additions & 5 deletions R/drawdag_igraph.R
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,11 @@ if (FALSE) {
}")

coordinates(exdag) <- list(x=c(U=1,X=1,Y=2,Z=0),y=c(U=0,X=1,Y=1,Z=1))
drawdag(exdag,margin=-0.25,edge.curve=0.1 )
graphdag(exdag,margin=-0.25,edge.curve=0.1 )

l <- drawdag( exdag , layout=layout_in_circle )
l <- drawdag( exdag , layout=layout_nicely )
drawdag( exdag , layout=l )
l <- graphdag( exdag , layout=layout_in_circle )
l <- graphdag( exdag , layout=layout_nicely )
graphdag( exdag , layout=l )

exdag2 <- dagitty( 'dag {
G [exposure,unobserved]
Expand All @@ -144,7 +144,7 @@ if (FALSE) {
RG -> "G*"
}')

drawdag( exdag2 , edge.curve=0.2 )
graphdag( exdag2 , edge.curve=0.2 )

l <- sketchdag( exdag2 )
drawdag( exdag2 , layout=round(l,2) )
Expand Down
2 changes: 2 additions & 0 deletions R/ensemble.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ ensemble <- function( ... , data , n=1e3 , func=WAIC , weights , refresh=0 , rep
if ( missing(weights) ) {
if ( length(L)>1 ) {
use_func <- func
if ( class(use_func) != "character" )
use_func <- deparse(substitute(func))
ictab <- compare( ... , func=use_func , refresh=refresh , n=n , sort=FALSE )
rownames(ictab) <- mnames
weights <- ictab$weight
Expand Down
10 changes: 7 additions & 3 deletions R/map2stan-class.r
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,16 @@ setMethod("show", "map2stan", function(object){

if ( !is.null(attr(object,"WAIC")) ) {
waic <- attr(object,"WAIC")
use_waic <- sum(waic)
cat("\nWAIC (SE): ")
cat( concat(round(as.numeric(use_waic),2) , " (" , round(as.numeric(attr(waic,"se")),1) , ")" , "\n" ) )
cat( concat(
round(as.numeric(sum(waic[,1]),2)) ,
" (" ,
round(as.numeric(waic[1,4]),1) ,
")" ,
"\n" ) )

cat("pWAIC: ")
use_pWAIC <- sum( unlist(attr(waic,"pWAIC")) )
use_pWAIC <- sum( waic[,3] )
cat( round(as.numeric(use_pWAIC),2) , "\n" )
}

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
rethinking
==========

This R package accompanies a course and book on Bayesian data analysis (McElreath 2016. Statistical Rethinking. CRC Press.). It contains tools for conducting both quick quadratic approximation of the posterior distribution as well as Hamiltonian Monte Carlo (through RStan - mc-stan.org). Many packages do this. The signature difference of this package is that it forces the user to specify the model as a list of explicit distributional assumptions. This is more tedious than typical formula-based tools, but it is also much more flexible and powerful and---most important---useful for teaching and learning. When students have to write out every detail of the model, they actually learn the model.
This R package accompanies a course and book on Bayesian data analysis: McElreath 2020. Statistical Rethinking, 2nd edition. CRC Press. It contains tools for conducting both quick quadratic approximation of the posterior distribution as well as Hamiltonian Monte Carlo (through RStan - mc-stan.org). Many packages do this. The signature difference of this package is that it forces the user to specify the model as a list of explicit distributional assumptions. This is more tedious than typical formula-based tools, but it is also much more flexible and powerful and---most important---useful for teaching and learning. When students have to write out every detail of the model, they actually learn the model.

For example, a simple Gaussian model could be specified with this list of formulas:

Expand Down Expand Up @@ -202,7 +202,7 @@ m_glmm5 <- ulam(
```
In the above, the varying effects matrix `v` is constructed from a matrix of z-scores `z` and a covariance structure contained in `sigma` and a Cholesky factor `L_Rho`. Note the double-bracket notation `v_mu[[1]]` allowing distinct priors for each index of a vector.

## log-likelihood calculations for WAIC and LOO
## log-likelihood calculations for WAIC and LOOCV

`ulam` can optionally return pointwise log-likelihood values. These are needed for computing WAIC and PSIS-LOO. The `log_lik` argument toggles this on:
```
Expand Down
Loading

0 comments on commit b17cb2a

Please sign in to comment.