0

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?

Geoff
  • 6,277
  • 23
  • 87
  • 197

2 Answers2

1

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

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

Read the documentation for more information.

Alex
  • 4,925
  • 2
  • 32
  • 48
0

This is the output from Alex's suggestion:

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

enter image description here

Agarp
  • 433
  • 7
  • 15