---
title: "Homework 14"
author: "Alizeh Azhar"
date: "12/1/2021"
output: pdf_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

# Dataset Selection

The dataset that I have chosen for my final project is the *Housing dataset*, which contains *Sales Prices of Houses in the City of Windsor*. The dataset contains 546 number of observations and 12 variables. Out of the 12 variables, 6 are numeric and 6 are categorical. Table 1 below shows the summary of the dataframe.

```{r, results='asis'}
Housing <- read.csv("C:/Users/hp/Downloads/Housing.csv")
Housing= Housing[,-1]

library(tibble)
Housing<- tibble(Housing)
# str(Housing)
library(skimr)
skim_without_charts(Housing)
```

# Exploratory Analysis and Data Summary

In this section, all the 12 variables in the dataset are summarized.

## Price

It is a numeric continuous variable that represents the sale price of a house. In our analysis, it will be the dependent variable. The table below shows the summary statistics of the variable.

```{r, results='asis'}
library(summarytools)
descr(Housing$price, stats = c("mean", "sd", "min", "q1", "med", "q3", "max"), transpose = T, display.labels = F, headings = F)
```

We can summarize the distribution of the `price` variable using a histogram.

```{r, fig.align='center', out.width="70%"}
library(ggplot2)
ggplot(data= Housing, aes(x= price))+
  geom_histogram(bins = 10, color="darkblue",fill= "lightblue")+
  theme_bw()+
  ggtitle("Histogram for Price")

```

From the histogram above, the peak of the price variable occurs where the average sale prices of he houses is 50,000. The data is right skewed. Most of the sample values are clustered on the right side of the histogram. The number of houses decreases with increase in price. Most houses that were observed had low prices.

## Lot size

It is a numeric variable that represents the lot size of a house in square feet. In our analysis, it will be one of the independent variables. The table below shows the summary statistics of the variable.

```{r, results='asis'}
descr(Housing$lotsize, stats = c("mean", "sd", "min", "q1", "med", "q3", "max"), transpose = T, display.labels = F, headings = F)

```

We can summarize the variable graphically using an histogram

```{r, fig.align='center', out.width="70%"}
ggplot(data= Housing, aes(x= lotsize))+
  geom_histogram(bins = 10, color="darkblue",fill= "lightblue")+
  theme_bw()+
  ggtitle("Histogram for Lot size")

```

The lot size of the houses has a mean of `r round(mean(Housing$lotsize),2)` and the standard deviation of `r round(sd(Housing$lotsize),2)`. The lot size has a right skew but has only one peak. From the position of the peak, number of houses are decreasing as the lot size is increasing. From the histogram, there are some visible outliers in the lot size.

## Driveway

This is an independent categorical variable. It has two levels, `yes` and `no`. The response is *yes* if the house has a driveway, otherwise, it is *no*. In this analysis, it will be an independent variable. Below is the frequency table and the bar chart of the driveway variable.

```{r, results='asis'}
library(summarytools)
freq(Housing$driveway, report.nas = F, headings = F)
```

```{r, out.width="70%", fig.align='center'}
library(ggplot2)
ggplot(data = Housing, aes(driveway, fill=driveway))+
  geom_bar(color="darkblue",fill= "lightblue")+
  scale_fill_manual(values = c("#E69F00","#56B4E9"))+
  theme_bw()+
  ggtitle("Bar Chart for Driveway")
```

From the bar plot above, the number of houses that had a driveway were approximately 6 times the number of houses that did not have a driveway.

## Number of bedrooms

The number of bedrooms is represented by *bedrooms*. It is an independent discrete variable. However, it will not be used in this analysis. Below is the summary statistics and bar chart of the number of bedrooms.

```{r, results='asis'}
freq(Housing$bedrooms, report.nas = F, headings = F)
```

```{r,  out.width="70%", fig.align='center'}

library(ggplot2)
ggplot(data = Housing, aes(x=bedrooms))+
  geom_bar()+
  theme_bw()+
  xlab("Number of bedrooms")+
  ggtitle("Bar Chart for Number of bedrooms")

```

The number of bedrooms range from 1 to 6. A few houses had less than 2 bedrooms. Most houses had 2 and 3 bedrooms, and the number of bedrooms increased.

## Number of full bathrooms

The number of full bathrooms is represented by *bathrms*. It is an independent discrete variable. However, it will not be used in this analysis, despite that it has an effect on the prices of houses. Below is the table of summary statistics and bar chart of the number of bathrooms.

```{r, results='asis'}

freq(Housing$bathrms, report.nas = F, headings = F)
```

```{r, out.width="70%", fig.align='center'}

ggplot(data= Housing, aes(x= bathrms))+
  geom_bar()+
  theme_bw()+
  xlab("Number of full bathrooms")+
  ggtitle("Bar chart for Number of Full Bathrooms")
```

The number of bathrooms range from 1 to 4. Most houses had one bathroom the least number of houses had 4 bedrooms.

## Stories

This variable contains the number of stories excluding basement. It is a discrete independent variable. This variable will not be used in our analysis. Below is the summary statistics and the bar chart of the *stories* variable.

