Geoff
Geoff

Reputation: 6639

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

enter image description here

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

Where am i going wrong?

Upvotes: 0

Views: 7251

Answers (2)

Agarp
Agarp

Reputation: 433

This is the output from Alex's suggestion:

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

enter image description here

Upvotes: 0

Alex
Alex

Reputation: 4995

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

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

Read the documentation for more information.

Upvotes: 1

Related Questions