In this exercise, you will apply lessons you learned from Quiz3-a to a new data set, Sacramento. I recommend that you try it on your own before watching the video.

This data set is imported from the caret package. For more information about the data set, Google the caret package, find a link to its manual on CRAN, and scroll down on the manual to the page that explains Sacramento. Or click this link to download its manual.

# Load the package
library(tidyverse)
library(caret)

# Import data
data(Sacramento, package = "caret")

# Print the first 6 rows
head(Sacramento)
##         city    zip beds baths sqft        type price latitude longitude
## 1 SACRAMENTO z95838    2     1  836 Residential 59222 38.63191 -121.4349
## 2 SACRAMENTO z95823    3     1 1167 Residential 68212 38.47890 -121.4310
## 3 SACRAMENTO z95815    2     1  796 Residential 68880 38.61830 -121.4438
## 4 SACRAMENTO z95815    2     1  852 Residential 69307 38.61684 -121.4391
## 5 SACRAMENTO z95824    2     1  797 Residential 81900 38.51947 -121.4358
## 6 SACRAMENTO z95841    3     1 1122       Condo 89921 38.66260 -121.3278

Q1 You are moving to the Sacramento area and found a house you like. But you are surprised at its price tag. It’s half a million dollars. You wonder how rare it would be to encounter a house this expensive or how close this price is to the typical home price in the area. What would you use to answer this question?

In order to answer this question, I would look to the data on the histogram at the 500,000 mark on the X axis and realized that there are less than 15 listings for $500,000, as opposed to the prices to the left which the maximum lies at the 250,000 mark at upwards of 100 listings.

Q2 Plot price in a histogram. Is the data normally distributed?

ggplot(Sacramento, aes(x = price)) +
  geom_histogram() + 
  labs(title = "Price of Houses",
       x = "Price")

The data is not normally distributed. There is no “bell curve” and the data on the histogram is skewed to the right.

Q3 Calculate the mean and the standard deviation of price.

mean(Sacramento$price)
## [1] 246661.6
sd(Sacramento$price)
## [1] 131126.9

Q4 empirical rule Base on your analysis in Q3 and Q4, would it be appropriate to use the empirical rule to find the probability of seeing a house that’s more expensive than half a million dollar home? Why? Why not?

Based on my analysis in Q3 and Q4, it would not be appropriate to find the probability of a house that is more expensive than a half a million dollars because the empirical rule only applies to data that is normally distributed.

Q5 empirical rule Let’s just assume that home prices are normally distributed for the sake of exercise. What’s the probability of seeing a house that’s more expensive than half a million dollar home ($508,915 to be exact)?

The probability of seeing a house that is more than $508,915 is 2.5%.

Q6 What’s the unit of standard deviation in Q5? What would be the unit of variance?

The unit of standard deviation in Q5 is 2. The unit of variance is would be 4.

Q7 Assume that you are sampling homes from the Sacramento area for the housing market analysis. You took a very small sample, smaller than 30 homes, due to a small budget. Discuss the risks you are taking in terms of it’s likely effects on the sample mean and the sample variance/standard deviation.

The risk that you are taking here is that the sample mean often does not reflect the population mean. When the means of population and the sample do not align, there is a large downward bias in the standard deviation and variance.

Q8 Hide the messages, but display the code and its results on the webpage.

Hint: Use message, echo and results in the chunk options. Refer to the RMarkdown Reference Guide.

Q9 Display the title and your name correctly at the top of the webpage.

Q10 Use the correct slug.