Question

In: Statistics and Probability

in R. Generate a random sample of size 700 from a gamma distribution with shape parameter...

in R.

Generate a random sample of size 700 from a gamma distribution with shape parameter 8 and scale parameter 0.1. Create a histogram of the sample data. Draw the true parametric density (for the specified gamma distribution) on the histogram. The curve for the density should be red.
(Note: The “true parametric density” is the distribution from which the sample values were generated. It is NOT the kernel density that is estimated from the data.)

Solutions

Expert Solution

> set.seed(123)
> x=rgamma(700,shape=8,scale=0.1)
> x
[1] 0.7261421 1.2577645 0.8524465 0.8962943 0.8100865 1.0637966 0.5132419
[8] 0.5488641 0.8673218 0.5672609 1.0054602 0.4132956 1.0709271 0.6402915
[15] 0.5897996 0.6922805 0.9794569 0.8098421 1.2440842 0.7445203 0.8948960
[22] 0.9720649 0.9365638 0.8543201 0.9170074 0.4547145 0.8446669 0.4101387
[29] 0.7824609 0.5691286 1.3931220 0.8301588 0.8424295 1.2698421 1.5168628
[36] 0.3026280 0.5308125 0.6159250 0.8259505 0.7008397 0.6969304 0.6628409
[43] 0.4098256 0.6273920 1.0654469 0.8699054 0.6920524 1.0592520 1.1072152
[50] 0.8202671 0.7666252 1.3232281 0.7539873 0.6361739 0.8045667 0.8342377
[57] 0.4158623 0.5785114 0.5540159 0.9299721 0.6097351 0.7546496 0.5417740
[64] 0.3141671 0.7631323 0.6975184 1.0382416 0.8829689 0.8890381 0.9662449
[71] 0.2066224 0.9663350 0.9032985 0.5265950 0.5401370 0.4711868 1.0916141
[78] 0.9668035 1.0587481 0.4093063 0.6830550 0.4260183 0.4583232 1.1829081
[85] 0.6420203 0.8466845 0.5268728 0.7337468 1.4035091 0.7096055 0.6257919
[92] 0.8709991 1.1268500 0.9522547 1.0841129 0.9762365 0.6495027 1.3468171
[99] 1.2634551 1.5096795 0.4293510 0.8130882 0.8310663 0.6563846 0.6584094
[106] 0.7400449 0.8567449 1.4971907 0.3630157 0.7431414 0.5666476 0.8217983
[113] 0.6874539 1.1191089 0.9485858 0.7089663 0.4228837 0.8617208 0.8337967
[120] 0.5361666 0.4164194 1.5135897 0.6146478 0.7522584 0.6150444 0.9538494
[127] 0.7642277 0.6824530 0.6774121 0.8807386 0.6049754 0.4411254 1.5167205
[134] 0.9520350 1.0501817 1.0315366 0.7469310 0.8493276 1.1257999 1.2600685
[141] 0.9515774 0.4218603 0.9389579 0.9840136 0.8684611 0.7053594 0.9216017
[148] 1.2556438 0.6132407 0.4031728 0.8731397 0.5358526 1.1421523 1.1182041
[155] 0.5471550 1.6565487 1.1629724 0.8869966 0.5421059 0.6322531 0.7283824
[162] 0.5739482 0.3940164 0.6214322 1.0646989 1.0572741 0.7701700 1.5377102
[169] 0.6561928 1.0007997 0.7159538 0.3078832 0.4955044 0.9440101 0.9909227
[176] 1.0181417 0.9164731 0.8214651 1.0468034 0.7116661 0.7997619 0.8275267
[183] 0.6743751 1.5986841 0.7629803 0.5293191 0.5759588 0.9758087 1.1452942
[190] 0.6075181 0.7081564 1.0369363 0.8959389 0.2649960 0.4395863 1.0823066
[197] 1.3295924 1.2547837 0.4355949 1.0087559 0.7889486 1.1536906 0.9522508
[204] 1.6049816 0.9003246 1.1746081 0.3356781 1.1673541 0.6144812 0.2893824
[211] 0.5259653 1.1513304 0.4983153 1.1083026 0.4422136 0.7333431 1.0407703
[218] 0.6210592 0.4823015 0.5436914 1.0432505 0.4217901 0.6108809 0.5986456
[225] 0.5556287 1.0676826 0.4887474 0.8894746 0.8256050 0.7575364 0.9821963
[232] 0.8117956 0.8853387 0.8220467 0.7108487 0.8829362 0.4893551 0.3646841
[239] 0.8697659 0.3016059 0.4767202 0.5167791 1.1678543 0.5719350 0.5044869
[246] 0.7448238 0.7214336 0.6573966 0.6304259 0.7361052 0.6367861 0.4576534
[253] 0.9662553 0.3639049 0.6210399 0.8194601 0.8332324 0.9164577 0.5015196
[260] 1.2646976 0.6849648 1.0536704 0.9057415 0.7139298 0.9000165 0.9601780
[267] 0.6186325 0.9032454 0.6297311 0.7143861 0.7298441 1.2149251 0.5544656
[274] 0.9877426 0.9596658 0.7033186 0.4740083 0.9885783 0.4166752 0.7728444
[281] 0.9278097 0.9037898 0.4484660 0.5954417 1.3006869 1.0857501 0.9381048
[288] 0.6453142 0.9084756 0.4126576 1.6604249 0.9723239 0.8185071 0.8056123
[295] 1.3995674 1.5287671 0.6094658 0.6493736 0.9747385 0.5344248 0.4115891
[302] 0.7505854 0.4870877 1.5050721 0.9609021 1.0797086 0.6404775 0.7811656
[309] 0.8064657 0.5262228 0.4723171 0.7782162 1.3917517 0.3240543 0.7540119
[316] 1.3601477 0.6997370 0.7809022 1.4126327 0.7351911 1.5619231 0.4623002
[323] 0.7812231 0.5097653 0.5501270 0.5536367 0.6225557 0.5268249 0.5652445
[330] 0.6957973 0.5293514 0.8876571 0.4885601 0.7238100 0.4714464 0.9876342
[337] 0.7874591 0.7109774 1.1348942 0.5448925 0.6403852 0.8464199 0.9345873
[344] 0.5781102 0.5665776 0.5003257 0.7672171 0.7231660 0.7325368 1.1913924
[351] 0.9299521 1.1449429 0.7858560 1.0902187 0.8820487 0.6438319 0.3990705
[358] 2.8008551 0.8565581 0.8185801 0.9241775 0.7933559 0.2979338 1.0454015
[365] 1.3837782 0.5344895 0.2699220 0.9097371 0.4677365 0.5953677 0.8445639
[372] 0.3958146 0.7441789 1.0486070 1.2062913 0.6730801 0.9243744 0.7384276
[379] 0.8455144 0.7676551 0.4145160 1.0388405 1.0914029 0.3936330 0.5156904
[386] 0.8381506 0.6429574 0.5816648 0.9017047 1.0296915 0.5739039 0.5650503
[393] 0.7000276 0.7198737 0.5508280 0.8040702 1.0235463 0.7125969 0.7784940
[400] 0.4010830 1.0204027 1.0727917 0.9639846 0.7773581 0.6976318 0.5137968
[407] 0.5484589 0.6270894 0.6228611 1.1157721 0.7487842 0.8926685 0.8122203
[414] 0.7100979 0.5568421 0.5873685 1.0427777 0.5426757 0.8473808 0.6054226
[421] 1.0508852 1.0473380 0.7958132 1.6456284 1.0034519 0.7427205 0.5859804
[428] 0.8261871 0.4492368 0.8252717 1.2000037 0.7267812 0.4960402 0.4150558
[435] 0.4919350 0.6342343 0.8353427 0.8711057 0.5007829 0.4408307 1.2364132
[442] 1.0540506 0.8330619 0.4390980 0.6349920 0.7573318 0.6820404 1.3763876
[449] 0.9930492 1.2476628 0.5310578 0.6396803 1.1072467 0.7204006 0.4340079
[456] 1.5851682 0.7479853 0.9333412 0.9257214 0.7886491 0.9651195 0.2284677
[463] 1.0789191 0.9548526 0.9536164 0.4794176 0.8178927 0.7214561 0.3934200
[470] 0.5310652 0.5156203 0.6818026 1.4064872 0.2270593 1.0435729 0.5459433
[477] 0.8152939 0.8568870 1.4352083 0.7590723 0.4386921 0.6489825 0.5092228
[484] 0.7834052 0.7078122 1.1635104 1.1455131 0.5953204 0.8536294 0.4419701
[491] 1.1240836 0.8249370 0.4617554 0.5064816 0.6450445 0.7826512 1.1803461
[498] 0.6238817 1.4289982 0.6832922 1.6627792 0.7641628 0.4579708 0.4548603
[505] 1.1554284 0.6794064 0.4794295 1.0201551 0.7538110 1.2352575 0.5595768
[512] 1.0112310 0.6409666 0.8534625 1.3640496 0.9392751 0.4385663 0.5889099
[519] 0.7668460 0.3767050 0.4947013 0.9676869 0.5354566 0.8631809 1.0094775
[526] 0.8162623 0.4963203 0.7082475 0.8082470 0.5623229 0.8079673 1.5201163
[533] 0.8250206 0.9075229 0.5993452 0.5608940 0.7168208 0.9984379 0.7202980
[540] 0.6278781 0.7659756 0.6537815 0.4658206 0.5671984 0.9694592 0.7357215
[547] 0.7795027 0.8850237 0.9226795 0.6860298 1.0345415 0.4568311 0.5791311
[554] 0.3985145 0.9361587 0.6032355 0.8760527 0.8425602 0.8901350 0.3067757
[561] 0.8500907 0.6617082 0.7887177 0.5422731 0.6454695 0.6856767 0.9135452
[568] 0.6289241 0.5473429 1.0960719 0.3299953 1.1433470 0.6426050 0.7682035
[575] 0.8357382 1.5345752 0.5514216 0.4779444 0.4834729 0.7841294 1.2019942
[582] 0.9181586 0.8316864 0.6809156 1.3763491 1.0770538 0.8774050 1.1772679
[589] 0.3978535 0.8942758 0.9356764 1.5222307 0.5307556 1.5889620 1.1462226
[596] 1.1874061 0.2997786 0.5989627 0.7242488 0.9612420 0.7087779 0.9028685
[603] 0.7825736 1.1023670 0.7995865 0.7714499 0.6684863 0.6891801 0.3568199
[610] 0.8770966 0.5524704 0.9746456 1.2547557 0.6256006 1.1503729 0.9690331
[617] 0.4530697 0.9711648 0.7707195 0.8659226 0.4332424 0.7377128 0.4814675
[624] 1.0728385 0.7519224 1.5669142 0.7715590 1.5390908 0.7839747 0.7674469
[631] 0.4849953 0.8155819 0.7458920 0.7350949 0.5880478 0.9721515 1.3412546
[638] 0.8682425 0.5200699 1.1599719 1.2863277 1.0734441 0.5887210 0.2166858
[645] 0.7799513 0.6887165 1.0971683 0.5706542 0.6987321 1.0010561 0.6004868
[652] 0.6030082 0.6981712 1.3911616 0.7126917 0.9042652 1.0238161 0.6233105
[659] 0.7414379 0.8868694 0.9513463 0.7516247 0.8147179 0.5314940 0.7814335
[666] 0.8946454 0.5862416 0.6066887 0.5906787 0.8863528 0.7340588 0.9011457
[673] 1.2499191 0.6454542 0.8015713 1.0332747 0.5573483 0.4965632 1.1069560
[680] 0.2449659 0.9859800 0.7037275 0.6921864 0.8779050 0.5114995 1.3061122
[687] 0.4557770 0.6242150 1.0347030 0.6410932 0.5107775 0.6392118 0.5367732
[694] 0.7679738 1.1610478 0.4249442 0.6800061 0.4511350 0.7744056 0.7336491
> hist(x,prob=TRUE,Main=" Histogram of Gamma")
lines(sort(x),y=dgamma(sort(x),shape=8,scale=0.1),col="red",lty=2,lwd=2)
#OR
curve(dgamma(x,shape=8,scale=0.1),add=TRUE,col="red")


Related Solutions

Let X1,...,Xn be a random sample from a gamma distribution with shape parameter α and rate...
Let X1,...,Xn be a random sample from a gamma distribution with shape parameter α and rate β (note that this may be a different gamma specification than you are used to). Then f(x | α, β) = (βα/Γ(α))*x^(α−1) * e^(−βx). where x, α, β > 0 (a) Derive the equations that yield the maximum likelihood estimators of α and β. Can they be solved explicitly? Hint: don’t forget your maximum checks, and it may help to do some internet searching...
Suppose X is a Gamma random variable with shape parameter α and scale parameter θ >...
Suppose X is a Gamma random variable with shape parameter α and scale parameter θ > 0, i.e., the pdf is given as, f(x|α, θ) = 1 Γ(α)θ α x α−1 e −x/θ , 0 < x < ∞, (1) where α > 0, θ > 0 and Γ(a) = Z ∞ 0 x a−1 e −x dx. HINT: see section 3.2 of the textbook. (a) What is the support of X? That is, X = ? (b) Show that...
Dr. Lee now wants to generate a random sample of size 10,000 from the F distribution...
Dr. Lee now wants to generate a random sample of size 10,000 from the F distribution with df1 = 1 and df2 = 4 degrees of freedom. But he doesn’t remember the probability density function (pdf) of the F distribution at all. Fortunately, he knows the relationship between t distribution and F distribution. He knows that if X follows the t distribution with ν = 4 degrees of freedom, then X2 follows the F distribution with df1 = 1 and...
A random variable X is said to follow the Weibull distribution with shape parameter
A random variable \(X\) is said to follow the Weibull distribution with shape parameter \(\alpha\) and scale parameter \(\beta\), written \(W(\alpha, \beta)\) if its p.d.f. is given by $$ f(x)=\frac{\alpha}{\beta^{\alpha}} x^{\alpha-1} e^{-\left(\frac{g}{3}\right)^{\alpha}} $$ for \(x>0\). The Weibull distribution is used to model lifetime of item subject to failure. If \(\alpha \in(0,1),\) it is used to model decreasing failure rate overtime, whereas if \(\alpha>1,\) one models increasing failure rate over time. It is easy to show that the c.d.f. of \(X\)...
Let Xl, n be a random sample from a gamma distribution with parameters a = 2...
Let Xl, n be a random sample from a gamma distribution with parameters a = 2 and p = 20.      a)         Find an estimator , using the method of maximum likelihood b) Is the estimator obtained in part a) is unbiased and consistent estimator for the parameter 0? c) Using the factorization theorem, show that the estimator found in part a) is a sufficient estimator of 0.
Suppose that you have a random sample of size n from a population with Gamma density...
Suppose that you have a random sample of size n from a population with Gamma density with α= 3 but unknown β. Write down the likelihood function, and find a sufficient statistic. Find the MLE and the MOM estimators forβ. (Hint: They should be equal.) Then find the MSE for this estimator by finding the bias and the variance. Is it consistent? Is it MVUE? Explain why or why not.
Let X1, … , Xn. be a random sample from gamma (2, theta) distribution. a) Show...
Let X1, … , Xn. be a random sample from gamma (2, theta) distribution. a) Show that it is the regular case of the exponential class of distributions. b) Find a complete, sufficient statistic for theta. c) Find the unique MVUE of theta. Justify each step.
Suppose X1, X2, ..., Xn is a random sample from a Poisson distribution with unknown parameter...
Suppose X1, X2, ..., Xn is a random sample from a Poisson distribution with unknown parameter µ. a. What is the mean and variance of this distribution? b. Is X1 + 2X6 − X8 an estimator of µ? Is it a good estimator? Why or why not? c. Find the moment estimator and MLE of µ. d. Show the estimators in (c) are unbiased. e. Find the MSE of the estimators in (c). Given the frequency table below: X 0...
A random sample of size 9 from a distribution of ?(?, 36) yielded ?̅ = 40....
A random sample of size 9 from a distribution of ?(?, 36) yielded ?̅ = 40. Find the confidence intervals for ? a. 99% b. 97.5% c. 95% d. 90%
1. (a) Simulate a random sample of size 100 from the exponential distribution with the rate...
1. (a) Simulate a random sample of size 100 from the exponential distribution with the rate parameter λ = 10. Then make a histogram of the simulated data. (b) We use the simulated data as a data set to construct the log-likelihood function as an R function. We will find the MEL of the value λ = 10. Choose the appropriate range for the parameter λ, then make a plot of the log-likelihood function. (c) Use R function ‘optim‘ to...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT