-
Notifications
You must be signed in to change notification settings - Fork 0
/
Marketing-Analytics-Hw1-Khachatryan-Ela.Rmd
110 lines (78 loc) · 2.31 KB
/
Marketing-Analytics-Hw1-Khachatryan-Ela.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
---
title: "Marketing Analytics Homework 1 Khachatryan Ela"
output: pdf_document
date: "2023-09-27"
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## R Markdown
#importing necessary libraries
```{r}
libs <- c('ggplot2', 'knitr', 'diffusion', 'ggpubr')
load_libraries <- function(libs) {
new_libs <- libs[!(libs %in% installed.packages()[,"Package"])]
if (length(new_libs) > 0) {
install.packages(new_libs)
}
lapply(libs, library, character.only = TRUE)
}
load_libraries(libs)
```
## Getting data for the look-alike innovation
```{r}
tesla <- read.csv("Tesla sales by year.csv", fileEncoding="UTF-8-BOM", sep = ";")
tesla
```
## Visualizing Tesla sales
```{r}
tesla$year <- factor(tesla$year)
plot_tesla = ggplot(data = tesla, aes(x = year, y = sales)) +
geom_bar(stat = 'identity') +
ggtitle('Tesla sales in thousand units')
plot_tesla
```
## 4. Estimating Bass model parameters for the look-alike innovation.
```{r}
sales_tesla = tesla$sales
t = 1:length(sales_tesla)
bass_m = nls(sales_tesla ~ m*(((p+q)**2/p)*exp(-(p+q)*t))/
(1+(q/p)*exp(-(p+q)*t))**2,
start=c(list(m=sum(sales_tesla),p=0.02,q=0.4)))
options(scipen = 999, digits = 4) ## to avoid scientific notations
summary(bass_m)
```
## 5. Make predictions of the diffusion of the innovation you chose at stage 1.
```{r}
diff_m = diffusion(sales_tesla)
p=round(diff_m$w,4)[1]
q=round(diff_m$w,4)[2]
m=round(diff_m$w,4)[3]
diff_m
```
```{r}
## Period when the sales will reach to the peak.
data.frame(Predicted=log(q/p)/(p+q),
Actual=which.max(tesla$sales))
```
``` {r}
## Defining bass function
bass.f <- function(t,p,q){ ((p+q)**2/p)*exp(-(p+q)*t)/
(1+(q/p)*exp(-(p+q)*t))**2
}
```
## 6. Estimate the number of adopters by time period. Thus, you will need to estimate the potential market share. You can use Fermi’s logic here.
```{r}
## Modeling f(t) and visualizing it
time_ad = ggplot(data.frame(t = c(1:9)), aes(t)) +
stat_function(fun = bass.f, args = c(p=0.0298, q=0.073)) +
labs(title = 'f(t)')
ggarrange(time_ad, plot_tesla)
```
```{r}
## Predicting sales
tesla$pred_sales = bass.f(1:9, p = 0.000847, q = 0.540172)*17339.9
ggplot(data = tesla, aes(x = year, y = sales)) +
geom_bar(stat = 'identity') +
geom_point(mapping = aes(x=year, y=pred_sales), color = 'red')
```