Docsity

Linear Regression Models in Marketing Analytics - Prof. Suresh Sundaram, Exercises of Marketing

Partial preview of the text

Download Linear Regression Models in Marketing Analytics - Prof. Suresh Sundaram and more Exercises Marketing in PDF only on Docsity!

Module 2: Linear Models

Prof. Yuanchen Su

BUAD476: Marketing Analytics

Motivation

Up to this point, we’ve been focused on describing patterns that are

observable within a data set.

However, the answers to many interesting questions are not directly

observable:

  • How would a consumer that is not in customer database behave?
  • How would a new product perform in the market?

To answer these questions, we’ll build models that help us

extrapolate to similar but unobserved settings.

Module 2 Overview

Linear model question structure : How does a single numeric outcome relate to one or more predictor variables?

  • Outcomes are also called response or dependent variables (“Y”)
  • Predictors are also called explanatory or independent variables (“X”)

We will divide the module into two parts

  • Part 1: Univariate linear model and basic concepts
  • Part 2: Multivariate linear model

Example: What explains the demand (sales) for eggs?

Set the working directory and load the data

rm(list = ls()) setwd("C:\Users\ysu\Dropbox\Teaching\BUAD476\F25\Modules\Module 2 eggs_df <- read.csv(file="eggsdata.csv",stringsAsFactors=TRUE)

Do a quick inspection of the data

head(eggs_df) str(eggs_df) summary(eggs_df)

0. Before modeling...

0. Before modeling...

There are two important things to check:

1. Any variables that need log transformations?

  • Any highly-skewed distributions?

2. Are there any relationships among variables worth modeling?

  • Correlation between the outcome of interest and all potential predictor variables?

Price of eggs: not as skewed

ggplot(data=eggs_df, mapping = aes(x=price.eggs)) + geom_histogram() + theme_bw()

0

2

4

6

8

80 90 100 110 price.eggs

count

Price of beef: not as skewed

ggplot(data=eggs_df, mapping = aes(x=price.beef)) + geom_histogram() + theme_bw()

130 140 150 160 price.beef

count

Price of chicken: not as skewed

ggplot(data=eggs_df, mapping = aes(x=price.chicken)) + geom_histogram() + theme_bw()

55 60 65 70 75 price.chicken

count

Price of cereal: not as skewed

ggplot(data=eggs_df, mapping = aes(x=price.cereal)) + geom_histogram() + theme_bw()

0

5

10

15

110 120 130 price.cereal

count

0.1 Apply the log transformations

To get elasticity interpretation, it is common to estimate a log-log demand model.

  • Apply log() function to quantity.sold
  • Apply log() function to price predictors

For this reason (not because the variables are heavily right-skewed – they aren’t!), we will also transform the price variables.

eggs_df$log.price.eggs <- log(eggs_df$price.eggs) eggs_df$log.price.beef <- log(eggs_df$price.beef) eggs_df$log.price.pork <- log(eggs_df$price.pork) eggs_df$log.price.chicken <- log(eggs_df$price.chicken) eggs_df$log.price.cereal <- log(eggs_df$price.cereal)

0.2 Correlation among variables of interest

data.frame(colnames(eggs_df)) #Getting the column indices of the variables

colnames.eggs_df.

1 week

2 month

3 first.week

4 easter

5 quantity.sold

6 price.eggs

7 price.beef

8 price.pork

9 price.chicken

10 price.cereal

11 log.quantity.sold

12 log.price.eggs

13 log.price.beef

14 log.price.pork

15 log.price.chicken

16 log.price.cereal

0.2 Visualizing correlations: corrplot.mixed()

−

−0.

−0.

−0.

−0.

0

log.quantity.soldlog.price.eggslog.price.beeflog.price.porklog.price.chickenlog.price.cereal 1 log.quantity.sold

log.price.eggs

log.price.beef

log.price.pork

log.price.chicken

log.price.cereal

−0.

0.

0.

0.

−0.

−0.

−0.

−0.

0.

0.

0.

0.

−0.

0.37 −0.

0.2 Codes: corrplot.mixed()

_# If you have not installed "corrplot"

install.packages("corrplot")

If you have installed corrplot_

library(corrplot) corrplot.mixed(corr=cor(eggs_df[,11:16]), # cor() output upper="ellipse", # geometric representation tl.pos="lt", # variable name labels tl.cex=0.7) # label font size