Skip to content

Commit

Permalink
Syncing in new data examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard McElreath committed Jun 11, 2013
1 parent bdcd3e0 commit 0591449
Show file tree
Hide file tree
Showing 6 changed files with 1,841 additions and 3 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
Package: rethinking
Type: Package
Title: Statistical Rethinking book package
Version: 1.10
Version: 1.11
Date: 2012-09-27
Author: Richard McElreath
Maintainer: Richard McElreath <[email protected]>
Depends: MASS, bbmle, coda
Description: Utilities for fitting and comparing models
License: GPL version 2 or newer
License: GPLv3
37 changes: 37 additions & 0 deletions R/map.r
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# MAP - maximum a posteriori
# uses Bolker's mle2 (bbmle) as the engine, just smuggling in priors as penalized likelihood

# format for priors:
# list( formula1 , formula2 , ... )
# formulas are in format of the likelihood formula, i.e.
# parameter ~ dfunction( pars )
# e.g.:
# a ~ dnorm(0,1)
# s ~ dunif(0,100)

# map() then builds the likelihood formula and prior formulas into a unified enclosure that returns penalized log-likelihood. optim() does the rest.

map <- function( formula , data , start , prior , ... ) {

require(bbmle)

# check parameters

if ( missing( formula ) | missing( data ) | missing( start ) ) {
stop( "Must specify formula, data, and start." )
}
if ( missing( prior ) ) {
# okay, but mark as NULL
prior <- NULL
}

# check that none of the declared priors are for a parameter not in start list

#################
# build enclosure

}

# testing examples
# data(cars)
# fit <- map( dist ~ dnorm( mean=a+b*speed , sd=sigma ) , data=cars , start=list( a=mean(cars$dist) , b=0 , sigma=sd(cars$dist) ) , prior=list( b ~ dnorm(0,1) , sigma ~ dunif(0,100) ) )
Loading

0 comments on commit 0591449

Please sign in to comment.