-
Notifications
You must be signed in to change notification settings - Fork 607
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Richard McElreath
committed
Jun 11, 2013
1 parent
bdcd3e0
commit 0591449
Showing
6 changed files
with
1,841 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) ) ) |
Oops, something went wrong.