-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLanguage Service Baseline.r
102 lines (84 loc) · 3.84 KB
/
Language Service Baseline.r
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
# Load SiteCatalyst program
library(RSiteCatalyst)
SCAuth("username:company","secret key")
# Get report suites and metrics (only need these if you want to see what's available)
bbg <- GetReportSuites()
seg <- GetSegments("bbgunitvoakurdish")
# QueueOvertime gets metric(s) overtime, QueueTrended gets same plus an element
q <- QueueOvertime("bbgunitvoaturkish","2013-09-29","2014-06-28",segment_id="All Visits","visits","week")
trend <- QueueTrended("bbgunitvoakurdish",dateFrom="2013-09-29",dateTo="2014-06-28","week","visits","geocountry",segment_id="All Visits")
# Creates date variable of length 39 to plot weeks
date <- seq(as.Date("2013-09-29"),length=39,by="weeks")
n.hour <- c(1:6552)
# Creates data frame with data from adobe and date object
q <- data.frame(q,date)
# Descriptive Statistics-Use for analyzing numbers in baseline
mean(q$visits)
# Highlights which is the max
which.max(q[,6])
q[10,]
which.min([,6])
q[27,]
sd(q$visits)
# Fits linear model
lm3 <- lm(visits~n.week,data=q)
p_conf1 <- predict(lm3,interval="confidence")
p_pred1 <- predict(lm1,interval="prediction")
summary(lm3)
plot(q$n.week,q$visits,main="October 2013-June 2014 Weekly Visit Trend",xlab="Week",ylab="Visits",type="l",ylim=c(0,8500))
new <- data.frame(n.week =seq(40,52,1) ,name=NA,year=2014,month=6:9,day=1,segment="All Visits",visits=NA,stringsAsFactors=FALSE)
newq <- rbind(q,new)
# Plot with error bars
plot(newq$n.month,newq$visits,main="August 2013-June 2014 Visit Trend",xlab="Month",ylab="Visits",type="l")
abline(lm3, col="red")
matlines(q$n.week,p_conf1[,c("lwr","upr")],col=2,lty=1,type="b",pch="+")
pred <- predict(lm3,newq,se.fit = TRUE)
plot(pred$se.fit)
# Plot using moving averages
library(forecast)
lm4 <- lm(visits~n.month,data=q)
p_conf2 <- predict(lm4,interval="confidence")
ma2 <- ma(newq$visits, order=2, centre=FALSE)
pred2 <- predict(lm4,newq,se.fit = TRUE)
plot(ma2,type="l",col="red",main="August 2013-June 2014 2 Month Moving Average Visit Trend",xlab="Month",ylab="Visits")
abline(lm4, col="blue")
# Hour of day
kurd <- QueueOvertime("bbgunitvoakurdish","2014-06-01","2014-06-30",segment_id="All Visits","visits","hour")
plot(kurd$hour,kurd$visits,col="purple",main="June 2014 Hourly Visits",xlab="Hour",ylab="Visits")
# Loads ggplot2 package for better plotting
library(ggplot2)
# Creates new variable
n.hour <- c(1:6552)
ggplot(ash, aes(x = n.week, y = event5)) +
geom_point(size = 3,color="blue") +
theme(axis.text.x = element_text(size=13)) +
theme(axis.text.y = element_text(hjust = 1, size=13)) +
labs(title = "Weekly Video Views March - June 2014",x="Week",y="Video Views")+
ylim(0,400)
geom_errorbar(aes(ymax = 120, ymin = 0))
# plyr allows you to manipulate data if needed
library(plyr)
hour$Country <- hour$GeoSegmentation.Countries
ds <- ddply(q,.(hour,visits),summarise, mean = mean(visits), sd = sd(visits))
ggplot(q, aes(x = country, y = visits)) +
geom_point() +
geom_point(data = ds, aes(y = mean),
colour = 'red', size = 3)
ggplot() +
geom_point(data = q, aes(x = hour, y = visits)) +
geom_point(data = ds, aes(x = hour, y = mean),
colour = 'red', size = 3) +
geom_errorbar(data = ds, aes(x = hour, y = mean,
ymin = mean - sd, ymax = mean + sd),
colour = 'red', width = 0.4)
# Plot colored by language
ggplot(kurdig,aes(x=country,y=visits,color=language)) +
geom_point(size=3) +
theme(axis.text.x = element_text(size=13)) +
theme(axis.text.y = element_text(hjust = 1, size=13)) +
labs(title = "Weekly Visits by Country and Language - October '13 - June '14",x="Country",y="Visits")
# ggplot Boxplot
ggplot(kurdishg, aes(x=country, y=visits)) + geom_boxplot(color="black",fill="green") +
theme(axis.text.x = element_text(size=13)) +
theme(axis.text.y = element_text(hjust = 1, size=13)) +
labs(title = "VOA Kurdish Visits October - June 2014",x="Country",y="Weekly Visits")