Dayvon B.

asked • 02/12/24

The Orange data frame from datasets...

Using the dataset Orange from R can help solve this question.



Part c)

According to the model, what is the estimate of the mean of circumference 𝑌 for a tree of age 𝑥 = 900. That is, find 𝜇̂ 𝑌|𝑥=900= estimate of 𝐸[𝑌|𝑥=900]? Do NOT round your answer! Hint: Use the command

predict(mod, data.frame(age=??))

for appropriately chosen replacement of the symbol ??

Write your answer as

ans = <something here>



Part d)

Find 92% confidence interval for 𝐸[𝑌|𝑥=900]. You should use command of the format

predict(mod, data.frame(age=??), data=Orange, interval="confidence", level=??)

and replace the two ?? simbols with appropriate values.

Create variables CIlwr and CIupr with lower and upper end points of the desired interval. Do NOT round your answers.


My code for part(c):


```

x <- 900

predicted_mean <- predict(mod, newdata = data.frame(age = x))

x

```

My code for part(d):

```

x <- 900


# Use predict() to calculate the confidence interval


confidence_interval <- predict(mod, newdata = data.frame(age = x), data = Orange, interval = "confidence", level = 0.92)


# Extract the lower and upper bounds of the confidence interval


CIlwr <- confidence_interval[1]

CIupr <- confidence_interval[2]


# Print the confidence interval


CIlwr

CIupr

```


My code does not pass certain test. Feel free to correct my code with the appropriate one.


Your code my pass ALL test put forward by the following:

Part (c)

```

## check whether variable ans exists and is numeric


if (test_that(desc="", code={

expect_equal(exists("ans", mode="numeric"), TRUE)

}) != TRUE) stop("variable ans not created or is not numeric!")


```

And

(I received an error for this test:

── Failure (<text>:4:5): ──────────────────────────────────────────────────────
floor(as.numeric(ans) * 10^6)%%10 == 2 not equal to TRUE.
1 element mismatch

Error in eval(expr, envir, enclos): variable ans not created or is not numeric!
Traceback:

1. stop("variable ans not created or is not numeric!")

)


```

## check whether the 6th decimal digit is 2


if (test_that(desc="", code={

expect_equal(floor(as.numeric(ans)*10^6) %% 10 == 2, TRUE)

}) != TRUE) stop("variable ans not created or is not numeric!")

```


Part (D):


```

## check whether variables CIlwr and CIupr exist and are numeric


if (test_that(desc="", code={

expect_equal(exists("CIlwr", mode="numeric"), TRUE)

}) != TRUE) stop("variable CIlwr is not created or not numeric!")


if (test_that(desc="", code={

expect_equal(exists("CIupr", mode="numeric"), TRUE)

}) != TRUE) stop("variable CIupr is not created or not numeric!")


```


And


(I received an error message for this one:── Failure (<text>:4:5): Sorry, wrong answer. ──────────────────────────────────
floor(as.numeric(CIlwr) * 10^8)%%10 == 8 not equal to TRUE.
1 element mismatch

Error in eval(expr, envir, enclos): Sorry, wrong answer.
Traceback:

1. stop("Sorry, wrong answer.")

)


```


## check whether the 8th decimal digit of CIlwr is correct


if (test_that(desc="Sorry, wrong answer.", code={

expect_equal(floor(as.numeric(CIlwr)*10^8) %% 10 == 8, TRUE)

}) != TRUE) stop("Sorry, wrong answer.")



## check whether the 8th decimal digit of CIupr is correct


if (test_that(desc="Sorry, wrong answer.", code={

expect_equal(floor(as.numeric(CIupr)*10^8) %% 10 == 1, TRUE)

}) != TRUE) stop("Sorry, wrong answer.")

```


Michael H.

tutor
Is there, somewhere in this question, a URL where that particular data set is found? If not, it may be impossible to answer this.
Report

08/20/24

1 Expert Answer

By:

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.