-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.Rhistory
512 lines (512 loc) · 36.9 KB
/
.Rhistory
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
count.high.SES.line
# high SES SVM modeling
subway_lm_high <- train(rating ~ .,
data = above.avg.subway,
method = "svmRadial",
trControl=subway.above.ctrl,
tunelength= 10)
#subway_lm_high_2 <- lm(formula = rating ~ reviewCount * price, data = above.avg.subway.train)
summary(subway_lm_high)
predict_subway_lm_high <- predict(subway_lm_high, below.avg.subway)
#postResample(predict_yelp_svm_high, below.avg$rating)
#actual minus predicted
delta.subway.high.SES <- below.avg.subway$rating - predict_subway_lm_high
count.subway.high.SES.line <- length(which(delta.subway.high.SES < 0)) / length(delta.subway.high.SES)
count.high.SES.line
above.avg.subway <- filter(above.avg, name %in% "Subway")
below.avg.subway <- filter(below.avg, name %in% "Subway")
check.unique.dummy.variable(above.avg.subway)
check.unique.dummy.variable(below.avg.subway)
View(above.avg.subway)
# filter only Subways for high and low SES
above.avg.subway <- filter(above.avg, name %in% "Subway")
below.avg.subway <- filter(below.avg, name %in% "Subway")
above.avg.subway <- subset(above.avg.subway, select=c("rating", "reviewCount", "recentHealthInspectionScore","totalInspectionScore", "totalInspectionCount", "avgInspectionScore", "restaurantTotalMonths", "restaurantMaxSeats", "recentHealthInspectionResultSatisfactory", "recentHealthInspectionResultUnsatisfactory", "recentHealthViolationType.1", "recentHealthViolationTypeblue", "recentHealthViolationTypered", "recentHealthInspectionGrade.1", "recentHealthInspectionGrade.2", "recentHealthInspectionGrade.3", "recentHealthInspectionGrade.4"))
above.avg.subway <- subset(below.avg.subway, select=c("rating", "reviewCount", "recentHealthInspectionScore","totalInspectionScore", "totalInspectionCount", "avgInspectionScore", "restaurantTotalMonths", "restaurantMaxSeats", "recentHealthInspectionResultSatisfactory", "recentHealthInspectionResultUnsatisfactory", "recentHealthViolationType.1", "recentHealthViolationTypeblue", "recentHealthViolationTypered", "recentHealthInspectionGrade.1", "recentHealthInspectionGrade.2", "recentHealthInspectionGrade.3", "recentHealthInspectionGrade.4"))
subway.above.ctrl <- trainControl(method = "repeatedcv", number=nrow(above.avg.subway) - 1, repeats=3) # 10 fold cross-validation, repeated 3 times. better way to do it but takes longer.
subway.below.ctrl <- trainControl(method = "repeatedcv", number=nrow(below.avg.subway) - 1, repeats=3)
above.avg.subway
View(above.avg.subway)
View(below.avg.subway)
# splitting boston data into train+validate and test sets
split_proportion = 0.8
# select outcome variable for below avg HH income
below.avg.subway.outcome <- subway.below.avg.wo.census %>% dplyr::select(rating) # rating column only
# randomly select indices for train/validate set
below.avg.subway.train_ind <- createDataPartition(below.avg.subway.outcome$rating, p = split_proportion, list = FALSE)
below.avg.subway.train <- subway.below.avg.wo.census[below.avg.subway.train_ind,] # get training below avg data
below.avg.subway.test <- subway.below.avg.wo.census[-below.avg.subway.train_ind,] # get test below avg data
# select outcome variable for above avg HH income
above.avg.subway.outcome <- subway.above.avg.wo.census %>% dplyr::select(rating) # rating column only
# randomly select indices for train/validate set
above.avg.subway.train_ind <- createDataPartition(above.avg.subway.outcome$rating, p = split_proportion, list = FALSE)
above.avg.subway.train <- subway.above.avg.wo.census[above.avg.subway.train_ind,] # get training above avg data
above.avg.subway.test <- subway.above.avg.wo.census[-above.avg.subway.train_ind,] # get test above avg data
# filter only Subways for high and low SES
above.avg.subway <- filter(above.avg, name %in% "Subway")
below.avg.subway <- filter(below.avg, name %in% "Subway")
above.avg.subway <- subset(above.avg.subway, select=c("rating", "reviewCount", "recentHealthInspectionScore","totalInspectionScore", "totalInspectionCount", "avgInspectionScore", "restaurantTotalMonths", "restaurantMaxSeats", "recentHealthInspectionResultSatisfactory", "recentHealthInspectionResultUnsatisfactory", "recentHealthViolationType.1", "recentHealthViolationTypeblue", "recentHealthViolationTypered", "recentHealthInspectionGrade.1", "recentHealthInspectionGrade.2", "recentHealthInspectionGrade.3", "recentHealthInspectionGrade.4"))
below.avg.subway <- subset(below.avg.subway, select=c("rating", "reviewCount", "recentHealthInspectionScore","totalInspectionScore", "totalInspectionCount", "avgInspectionScore", "restaurantTotalMonths", "restaurantMaxSeats", "recentHealthInspectionResultSatisfactory", "recentHealthInspectionResultUnsatisfactory", "recentHealthViolationType.1", "recentHealthViolationTypeblue", "recentHealthViolationTypered", "recentHealthInspectionGrade.1", "recentHealthInspectionGrade.2", "recentHealthInspectionGrade.3", "recentHealthInspectionGrade.4"))
subway.above.ctrl <- trainControl(method = "repeatedcv", number=nrow(above.avg.subway) - 1, repeats=3) # 10 fold cross-validation, repeated 3 times. better way to do it but takes longer.
subway.below.ctrl <- trainControl(method = "repeatedcv", number=nrow(below.avg.subway) - 1, repeats=3)
# filter only Subways for high and low SES
above.avg.subway <- filter(above.avg, name %in% "Subway")
below.avg.subway <- filter(below.avg, name %in% "Subway")
# remove violationTypeRed, InspectionGrade 2 ,3 ,4 for above.avg since those columns aren't unique
above.avg.subway <- subset(above.avg.subway, select=c("rating", "reviewCount", "recentHealthInspectionScore","totalInspectionScore", "totalInspectionCount", "avgInspectionScore", "restaurantTotalMonths", "restaurantMaxSeats", "recentHealthInspectionResultSatisfactory", "recentHealthInspectionResultUnsatisfactory", "recentHealthViolationType.1", "recentHealthViolationTypeblue", "recentHealthInspectionGrade.1"))
# remove InspectionGrade 3 ,4 for above.avg since those columns aren't unique
below.avg.subway <- subset(below.avg.subway, select=c("rating", "reviewCount", "recentHealthInspectionScore","totalInspectionScore", "totalInspectionCount", "avgInspectionScore", "restaurantTotalMonths", "restaurantMaxSeats", "recentHealthInspectionResultSatisfactory", "recentHealthInspectionResultUnsatisfactory", "recentHealthViolationType.1", "recentHealthViolationTypeblue", "recentHealthInspectionGrade.1"))
subway.above.ctrl <- trainControl(method = "repeatedcv", number=nrow(above.avg.subway) - 1, repeats=3) # 10 fold cross-validation, repeated 3 times. better way to do it but takes longer.
subway.below.ctrl <- trainControl(method = "repeatedcv", number=nrow(below.avg.subway) - 1, repeats=3)
# high SES SVM modeling
subway_lm_high <- train(rating ~ .,
data = above.avg.subway,
method = "lm",
trControl=subway.above.ctrl)
#subway_lm_high_2 <- lm(formula = rating ~ reviewCount * price, data = above.avg.subway.train)
summary(subway_lm_high)
predict_subway_lm_high <- predict(subway_lm_high, below.avg.subway)
#postResample(predict_yelp_svm_high, below.avg$rating)
#actual minus predicted
delta.subway.high.SES <- below.avg.subway$rating - predict_subway_lm_high
count.subway.high.SES.line <- length(which(delta.subway.high.SES < 0)) / length(delta.subway.high.SES)
count.high.SES.line
# high SES SVM modeling
subway_lm_high <- train(rating ~ .,
data = above.avg.subway,
method = "lm",
trControl=subway.above.ctrl)
#subway_lm_high_2 <- lm(formula = rating ~ reviewCount * price, data = above.avg.subway.train)
summary(subway_lm_high)
predict_subway_lm_high <- predict(subway_lm_high, below.avg.subway)
#postResample(predict_yelp_svm_high, below.avg$rating)
#actual minus predicted
delta.subway.high.SES <- below.avg.subway$rating - predict_subway_lm_high
count.subway.high.SES.line <- length(which(delta.subway.high.SES < 0)) / length(delta.subway.high.SES)
count.subway.high.SES.line
# high SES SVM modeling
subway_lm_low <- train(rating ~ .,
data = below.avg.subway,
method = "lm",
trControl=subway.below.ctrl)
predict_subway_lm_low <- predict(subway_lm_low, above.avg.subway)
#postResample(predict_yelp_svm_high, below.avg$rating)
#actual minus predicted
delta.subway.low.SES <- above.avg.subway$rating - predict_subway_lm_low
count.subway.low.SES.line <- length(which(delta.subway.low.SES < 0)) / length(delta.subway.low.SES)
count.subway.low.SES.line
# high SES SVM modeling
subway_lm_high <- train(rating ~ .,
data = above.avg.subway,
method = "lm",
trControl=subway.above.ctrl)
#subway_lm_high_2 <- lm(formula = rating ~ reviewCount * price, data = above.avg.subway.train)
summary(subway_lm_high)
predict_subway_lm_high <- predict(subway_lm_high, below.avg.subway)
#postResample(predict_yelp_svm_high, below.avg$rating)
#actual minus predicted
delta.subway.high.SES <- below.avg.subway$rating - predict_subway_lm_high
count.subway.high.SES.below.line <- length(which(delta.subway.high.SES < 0)) / length(delta.subway.high.SES)
count.subway.high.SES.below.line
count.subway.high.SES.above.line <- length(which(delta.subway.high.SES > 0)) / length(delta.subway.high.SES)
count.subway.high.SES.above.line
count.subway.high.SES.on.line <- length(which(delta.subway.high.SES = 0)) / length(delta.subway.high.SES)
# high SES SVM modeling
subway_lm_high <- train(rating ~ .,
data = above.avg.subway,
method = "lm",
trControl=subway.above.ctrl)
#subway_lm_high_2 <- lm(formula = rating ~ reviewCount * price, data = above.avg.subway.train)
summary(subway_lm_high)
predict_subway_lm_high <- predict(subway_lm_high, below.avg.subway)
#postResample(predict_yelp_svm_high, below.avg$rating)
#actual minus predicted
delta.subway.high.SES <- below.avg.subway$rating - predict_subway_lm_high
count.subway.high.SES.below.line <- length(which(delta.subway.high.SES < 0)) / length(delta.subway.high.SES)
count.subway.high.SES.below.line
count.subway.high.SES.above.line <- length(which(delta.subway.high.SES > 0)) / length(delta.subway.high.SES)
count.subway.high.SES.above.line
count.subway.high.SES.on.line <- length(which(delta.subway.high.SES == 0)) / length(delta.subway.high.SES)
count.subway.high.SES.on.line
# high SES SVM modeling
subway_lm_low <- train(rating ~ .,
data = below.avg.subway,
method = "lm",
trControl=subway.below.ctrl)
predict_subway_lm_low <- predict(subway_lm_low, above.avg.subway)
#postResample(predict_yelp_svm_high, below.avg$rating)
#actual minus predicted
delta.subway.low.SES <- above.avg.subway$rating - predict_subway_lm_low
count.subway.low.SES.below.line <- length(which(delta.subway.low.SES < 0)) / length(delta.subway.low.SES)
count.subway.low.SES.below.line
count.subway.low.SES.above.line <- length(which(delta.subway.low.SES > 0)) / length(delta.subway.low.SES)
count.subway.low.SES.above.line
count.subway.low.SES.on.line <- length(which(delta.subway.low.SES == 0)) / length(delta.subway.low.SES)
count.subway.low.SES.on.line
ggplot(data=subway_lm_high) + geom_point()
subway_highSES_grid <- below.avg.subway %>%
gather_predictions(subway_lm_high)
ggplot( below.avg.subway, aes(rating, color = rm)) +
geom_point() +
geom_line(data = subway_highSES_grid, aes(y = pred))
ggplot( below.avg.subway, aes(rating)) +
geom_point() +
geom_line(data = subway_highSES_grid, aes(y = pred))
ggplot( below.avg.subway, aes(rating,totalInspectionCount)) +
geom_point() + geom_line(data = subway_highSES_grid, aes(y = pred))
ggplot( below.avg.subway, aes(totalInspectionCount,rating)) +
geom_point() + geom_line(data = subway_highSES_grid, aes(y = pred))
subway_high_with_residual <- below.avg.subway %>%
mutate(
residuals = rating - predict_subway_lm_high
)
ggplot(subway_high_with_residual, aes(x)) +
geom_point(aes(y=residuals)) +
geom_abline(intercept=0, slope = 0)
ggplot(subway_high_with_residual, aes(rating)) +
geom_point(aes(y=residuals)) +
geom_abline(intercept=0, slope = 0)
# high SES SVM modeling
subway_lm_high <- train(rating ~ .,
data = above.avg.subway,
method = "lm",
trControl=subway.above.ctrl)
#subway_lm_high_2 <- lm(formula = rating ~ reviewCount * price, data = above.avg.subway.train)
summary(subway_lm_high)
predict_subway_lm_high <- predict(subway_lm_high, below.avg.subway)
#postResample(predict_yelp_svm_high, below.avg$rating)
#actual minus predicted
delta.subway.high.SES <- below.avg.subway$rating - predict_subway_lm_high
count.subway.high.SES.below.line <- length(which(delta.subway.high.SES < 0)) / length(delta.subway.high.SES)
count.subway.high.SES.below.line
count.subway.high.SES.above.line <- length(which(delta.subway.high.SES > 0)) / length(delta.subway.high.SES)
count.subway.high.SES.above.line
count.subway.high.SES.on.line <- length(which(delta.subway.high.SES == 0)) / length(delta.subway.high.SES)
count.subway.high.SES.on.line
subway_high_with_residual <- below.avg.subway %>%
mutate(
residuals = rating - predict_subway_lm_high
)
ggplot(subway_high_with_residual, aes(rating)) +
geom_point(aes(y=residuals)) +
geom_abline(intercept=0, slope = 0)
View(subway_high_with_residual)
# high SES SVM modeling
subway_lm_low <- train(rating ~ .,
data = below.avg.subway,
method = "lm",
trControl=subway.below.ctrl)
predict_subway_lm_low <- predict(subway_lm_low, above.avg.subway)
#postResample(predict_yelp_svm_high, below.avg$rating)
#actual minus predicted
delta.subway.low.SES <- above.avg.subway$rating - predict_subway_lm_low
count.subway.low.SES.below.line <- length(which(delta.subway.low.SES < 0)) / length(delta.subway.low.SES)
count.subway.low.SES.below.line
count.subway.low.SES.above.line <- length(which(delta.subway.low.SES > 0)) / length(delta.subway.low.SES)
count.subway.low.SES.above.line
count.subway.low.SES.on.line <- length(which(delta.subway.low.SES == 0)) / length(delta.subway.low.SES)
count.subway.low.SES.on.line
subway_low_with_residual <- above.avg.subway %>%
mutate(
residuals = rating - predict_subway_lm_low
)
ggplot(subway_low_with_residual, aes(rating)) +
geom_point(aes(y=residuals)) +
geom_abline(intercept=0, slope = 0)
# high SES SVM modeling
model_svm_high <- train(rating ~ .,
data = above.avg.train,
method = "svmRadial",
trControl=ctrl, # Radial kernel
tuneLength = 10)
predict_yelp_svm_high <- predict(model_svm_high, below.avg.test)
#postResample(predict_yelp_svm_high, below.avg$rating)
#actual minus predicted
delta.high.SES <- below.avg.test$rating - predict_yelp_svm_high
count.high.SES.below.line <- length(which(delta.high.SES < 0)) / length(delta.high.SES)
count.high.SES.below.line
count.high.SES.above.line <- length(which(delta.high.SES > 0)) / length(delta.high.SES)
count.high.SES.above.line
count.high.SES.on.line <- length(which(delta.high.SES == 0)) / length(delta.high.SES)
count.high.SES.on.line
highSES_with_residual <- below.avg.test %>%
mutate(
residuals = rating - model_svm_high
)
# high SES SVM modeling
model_svm_high <- train(rating ~ .,
data = above.avg.train,
method = "svmRadial",
trControl=ctrl, # Radial kernel
tuneLength = 10)
predict_yelp_svm_high <- predict(model_svm_high, below.avg.test)
#postResample(predict_yelp_svm_high, below.avg$rating)
#actual minus predicted
delta.high.SES <- below.avg.test$rating - predict_yelp_svm_high
count.high.SES.below.line <- length(which(delta.high.SES < 0)) / length(delta.high.SES)
count.high.SES.below.line
count.high.SES.above.line <- length(which(delta.high.SES > 0)) / length(delta.high.SES)
count.high.SES.above.line
count.high.SES.on.line <- length(which(delta.high.SES == 0)) / length(delta.high.SES)
count.high.SES.on.line
highSES_with_residual <- below.avg.test %>%
mutate(
residuals = rating - predict_yelp_svm_high
)
ggplot(highSES_with_residual, aes(rating)) +
geom_point(aes(y=residuals)) +
geom_abline(intercept=0, slope = 0)
ggplot(highSES_with_residual) +
geom_point(aes(y=residuals)) +
geom_abline(intercept=0, slope = 0)
# low SES SVM modeling
model_svm_low <- train(rating ~ .,
data = below.avg.train,
method = "svmRadial",
trControl=ctrl, # Radial kernel
tuneLength = 10)
predict_yelp_svm_low <- predict(model_svm_low, above.avg.test)
#postResample(predict_yelp_svm_low, below.avg$rating)
#actual minus predicted
delta.low.SES <- above.avg.test$rating - predict_yelp_svm_low
count.low.SES.below.line <- length(which(delta.low.SES < 0)) / length(delta.low.SES)
count.low.SES.below.line
count.low.SES.above.line <- length(which(delta.low.SES > 0)) / length(delta.low.SES)
count.low.SES.above.line
count.low.SES.on.line <- length(which(delta.low.SES == 0)) / length(delta.low.SES)
count.low.SES.on.line
lowSES_with_residual <- above.avg.test %>%
mutate(
residuals = rating - predict_yelp_svm_low
)
ggplot(lowSES_with_residual, aes(rating)) +
geom_point(aes(y=residuals)) +
geom_abline(intercept=0, slope = 0)
View(predict_subway_lm_high)
ggplot(lowSES_with_residual, aes(1:nrow())) +
geom_point(aes(y=residuals)) +
geom_abline(intercept=0, slope = 0)
ggplot(lowSES_with_residual, aes(1:nrow(lowSES_with_residual))) +
geom_point(aes(y=residuals)) +
geom_abline(intercept=0, slope = 0)
ggplot(highSES_with_residual, aes(1:nrow(highSES_with_residual))) +
geom_point(aes(y=residuals)) +
geom_abline(intercept=0, slope = 0)
# low SES SVM modeling
model_svm_low <- train(rating ~ .,
data = below.avg.train,
method = "svmRadial",
trControl=ctrl, # Radial kernel
tuneLength = 10)
predict_yelp_svm_low <- predict(model_svm_low, above.avg.test)
#postResample(predict_yelp_svm_low, below.avg$rating)
#actual minus predicted
delta.low.SES <- above.avg.test$rating - predict_yelp_svm_low
count.low.SES.below.line <- length(which(delta.low.SES < 0)) / length(delta.low.SES)
count.low.SES.below.line
count.low.SES.above.line <- length(which(delta.low.SES > 0)) / length(delta.low.SES)
count.low.SES.above.line
count.low.SES.on.line <- length(which(delta.low.SES == 0)) / length(delta.low.SES)
count.low.SES.on.line
lowSES_with_residual <- above.avg.test %>%
mutate(
residuals = rating - predict_yelp_svm_low
)
ggplot(lowSES_with_residual, aes(1:nrow(lowSES_with_residual))) +
geom_point(aes(y=residuals)) +
geom_abline(intercept=0, slope = 0)
nrow(above.avg)
nrow(mid.avg)
nrow(below.avg)
ggplot(subway_high_with_residual, aes(rating)) +
geom_point(aes(y=residuals)) +
geom_abline(intercept=0, slope = 0)
ggplot(highSES_with_residual, aes(1:nrow(highSES_with_residual))) +
geom_point(aes(y=residuals)) +
geom_abline(intercept=0, slope = 0) + ylim(-3,3)
ggplot(lowSES_with_residual, aes(1:nrow(lowSES_with_residual))) +
geom_point(aes(y=residuals)) +
geom_abline(intercept=0, slope = 0) + ylim(-3,3)
highSES <- ggplot(sorted.highSES, aes(censusTract, fill=censusMedianHHIncome)) +geom_bar() + theme(axis.text.x = element_text(angle = 90, hjust = 1)) + labs(title="Seattle Restaurants in High Socio-Economic Neighborhoods on Yelp",y="Number of Restaurants", x="Seattle Census Tract Code")
highSES
highSES <- ggplot(sorted.highSES, aes(censusTract, fill=censusMedianHHIncome)) +geom_bar() + theme(axis.text.x = element_text(angle = 90, hjust = 1)) + labs(title="Seattle Restaurants in High Socio-Economic Neighborhoods on Yelp", y="Number of Restaurants", x="Seattle Census Tract Code", legend="test")
highSES
highSES <- ggplot(sorted.highSES, aes(censusTract, fill=censusMedianHHIncome)) +geom_bar() + theme(axis.text.x = element_text(angle = 90, hjust = 1)) + labs(title="Seattle Restaurants in High Socio-Economic Neighborhoods on Yelp", y="Number of Restaurants", x="Seattle Census Tract Code", color="test")
highSES
highSES <- ggplot(sorted.highSES, aes(censusTract, fill=censusMedianHHIncome)) +geom_bar() + theme(axis.text.x = element_text(angle = 90, hjust = 1)) + labs(title="Seattle Restaurants in High Socio-Economic Neighborhoods on Yelp", y="Number of Restaurants", x="Seattle Census Tract Code", colour="test")
highSES
highSES <- ggplot(sorted.highSES, aes(censusTract, fill=censusMedianHHIncome)) +geom_bar() + theme(axis.text.x = element_text(angle = 90, hjust = 1)) + labs(title="Seattle Restaurants in High Socio-Economic Neighborhoods on Yelp", y="Number of Restaurants", x="Seattle Census Tract Code", colour="test", caption="(based on data from Yelp Fusion API and Seattle and Census Reporter)")
highSES
highSES <- ggplot(sorted.highSES, aes(censusTract, fill=censusMedianHHIncome)) +geom_bar() + theme(axis.text.x = element_text(angle = 90, hjust = 1)) + labs(title="Seattle Restaurants in High Socio-Economic Neighborhoods on Yelp", y="Number of Restaurants", x="Seattle Census Tract Code", color="Median Household Income", caption="(based on data from Yelp Fusion API and Seattle and Census Reporter)")
highSES
highSES <- ggplot(sorted.highSES, aes(censusTract, fill=censusMedianHHIncome)) +geom_bar() + theme(axis.text.x = element_text(angle = 90, hjust = 1)) + labs(title="Seattle Restaurants in High Socio-Economic Neighborhoods on Yelp", y="Number of Restaurants", x="Seattle Census Tract Code", colour="Median Household Income", caption="(based on data from Yelp Fusion API and Seattle and Census Reporter)")
highSES
highSES <- ggplot(sorted.highSES, aes(censusTract, fill=censusMedianHHIncome)) +geom_bar() + theme(axis.text.x = element_text(angle = 90, hjust = 1)) + labs(title="Seattle Restaurants in High Socio-Economic Neighborhoods on Yelp", y="Number of Restaurants", x="Seattle Census Tract Code", col="Median Household Income", caption="(based on data from Yelp Fusion API and Seattle and Census Reporter)")
highSES
highSES <- ggplot(sorted.highSES, aes(censusTract, fill=censusMedianHHIncome)) +geom_bar() + theme(axis.text.x = element_text(angle = 90, hjust = 1)) + labs(title="Seattle Restaurants in High Socio-Economic Neighborhoods on Yelp", y="Number of Restaurants", x="Seattle Census Tract Code", fill="Median Household Income", caption="(based on data from Yelp Fusion API and Seattle and Census Reporter)")
highSES
highSES <- ggplot(sorted.highSES, aes(censusTract, fill=censusMedianHHIncome)) +geom_bar() + theme(axis.text.x = element_text(angle = 90, hjust = 1)) + labs(title="Seattle Restaurants in High Socio-Economic Neighborhoods on Yelp", y="Number of Restaurants", x="Seattle Census Tract Code", fill="Median Household Income ($)", caption="(based on data from Yelp Fusion API and Seattle and Census Reporter)")
highSES
highSES <- ggplot(sorted.highSES, aes(censusTract, fill=censusMedianHHIncome)) +geom_bar() + theme(axis.text.x = element_text(angle = 90)) + labs(title="Seattle Restaurants in High Socio-Economic Neighborhoods on Yelp", y="Number of Restaurants", x="Seattle Census Tract Code", fill="Median Household Income ($)", caption="(based on data from Yelp Fusion API and Seattle and Census Reporter)")
highSES
highSES <- ggplot(sorted.highSES, aes(censusTract, fill=censusMedianHHIncome)) +geom_bar() + theme(axis.text.x = element_text(angle = 90, hjust = 1)) + labs(title="Seattle Restaurants in High Socio-Economic Neighborhoods on Yelp", y="Number of Restaurants", x="Seattle Census Tract Code", fill="Median Household Income ($)", caption="(based on data from Yelp Fusion API and Seattle and Census Reporter)")
highSES
highSES <- ggplot(sorted.highSES, aes(censusTract, fill=censusMedianHHIncome)) +geom_bar() + theme(axis.text.x = element_text(angle = 90, hjust = 1)) + labs(title="Seattle Restaurants in High Socio-Economic Neighborhoods on Yelp", y="Number of Restaurants", x="Seattle Census Tract Code", fill="Median Household Income ($)", caption="(based on data from Yelp Fusion API and Seattle, FCC Data, Census Reporter, and the U.S. Census bureau)")
highSES
sorted.highSES <- transform(above.avg, censusTract = reorder(censusTract, censusMedianHHIncome))
highSES <- ggplot(sorted.highSES, aes(censusTract, fill=censusMedianHHIncome)) +geom_bar() + theme(axis.text.x = element_text(angle = 90, hjust = 1)) + labs(title="Seattle Restaurants in High Socio-Economic Neighborhoods on Yelp", y="Number of Restaurants", x="Seattle Census Tract Code", fill="Median Household Income ($)", caption="(based on data from Yelp Fusion API and Seattle, FCC Data, Census Reporter, and the U.S. Census Bureau)")
sorted.midSES <- transform(mid.avg, censusTract = reorder(censusTract, censusMedianHHIncome))
midSES <- ggplot(sorted.midSES, aes(censusTract, fill=censusMedianHHIncome)) +geom_bar() + theme(axis.text.x = element_text(angle = 90, hjust = 1)) + labs(title="Seattle Restaurants in Median Socio-Economic Neighborhoods on Yelp", y="Number of Restaurants", x="Seattle Census Tract Code", fill="Median Household Income ($)", caption="(based on data from Yelp Fusion API and Seattle, FCC Data, Census Reporter, and the U.S. Census Bureau)")
sorted.lowSES <- transform(below.avg, censusTract = reorder(censusTract, censusMedianHHIncome))
lowSES <- ggplot(sorted.lowSES, aes(censusTract, fill=censusMedianHHIncome)) +geom_bar() + theme(axis.text.x = element_text(angle = 90, hjust = 1)) + labs(title="Seattle Restaurants in Low Socio-Economic Neighborhoods on Yelp", y="Number of Restaurants", x="Seattle Census Tract Code", fill="Median Household Income ($)", caption="(based on data from Yelp Fusion API and Seattle, FCC Data, Census Reporter, and the U.S. Census Bureau)")
highSES
midSES
lowSES
restaurantsByPrice <- ggplot(priceFreq, aes(fill=Var2, y=Freq, x=Var1)) +
geom_bar( stat="identity", position="dodge") + labs(title="Distribution of Seattle Restaurants by Price Level in various Socio-Economic neighborhoods on Yelp", y="Number of Restaurants", x="Price Level on Yelp ($ - $$$$)", fill="Socio-Economic Level (based on Median Household Income)", caption="(based on data from Yelp Fusion API and Seattle, Census Reporter, and the U.S. Census Bureau)")
restaurantsByPrice
restaurantsByPrice <- ggplot(priceFreq, aes(fill=Var2, y=Freq, x=Var1)) +
geom_bar( stat="identity", position="dodge") + labs(title="Distribution of Seattle Restaurants by Price Level", y="Number of Restaurants", x="Price Level on Yelp ($ - $$$$)", fill="Socio-Economic Level (based on Median Household Income)", caption="(based on data from Yelp Fusion API and Seattle, Census Reporter, and the U.S. Census Bureau)")
restaurantsByPrice
restaurantsByPrice <- ggplot(priceFreq, aes(fill=Var2, y=Freq, x=Var1)) +
geom_bar( stat="identity", position="dodge") + labs(title="Distribution of Seattle Restaurants by Price Level", y="Number of Restaurants", x="Price Level on Yelp ($ - $$$$)", fill="Socio-Economic Level /b (based on Median Household Income)", caption="(based on data from Yelp Fusion API and Seattle, Census Reporter, and the U.S. Census Bureau)")
restaurantsByPrice
restaurantsByPrice <- ggplot(priceFreq, aes(fill=Var2, y=Freq, x=Var1)) +
geom_bar( stat="identity", position="dodge") + labs(title="Distribution of Seattle Restaurants by Price Level", y="Number of Restaurants", x="Price Level on Yelp ($ - $$$$)", fill="Socio-Economic Level /n (based on Median Household Income)", caption="(based on data from Yelp Fusion API and Seattle, Census Reporter, and the U.S. Census Bureau)")
restaurantsByPrice
restaurantsByPrice <- ggplot(priceFreq, aes(fill=Var2, y=Freq, x=Var1)) +
geom_bar( stat="identity", position="dodge") + labs(title="Distribution of Seattle Restaurants by Price Level", y="Number of Restaurants", x="Price Level on Yelp ($ - $$$$)", fill="Socio-Economic Level \n (based on Median Household Income)", caption="(based on data from Yelp Fusion API and Seattle, Census Reporter, and the U.S. Census Bureau)")
restaurantsByPrice
restaurantsByPrice <- ggplot(priceFreq, aes(fill=Var2, y=Freq, x=Var1)) +
geom_bar( stat="identity", position="dodge") + labs(title="Distribution of Seattle Restaurants by Price Level", y="Number of Restaurants", x="Price Level on Yelp ($ - $$$$)", fill="Socio-Economic Level \n(based on Median Household Income)", caption="(based on data from Yelp Fusion API and Seattle, Census Reporter, and the U.S. Census Bureau)")
restaurantsByPrice
restaurantsByPrice <- ggplot(priceFreq, aes(fill=Var2, y=Freq, x=Var1)) +
geom_bar( stat="identity", position="dodge") + labs(title="Distribution of Seattle Restaurants by Price Level on Yelp", y="Number of Restaurants", x="Price Level on Yelp ($ - $$$$)", fill="Socio-Economic Level \n(based on Median Household Income)", caption="(based on data from Yelp Fusion API and Seattle, Census Reporter, and the U.S. Census Bureau)")
restaurantsByPrice
ratingFreq <- as.data.frame(table(yelp.data$rating))
ratingFreq$percentage = ratingFreq$Freq / sum(ratingFreq$Freq)
restaurantsByRating <- ggplot(ratingFreq, aes(y=percentage, x=Var1,group=1)) +
geom_line() + labs(title="Distribution of Seattle Restaurants by Rating on Yelp", y="Total Proportion of Restaurants", x="Average Rating on Yelp", caption="(based on data from Yelp Fusion API and Seattle, Census Reporter, and the U.S. Census Bureau)")
restaurantsByRating
ratingFreq <- as.data.frame(table(yelp.data$rating))
ratingFreq$percentage = ratingFreq$Freq / sum(ratingFreq$Freq)
restaurantsByRating <- ggplot(ratingFreq, aes(y=percentage, x=Var1,group=1)) +
geom_line() + labs(title="Distribution of Seattle Restaurants by Rating on Yelp", y="Total Proportion of Restaurants", x="Average Rating on Yelp", caption="(based on data from Yelp Fusion API)")
restaurantsByRating
ratingViolinPlot <- ggplot(yelp.data, aes(as.factor(rating), censusMedianHHIncome)) +
geom_violin() +
geom_boxplot(width=0.1) +
stat_summary(fun.y=mean, geom="point", shape=23, size=2, color="blue") +
stat_summary(fun.y=median, geom="point", size=2, color="red")
ratingViolinPlot
ratingViolinPlot <- ggplot(yelp.data, aes(as.factor(rating), censusMedianHHIncome)) +
geom_violin() +
geom_boxplot(width=0.1) +
stat_summary(fun.y=mean, geom="point", shape=23, size=2, color="blue",show.legend =TRUE) +
stat_summary(fun.y=median, geom="point", size=2, color="red") +
labs(title="Distribution of Seattle Restaurants Rating \nin various Median Household Income on Yelp", y="Median Household Income", x="Average Rating on Yelp", caption="(based on data from Yelp Fusion API and Seattle, Census Reporter, and the U.S. Census Bureau)")
ratingViolinPlot
ratingViolinPlot <- ggplot(yelp.data, aes(as.factor(rating), censusMedianHHIncome)) +
geom_violin() +
geom_boxplot(width=0.1) +
stat_summary(fun.y=mean, geom="point", shape=23, size=2, color="blue",show.legend =TRUE) +
stat_summary(fun.y=median, geom="point", size=2, color="red",show.legend = TRUE) +
labs(title="Distribution of Seattle Restaurants Rating \nin various Median Household Income on Yelp", y="Median Household Income", x="Average Rating on Yelp", caption="(based on data from Yelp Fusion API and Seattle, Census Reporter, and the U.S. Census Bureau)")
ratingViolinPlot
ratingViolinPlot <- ggplot(yelp.data, aes(as.factor(rating), censusMedianHHIncome)) +
geom_violin() +
geom_boxplot(width=0.1) +
stat_summary(fun.y=mean, geom="point", shape=23, size=2, color="blue") +
stat_summary(fun.y=median, geom="point", size=2, color="red") + scale_shape_manual("", values=c("mean"="x")) +
labs(title="Distribution of Seattle Restaurants Rating \nin various Median Household Income on Yelp", y="Median Household Income ($)", x="Average Rating on Yelp", caption="(based on data from Yelp Fusion API and Seattle, Census Reporter, and the U.S. Census Bureau)")
ratingViolinPlot
ratingViolinPlot <- ggplot(yelp.data, aes(as.factor(rating), censusMedianHHIncome)) +
geom_violin() +
geom_boxplot(width=0.1) +
stat_summary(fun.y=mean, geom="point", shape=23, size=2, color="blue") +
stat_summary(fun.y=median, geom="point", size=2, color="red", show.legend = TRUE) + scale_shape_manual("", values=c("mean"="x")) +
labs(title="Distribution of Seattle Restaurants Rating \nin various Median Household Income on Yelp", y="Median Household Income ($)", x="Average Rating on Yelp", caption="(based on data from Yelp Fusion API and Seattle, Census Reporter, and the U.S. Census Bureau)")
ratingViolinPlot
ratingViolinPlot <- ggplot(yelp.data, aes(as.factor(rating), censusMedianHHIncome)) +
geom_violin() +
geom_boxplot(width=0.1) +
stat_summary(fun.y=mean, geom="point", shape=23, size=2, color="blue") +
stat_summary(fun.y=median, geom="point", size=2, color="red") + scale_shape_manual("", values=c("blue","red")) +
labs(title="Distribution of Seattle Restaurants Rating \nin various Median Household Income on Yelp", y="Median Household Income ($)", x="Average Rating on Yelp", caption="(based on data from Yelp Fusion API and Seattle, Census Reporter, and the U.S. Census Bureau)")
ratingViolinPlot
ratingViolinPlot <- ggplot(yelp.data, aes(as.factor(rating), censusMedianHHIncome)) +
geom_violin() +
geom_boxplot(width=0.1) +
stat_summary(aes(color="mean"),fun.y=mean, geom="point", shape=23, size=2, color="blue") +
stat_summary(fun.y=median, geom="point", size=2, color="red") +
labs(title="Distribution of Seattle Restaurants Rating \nin various Median Household Income on Yelp", y="Median Household Income ($)", x="Average Rating on Yelp", caption="(based on data from Yelp Fusion API and Seattle, Census Reporter, and the U.S. Census Bureau)")
ratingViolinPlot
ratingViolinPlot <- ggplot(yelp.data, aes(as.factor(rating), censusMedianHHIncome)) +
geom_violin() +
geom_boxplot(width=0.1) +
stat_summary(aes(color="mean"),fun.data=mean_cl_normal, geom="point", shape=23, size=2, color="blue") +
stat_summary(fun.y=median, geom="point", size=2, color="red") +
labs(title="Distribution of Seattle Restaurants Rating \nin various Median Household Income on Yelp", y="Median Household Income ($)", x="Average Rating on Yelp", caption="(based on data from Yelp Fusion API and Seattle, Census Reporter, and the U.S. Census Bureau)")
ratingViolinPlot
ratingViolinPlot <- ggplot(yelp.data, aes(as.factor(rating), censusMedianHHIncome)) +
geom_violin() +
geom_boxplot(width=0.1) +
stat_summary(aes(col="mean"),fun.data=mean, geom="point", shape=23, size=2, color="blue") +
stat_summary(fun.y=median, geom="point", size=2, color="red") +
labs(title="Distribution of Seattle Restaurants Rating \nin various Median Household Income on Yelp", y="Median Household Income ($)", x="Average Rating on Yelp", caption="(based on data from Yelp Fusion API and Seattle, Census Reporter, and the U.S. Census Bureau)")
ratingViolinPlot
ratingViolinPlot <- ggplot(yelp.data, aes(as.factor(rating), censusMedianHHIncome)) +
geom_violin() +
geom_boxplot(width=0.1) +
stat_summary(aes(color="mean")fun.y=mean, geom="point", shape=23, size=2, color="blue") +
ratingViolinPlot <- ggplot(yelp.data, aes(as.factor(rating), censusMedianHHIncome)) +
geom_violin() +
geom_boxplot(width=0.1) +
stat_summary(aes(color="mean"),fun.y=mean, geom="point", shape=23, size=2, color="blue") +
stat_summary(fun.y=median, geom="point", size=2, color="red") + scale_shape_manual("", values=c("blue","red")) +
labs(title="Distribution of Seattle Restaurants Rating \nin various Median Household Income on Yelp", y="Median Household Income ($)", x="Average Rating on Yelp", caption="(based on data from Yelp Fusion API and Seattle, Census Reporter, and the U.S. Census Bureau)")
ratingViolinPlot
ratingViolinPlot <- ggplot(yelp.data, aes(as.factor(rating), censusMedianHHIncome)) +
geom_violin() +
geom_boxplot(width=0.1) +
stat_summary(fun.y=mean, geom="point", shape=23, size=2, color="blue") +
stat_summary(fun.y=median, geom="point", size=2, color="red")
labs(title="Distribution of Seattle Restaurants Rating \nin various Median Household Income on Yelp", y="Median Household Income ($)", x="Average Rating on Yelp", caption="(based on data from Yelp Fusion API and Seattle, Census Reporter, and the U.S. Census Bureau)")
ratingViolinPlot
ratingViolinPlot <- ggplot(yelp.data, aes(as.factor(rating), censusMedianHHIncome)) +
geom_violin() +
geom_boxplot(width=0.1) +
stat_summary(fun.y=mean, geom="point", shape=23, size=2, color="blue") +
stat_summary(fun.y=median, geom="point", size=2, color="red") +
labs(title="Distribution of Seattle Restaurants Rating \nin various Median Household Income on Yelp", y="Median Household Income ($)", x="Average Rating on Yelp", caption="(based on data from Yelp Fusion API and Seattle, Census Reporter, and the U.S. Census Bureau)")
ratingViolinPlot
ggplot(highSES_with_residual, aes(1:nrow(highSES_with_residual))) +
geom_point(aes(y=residuals)) +
geom_abline(intercept=0, slope = 0) + ylim(-3,3) +
labs(title="High Socio-Economic Predicted Model Residuals \nfrom Prediction with Low Socio-Economic Restaurants")
ggplot(highSES_with_residual, aes(1:nrow(highSES_with_residual))) +
geom_point(aes(y=residuals)) +
geom_abline(intercept=0, slope = 0) + ylim(-3,3) +
labs(title="High Socio-Economic Predicted Model Residuals \nfrom Prediction with Low Socio-Economic Restaurants", x="Row Number")
ggplot(highSES_with_residual, aes(1:nrow(highSES_with_residual))) +
geom_point(aes(y=residuals)) +
geom_abline(intercept=0, slope = 0) + ylim(-3,3) +
labs(title="High Socio-Economic Predicted Model Residuals \nfrom Prediction with Low Socio-Economic Restaurants",y="Residuals", x="Row Number")
ggplot(highSES_with_residual, aes(1:nrow(highSES_with_residual))) +
geom_point(aes(y=residuals)) +
geom_abline(intercept=0, slope = 0) + ylim(-3,3) +
labs(title="High Socio-Economic Predicted Model Residuals \nwhen predicting with Low Socio-Economic Restaurants",y="Residuals", x="Row Number")
ggplot(lowSES_with_residual, aes(1:nrow(lowSES_with_residual))) +
geom_point(aes(y=residuals)) +
geom_abline(intercept=0, slope = 0) + ylim(-3,3) +
labs(title="Low Socio-Economic Predicted Model Residuals \nwhen predicting with High Socio-Economic Restaurants",y="Residuals", x="Row Number")
ggplot(subway_high_with_residual, aes(rating)) +
geom_point(aes(y=residuals)) +
geom_abline(intercept=0, slope = 0) + ylim(-2,2) +
labs(title="Subway High Socio-Economic Predicted Model Residuals \nwhen predicting with Low Socio-Economic Subways",y="Residuals", x="Row Number")
ggplot(subway_low_with_residual, aes(rating)) +
geom_point(aes(y=residuals)) +
geom_abline(intercept=0, slope = 0) + ylim(-2,2) +
labs(title="Subway Low Socio-Economic Predicted Model Residuals \nwhen predicting with High Socio-Economic Subways",y="Residuals", x="Row Number")
count.subway.low.SES.above.line
count.subway.high.SES.above.line