














































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!















































































BUAD476: Marketing Analytics
Linear model question structure : How does a single numeric outcome relate to one or more predictor variables?
We will divide the module into two parts
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)
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
ggplot(data=eggs_df, mapping = aes(x=price.beef)) + geom_histogram() + theme_bw()
130 140 150 160 price.beef
count
ggplot(data=eggs_df, mapping = aes(x=price.chicken)) + geom_histogram() + theme_bw()
55 60 65 70 75 price.chicken
count
ggplot(data=eggs_df, mapping = aes(x=price.cereal)) + geom_histogram() + theme_bw()
0
5
10
15
110 120 130 price.cereal
count
To get elasticity interpretation, it is common to estimate a log-log demand model.
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)
data.frame(colnames(eggs_df)) #Getting the column indices of the variables
−
−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.
_# If you have not 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