Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Calculus An Applied Approach

Authors: Ron Larson, Dennis J McKenzie, Larson/Edwards, Bruce H Edwards

7th Edition

1111809720, 9781111809720

More Books

Students also viewed these Mathematics questions

Question

Explain the various methods of job evaluation

Answered: 1 week ago

Question

Differentiate Personnel Management and Human Resource Management

Answered: 1 week ago

Question

Describe the functions of Human resource management

Answered: 1 week ago

Question

8. Explain the relationship between communication and context.

Answered: 1 week ago

Question

d. How were you expected to contribute to family life?

Answered: 1 week ago