-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPlotResults.R
More file actions
79 lines (72 loc) · 3.13 KB
/
PlotResults.R
File metadata and controls
79 lines (72 loc) · 3.13 KB
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
## We'll bucket the continuous variables in order to plot along them later.
ResultData <- ResultData %>%
mutate(budget.buckets = cut(ModelData$budget.capped, breaks = quantile(ModelData$budget.capped, probs = seq(0, 1, 0.1)), include.lowest = T),
facebook.buckets = cut(ModelData$facebook.capped, breaks = quantile(ModelData$facebook.capped, probs = seq(0, 1, 0.1)), include.lowest = T)) %>%
group_by(budget.buckets) %>%
mutate(budget.mid = median(budget.capped)) %>%
group_by(facebook.buckets) %>%
mutate(facebook.mid = median(facebook.capped)) %>%
ungroup()
## Choose whether to create plots on the training data or the holdout data
DataSubset <- "Training"
# DataSubset <- "Holdout"
## b1 gives record counts by budget bucket
b1 <- ResultData %>%
filter(Sample == DataSubset) %>%
group_by(budget.buckets, Audience) %>%
summarize(Count = n()) %>%
ggplot(aes(x = budget.buckets, y = Count, fill = Audience)) +
geom_bar(stat = "identity")
## b2 plots the predicted success rates by budget, with observed rates on the same chart
b2 <- ResultData %>%
filter(Sample == DataSubset) %>%
group_by(budget.buckets, Audience) %>%
summarize(Actual = mean(Success),
Expected = mean(Prediction),
budget.mid = median(budget.mid)) %>%
ggplot(aes(x = budget.mid, colour = Audience)) +
geom_line(aes(y = Actual), lty = 1, lwd = 1) +
geom_line(aes(y = Expected), lty = 2, lwd = 1) +
ylim(0, 1)
## b3 validates the predictions against the observations by plotting A/E ratios across budget
b3 <- ResultData %>%
filter(Sample == DataSubset) %>%
group_by(budget.buckets, Audience) %>%
summarize(Actual = mean(Success),
Expected = mean(Prediction),
budget.mid = median(budget.mid)) %>%
mutate(AE = Actual/Expected) %>%
ggplot(aes(x = budget.mid, colour = Audience)) +
geom_line(aes(y = AE), lty = 1, lwd = 1) +
geom_hline(aes(yintercept = 1)) +
coord_cartesian(ylim = c(0, 2))
## The following set of charts are analagous to those three created above, with the facebook like count as
## the horizontal variable
f1 <- ResultData %>%
filter(Sample == DataSubset) %>%
group_by(facebook.buckets, Audience) %>%
summarize(Count = n(),
facebook.mid = median(facebook.mid)) %>%
ggplot(aes(x = facebook.buckets, y = Count, fill = Audience)) +
geom_bar(stat = "identity")
f2 <- ResultData %>%
filter(Sample == DataSubset) %>%
group_by(facebook.buckets, Audience) %>%
summarize(Actual = mean(Success),
Expected = mean(Prediction),
facebook.mid = median(facebook.mid)) %>%
ggplot(aes(x = facebook.mid, colour = Audience)) +
geom_line(aes(y = Actual), lty = 1, lwd = 1) +
geom_line(aes(y = Expected), lty = 2, lwd = 1) +
ylim(0, 1)
f3 <- ResultData %>%
filter(Sample == DataSubset) %>%
group_by(facebook.buckets, Audience) %>%
summarize(Actual = mean(Success),
Expected = mean(Prediction),
facebook.mid = median(facebook.mid)) %>%
mutate(AE = Actual/Expected) %>%
ggplot(aes(x = facebook.mid, colour = Audience)) +
geom_line(aes(y = AE), lty = 1, lwd = 1) +
geom_hline(aes(yintercept = 1)) +
coord_cartesian(ylim = c(0, 2))