0% found this document useful (0 votes)
16 views9 pages

BA Soln

Uploaded by

Sunil Murty
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views9 pages

BA Soln

Uploaded by

Sunil Murty
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

import pandas as pd

import numpy as np

import statsmodels.api as sm

import matplotlib.pyplot as plt


# Corrected Data

data = {

"Revenue": [5, 6, 6.5, 7, 7.5, 8, 10, 10.8, 12, 13, 15.5, 15, 16, 17, 18, 18, 18.5, 21, 20, 22, 23, 7.1, 10.5, 15.8],

"Promotional Expenses": [1, 1.8, 1.6, 1.7, 2, 2, 2.3, 2.8, 3.5, 3.3, 4.8, 5, 7, 8.1, 8, 10, 8, 12.7, 12, 15, 14.4, 1, 2.1,
4.75]

df = pd.DataFrame(data)

# Log Transformation

df["Log_Revenue"] = np.log(df["Revenue"])

df["Log_Promotional_Expenses"] = np.log(df["Promotional Expenses"])

# Fit the regression model

X = sm.add_constant(df["Log_Promotional_Expenses"])

y = df["Log_Revenue"]

model = sm.OLS(y, X).fit()

# Print model summary

model_summary = model.summary()

# Residual plot

plt.figure(figsize=(10, 6))

plt.scatter(model.fittedvalues, model.resid)

plt.axhline(y=0, color='r', linestyle='-')

plt.xlabel('Fitted values')

plt.ylabel('Residuals')

plt.title('Residuals vs Fitted values')

residual_plot = plt.gcf()

model_summary, residual_plot

Result
(<class 'statsmodels.iolib.summary.Summary'>

"""

OLS Regression Results

==============================================================================

Dep. Variable: Log_Revenue R-squared: 0.925

Model: OLS Adj. R-squared: 0.921

Method: Least Squares F-statistic: 270.3

Date: Thu, 27 Jun 2024 Prob (F-statistic): 7.67e-14

Time: 17:21:35 Log-Likelihood: 16.030

No. Observations: 24 AIC: -28.06

Df Residuals: 22 BIC: -25.70

Df Model: 1

Covariance Type: nonrobust

============================================================================================

coef std err t P>|t| [0.025 0.975]

--------------------------------------------------------------------------------------------

const 1.7715 0.052 34.127 0.000 1.664 1.879

Log_Promotional_Expenses 0.5235 0.032 16.439 0.000 0.457 0.589

==============================================================================

Omnibus: 0.319 Durbin-Watson: 0.540

Prob(Omnibus): 0.853 Jarque-Bera (JB): 0.489

Skew: -0.152 Prob(JB): 0.783

Kurtosis: 2.371 Cond. No. 4.16

==============================================================================

Notes:

[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.

""",

<Figure size 2000x1200 with 1 Axes>)


Addressing the Functional Form

To address the issues with the functional form, we applied a logarithmic transformation to both the dependent
variable (Revenue) and the independent variable (Promotional Expenses). This transformation can help in dealing
with non-linearity and heteroscedasticity.

Steps:

1. Data Transformation:

o Applied log transformation: Log(Revenue)=log⁡(Revenue)\text{Log(Revenue)} = \log(\


text{Revenue})Log(Revenue)=log(Revenue) Log(Promotional Expenses)=log⁡(Promotional Expenses)\
text{Log(Promotional Expenses)} = \log(\text{Promotional
Expenses})Log(Promotional Expenses)=log(Promotional Expenses)

2. Fitted the Transformed Model:

o Used the transformed variables to fit an Ordinary Least Squares (OLS) regression model.

3. Model Summary and Diagnostics:

o Obtained the regression summary to check the model's performance and diagnostic statistics.

Transformed Model Summary:

OLS Regression Results

==============================================================================

Dep. Variable: Log_Revenue R-squared: 0.925

Model: OLS Adj. R-squared: 0.921

Method: Least Squares F-statistic: 270.3

Date: Thu, 27 Jun 2024 Prob (F-statistic): 7.67e-14


Time: 17:21:35 Log-Likelihood: 16.030

No. Observations: 24 AIC: -28.06

Df Residuals: 22 BIC: -25.70

Df Model: 1

Covariance Type: nonrobust

============================================================================================

coef std err t P>|t| [0.025 0.975]

--------------------------------------------------------------------------------------------

const 1.7715 0.052 34.127 0.000 1.664 1.879

Log_Promotional_Expenses 0.5235 0.032 16.439 0.000 0.457 0.589

==============================================================================

Omnibus: 0.319 Durbin-Watson: 0.540

Prob(Omnibus): 0.853 Jarque-Bera (JB): 0.489

Skew: -0.152 Prob(JB): 0.783

Kurtosis: 2.371 Cond. No. 4.16

==============================================================================

Notes:

[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.

Interpretation of Results:

 R-squared and Adjusted R-squared: The model explains about 92.5% of the variance in the log-transformed
revenue, which indicates a strong fit.

 Coefficients: The coefficient for log(Promotional Expenses) is 0.5235, which means that a 1% increase in
Promotional Expenses is associated with approximately a 0.52% increase in Revenue, holding other factors
constant.

 P-values: Both the intercept and the independent variable are statistically significant (p < 0.05).

 Diagnostic Tests: The Omnibus test, Durbin-Watson statistic, and Jarque-Bera test indicate that the residuals
are normally distributed, and there is no indication of severe autocorrelation or heteroscedasticity.

Residual Plot:

The residual plot is shown below. It helps in assessing the assumption of homoscedasticity (constant variance of
residuals).

The plot shows no clear pattern, suggesting that the residuals have constant variance, which indicates that the
transformation has successfully addressed the issue of heteroscedasticity.

Conclusion:

By transforming the data using logarithms, we have improved the functional form of the model and addressed issues
related to heteroscedasticity. The transformed model provides a good fit for predicting revenue based on
promotional expenses.

You might also like