Amelia Marsh
2015-Mar-11 09:41 UTC
[R] Gamma Distribution - is there any problem with "pgamma"?
Dear R forum I have following data amounts = c(928906.144,156091.0576,433798.3404,993425.7224,1323976.364,649106.9339, 369967.2612,2528872.35,1226093.655,1145446.149,1809624.453,599329.0394,2200955.213,2583318.064,745625.8069,961828.8828,1744841.313,1939390.005,1077873.654,729924.2713,803584.2636,287020.8529,530910.9004,818574.0089,1908133.51,262336.0893,593808.2542,780258.1354) # Estimating Gamma distribution parameters shape_gamma <- (mean(amounts)/sd(amounts))^2 scale_gamma <- (sd(amounts)^2/mean(amounts)) Fx <- pgamma(amounts, shape_gamma, scale_gamma) I get following values of Fx> Fx[1] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 I have tried this for different dataset but still each time I am getting values of Fx as 1's only. Is there any problem with pgamma command? Kindly advise. Regards Amelia
Martyn Byng
2015-Mar-11 11:48 UTC
[R] Gamma Distribution - is there any problem with "pgamma"?
Hi, Try pgamma(amounts,shape_gamma,scale=scale_gamma) as I am guessing you mean scale_gamma to be the scale of the distribution, but are using it as the rate ( = 1 / scale) instead Martyn -----Original Message----- From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of Amelia Marsh Sent: 11 March 2015 09:42 To: r-help at r-project.org Subject: [R] Gamma Distribution - is there any problem with "pgamma"? Dear R forum I have following data amounts = c(928906.144,156091.0576,433798.3404,993425.7224,1323976.364,649106.9339, 369967.2612,2528872.35,1226093.655,1145446.149,1809624.453,599329.0394,2200955.213,2583318.064,745625.8069,961828.8828,1744841.313,1939390.005,1077873.654,729924.2713,803584.2636,287020.8529,530910.9004,818574.0089,1908133.51,262336.0893,593808.2542,780258.1354) # Estimating Gamma distribution parameters shape_gamma <- (mean(amounts)/sd(amounts))^2 scale_gamma <- (sd(amounts)^2/mean(amounts)) Fx <- pgamma(amounts, shape_gamma, scale_gamma) I get following values of Fx> Fx[1] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 I have tried this for different dataset but still each time I am getting values of Fx as 1's only. Is there any problem with pgamma command? Kindly advise. Regards Amelia ______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. ________________________________________________________________________ This e-mail has been scanned for all viruses by Star.\ _...{{dropped:3}}
Ben Bolker
2015-Mar-11 11:54 UTC
[R] Gamma Distribution - is there any problem with "pgamma"?
Amelia Marsh <amelia_marsh08 <at> yahoo.com> writes:> > Dear R forum > > I have following data > > amounts = c(928906.144,156091.0576,433798.3404,993425.7224, > 1323976.364,649106.9339, 369967.2612,2528872.35,1226093.655, > 1145446.149,1809624.453,599329.0394,2200955.213,2583318.064, > 745625.8069,961828.8828,1744841.313,1939390.005,1077873.654, > 729924.2713,803584.2636,287020.8529,530910.9004,818574.0089, > 1908133.51,262336.0893,593808.2542,780258.1354)> # Estimating Gamma distribution parameters > > shape_gamma <- (mean(amounts)/sd(amounts))^2 > > scale_gamma <- (sd(amounts)^2/mean(amounts)) >The default parameterization of the Gamma distribution in R uses a rate parameter, not a scale parameter. You can override this: Fx <- pgamma(amounts, shape_gamma, scale=scale_gamma) or Fx <- pgamma(amounts, shape_gamma, rate=1/scale_gamma) One place you can find a description of the parameterizations in R is http://journal.r-project.org/archive/2013-1/lebauer-dietze-bolker.pdf
Amelia Marsh
2015-Mar-11 18:58 UTC
[R] Gamma Distribution - is there any problem with "pgamma"?
Dear Mr Byng, Thanks a lot for your great help. Appreciate. Regards Amelia -------------------------------------------- On Wed, 11/3/15, Martyn Byng <martyn.byng at nag.co.uk> wrote: Subject: RE: [R] Gamma Distribution - is there any problem with "pgamma"? elp at r-project.org> Date: Wednesday, 11 March, 2015, 11:48 AM Hi, Try pgamma(amounts,shape_gamma,scale=scale_gamma) as I am guessing you mean scale_gamma to be the scale of the distribution, but are using it as the rate ( = 1 / scale) instead Martyn -----Original Message----- From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of Amelia Marsh Sent: 11 March 2015 09:42 To: r-help at r-project.org Subject: [R] Gamma Distribution - is there any problem with "pgamma"? Dear R forum I have following data amounts c(928906.144,156091.0576,433798.3404,993425.7224,1323976.364,649106.9339, 369967.2612,2528872.35,1226093.655,1145446.149,1809624.453,599329.0394,2200955.213,2583318.064,745625.8069,961828.8828,1744841.313,1939390.005,1077873.654,729924.2713,803584.2636,287020.8529,530910.9004,818574.0089,1908133.51,262336.0893,593808.2542,780258.1354) # Estimating Gamma distribution parameters shape_gamma??? ? ? ??? <-? ? ??? ??? (mean(amounts)/sd(amounts))^2 scale_gamma? ? ? <-? ? ??? ??? (sd(amounts)^2/mean(amounts)) Fx? ? ??? ??? ??? ??? <-? ? ??? ??? pgamma(amounts, shape_gamma, scale_gamma) I get following values of Fx > Fx [1] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 I have tried this for different dataset but still each time I am getting values of Fx as 1's only. Is there any problem with pgamma command? Kindly advise. Regards Amelia ______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. ________________________________________________________________________ This e-mail has been scanned for all viruses by Star.
Amelia Marsh
2015-Mar-11 19:00 UTC
[R] Gamma Distribution - is there any problem with "pgamma"?
Dear Sir, Thanks a lot for your help and guidance. Regards Amelia --`------------------------------------------ On Wed, 11/3/15, Ben Bolker <bbolker at gmail.com> wrote: Subject: Re: [R] Gamma Distribution - is there any problem with "pgamma"? To: r-help at stat.math.ethz.ch Date: Wednesday, 11 March, 2015, 11:54 AM Amelia Marsh <amelia_marsh08 <at> yahoo.com> writes: > > Dear R forum > > I have following data > > amounts c(928906.144,156091.0576,433798.3404,993425.7224, > 369967.2612,2528872.35,1226093.655, > 1145446.149,1809624.453,599329.0394,2200955.213,2583318.064, > 745625.8069,961828.8828,1744841.313,1939390.005,1077873.654, > 729924.2713,803584.2636,287020.8529,530910.9004,818574.0089, > 1908133.51,262336.0893,593808.2542,780258.1354) > # Estimating Gamma distribution parameters > > shape_gamma??? ? ? ??? <-? ? ??? ??? (mean(amounts)/sd(amounts))^2 > > scale_gamma? ? ? <-? ? ??? ??? (sd(amounts)^2/mean(amounts)) > The default parameterization of the Gamma distribution in R uses a rate parameter, not a scale parameter.? You can override this: Fx <-??? pgamma(amounts, shape_gamma, scale=scale_gamma) or Fx <-??? pgamma(amounts, shape_gamma, rate=1/scale_gamma) One place you can find a description of the parameterizations in R is http://journal.r-project.org/archive/2013-1/lebauer-dietze-bolker.pdf ______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.