简体   繁体   中英

Plotting gamma distribution in R

Am trying to plot a gamma distribution histogram using R

so i have

gam(10, 0.5)

I have previously calculated mean as

10* 0.5 = 5

So Am supposed to plot a histoigram of 100 observations with scale = 10 and shape = 0.5

So i have tried

x <- round(rgamma(100,shape = 0.5,rate = 10),1)
hist(x)

and i get

在此处输入图片说明

which is wrong as the mean is supposed to be 5 but my plot doesnt produce 5

Where am i going wrong?

Use scale instead of rate . So simulate your data as follows:

rgamma(100,shape = 0.5,scale = 10)

Read the documentation for more information.

This is the output from Alex's suggestion:

 x <- round(rgamma(100,shape = 0.5,rate = 10),1)
 hist(x)

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM