Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PLEASE USE R to answer.: 1. Estimates and Standard Errors. a. Write a function, gamma.est, which takes as input a vector of data values, and

PLEASE USE R to answer.:

1. Estimates and Standard Errors.

a. Write a function, gamma.est, which takes as input a vector of data values, and returns a vector containing the two estimated parameters of the gamma distribution, with components named shape and scale as appropriate.

b. Verify that your function implements the appropriate formulas by showing that it matches the results from lecture for the cat heart data. (just start this one please I can match the data later.)

c. Generate a vector containing ten thousand random values from the gamma distribution with a = 19 and s = 0.56. What are the theoretical values of the mean and of the variance? What are their sample values?

d. Plot the histogram of the random values, and add the curve of the theoretical probability density function.

e. Apply your gamma.est function to your random sample. Report the estimated parameters and how far they are from the true values.

f. Write a function, gamma.est.se, to calculate the standard error of your estimates of the gamma parameters, on simulated data drawn from the gamma distribution. It should take the following arguments: true shape parameter shape (or a), true scale parameter scale (or s), size of each sample n, and number of repetitions at that sample size B. It should return two standard errors, one for the shape parameter a and one for the scale parameter s. (These can be either in a vector or in a list, but should be named clearly.) It should call a function gamma.est.sim which takes the same arguments as gamma.est.se, and returns an array with two rows and B columns, one row holding shape estimates and the other row scale estimates. Your gamma.est.se function should not, itself, estimate any parameters or generate any random values

Note: To check that gamma.est.se works properly, write a stub or dummy version of gamma.est.sim, which takes the correct arguments and returns an array of the proper size, but whose entries are fixed so that its easy for us to calculate what gamma.est.se ought to do.

g. Write gamma.est.sim so that the entries in the first row of the returned array alternate between shape and shape+1, and those in the second row alternate between scale and scale+n. For example gamma.est.sim(2,1,10,10) should return (row names are optional)

## [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] ## shapes 2 3 2 3 2 3 2 3 2 3 ## scales 1 11 1 11 1 11 1 11 1 11 and gamma.est.sim(2,8,5,7) should return ## [,1] [,2] [,3] [,4] [,5] [,6] [,7] ## [1,] 2 3 2 3 2 3 2 ## [2,] 8 13 8 13 8 13 8

h. Calculate the standard deviations of each row in the two arrays above. i. Run your gamma.est.se, with this version of gamma.est.sim. Do its standard errors match the standard deviations you just calculated? Should they?

j. Write the actual gamma.est.sim. Each of the B columns in its output should be the result of applying gamma.est to a vector of n random numbers generated by a different call to rgamma, all with the same shape and scale parameters.

k. Run gamma.est.se, calling your new gamma.est.sim, with shape=2, scale=1, n=10 and B=1e5. Check that the standard error for shape is approximately 1.6 and that for scale approximately 0.54. Explain why your answers are not exactly 1.6 and 0.54.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Principles Of Accounting

Authors: Robert Libby, Patricia Libby, Fred Phillips, Stacey Whitecotton

1st Edition

978-0077300456, 0077300459

Students also viewed these Accounting questions