以年份與坪數解釋房價

在 Tidyverse 中進行資料建模

Albert Y. Kim

Assistant Professor of Statistical and Data Sciences

複習:西雅圖房價

library(dplyr)
library(moderndive)

# Preview only certain variables:
house_prices %>% 
  select(price, sqft_living, condition, waterfront) %>% 
  glimpse()
Observations: 21,613
Variables: 4
$ price       <dbl> 221900, 538000, 180000, 604000...
$ sqft_living <int> 1180, 2570, 770, 1960, 1680, 5420...
$ condition   <fct> 3, 3, 3, 5, 3, 3, 3, 3, 3, 3, 3...
在 Tidyverse 中進行資料建模

複習:價格與坪數變數

在 Tidyverse 中進行資料建模

複習:log10 轉換

在 Tidyverse 中進行資料建模

複習:資料轉換

# log10() transform price and size
house_prices <- house_prices %>%
  mutate(
    log10_price = log10(price),
    log10_size = log10(sqft_living)
  )
在 Tidyverse 中進行資料建模

房價模型

  • 反應變數 $y$-房價(USD):price
  • 兩個數值型解釋/預測變數:
    • $x_1$-房屋坪數:log10_size
    • $x_2$-建造年份:yr_built
在 Tidyverse 中進行資料建模

探索式視覺化:房價、坪數與年份

log10_pricelog10_sizeyr_built 的 3D 散佈圖

在 Tidyverse 中進行資料建模

迴歸平面

帶有迴歸平面的 3D 散佈圖(連結至互動版)。

在 Tidyverse 中進行資料建模

迴歸表

# Fit regression model using formula of form: y ~ x1 + x2
model_price_1 <- lm(log10_price ~ log10_size + yr_built, 
                    data = house_prices)

# Output regression table get_regression_table(model_price_1)
# A tibble: 3 x 7
  term       estimate std_error statistic p_value...
  <chr>         <dbl>     <dbl>     <dbl>   <dbl>...
1 intercept   5.38      0.0754       71.4       0...
2 log10_size  0.913     0.00647     141.        0...
3 yr_built   -0.00138   0.00004     -33.8       0...
在 Tidyverse 中進行資料建模

一起來練習吧!

在 Tidyverse 中進行資料建模

Preparing Video For Download...