+ - 0:00:00
Notes for current slide
Notes for next slide

Lab 04: Interpreting Results

1 / 10

Agenda

  • Creating a data.frame
  • Exam expectations
  • Creating a project
  • Tips: Review some common mistakes
  • Lab 04: on your own
2 / 10

Creating a data frame

  • We have been working with a lot of data frames in R, for example PorschePrice, Sparrows, Pines.
3 / 10

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.
3 / 10

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.
3 / 10

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:
new_porscheprice <- data.frame(
Mileage = 50
)
3 / 10

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:
new_porscheprice <- data.frame(
Mileage = 50
)
  • Then we can use this in the predict() function:
lm(Price ~ Mileage, PorschePrice) %>%
predict(newdata = new_porscheprice, interval = "prediction")
## fit lwr upr
## 1 41.62041 26.58711 56.6537
4 / 10

R output

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
5 / 10

R Output

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
6 / 10

Exam expectations

  • 3 or 4 questions with multiple parts
  • bring a calculator
7 / 10

Exam expectations

  • 3 or 4 questions with multiple parts
  • bring a calculator
  • Definitions
7 / 10

Exam expectations

  • 3 or 4 questions with multiple parts
  • bring a calculator
  • Definitions
  • Assess the fit of a model based on visualizations
7 / 10

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
7 / 10

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
7 / 10

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
7 / 10

Lab introduction

  • Lab instructions posted on the course website under </>
8 / 10

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
9 / 10

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!
10 / 10

Agenda

  • Creating a data.frame
  • Exam expectations
  • Creating a project
  • Tips: Review some common mistakes
  • Lab 04: on your own
2 / 10
Paused

Help

Keyboard shortcuts

, , Pg Up, k Go to previous slide
, , Pg Dn, Space, j Go to next slide
Home Go to first slide
End Go to last slide
Number + Return Go to specific slide
b / m / f Toggle blackout / mirrored / fullscreen mode
c Clone slideshow
p Toggle presenter mode
t Restart the presentation timer
?, h Toggle this help
Esc Back to slideshow