Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please use RStudio answer part 2 (problem 6-9) questiones and give the R command

ID: 3258723 • Letter: P

Question

Please use RStudio answer part 2 (problem 6-9) questiones and give the R command, please load data use data:

Problem 1. (10 points)

The data is contained in a data frame called cats, in the R package MASS. (This package is part of the standard R installation.) This records the sex of each cat, its weight in kilograms, and the weight of its heart in grams. Load the data as follows:

Run summary(cats) and explain the results.

Solution

Type your answer here

Problem 2. (10 points)

Plot a histogram of these weights using the probability=TRUE option. Add a vertical line with your calculated mean using abline(v=yourmeanvaluehere). Does this calculated mean look correct?

Solution

Type your answer here

Problem 3. (10 points)

Define two variables, fake.mean <- 10 and fake.var <- 8. Write an expression for aa using these placeholder values. Does it equal what you expected given the solutions above? Once it does, write another such expression for ss and confirm.

Solution

Type your answer here

Problem 4. (10 points)

Calculate the mean, standard deviation, and variance of the heart weights using R’s existing functions for these tasks. Plug the mean and variance of the cats’ hearts into your formulas from the previous question and get estimates of aa and ss. What are they? Do not report them to more significant digits than is reasonable.

Solution

Type your answer here

Problem 5. (10 points)

Write a function, cat.stats(), which takes as input a vector of numbers and returns the mean and variances of these cat hearts. (You can use the existing mean and variance functions within this function.) Confirm that you are returning the values from above.

Solution

Type your answer here

Part II

Problem 6. (10 points)

Now, use your existing function as a template for a new function, gamma.cat(), that calculates the mean and variances and returns the estimate of aa and ss. What estimates does it give on the cats’ hearts weight? Should it agree with your previous calculation?

Solution

Type your answer here

Problem 7. (10 points)

Estimate the aa and ss separately for all the male cats and all the female cats, using gamma.cat(). Give the commands you used and the results.

Solution

Type your answer here

Problem 8. (10 points)

Now, produce a histogram for the female cats. On top of this, add the shape of the gamma PDF using curve() with its first argument as dgamma(), the known PDF for the Gamma distribution. Is this distribution consistent with the empirical probability density of the histogram?

Solution

Type your answer here

Problem 9. (10 points)

Repeat the previous step for male cats. How do the distributions compare?

Solution

Explanation / Answer

Problem-6

mean of cats weight = 2.723611 kg

mean of Hearts weight = 10.63056 gram

variance of cats weight = 0.2355225 kg2

variance of Hearts weight = 5.927451 gram2

Sum of Square (SS) for cats weight = 144*0.2355225 = 33.91524

Sum of Square (SS) for Hearts weight = 144*5.927451 = 853.552944