your_name <- readline(prompt = "What is your name?      ")
## What is your name?
# Go to the Console pane and type your name AND hit Enter Key

your_name <- "Blake Gamber"

print(your_name)
## [1] "Blake Gamber"
# (2) Date Function
#     Run line 32 below (click Run button or Ctrl + Enter)
date()
## [1] "Wed May  8 12:21:17 2024"
# (3) IP Address for Window (may not work for Mac)
#     Getting and Printing IP address of your computer
#     This IP address will be unique.
#     If there are errors realted to the below commands, 
#     just include all the error messages in the output.
#     Run the followings

x <- system("ipconfig", intern=TRUE)
x[grep("IPv4", x)]
## [1] "   IPv4 Address. . . . . . . . . . . : 192.168.86.194"
z <- x[grep("IPv4", x)]
gsub(".*? ([[:digit:]])", "\\1", z)
## [1] "192.168.86.194"

Introduction

In this report, I explore the forecasting of Tesla’s quarterly car sales using the Bass diffusion model. The Bass model is particularly suited for new products and technologies, making it an ideal choice for analyzing the sales of Tesla’s innovative vehicles.

Data Loading and Preparation

I loaded Tesla’s sales data from a CSV file, which includes quarterly sales figures from 2015 to 2018. The str() function helps us confirm the structure of our data, ensuring that it includes sales, quarters, and years as expected.

tesla_sales=read.csv(file="tesla_sales.csv", header = TRUE)

# Check the structure of the data
str(tesla_sales)
## 'data.frame':    16 obs. of  3 variables:
##  $ Sales  : num  5.45 5.1 5.1 5.34 8.79 ...
##  $ Quarter: int  1 2 3 4 1 2 3 4 1 2 ...
##  $ Year   : int  2015 2015 2015 2015 2016 2016 2016 2016 2017 2017 ...

Time Series Creation

Here, I convert the quarterly sales data into a time series object, tesla_ts, specifying the start of the series in the first quarter of 2015 and indicating that the data are quarterly (frequency=5).

# Convert to time series
tesla_ts <- ts(tesla_sales$Sales, start=c(2015, 1), frequency=5)

Plotting the Data

# Plot the data
plot(tesla_ts, type="l", lty=2, col="red", ylab = "Sales", xlab="Time")
points(tesla_ts, pch=20, col="blue")
title("Quarterly Tesla Car Sales")

# Cumulative sales
cum_sales <- cumsum(tesla_ts)
cum_sales_ts <- ts(cum_sales, start=c(2015, 1), frequency=5)

plot(cum_sales_ts, type="l", lty=2, col="red", ylab="Cumulative Sales", xlab="Time")
points(cum_sales_ts, pch=20, col="blue")
title("Cumulative Tesla Car Sales")

Model Estimation

In this section, I use a linear regression model to estimate the parameters needed for the Bass model. The regression model predicts Tesla’s quarterly sales based on previous cumulative sales (Y) and its square (Y_sq), helping us understand non-linear growth patterns in the data.

# Preparing for the Bass Model
# This model will be a simplified estimation; adjust coefficients a, b, c as per detailed statistical analysis
Y <- c(0, cum_sales_ts[1:(length(cum_sales_ts)-1)])  # Shift sales for model
Y_sq <- Y**2  # Squared term for the model

# Linear model to estimate coefficients
model <- lm(tesla_ts ~ Y + Y_sq)
summary(model)
## 
## Call:
## lm(formula = tesla_ts ~ Y + Y_sq)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -13.138  -6.974  -0.535   1.935  39.666 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)  
## (Intercept)  1.5462793  6.1755628   0.250   0.8062  
## Y            0.2674396  0.1485846   1.800   0.0951 .
## Y_sq        -0.0005599  0.0006811  -0.822   0.4259  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 12.65 on 13 degrees of freedom
## Multiple R-squared:  0.4341, Adjusted R-squared:  0.347 
## F-statistic: 4.986 on 2 and 13 DF,  p-value: 0.02471
a <- coef(model)[1]
b <- coef(model)[2]
c <- coef(model)[3]

