Skip to content

Commit

Permalink
functions for exercises
Browse files Browse the repository at this point in the history
  • Loading branch information
avehtari committed Feb 23, 2018
1 parent 2a42eb1 commit 2681da9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
16 changes: 16 additions & 0 deletions functions/bioassaylp.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
bioassaylp <- function(a,b,x,y,n) {

# unnormalized log-posterior for bioassay (assuming uniform prior)

t <- a + b*x
et <- exp(t)
z <- et/(1+et)

# ensure that log(z) and log(1-z) are computable
eps <- 1e-12
z <- pmin(z, 1-eps)
z <- pmax(z, eps)
lp <- sum(y*log(z) + (n-y)*log(1-z))
return(lp)
}

7 changes: 7 additions & 0 deletions functions/dtnew.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@




dtnew <- function(x, df, mean=0, scale=1, ...) {
dt((x-mean)/scale, df=df, ...) / scale
}

0 comments on commit 2681da9

Please sign in to comment.