library(socsci)
## Loading required package: tidyverse
## -- Attaching packages ----------------------------------------------------------------------------------------------------------------------- tidyverse 1.2.1 --
## v ggplot2 3.1.0 v purrr 0.3.0
## v tibble 2.0.1 v dplyr 0.8.0.1
## v tidyr 0.8.2 v stringr 1.4.0
## v readr 1.3.1 v forcats 0.4.0
## -- Conflicts -------------------------------------------------------------------------------------------------------------------------- tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
## Loading required package: rlang
##
## Attaching package: 'rlang'
## The following objects are masked from 'package:purrr':
##
## %@%, as_function, flatten, flatten_chr, flatten_dbl,
## flatten_int, flatten_lgl, flatten_raw, invoke, list_along,
## modify, prepend, splice
## Loading required package: scales
##
## Attaching package: 'scales'
## The following object is masked from 'package:purrr':
##
## discard
## The following object is masked from 'package:readr':
##
## col_factor
## Loading required package: broom
## Loading required package: glue
##
## Attaching package: 'glue'
## The following object is masked from 'package:dplyr':
##
## collapse
house <- read_csv("https://raw.githubusercontent.com/ryanburge/pls2003_sp17/master/house.csv")
## Parsed with column specification:
## cols(
## id = col_double(),
## date = col_datetime(format = ""),
## price = col_double(),
## bedrooms = col_double(),
## bathrooms = col_double(),
## sqft_living = col_double(),
## sqft_lot = col_double(),
## floors = col_double(),
## waterfront = col_double(),
## condition = col_double(),
## grade = col_double(),
## yr_built = col_double()
## )
The question says: 4 bedrooms, 2 bathrooms. The house was built in 1987 and has 1800 sq feet of living space
options(scipen = 999) ## To get rid of scientific notation
reg1 <- lm(price ~ bedrooms + bathrooms + sqft_living + yr_built, data = house)
summary(reg1)
##
## Call:
## lm(formula = price ~ bedrooms + bathrooms + sqft_living + yr_built,
## data = house)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1850266 -131910 -17121 100494 3950375
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 6028494.849 130027.974 46.36 <0.0000000000000002 ***
## bedrooms -69666.804 2244.860 -31.03 <0.0000000000000002 ***
## bathrooms 82968.984 3731.591 22.23 <0.0000000000000002 ***
## sqft_living 300.224 2.956 101.57 <0.0000000000000002 ***
## yr_built -3071.211 66.987 -45.85 <0.0000000000000002 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 246300 on 21608 degrees of freedom
## Multiple R-squared: 0.5506, Adjusted R-squared: 0.5506
## F-statistic: 6620 on 4 and 21608 DF, p-value: < 0.00000000000000022
So, we can do the math now.
Bedrooms: -69666 * 4 = -278664 Bathrooms: 82968 * 2 = 165936 Sq Ft: 300 * 1800 = 540000 Year Built: -3071 * 1987 = -6102077
Let’s addd all this together: 540000 + 165936 - 278664 - 6102077 = -5674805
Then we add our intercept: 6028494 -5674805 = $353,689