alpha <- 4
beta <- 30
summary(rigamma(n=1000,alpha,beta))
xseq <- seq(.1,30,by=.1)
fx <- densigamma(xseq,alpha,beta)
plot(xseq,fx,type="n",
xlab="x",
ylab="f(x)",
ylim=c(0,1.01*max(fx)),
yaxs="i",
axes=FALSE)
axis(1)
title(substitute(list(alpha==a,beta==b),list(a=alpha,b=beta)))
q <- igammaHDR(alpha,beta,debug=TRUE)
xlo <- which.min(abs(q[1]-xseq))
xup <- which.min(abs(q[2]-xseq))
plotZero <- par()$usr[3]
polygon(x=xseq[c(xlo,xlo:xup,xup:xlo)],
y=c(plotZero,
fx[xlo:xup],
rep(plotZero,length(xlo:xup))),
border=FALSE,
col=gray(.45))
lines(xseq,fx,lwd=1.25)
if (FALSE) {
alpha <- beta <- .1
xseq <- exp(seq(-7,30,length=1001))
fx <- densigamma(xseq,alpha,beta)
plot(xseq,fx,
log="xy",
type="l",
ylim=c(min(fx),1.01*max(fx)),
yaxs="i",
xlab="x, log scale",
ylab="f(x), log scale",
axes=FALSE)
axis(1)
title(substitute(list(alpha==a,beta==b),list(a=alpha,b=beta)))
q <- igammaHDR(alpha,beta,debug=TRUE)
xlo <- which.min(abs(q[1]-xseq))
xup <- which.min(abs(q[2]-xseq))
plotZero <- min(fx)
polygon(x=xseq[c(xlo,xlo:xup,xup:xlo)],
y=c(plotZero,
fx[xlo:xup],
rep(plotZero,length(xlo:xup))),
border=FALSE,
col=gray(.45))
lines(xseq,fx,lwd=1.25)
}
Run the code above in your browser using DataLab