individual-assignment-5.pdf - Individual Assignment 5 Kevin Jin Problem 8 In this exercise we will generate simulated data and will then use this data

individual-assignment-5.pdf - Individual Assignment 5 Kevin...

This preview shows page 1 - 2 out of 13 pages.

Individual Assignment 5 Kevin Jin 9/27/2019 Problem 8: In this exercise, we will generate simulated data, and will then use this data to perform best subset selection. (a) Use the LaTeX: rnorm()r n o r m ( ) function to generate a predictor LaTeX: XX of length LaTeX: n = 100n = 100, as well as a noise vector of length LaTeX: n = 100n = 100. set.seed ( 1 ) x = rnorm ( 100 ) noise = rnorm ( 100 ) (b) Generate a response vector LaTeX: YY of length LaTeX: n = 100n = 100 according to the model set.seed ( 2 ) beta_ 0 = sample ( - 100 : 100 , 1 ) beta_ 1 = sample ( - 100 : 100 , 1 ) beta_ 2 = sample ( - 100 : 100 , 1 ) beta_ 3 = sample ( - 100 : 100 , 1 ) y = beta_ 0 + beta_ 1 * x + beta_ 2 * x + beta_ 3 * x + noise (c) Use the LaTeX: regsubsets()r e g s u b s e t s ( ) function to perform best subset selection in order to choose the best model containing the predictors LaTeX: X,:X 2,:. . . :,:X {10}X , X 2 , . . . , X 10. What is the best model obtained according to LaTeX: C_pC p, BIC, and adjusted LaTeX: Rˆ2R 2? Show some plots to provide evidence for your answer, and report the coefficients of the best model obtained. Note you will need to use the LaTeX: data.frame()d a t a . f r a m e ( ) function to create a single data set containing both LaTeX: XX and LaTeX: YY. library (leaps) ?regsubsets ## starting httpd help server ... done ?I data = data.frame ( y = y, x = x) regfit = regsubsets (y ~ x + I (x ^ 2 ) + I (x ^ 3 ) + I (x ^ 4 ) + I (x ^ 5 ) + I (x ^ 6 ) + I (x ^ 7 ) + I (x ^ 8 ) + I (x ^ 9 ) + I (x ^ reg.summary = summary (regfit) reg.summary ## Subset selection object ## Call: regsubsets.formula(y ~ x + I(x^2) + I(x^3) + I(x^4) + I(x^5) + ## I(x^6) + I(x^7) + I(x^8) + I(x^9) + I(x^10), data = data, ## nvmax = 10) ## 10 Variables (and intercept) ## Forced in Forced out ## x FALSE FALSE ## I(x^2) FALSE FALSE ## I(x^3) FALSE FALSE ## I(x^4) FALSE FALSE
Image of page 1

Subscribe to view the full document.

Image of page 2
  • Fall '17

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Ask Expert Tutors You can ask 0 bonus questions You can ask 0 questions (0 expire soon) You can ask 0 questions (will expire )
Answers in as fast as 15 minutes