I'm having trouble to fit and simulate a gamma distribution
using the fitdistr
function from the MASS
package:
My data is daily rainfall
, so i 'm adding 1
to all points to get rid the 0's:
require(MASS)
rainfall = scan('daily_rainfall_january.txt', '')
rainfall = rainfall + 1
# sometimes i get warnings here (NA produced)
fit = fitdistr(rainfall, 'gamma')
Now i want so simulate a January rainfall: (plot shows the accumulated rainfall over N simulations)
1 - Blue and red: output from 1000 rgamma simulations
2 - Dark line: 30 year climatology mean (monthly accumulated rainfall)
shape = fit$estimate['shape']
rate = fit$estimate['rate']
rainfall.simul = rgamma(31, shape = shape, rate = rate)
Now, how do i transform back rainfall.simul
? Is there a better way to handle the
0's problem?
more directly
? I'm using agamma
to simulate each month, not the whole year, which would be clearly absurd. $\endgroup$