jmcurran / Bolstad

0 stars 0 forks source link

Bug in normgcp #2

Closed abcnorio closed 5 years ago

abcnorio commented 5 years ago

Dear James,

in R package "Bolstad" the function "normgcp" should contain

function (x, sigma.x = NULL, density = c("normal", "uniform", "user"), params = NULL, n.mu = 50, mu = NULL, mu.prior = NULL, plot = TRUE)

but it lists "unform" as "density" parameter instead of "uniform". Can you please fix that? Thanks.

Version: 0.2-36 Packaged: 2018-01-24 02:08:29 UTC; jcur002

I also found out that it does not plot the likelihood. Just tweaked the plot, if that is of interest:

plot.mean.post <- function(res=NULL, TITLE="Bayes mean estimation", SUB="prior, likelihood, posterior",
                           xtext=expression(mu), ytext=expression(probability(mu)), colo=c("olivedrab","violetred3","blue"),
                           xlim=NULL, ylim=NULL, add=FALSE, fac=1.1)
{
 stopifnot(attr(res, "class") == "Bolstad")

 if(is.null(xlim)) xlim <- range(res$param.x)*fac
 if(is.null(ylim)) ylim <- range(c(res$prior,res$likelihood,res$post))*fac

 if(add == FALSE)
 {
  par(mar=c(5,5,4,2))
  par(oma=c(2,1,1,1))
  par("cex.axis"=0.8)
 }

 plot(0,0, xlim=xlim, ylim=ylim, main="", xlab="", ylab="", cex.lab=0.8, cex.axis=0.8, bty="n", axes=F, col="white")

 axis(side = 1, pretty(xlim), tck =- .02, labels=NA, line=.6)
 axis(side = 2, pretty(ylim), tck = -.02, labels=NA, line=.6)
 axis(side = 1, lwd = 0, line = .4)
 axis(side = 2, lwd = 0, line = .4, las = 1)

 grid(col="grey90", lwd=1.2, lty=2)
 mtext(xtext, 1, line=4, cex=1)
 mtext(ytext, 2, line=4, cex=1) 

 mtext(TITLE, 3, line=2, cex=1.5)
 mtext(SUB, 3, line=.4, cex=1.1)

 lines(res$param.x, res$prior, col=colo[1], lty=3)
 lines(res$param.x, res$likelihood, col=colo[2], lty=2)
 lines(res$param.x, res$posterior, col=colo[3], lty=1)

 legend("topright", c("prior","likelihood","posterior"),
        col=colo, lty=c(2,1), text.col=colo, bty="n", bg="white", xjust=0, lwd=2)
}
#call:
#plot.mean.post(bayes.mean.res)

jmcurran commented 5 years ago

My memory is that I don't plot the likelihood because you often need to do some arbitrary rescaling of the height to get all the curves on the same plot and visible.

However, the plot.Bolstad function will actually do this for you. For example

x = rnorm(20, -0.5, 1)
r = normgcp(x, 1, params = c(-3, 3))
plot(r, which = 1:3)

If you do need to scale the likelihood, then

plot(r, which = 1:3, scaleLike = TRUE)

should help.

jmcurran commented 5 years ago

New version with corrections uploaded to CRAN today. Should be accepted because the change is very small.

abcnorio commented 5 years ago

On Mon, 08 Oct 2018 14:57:47 -0700 jmcurran notifications@github.com wrote:

Dear James,

thanks for the update - I checked the code of the plot.Bolstad function and saw the scaling of the likelihood. Probably that is enough, my function just made it look "nicer" (at least for me). But as "normgcp" does not call plot.Bolstad but has its own plotting part, I will have a look whether my small changes make sense and lead to some benefit - and fits smoothly into the existent function. If it does, I will make a pull request of course. Thanks for the hint.

best wishes leo

Leo - can you submit the function as a pull request please? I haven't looked at this package for awhile. My memory is that I don't plot the likelihood because you often need to do some arbitrary rescaling of the height to get all the curves on the same plot and visible. However I can add your function to the package.

-- You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub: https://github.com/jmcurran/Bolstad/issues/2#issuecomment-427992464

--

jmcurran commented 5 years ago

Thanks Leo. Some of the "look and feel" is a little constrained by the fact that Bill wants things to look like they look in the book. However, as time goes by this is less important. See how you get along, and then maybe we can look at the aesthetics.

abcnorio commented 5 years ago

On Tue, 09 Oct 2018 14:09:02 -0700 jmcurran notifications@github.com wrote:

yes James, I assumed something like that after having a closer look on the various functions in Bolstad (I know the book and its figures). Pls see attached what I mean with "small tweaks". Looks - for me - much nicer to the eye.

best wishes leo

Thanks Leo. Some of the "look and feel" is a little constrained by the fact that Bill wants things to look like they look in the book. However, as time goes by this is less important. See how you get along, and then maybe we can look at the aesthetics.

-- You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub: https://github.com/jmcurran/Bolstad/issues/2#issuecomment-428353051

--