---
title: "Untitled"
author: "JIASHU MIAO"
date: "2/19/2019"
output: html_document
---
```{r}
pkg <- c("readr","readxl","dplyr","stringr","ggplot2","tidyr","stats")
pkgload <- lapply(pkg, require, character.only = TRUE)
```



Question 2 
How does the location affects the starts of the wine bar in Arizona that are open?
(latitude and longtitude)
```{r}
library(jsonlite)
#business <- fromJSON(sprintf("[%s]",paste(readLines("business.json"),collapse = ",")),flatten = TRUE)
#checkin <- fromJSON(sprintf("[%s]",paste(readLines("checkin.json"),collapse = ",")),flatten = TRUE)
checkin1=checkin
business1=business
```

```{r}
head(business,n=2)
str(business1$categories)
```

```{r}

```

```{r}
names(business1)
#attach(business1)
business1 <- business1 %>% filter(.,state=="ON" | state =="OH" | state =="AZ")
business1 <- business1 %>% filter(., is_open==1)
business1 <- business1 %>% select(.,longitude,latitude,stars,categories,state)
pattern1 <- c("Wine Bars", "Restaurants")
business1 <- business1[grepl(paste(pattern1),business1$categories),]
# business1 <- business1[categories,]
# business1$categories
business1$state <- as.factor(business1$state)
 levels(business1$state)
```

```{r}

business1 %>% group_by(business1$state) %>% summarise(., stars_mean=mean(stars))

businessAZ <-business1 %>% filter(., state=="AZ") %>% as.data.frame()
businessON <-business1 %>% filter(., state=="ON") %>% as.data.frame()
businessOH <-business1 %>% filter(., state=="OH") %>% as.data.frame()

modelAZ <- glm(data = businessAZ, formula = businessAZ$stars ~ businessAZ$longitude + businessAZ$latitude )

modelON <- glm(data = businessON, formula = businessON$stars ~ businessON$longitude + businessON$latitude )

modelOH <- glm(data = businessOH, formula = businessOH$stars ~ businessOH$longitude + businessOH$latitude )

colSums(is.na(businessOH))
```
```{r}
summary(modelAZ)


```
```{r}
summary(modelOH)
```
```{r}
summary(modelON)
par(mfrow = c(2,2))
plot(modelON)

```

```{r}
modelmix <- glm(data = business1, formula = business1$stars~ business1$longitude+business1$latitude)
summary(modelmix)

```
```{r}
plot(businessON$longitude,businessON$stars)
plot(businessON$latitude,businessON$stars)
#range(businessON$longitude)
```












