Using R for Marketing Research Dan Toomey 2/23/2015 [email protected].

19
Using R for Marketing Research Dan Toomey 2/23/2015 [email protected]

Transcript of Using R for Marketing Research Dan Toomey 2/23/2015 [email protected].

Page 1: Using R for Marketing Research Dan Toomey 2/23/2015 dan@dantoomeysoftware.com.

Using R for Marketing Research

Dan Toomey2/23/2015

[email protected]

Page 2: Using R for Marketing Research Dan Toomey 2/23/2015 dan@dantoomeysoftware.com.

Outline

• Overview of R– Language Basics– Basic Operations– Tools – R, R Studio, others

• Validate Data• Analyze Ad Campaign Effectiveness• Sales Impact Drivers• Determine Optimal Pricing

Page 3: Using R for Marketing Research Dan Toomey 2/23/2015 dan@dantoomeysoftware.com.

Language Basics

• Uses ‘library’s of open source code for specific applications

• Mostly statistics processing• Simple syntax• Free tools to use• Multiple platforms

Page 4: Using R for Marketing Research Dan Toomey 2/23/2015 dan@dantoomeysoftware.com.

Basic Operations

• Load data – variety of formats• Compute metrics– Again, mostly interested in statistics

• Display metrics– Textual– Graphical

Page 5: Using R for Marketing Research Dan Toomey 2/23/2015 dan@dantoomeysoftware.com.

Load Data># libraries used>library(s20x)>library(car)># load and display data>df <- read.csv("http://www.dataapple.net/wp-content/uploads/2013/04/grapeJuice.csv",header=T)>head(df) sales price ad_type price_apple price_cookies1 222 9.83 0 7.36 8.802 201 9.72 1 7.43 9.623 247 10.15 1 7.66 8.904 169 10.04 0 7.57 10.265 317 8.38 1 7.33 9.54

Page 6: Using R for Marketing Research Dan Toomey 2/23/2015 dan@dantoomeysoftware.com.

Validate Data

>par(mfrow = c(1,2))>boxplot(df$sales,horizontal = TRUE, xlab="sales")># histogram to explore the data distribution shape>hist(df$sales,main="",xlab="sales",prob=T)>lines(density(df$sales),lty="dashed",lwd=2.5,col="red")

Page 7: Using R for Marketing Research Dan Toomey 2/23/2015 dan@dantoomeysoftware.com.

Data ValidationNo outliers from box plotNormal distribution

Page 8: Using R for Marketing Research Dan Toomey 2/23/2015 dan@dantoomeysoftware.com.

Ad Effectiveness> sales_ad_nature = subset(df,ad_type==0)> sales_ad_family = subset(df,ad_type==1)

> # graph the two> par(mfrow = c(1,2))

> hist(sales_ad_nature$sales,main="",xlab="sales with nature production theme ad",prob=T)> lines(density(sales_ad_nature$sales), lty="dashed",lwd=2.5,col="red")

> hist(sales_ad_family$sales,main="",xlab="sales with family health caring theme ad",prob=T)> lines(density(sales_ad_family$sales),lty="dashed",lwd=2.5,col="red")

Page 9: Using R for Marketing Research Dan Toomey 2/23/2015 dan@dantoomeysoftware.com.

Ad EffectivenessNormal distributions

Page 10: Using R for Marketing Research Dan Toomey 2/23/2015 dan@dantoomeysoftware.com.

Test Null Hypothesis(Normal)>shapiro.test(sales_ad_nature$sales)

Shapiro-Wilk normality test

data: sales_ad_nature$salesW = 0.9426, p-value = 0.4155

>shapiro.test(sales_ad_family$sales)

Shapiro-Wilk normality test

data: sales_ad_family$salesW = 0.8974, p-value = 0.08695

Page 11: Using R for Marketing Research Dan Toomey 2/23/2015 dan@dantoomeysoftware.com.

Test Means> t.test(sales_ad_nature$sales,sales_ad_family$sales)

Welch Two Sample t-test

data: sales_ad_nature$sales and sales_ad_family$salest = -3.7515, df = 25.257, p-value = 0.0009233alternative hypothesis: true difference in means is not equal to 095 percent confidence interval:-92.92234 -27.07766sample estimates:mean of x mean of y 186.6667 246.6667

Page 12: Using R for Marketing Research Dan Toomey 2/23/2015 dan@dantoomeysoftware.com.

Sales Drivers> pairs(df,col="blue",pch=20)> pairs20x(df)

Page 13: Using R for Marketing Research Dan Toomey 2/23/2015 dan@dantoomeysoftware.com.

Regression Model> sales.reg<-lm(sales~price+ad_type+price_apple+price_cookies,df)summary(sales.reg)Call:lm(formula = sales ~ price + ad_type + price_apple + price_cookies, data = df)Residuals: Min 1Q Median 3Q Max -36.290 -10.488 0.884 10.483 29.471 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 774.813 145.349 5.331 1.59e-05 ***price -51.239 5.321 -9.630 6.83e-10 ***ad_type 29.742 7.249 4.103 0.000380 ***price_apple 22.089 12.512 1.765 0.089710 . price_cookies -25.277 6.296 -4.015 0.000477 ***---Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 18.2 on 25 degrees of freedomMultiple R-squared: 0.8974, Adjusted R-squared: 0.881 F-statistic: 54.67 on 4 and 25 DF, p-value: 5.318e-12

Page 14: Using R for Marketing Research Dan Toomey 2/23/2015 dan@dantoomeysoftware.com.

Test DataCheck distribution of residuals

Page 15: Using R for Marketing Research Dan Toomey 2/23/2015 dan@dantoomeysoftware.com.

Multicolinearity

> vif(sales.reg)price ad_type price_apple price_cookies 1.246084 1.189685 1.149248 1.099255

Page 16: Using R for Marketing Research Dan Toomey 2/23/2015 dan@dantoomeysoftware.com.

Price Elasticity

Sales = 774.81 – (51.24 * price) + (29.74 * ad_type) + (22.1 * price_apple) – (25.28 * price_cookies)PE = (ΔQ/Q) / (ΔP/P) = (ΔQ/ΔP) * (P/Q) = -51.24 * 0.045 = -2.3P/Q = 9.738 / 216.7 = 0.045The PE indicates that 10% decrease in price will increase the sales by 23%

Page 17: Using R for Marketing Research Dan Toomey 2/23/2015 dan@dantoomeysoftware.com.

Optimal PricingSubstituting means for price changes in above model we come down to

Sales = 772.64 – 51.24*priceestimate profit(Y) = (price – C) * Sales Quantity = (price – 5) * (772.64 – 51.24*price)reduces to Y = – 51.24 * price2 + 1028.84 * price – 3863.2

> f<-function(x) { result <- -51.24*x^2 + 1028.84*x - 3863.2 return(result)}

#have R optimize the function>optimize(f,lower=0,upper=20,maximum=TRUE)$maximum[1] 10.03942$objective[1] 1301.28

Page 18: Using R for Marketing Research Dan Toomey 2/23/2015 dan@dantoomeysoftware.com.

Predict Sales

>inputData <- data.frame(price=10,ad_type=1,price_apple=7.659,price_cookies=9.738)>predict(sales.reg,inputData,interval="p") fit lwr upr1 215.1978 176.0138 254.3817

Page 19: Using R for Marketing Research Dan Toomey 2/23/2015 dan@dantoomeysoftware.com.

References

• Analyze sales pricing http://www.r-bloggers.com/data-analysis-for-marketing-research-with-r-language-1/