```{r, results='asis'}

freq(Housing$stories, report.nas = F, headings = F)
```

```{r, out.width="70%", fig.align='center'}

library(ggplot2)
ggplot(data= Housing, aes(x= stories))+
  geom_bar(color="darkblue",fill= "lightblue")+
  theme_bw()+
  ggtitle("Bar plot for Number of Stories")
```

The number of stories range from 1 to 4. Most houses had 2 stories. The number of houses that had 3 and 4 stories have almost equal frequencies.

## Recreational room

In the dataset, the variable is represented by `recroom`. It is an independent categorical variable. It has two levels, `yes` and `no`. The response is *yes* if the house has a recreational room, otherwise, it is *no*. The variable will not be used in this analysis. Below is the frequency table and the bar chart of this variable.

```{r, results='asis'}

library(summarytools)
freq(Housing$recroom, report.nas = F, headings = F)
```

```{r, out.width="70%", fig.align='center'}

library(ggplot2)
ggplot(data = Housing, aes(recroom, fill=recroom))+
  geom_bar()+
  scale_fill_manual(values = c("#E69F00","#56B4E9"))+
  theme_bw()+
  ggtitle("Bar Chart for Recreational Room")

```

Most houses did not have a recreation room. Only a few houses had a recreation room.

## Full finished basement

In the dataset, the variable is represented by `fullbase`. It is an independent categorical variable. It has two levels, `yes` and `no`. The response is *yes* if the house has a full finished basement, otherwise, it is *no*. The variable will not be used in this analysis. Below is the frequency table and the bar chart of this variable.

```{r, results='asis'}

library(summarytools)
freq(Housing$fullbase, report.nas = F, headings = F)
```

```{r, out.width="70%", fig.align='center'}

library(ggplot2)
ggplot(data = Housing, aes(fullbase, fill=fullbase))+
  geom_bar()+
  scale_fill_manual(values = c("#E69F00","#56B4E9"))+
  theme_bw()+
  ggtitle("Bar Chart for Full Finished Basement")

```

From the above bar chart, most houses had a furnished basement.

## Gas for hot water heating

In the dataset, the variable is represented by `gashw`. It is an independent categorical variable. It has two levels, `yes` and `no`. The response is *yes* if the house has a gas for hot water heating, otherwise, it is *no*. The variable will not be used in this analysis. Below is the frequency table and the bar chart of this variable.

```{r, results='asis'}

library(summarytools)
freq(Housing$gashw, report.nas = F, headings = F)
```

```{r, out.width="70%", fig.align='center'}

library(ggplot2)
ggplot(data = Housing, aes(gashw, fill=gashw))+
  geom_bar()+
  scale_fill_manual(values = c("#E69F00","#56B4E9"))+
  theme_bw()+
  ggtitle("Bar Chart for Hot Water Heating")
```

Most houses had a gas for heating water. Very few houses did not have a gas for heating water

## Central air conditioning

In the dataset, the variable is represented by `airco`. It is an independent categorical variable. It has two levels, `yes` and `no`. The response is *yes* if the house has a central air conditioning, otherwise, it is *no*. The variable will not be used in this analysis. Below is the frequency table and the bar chart of this variable.

```{r, results='asis'}

library(summarytools)
freq(Housing$airco, report.nas = F, headings = F)
```

```{r, out.width="70%", fig.align='center'}

library(ggplot2)
ggplot(data = Housing, aes(airco, fill=airco))+
  geom_bar()+
  scale_fill_manual(values = c("#E69F00","#56B4E9"))+
  theme_bw()+
  ggtitle("Bar Chart for central air conditioning")
```

More than half of the observed houses had a central air conditioning.

## Garage places

The number of garage places is represented by *garagepl*. It is an independent descrete variable. However, it will not be used in this analysis. Below is the summary statistics and histogram of the number of garage places.

```{r, results='asis'}
library(summarytools)
freq(Housing$garagepl, report.nas = F, headings = F)
```

```{r,  out.width="70%", fig.align='center'}

ggplot(data= Housing, aes(garagepl, fill=garagepl))+
  geom_bar()+
  scale_fill_manual(values = c("#E69F00","#56B4E9"))+
  theme_bw()+
  ggtitle("Bar chart for Garage Places")
```

The number of garage places range from 0 to 3. Most houses did not have a garage place. The frequency decreased as the number of garage places increased.

## Preferred area

In the dataset, the variable is represented by `prefarea`. It is an independent categorical variable. It has two levels, `yes` and `no`. The response is *yes* if the house located in the preferred neighborhood of the city, otherwise, it is *no*. The variable will not be used in this analysis. Below is the frequency table and the bar chart of this variable.

```{r, results='asis'}

freq(Housing$airco, report.nas = F, headings = F)
```

```{r, out.width="70%", fig.align='center'}

library(ggplot2)
ggplot(data = Housing, aes(prefarea, fill=prefarea))+
  geom_bar()+
  scale_fill_manual(values = c("#E69F00","#56B4E9"))+
  theme_bw()+
  ggtitle("Bar Chart for preferred area")
```

More than half of the observed houses were not located in the preferred neighborhood of the city.
