class: center, middle, inverse, title-slide # CV Lab ### Dr. D’Agostino McGowan --- layout: true <div class="my-footer"> <span> Dr. Lucy D'Agostino McGowan <i>adapted from slides by Hastie & Tibshirani</i> </span> </div> --- ## RStudio Pro # rstudio.hpc.ar53.wfu.edu:8787 ## pw: R2D2Star! --- class: center, middle ## Practice getting your lab into RStudio Pro --- class: center, middle ## Now get your lab into RStudio Cloud --- ## Practice pushing and pulling in GitHub * So far we have just been **pushing** to GitHub, but a nice feature is that you can then **pull** your results at any time. * Make a change to your Lab file in RStudio Pro and **push** this to GitHub (check the GitHub repo to make sure your changes showed up) * Check RStudio cloud - did those changes show up? -- * Click the pull (down) arrow in RStudio cloud. Do you see the changes now? --- ## Some R functions ```r sample(10) ``` ``` ## [1] 3 1 8 5 7 2 4 9 6 10 ``` ```r sample(10) ``` ``` ## [1] 8 3 9 1 7 10 4 6 2 5 ``` --- ## Some R functions ```r set.seed(1) sample(10) ``` ``` ## [1] 3 4 5 7 2 8 9 6 10 1 ``` ```r set.seed(1) sample(10) ``` ``` ## [1] 3 4 5 7 2 8 9 6 10 1 ``` --- class: center, middle ## Use the `set.seed()` function before performing cross validation so you get consistent (reproducible) answers! --- ## Polynomial regression in R `\(y = \beta_0 + \beta_1 x + \beta_2 x^2 + \beta_3 x^3 + \epsilon\)` .small[ ```r lm(y ~ x + I(x^2) + I(x^3), data = data) ``` ``` ## ## Call: ## lm(formula = y ~ x + I(x^2) + I(x^3), data = data) ## ## Coefficients: ## (Intercept) x I(x^2) I(x^3) ## 0.10276 -0.06669 -0.13772 0.02546 ``` ] -- .small[ ```r lm(y ~ poly(x, 3), data = data) ``` ``` ## ## Call: ## lm(formula = y ~ poly(x, 3), data = data) ## ## Coefficients: ## (Intercept) poly(x, 3)1 poly(x, 3)2 poly(x, 3)3 ## -0.007264 -0.205147 -1.465710 0.382521 ``` ] --- ## Polynomial regression in R `\(y = \beta_0 + \beta_1 x + \beta_2 x^2 + \beta_3 x^3 + \epsilon\)` ```r model1 <- lm(y ~ x + I(x^2) + I(x^3), data = data) model2 <- lm(y ~ poly(x, 3), data = data) all.equal(predict(model1), predict(model2)) ``` ``` ## [1] TRUE ``` --- class: center, middle ## When doing polynomial regression, you can use the `poly()` function in R