Description Usage Arguments Value Examples
View source: R/Method of moments.R
Method of Moments to determine parameters for gamma or beta distributions.
1 | mom(distribution, mean, sd)
|
distribution |
enter "beta" or "gamma" |
mean |
mean value of samples |
sd |
standard deviation of samples |
Returns parameters a
(i.e., shape 1) and b
(i.e., shape
2) of the beta distribution.
Returns parameters c
(i.e., shape) and b
(i.e., rate) of the
gamma distribution. Note that the scale parameter = 1/b (See example).
A warning will show if negative values are obtained. distribution.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | ##Beta Distribution
##assign beta parms from mean = 0.5 and sd = 0.2 to outz
outz = mom("beta",0.5, 0.2)
##use outz to generate 10 random beta observations from mean = 0.5 and sd = 0.2
rbeta(10,outz[1],outz[2])
##Example of negative parameter estimate function
mom("beta",50, 0.2)
##Gamma Distribution
##Generate some probability levels
prob_levels<-c(0.001,.05,.25,.5,.75,.95,0.999)
##Generate gamma parms with man of 10 and sd of 5
outz <- mom("gamma",10, 5)
##Use the gamma parms (outz) and the probability with qgamma to find the
##quantile values of a gamma dist. Note the 1/b component to calculate the scale parameter
qgamma(prob_levels,outz[1],1/outz[2])
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.