# NOT RUN {
x = seq(0.001, 5, length=1000);
plot(x, dollggamma(x, 0.5, 1.2, 5, 0.3), col=2, type="l", lwd=4, ylim=c(0, 1));
lines(x, pollggamma(x, 0.5, 1.2, 5, 0.3), col=4, type="l", lwd=4, ylim=c(0, 1));
legend("right", c("PDF", "CDF"), col=c(2, 4), lwd=4);
r = rgamma(n = 100, 2, 2);
lik = function(params) -sum(dollggamma(r, params[1], params[2], params[3], params[4], log=TRUE));
optPar = optim(lik, par=c(1, 1, 1, 1), method="L-BFGS", lower=0.00001, upper=Inf)$par;
x = seq(0.001, 5, length=1000);
plot(x, dgamma(x, 2, 2), type="l", col=2, lwd=4, ylim=c(0, 1));
lines(x, dollggamma(x, optPar[1], optPar[2], optPar[3], optPar[4]), col=4, lwd=4);
legend("topright", c("Gamma(shape=2, rate=2)", "MLE OLL-Gen.Gamma"), col=c(2, 4), lwd=4);
# }
Run the code above in your browser using DataLab