ShanaScogin / BayesPostEst

An R package to generate and plot postestimation quantities after estimating Bayesian regression models using MCMC
https://shanascogin.github.io/BayesPostEst/
GNU General Public License v3.0
12 stars 2 forks source link

mcmcFDplot multiplies FDs by 100 twice (but should only once) #81

Closed jkarreth closed 3 years ago

jkarreth commented 3 years ago

just noticed this while teaching... see here

I need to remove the 100 at one of the two locations, `fdfull <- fdfull 100orscale_x_continuous(labels = function(x) x * 100)`. Probably the latter!

Will update this issue when I've fixed this and updated in the develop branch (ok, @ShanaScogin ?)

function (fdfull, ROPE = NULL) 
{
    .Deprecated("plot.mcmcFD", package = "BayesPostEst")
    ROPE <- check_ROPE_argument(ROPE)
    fdfull <- fdfull * 100
    fd_dat <- tidyr::gather(as.data.frame(fdfull))
    if (!is.null(ROPE)) {
        fd_plot <- ggplot2::ggplot(data = fd_dat, aes(x = .data$value, 
            y = .data$key)) + ggplot2::geom_rect(xmin = ROPE[1], 
            xmax = ROPE[2], ymin = 0, ymax = Inf, fill = "black") + 
            ggridges::stat_density_ridges(quantile_lines = TRUE, 
                quantiles = c(0.025, 0.5, 0.975), vline_color = "white") + 
            ggplot2::scale_x_continuous(labels = function(x) x * 
                100) + ggplot2::xlab("Percentage point change in Pr(y = 1)") + 
            ggplot2::ylab("")
        fd_outROPE <- apply(fdfull, 2, function(x) ifelse(median(x) < 
            0, sum(x < ROPE[1])/length(x), sum(x > ROPE[2])/length(x)))
        fd_annotate <- data.frame(xpos = apply(fdfull, 2, function(x) ifelse(median(x) < 
            0, quantile(x, probs = 0.01) - 0.02, quantile(x, 
            probs = 0.99) + 0.02)), ypos = as.factor(colnames(fdfull)), 
            outROPE = paste(round(fd_outROPE * 100, digits = 1), 
                "%", sep = ""))
        fd_plot <- fd_plot + geom_text(data = fd_annotate, aes(x = .data$xpos, 
            y = .data$ypos, label = .data$outROPE), color = "black", 
            nudge_y = 0.1, size = 4)
    }
    else {
        fd_plot <- ggplot2::ggplot(data = fd_dat, aes(x = .data$value, 
            y = .data$key)) + ggplot2::geom_vline(xintercept = 0) + 
            ggridges::stat_density_ridges(quantile_lines = TRUE, 
                quantiles = c(0.025, 0.5, 0.975), vline_color = "white") + 
            ggplot2::scale_x_continuous(labels = function(x) x * 
                100) + ggplot2::xlab("Percentage point change in Pr(y = 1)") + 
            ggplot2::ylab("")
        fd_out0 <- apply(fdfull, 2, function(x) ifelse(median(x) < 
            0, sum(x < 0)/length(x), sum(x > 0)/length(x)))
        fd_annotate <- data.frame(xpos = apply(fdfull, 2, function(x) ifelse(median(x) < 
            0, quantile(x, probs = 0.01) - 0.02, quantile(x, 
            probs = 0.99) + 0.02)), ypos = as.factor(colnames(fdfull)), 
            out0 = paste(round(fd_out0 * 100, digits = 1), "%", 
                sep = ""))
        fd_plot <- fd_plot + ggplot2::geom_text(data = fd_annotate, 
            aes(x = .data$xpos, y = .data$ypos, label = .data$out0), 
            color = "black", nudge_y = 0.1, size = 4)
    }
    fd_plot
}
jkarreth commented 3 years ago

Ohh, not a bug at all... I hadn't updated to using plot.mcmcFD instead. My bad 😔