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

Please use RStudio answer these questiones and give the R command, please load d

ID: 3142552 • Letter: P

Question

Please use RStudio answer these questiones and give the R command, please load data use data:

Problem 1. (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 2. (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 3. (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

Explanation / Answer

Problem 1

aa <- 10* (fake.mean) + 5*(fake.var) : 140

ss <- 10* (fake.mean) - 5*(fake.var) : 60

Problem 2

mean_hwt <- mean(cats$Hwt) : Answer is 10.63056

variance_hwt <- var(cats$Hwt) : Answer is 5.927451

stand_dev_hwt <- sd(cats$Hwt) : Answer is 2.434636

aa <- 10* (mean_hwt) + 5*(variance_hwt) : Answer is 135.9428

ss <- 10* (mean_hwt) - 5*(variance_hwt) : Answer is 76.6683

Problem 3

cat.stats <- function(a)
{
mean <- mean(a);
variance <- var(a);
return(c(mean,variance))
}

temp <- cat.stats(cats$Hwt)

> temp
[1] 10.630556 5.927451

Which is the right answer. Please also find below complete code.

library(MASS)
data(cats)

fake.mean <- 10
fake.var <- 8

#Problem 1
aa <- 10* (fake.mean) + 5*(fake.var)
ss <- 10* (fake.mean) + 5*(fake.var)

#Problem 2
mean_hwt <- mean(cats$Hwt)
variance_hwt <- var(cats$Hwt)
stand_dev_hwt <- sd(cats$Hwt)

aa <- 10* (mean_hwt) + 5*(variance_hwt)
ss <- 10* (mean_hwt) - 5*(variance_hwt)

#Problem 3
cat.stats <- function(a)
{
mean <- mean(a);
variance <- var(a);
return(c(mean,variance))
}

temp <- cat.stats(cats$Hwt)