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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started