In-class example
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…”
Art
How much should we expect a painting to sell for if it was created in 2000, is a sculpture, is 360 inches, painted by a male artist who went to an elite art school?
Step 1: fit model
art_mod = lm (real_price_usd ~ year_of_artwork + genre + size_inch_by_inch + gender_male + elite_school, data = art)
tidy (art_mod)
# A tibble: 14 × 5
term estimate std.error statistic p.value
<chr> <dbl> <dbl> <dbl> <dbl>
1 (Intercept) -871468. 423020. -2.06 3.94e- 2
2 year_of_artwork 399. 180. 2.22 2.65e- 2
3 genreFurniture -22050. 233258. -0.0945 9.25e- 1
4 genreLighting 16834. 279905. 0.0601 9.52e- 1
5 genrePaintings 131746. 221991. 0.593 5.53e- 1
6 genrePhotographs 38462. 225012. 0.171 8.64e- 1
7 genrePrints 8849. 223350. 0.0396 9.68e- 1
8 genresculpture 502219. 585437. 0.858 3.91e- 1
9 genreSculpture 95405. 221369. 0.431 6.66e- 1
10 genreTextiles -502. 312996. -0.00160 9.99e- 1
11 genreWorks on Paper 22696. 224533. 0.101 9.19e- 1
12 size_inch_by_inch 27.6 1.36 20.3 8.00e-90
13 gender_male 62918. 15183. 4.14 3.44e- 5
14 elite_school 76471. 11665. 6.56 5.76e-11
Step 2: set scenario:
art_scen = crossing (year_of_artwork = 2000 , genre = "Sculpture" , size_inch_by_inch = 360 , gender_male = 1 , elite_school = 1 )
art_scen
# A tibble: 1 × 5
year_of_artwork genre size_inch_by_inch gender_male elite_school
<dbl> <chr> <dbl> <dbl> <dbl>
1 2000 Sculpture 360 1 1
Step 3: get estimate:
augment (art_mod, newdata = art_scen)
# A tibble: 1 × 6
year_of_artwork genre size_inch_by_inch gender_male elite_school .fitted
<dbl> <chr> <dbl> <dbl> <dbl> <dbl>
1 2000 Sculpture 360 1 1 170745.