-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLenovo_project.Rmd
156 lines (119 loc) · 5.57 KB
/
Lenovo_project.Rmd
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
---
title: "Lenovo_project"
author: "ISE 560"
date: "10/5/2019"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library("dplyr")
library("lubridate")
library(ggplot2)
library(cowplot)
source('src_lenovo_project.R')
```
# Extraction
```{r}
nps.main <-read.csv("RawData/Lenovo_Survey_Data_pNPS_Rev2.csv",header = TRUE)
cis.main <- read.csv("RawData/CID_Web_Sentiment.csv", header = TRUE)
battery.life.main <- read.csv("RawData/Battery Life.csv", header = TRUE)
ownership.durations <- c("Less than 3 months","More than 12 months","Between 3 – 6 months","Between 7 – 12 months")
nps.main <- nps.main[complete.cases(nps.main$Product),]
cis.main <- cis.main[complete.cases(cis.main$Product),]
nps.main <- mutate(nps.main, Product = tolower(as.character(Product)), Date.Survey = as.Date(Date.Survey, format = "%m/%d/%Y"), Ownership.Period = as.character(Ownership.Period), Product.NPS = as.numeric(levels(Product.NPS))[Product.NPS])
cis.main <- mutate(cis.main, Product = tolower(as.character(Product)), Comment.Date = as.Date(Comment.Date, format = "%m/%d/%y"), Stars.Rating = as.numeric(Stars.Rating))
# Choosing the consumer segment
nps.main <- nps.main[(nps.main$Segment == "Consumer")|(nps.main$Segment == "Lenovo - Consumer"),]#[nps.main$Ownership.Period,]
cis.main <- cis.main %>% filter(Business.Group == "LENOVO - CONSUMER")
#Choosing products that are common to both
product.list = unique(nps.main$Product)
cis.main = cis.main[cis.main$Product %in% product.list,]
product.list = unique(cis.main$Product)
nps.main = nps.main[nps.main$Product %in% product.list,]
unique(nps.main$Ownership.Period)
```
# Calcualte pNPS according to week
```{r}
pnps.working.week.all <- data.frame()
for(duration in ownership.durations){
pnps.working.week.all <- pnps.working.week.all %>%
rbind(nps.main[nps.main$Ownership.Period==duration,]%>%
group_by(week = floor_date(as.Date(Date.Survey, format = "%m/%d/%Y"), unit = "week")) %>%
summarise(promoter = sum(Product.NPS >= 9),
detractor = sum(Product.NPS <= 6),
total = n()) %>%
mutate(nps = 100 * (promoter - detractor) / total,
Ownership.period = duration))
}
psi.working.week.all <- cis.main %>%
group_by(week = floor_date(Comment.Date, unit = "week")) %>%
summarise(pos = sum(Sentiment == "POSITIVE"),
neg = sum(Sentiment == "NEGATIVE"),
pos.star = sum(Stars.Rating <3),
neg.star = sum(Stars.Rating>3),
total = n()) %>%
mutate(psi = 100 * (pos - neg)/(pos + neg),
star.index = 100*(pos.star - neg.star)/(total))
```
# Calcualte pNPS according to Month
```{r}
pnps.working.month.all <- data.frame()
for(duration in ownership.durations){
pnps.working.month.all <- pnps.working.month.all %>%
rbind(nps.main[nps.main$Ownership.Period==duration,]%>%
group_by(month = floor_date(as.Date(Date.Survey, format = "%m/%d/%Y"), unit = "month")) %>%
summarise(promoter = sum(Product.NPS >= 9),
detractor = sum(Product.NPS <= 6),
total = n()) %>%
mutate(nps = 100 * (promoter - detractor) / total,
Ownership.period = duration))
}
psi.working.month.all <- cis.main %>%
group_by(month = floor_date(Comment.Date, unit = "month")) %>%
summarise(pos = sum(Sentiment == "POSITIVE"),
neg = sum(Sentiment == "NEGATIVE"),
pos.star = sum(Stars.Rating <3),
neg.star = sum(Stars.Rating>3),
total = n()) %>%
mutate(psi = 100 * (pos - neg)/(pos + neg),
star.index = 100*(pos.star - neg.star)/(pos+neg))
```
```{r}
plt <- ggplot() +
geom_line(data = pnps.working.month.all, mapping = aes(x=month, y=nps, color="NPS")) +
geom_line(data = psi.working.month.all, mapping = aes(x=month, y=psi, color="PSI"))+
geom_line(data = psi.working.month.all, mapping = aes(x=month, y=star.index, color="Star Index"))+
facet_wrap(.~Ownership.period,nrow = 2)+
labs(title="NPS, PSI and Star Rating for All Consumer Products", color = "Metrics:")+ylab("")+xlab("Time")+
theme(legend.position = "bottom")
ggsave(plot = plt,filename = "Proposal/Figures/all_metric_summary_consumer.pdf",width = 8, height = 5,units = "in")
```
## Autocorrelation of Metrics based on series
We calcualte the ACF of the
```{r}
```
## Monthly evolution of sentiments
```{r}
psi.working = read.csv("RawData/cached_main_psi.csv")
pnps.working = read.csv("RawData/cached_main_pnps.csv")
psi.working$Comment.time = ymd(paste0(year_month = as.character(psi.working$Comment.time), day = "30"))
pnps.working$Survey.time = ymd(paste0(year_month = as.character(pnps.working$Survey.time), day = "30"))
```
## Correlation between CIS and Average Star Rating
```{r}
ggplot(psi.working)+geom_point(aes(x = psi, y = avg.star.rating))
```
# Analysis without time information
```{r}
psi.working <- calculate.psi(cis.working = cis.working, format.type = 2)
pnps.working <- calculate.NPS(nps.dataset = nps.working, format.type = 2)
merged.working = merge(psi.working, pnps.working, by = "Product")
plt.psi <- ggplot(merged.working)+geom_point(aes(x = psi, y = pNPS))+xlab("psi")+ggtitle("Average pNPS over all Surveys")+ ylab("pNPS")+facet_grid(.~ownership.duration,scales = "free")
plt.psi
plt.star <- ggplot(merged.working)+geom_point(aes(x = avg.star.rating, y = pNPS))+xlab("Avg. Star Rating")+ggtitle("Average pNPS in the Consumer Segment")+ ylab("pNPS")+facet_grid(.~ownership.duration,scales = "free")
plt.star
```
## Histograms
```{r}
ggplot(psi.working)+geom_histogram(aes(x = psi),binwidth = 1)
```