Skip to content

Instantly share code, notes, and snippets.

@benwhalley
Created August 21, 2017 13:02
Show Gist options
  • Save benwhalley/36b99ecfdccb19f5a3ed8cb8b3cd0a5f to your computer and use it in GitHub Desktop.
Save benwhalley/36b99ecfdccb19f5a3ed8cb8b3cd0a5f to your computer and use it in GitHub Desktop.
require('dplyr')
require('rethinking')
dmode <- function(x) {
den <- density(x, kernel=c("gaussian"))
( den$x[den$y==max(den$y)] )
}
meanhpdi <- function(x, prob=.95) {
i <- rethinking::HPDI(x, prob=prob)
data_frame(y=mean(x), ymin=i[1], ymax=i[2] )
}
mmmhpdi <- function(x, prob=.95) {
i <- rethinking::HPDI(x, prob=prob)
data_frame(y=mean(x), mode=dmode(x), median=median(x), ymin=i[1], ymax=i[2] )
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment