Plotting gamma distribution in r, confused about scale and shape
In the wikipedia article on the gamma distribution there are some examples
with particular scale and shape parameters.
Example A: scale = 5, shape = 1 Example B: scale = 9, shape = 0.5
So I try to replicate these probability densities in R
MyDensity <- function(scale1, shape1) {
xx <- seq(0,20, by=.01)
pdf1 <- dgamma(xx, scale=scale1, shape=shape1)
return(data.frame(pdf = pdf1, x = xx))
}
data1.dens <- rbind(data.frame(var1 = "A", MyDensity(5,1)),
data.frame(var1 = "B", MyDensity(9,0.5)))
ggplot(data1.dens, aes(x = x, y = pdf, color = var1, fill = var1)) +
geom_point()
However the results look totally different. I'm either doing something
wrong with R, or I'm confused about the scale and shape parameters. Can
anyone give me some hints. Thanks.
No comments:
Post a Comment