diff --git a/demos_ch3/demo3_6.R b/demos_ch3/demo3_6.R index d022b61..fa29f85 100644 --- a/demos_ch3/demo3_6.R +++ b/demos_ch3/demo3_6.R @@ -44,7 +44,8 @@ cB <- rep(B, length(A)) #' Make a helper function to calculate the log likelihood #' given a dataframe with x, y, and n and evaluation -#' points a and b. For the likelihood see BDA p. 75 +#' points a and b. For the likelihood see BDA3 p. 75
+#' `log1p(x)` computes log(x+1) in numerically more stable way. logl <- function(df, a, b) df['y']*(a + b*df['x']) - df['n']*log1p(exp(a + b*df['x'])) @@ -68,9 +69,6 @@ samp_B <- samp_B + runif(nsamp, (B[1] - B[2])/2, (B[2] - B[1])/2) samps <- data_frame(ind = 1:nsamp, alpha = samp_A, beta = samp_B) %>% mutate(ld50 = - alpha/beta) -#' Sample LD50 conditional beta > 0 -sampsposbeta <- filter(samps, beta > 0) - #' Plot draws of logistic curves invlogit <- plogis xr <- seq(-1.5, 1.5, length.out = 100)