# Compute m, p, q for the Bass model
m_plus <- (-b + sqrt(b**2 - 4*a*c)) / (2*c)
m_minus <- (-b - sqrt(b**2 - 4*a*c)) / (2*c)
m <- ifelse(m_plus > 0, m_plus, m_minus)  # Assuming positive market size
p <- a / m
q <- b + p

Bass Model Definition

I define the bass_model function, which computes predicted sales and cumulative sales based on the parameters p (coefficient of innovation), q (coefficient of imitation), and m (market potential). This function will simulate sales over specified periods (T).

# Define the Bass model function
bass_model <- function(p, q, m, T = length(tesla_ts) + 8) {
  S <- double(T)
  Y <- double(T + 1)
  Y[1] <- 0
  for (t in 1:T) {
    S[t] <- p * m + (q - p) * Y[t] - (q/m) * Y[t]**2
    Y[t+1] <- Y[t] + S[t]
  }
  list(Sales=S, cumSales=cumsum(S))
}

Forecasting and Visualization

In the forecasting section, I apply the Bass model to predict future sales. I then visualize these predictions alongside actual sales data, enabling a visual comparison of the model’s performance against real-world figures.

# Forecast sales
forecast <- bass_model(p, q, m)
forecast_ts <- ts(forecast$Sales, start=c(2015, 1), frequency=5)
# Plot actual vs. predicted sales
plot(tesla_ts, col="blue", type="o", pch=20, ylim=range(0, max(c(tesla_ts, forecast_ts))))
lines(forecast_ts, col="red", type="o", pch=22)
legend("topright", legend=c("Actual", "Bass Model"), col=c("blue", "red"), pch=c(20, 22))

# Cumulative forecasts
cum_forecast_ts <- ts(forecast$cumSales, start=c(2015, 1), frequency=5)
plot(cum_sales_ts, col="blue", type="o", pch=20, ylim=range(0, max(c(cum_sales_ts, cum_forecast_ts))))
lines(cum_forecast_ts, col="red", type="o", pch=22)
legend("topright", legend=c("Actual Cumulative", "Predicted Cumulative"), col=c("blue", "red"), pch=c(20, 22))

Conclusion

The application of the Bass Model to forecast Tesla’s car sales provided mixed results, reflecting both the strengths and limitations of this model in capturing the dynamics of a rapidly evolving market such as electric vehicles.

Interpretation of Forecast Results

  • Quarterly Sales Trends: The comparison of actual and predicted quarterly sales reveals that the Bass Model, while capturing the general trend, significantly underestimates sales in periods of rapid growth, particularly evident in the last quarter shown in the plot. This spike in actual sales in late 2018 might be due to external factors not captured by the model, such as market excitement around new model releases or advancements in battery technology which the model is unable to account for.

  • Cumulative Sales Analysis: The plot of cumulative sales shows that the model follows the actual sales trajectory reasonably well at the beginning but begins to diverge around mid-2017. This divergence could be indicative of the model’s parameters (market potential m, innovation coefficient p, and imitation coefficient q) being initially aligned but becoming less so as market conditions evolve. Notably, the model predicts a smoother approach to a market potential that may be underestimated, as actual sales continue to rise sharply.

Evaluation of the Bass Model

  • Data Sensitivity: The model’s performance underscores its sensitivity to the parameters m, p, and q. The estimates derived from the regression analysis provided a basis for these parameters, but they may need ongoing adjustment to reflect new data and market realities better.

  • Future Projections: If Tesla continues to innovate or if external market conditions such as government policies favoring electric vehicles intensify, actual sales could continue to outpace the predictions significantly. This potential underlines the importance of incorporating flexibility into the model or revisiting the assumptions about market saturation regularly.