class: center, middle, inverse, title-slide # Lab 04: Interpreting Results --- layout: true <div class="my-footer"> <span> Dr. Lucy D'Agostino McGowan </span> </div> --- # Agenda * **Creating a data.frame** * **Exam expectations** * **Creating a project** * **Tips:** Review some common mistakes * **Lab 04:** on your own --- ## Creating a data frame * We have been working with a lot of data frames in R, for example `PorschePrice`, `Sparrows`, `Pines`. -- * To use the `predict()` function to predict values for a _new_ observation, we need to create a data frame. -- * We can use the `data.frame()` function for this. -- * For example, if we fit a simple linear regression model predicting Porsche prices from mileage and we wanted to predict the price of a car with 50,000 miles, we could do this: ```r new_porscheprice <- data.frame( Mileage = 50 ) ``` --- ## Predict new values * If we fit a simple linear regression model predicting Porsche prices from mileage and we wanted to predict the price of a car with 50,000 miles, we could do this: ```r new_porscheprice <- data.frame( Mileage = 50 ) ``` * Then we can use this in the `predict()` function: ```r lm(Price ~ Mileage, PorschePrice) %>% predict(newdata = new_porscheprice, interval = "prediction") ``` ``` ## fit lwr upr ## 1 41.62041 26.58711 56.6537 ``` --- ## R output ```r lm(Price ~ Mileage, PorschePrice) %>% tidy() ``` ``` ## # A tibble: 2 x 5 ## term estimate std.error statistic p.value ## <chr> <dbl> <dbl> <dbl> <dbl> ## 1 (Intercept) 71.1 2.37 30.0 7.87e-23 ## 2 Mileage -0.589 0.0566 -10.4 3.98e-11 ``` --- ## R Output ```r lm(Price ~ Mileage, PorschePrice) %>% anova() ``` ``` ## Analysis of Variance Table ## ## Response: Price ## Df Sum Sq Mean Sq F value Pr(>F) ## Mileage 1 5565.7 5565.7 108.25 3.982e-11 ## Residuals 28 1439.6 51.4 ``` --- ## Exam expectations * 3 or 4 questions with multiple parts * **bring a calculator** -- * Definitions -- * Assess the fit of a model based on visualizations -- * Calculate predicted values, residuals, statistics, confidence intervals -- * Construct / interpret hypothesis tests -- * Interpret results --- ## Lab introduction - Lab instructions posted on the course website under `</>` + Let's go find today's lab! + [bit.ly/sta-212-f19](https://bit.ly/sta-212-f19) --- ## Create a project in RStudio on your own! * Go to rstudio.cloud * Go to our STA 212 - Fall 19 Workspace * Click "New Project" * Title your project "Lab 04: Interpreting Results" * Click File > New File > RMarkdown * Delete everything except the YAML --- ## Tips - Don't forget to change your name in the `yaml` - Be ready to troubleshoot your document, since it will likely fail to knit on multiple occasions throughout the process. Read the error message carefully and take note of which line is preventing a successful knit. - Make sure to keep track of your various chunks and to keep text and code in the right place. - Remember that your R Markdown file is not aware of your project's global environment and can only make use of variables, functions, etc. that you have loaded or defined in the document. - Remind yourself how the pipe operator (`%>%`) works. - If you're unsure how a function works or what its arguments are, simply type `?` in front of it and hit enter (`?read_csv` for instance). The "Help" tab will open and provide a summary of the function as well as some examples. - Make sure to label your plots!