Here’s the code we’ll be using in class. Download it and store it with the rest of your materials for this course. If simply clicking doesn’t trigger download, you should right-click and select “save link as…”
How much would a noble (noble), without military experience (military) expect to pay (rprice1) for a governorship with a suitability index of .8 (suitindex) and a repartimiento (reparto2) of 98,000 pesos?
Step 1: fit model
colony_model =lm(rprice1 ~ noble + military + suitindex + reparto2, data = colony)tidy(colony_model)
Note: turns out the movies dataset has an issue with the way I stored the title variable that makes it very difficult to filter() with 😔. I found a solution below, but you don’t have to worry about knowing it.
Fit a model that predicts gross (outcome) using genre1, duration, budget, year, imdb_score, and whether or not it’s in color.
movies_model =lm(gross ~ genre1 + duration + budget + year + imdb_score + color, data = movies)tidy(movies_model)
Look up a movie in the dataset. How well does the model predict a movie that shares that movie’s characteristics?
movies |>filter(str_detect(title, "Spider-Man 3")) ## note: there is something weird about how I coded the title of these movies that makes filter not work; here's the solution I found; you're not responsible for this solution
# A tibble: 2 × 13
title year decade director genre1 genre2 genre3 duration gross budget
<chr> <dbl> <fct> <chr> <chr> <chr> <chr> <dbl> <dbl> <dbl>
1 Spider-Man … 2007 2000s Sam Rai… Action Adven… Roman… 156 3.37e8 2.58e8
2 Spider-Man … 2007 2000s Sam Rai… Action Adven… Roman… 156 3.37e8 2.58e8
# ℹ 3 more variables: imdb_score <dbl>, color <chr>, content_rating <chr>