I want to draw the true density on histogram. Here is my code, I'm not sure if my codes are right or not.
set.seed(600)
x <- rgamma(500,shape=8,scale=0.1)
mean(x)
hist(x,prob=T,main='Gamma,scale=0.1')
lines(density(x),col='red',lwd=2)
Thanks!
density()
gives a local estimate of the density. The true density can be derived from dgamma
, and plotted like this...
lines( sort(x) , y = dgamma( sort(x) , shape = 8 , scale = 0.1 ) , col = "blue" , lty = 2 , lwd = 2 )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With