Question: Hi, When I copy this code exactly as written I'm receiving different output in R. Any idea why this is happening? Course: Predict 422, Northwestern

Hi, When I copy this code exactly as written I'm receiving different output in R. Any idea why this is happening?

Course: Predict 422, Northwestern

Document: LAB 3 Solutions.pdf

Question 4, Looking at Section 5.3.3

Your Code Reads:

set.seed(17) cv.error.5 <- rep(0, 10) degree <- 1:10 for(d in degree){glm.fit <- glm(mpg ~ poly(horsepower, d), data = Auto)cv.error.5[d] <- cv.glm(Auto, glm.fit, K = 5)$delta[1] }

Your Output:

cv.error.5[1] # 24.2624 cv.error.5[2] # 19.15424

When I type the exact code:

> set.seed(17)

> cv.error.5 <- rep(0, 10)

> degree <- 1:10

> for(d in degree){

+ glm.fit <- glm(mpg ~ poly(horsepower, d), data = Auto)

+ cv.error.5[d] <- cv.glm(Auto, glm.fit, K = 5)$delta[1]

+ }

My output is:

> cv.error.5[1]

[1] 24.51158

Can you please help explain why my R produces different results with same code?

Thank you

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Mathematics Questions!