# Final Project Format
# The final report should be presented in more formal format. Consider your audience to be non data analysts. Fellow data analysts (i.e. students) will be able to access your R Markdown file for details on the analysis. Submit a Zip file with your R Markdown file, the HTML output, and any supplementary files (e.g. data, figures, etc.). You must address the five following sections:
#
# Introduction: What is your research question? Why do you care? Why should others care?
#
# Data: Write about the data from your proposal in text form. Address the following points:
#
# Data collection: Describe how the data were collected.
# Cases: What are the cases? (Remember: case = units of observation or units of experiment)
# Variables: What are the two variables you will be studying? State the type of each variable.
# Type of study: What is the type of study, observational or an experiment? Explain how you've arrived at your conclusion using information on the sampling and/or experimental design.
# Scope of inference - generalizability: Identify the population of interest, and whether the findings from this analysis can be generalized to that population, or, if not, a subsection of that population. Explain why or why not. Also discuss any potential sources of bias that might prevent generalizability.
# Scope of inference - causality: Can these data be used to establish causal links between the variables of interest? Explain why or why not.
# Exploratory data analysis: Perform relevant descriptive statistics, including summary statistics and visualization of the data. Also address what the exploratory data analysis suggests about your research question.
#
# Inference: If your data fails some conditions and you can't use a theoretical method, then you should use simulation. If you can use both methods, then you should use both methods. It is your responsibility to figure out the appropriate methodology.
#
# Check conditions
# Theoretical inference (if possible) - hypothesis test and confidence interval
# Simulation based inference - hypothesis test and confidence interval
# Brief description of methodology that reflects your conceptual understanding
# Conclusion: Write a brief summary of your findings without repeating your statements from earlier. Also include a discussion of what you have learned about your research question and the data you collected. You may also want to include ideas for possible future research.
#
This is Sales data of from last 2 year, grouped by location and and quarter info.
What is your research question? Why do you care? Why should others care?
Approach :
Data : (Write about the data from your proposal in text form. Address the following points:) Data collection: (Describe how the data were collected.) This data is sample of sales by promotion for last two year. Data was shared by Marketting team to evaluate the sales performance.
Note : For Confidencilaty names and numbers have been changed in the data.
Cases : What are the cases? (Remember: case = units of observation or units of experiment) In This sample we have 1000 rows. Each row identify the Order from the given customer.
Variables : What are the two variables you will be studying? State the type of each variable.
Order Quantity is Response variable here . It’s Quantitative variable. Quarter Qt, is Independent varible , it’s qualitative variable as we can’t add them. Other qualitative variables: Brands,Promotions, Zipcode etc.
Type of study : What is the type of study, observational or an experiment? Explain how you’ve arrived at your conclusion using information on the sampling and/or experimental design.
We do studies to gather information and draw conclusions. The type of conclusion we draw depends on the study method used: In an observational study, we measure or survey members of a sample without trying to affect them. In a controlled experiment, we assign people or things to groups and apply some treatment to one of the groups, while the other group does not receive the treatment.
This is an observational study.
Scope of inference - generalizability: Identify the population of interest, and whether the findings from this analysis can be generalized to that population, or, if not, a subsection of that population. Explain why or why not. Also discuss any potential sources of bias that might prevent generalizability.
Since data set is too big and would take too much computing power and machine time. To save time I’ll be working on sample data of much smaller size. on computing I am keeping my sample size to 200 * 8 (each quarter from 2 year). These findings may be generlaized for the same customer and identify the posibility of sales .
Scope of inference - causality: Can these data be used to establish causal links between the variables of interest? Explain why or why not. Since its a observational study we can’t make Casue and Effect inference from here, but it being an observational study it will have some info about customers spending pttern over the years and Quarter.
#---------------------------------------------------------------------
# Create Sample A of 1000 customer
#---------------------------------------------------------------------
custA <- mkt_cust_qt[sample(nrow(mkt_cust_qt),1000),]
custAG <- gather(custA, key = "Qt",value = "order_unit",-KUNNR_NEW)
custAG$KUNNR_NEW <- as.character(custAG$KUNNR_NEW)
custAG$Qt = as.factor(custAG$Qt)
custAG$order_unit[which(is.na(custAG$order_unit))] <- 0
custAG$seq <- 0
custAG$seq[which(custAG$Qt=="Q1_17")] = 1
custAG$seq[which(custAG$Qt=="Q2_17")] = 2
custAG$seq[which(custAG$Qt=="Q3_17")] = 3
custAG$seq[which(custAG$Qt=="Q4_17")] = 4
custAG$seq[which(custAG$Qt=="Q1_18")] = 5
custAG$seq[which(custAG$Qt=="Q2_18")] = 6
custAG$seq[which(custAG$Qt=="Q3_18")] = 7
custAG$seq[which(custAG$Qt=="Q4_18")] = 8
custAG <- custAG[order(custAG$seq),]
#---------------------------------------------------------------------
# Create Sample A of 1000 customer
#---------------------------------------------------------------------
# Wide Data set
head(custA)
# Long Data set
head(custAG)
Perform relevant descriptive statistics, including summary statistics and visualization of the data. Also address what the exploratory data analysis suggests about your research question.
# Data
str(head(mkt_Data[,-c(1,2,3,4,5,6,7,8,7)]))
## Classes 'tbl_df', 'tbl' and 'data.frame': 6 obs. of 15 variables:
## $ Brand : chr "TY" "RX" "VO" "PR" ...
## $ Order Number : num 1.50e+08 2.02e+09 2.02e+09 2.02e+09 1.51e+08 ...
## $ Order Date : POSIXct, format: "2018-09-25" "2018-02-12" ...
## $ Order Quantity : num 12 9 23 21 8 11
## $ Promotion Order Doll: num 883 641 1067 2421 346 ...
## $ Promotion : num 114778 210 212 119 114777 ...
## $ External Description: chr "Other" "Other" "SY1" "SY250" ...
## $ Ship Sets : chr "S" "S" "S" "S" ...
## $ From Date : POSIXct, format: "2018-07-01" "2018-02-01" ...
## $ To Date : POSIXct, format: "2018-09-30" "2018-02-28" ...
## $ city : chr "ROUND ROCK" "ENID" "REYNOLDSBURG" "WHITE RIVER JUNCTION" ...
## $ state : chr "TX" "OK" "OH" "VT" ...
## $ zip : chr "78665" "73703" "43068-1211" "5001" ...
## $ Qt : chr "Q3_18" "Q1_18" "Q2_18" "Q1_18" ...
## $ KUNNR_NEW : chr "1262891" "1267348" "1255518" "1258474" ...
summary((mkt_Data[,-c(1,2,3,4,5,6,7,8,7)]))
## Brand Order Number Order Date
## Length:5000 Min. :1.481e+08 Min. :2017-01-03 00:00:00
## Class :character 1st Qu.:2.016e+09 1st Qu.:2017-07-03 00:00:00
## Mode :character Median :2.018e+09 Median :2018-01-20 00:00:00
## Mean :1.562e+09 Mean :2018-01-03 18:54:08
## 3rd Qu.:2.020e+09 3rd Qu.:2018-06-26 06:00:00
## Max. :2.402e+09 Max. :2018-12-29 00:00:00
## Order Quantity Promotion Order Doll Promotion
## Min. : 1.00 Min. : 0.0 Min. : 14
## 1st Qu.: 5.00 1st Qu.: 348.3 1st Qu.: 68
## Median : 10.00 Median : 741.5 Median : 104
## Mean : 14.22 Mean : 1094.8 Mean : 28137
## 3rd Qu.: 19.00 3rd Qu.: 1383.6 3rd Qu.: 241
## Max. :304.00 Max. :23339.4 Max. :114916
## External Description Ship Sets From Date
## Length:5000 Length:5000 Min. :2017-01-03 00:00:00
## Class :character Class :character 1st Qu.:2017-07-01 00:00:00
## Mode :character Mode :character Median :2018-01-01 00:00:00
## Mean :2017-12-03 18:05:11
## 3rd Qu.:2018-06-01 00:00:00
## Max. :2018-10-01 00:00:00
## To Date city state
## Min. :2017-03-31 00:00:00 Length:5000 Length:5000
## 1st Qu.:2017-07-31 00:00:00 Class :character Class :character
## Median :2018-01-31 00:00:00 Mode :character Mode :character
## Mean :2018-02-02 01:19:12
## 3rd Qu.:2018-07-30 00:00:00
## Max. :2018-12-31 00:00:00
## zip Qt KUNNR_NEW
## Length:5000 Length:5000 Length:5000
## Class :character Class :character Class :character
## Mode :character Mode :character Mode :character
##
##
##
head(mkt_Data[,-c(1,2,3,4,5,6,7,8,7)])
describe.by(custA)
ggplot(custAG,mapping = aes(x=KUNNR_NEW ,y= order_unit, color=Qt)) + geom_point() +ggtitle("Customer Order By Quarter")
ggplot(custAG[which(custAG$order_unit<= 100),],mapping = aes(y=KUNNR_NEW ,x= order_unit, color=Qt)) + geom_point() + facet_wrap(~Qt,ncol = 2) + ggtitle("Ordered Unit < 150 by Customer ") + ylab("Customer")
ggplot(custAG[which(custAG$order_unit> 100),],mapping = aes(y=KUNNR_NEW ,x= order_unit, color=Qt)) + geom_point() + facet_wrap(~Qt,ncol = 2) + ggtitle("Ordered Unit >150 by Customer ") + ylab("Customer")
# Graph by Plotly
plot_ly(data=custAG,y=custAG$order_unit ,x= custAG$KUNNR_NEW,color=custAG$Qt, type= "scatter") %>% layout( title = "scatter plot: Customer Order Qty by Quarter")
# plot_ly(data=custAG,y=custAG$order_unit ,x= custAG$KUNNR_NEW, z = custAG$Qt ,color=custAG$Qt, type= "scatter3d" )
custAG %>%
group_by(Qt) %>% summarise(order_unit = sum(order_unit)) %>%
ggplot(mapping = aes(x= Qt,y=order_unit,fill = Qt)) + geom_col() + geom_label(aes(label=order_unit))+
theme_light() + ggtitle("Order Quantity Over Each Quarter") +ylab("Ordered Unit") + xlab("Quarter")
# Line plot with multiple groups
custAG[order(custAG$seq),] %>%
ggplot( aes(x= seq, y=order_unit, group= KUNNR_NEW,color=Qt) )+
geom_line()+
geom_point() + ggtitle("Customer Order Qty Movement over Quarter")
If your data fails some conditions and you can’t use a theoretical method, then you should use simulation. If you can use both methods, then you should use both methods. It is your responsibility to figure out the appropriate methodology.
We will examine sample of data after tidying of the data in the below formt :
| Customer | Q1 | Q2 |
|---|---|---|
| 1 | 21 | 12 |
| 2 | 21 | 12 |
| 3 | 21 | 12 |
| 4 | 21 | 12 |
| . | . | . |
| . | . | . |
| n | n | n |
Note : # Check conditions # Theoretical inference (if possible) - hypothesis test and confidence interval # Simulation based inference - hypothesis test and confidence interval # Brief description of methodology that reflects your conceptual understanding
Oneway ANOVA Test & Results There are several ways to do so but let’s start with the simplest from the base R first ‘aov’. While it’s possible to wrap the command in a summary or print statement I saved the results out to an R object in this case ‘AOV_RESULT’.
The dependent variable goes to the left of the tilde and our independent or predictor variable to the right. aov is not limited to Oneway ANOVA so adding additional factors is possible. Steps:
1. Set the Hypothesis
2. Run the AOV test 3. Peforming eta squared test 3. Interpred the result and Check condition 4. Check with Paired t test. ##### Prepare H0 = Quarter doesn’t matter in predicting Order Quantity -all Quarters are the same H1 = At least one of the Quarter populations is different than the others. Our null is basically
If Pvalue is less than that of Alpha .05 we will rejct the null Hypothesis.
Rewording: H0: There is no difference between qunatity of Q1_17,Q2_17 and so on and so forth. pq1 = pq2 = pq3 …
HA: There is a difference between qunatity of Q1_17,Q2_17 and so on and so forth.
# # custAG[order(custAG$seq),] %>%spread(key = Qt,value = order_unit, fill=0)
# custAG[order(custAG$seq),] %>%spread(key = Qt,value = order_unit, fill=0)
# Creating QUarter data over each column
# Q1 Q2 Q3 ...
# 1 2 3 ...
# 1 2 3 ...
# 1 2 3 ...
#Conbined Data
Dt_ANOVA <- custAG[,c(3,2)]
Dt_ANOVA2017 <- Dt_ANOVA[which(Dt_ANOVA$Qt %in% c("Q1_17", "Q2_17", "Q3_17" ,"Q4_17")),]
boxplot(Dt_ANOVA2017$order_unit~Dt_ANOVA2017$Qt,
main="Boxplot comparing Qty of Quarter",
col= rainbow(4),
horizontal = TRUE)
library(Hmisc)
ggplot(Dt_ANOVA2017, aes(reorder(Qt,order_unit),order_unit,fill=Qt))+
# ggplot(tyre, aes(Brands,Mileage,fill=Brands))+ # if you want to leave them alphabetic
geom_jitter(colour = "dark gray",width=.1) +
stat_boxplot(geom ='errorbar',width = 0.4) +
geom_boxplot()+
labs(title="Boxplot, dotplot and SEM plot of mileage for four Quarters of Sales",
x = "Quarter (sorted)",
y = "Sales",
subtitle ="Gray dots=sample data points, Black dot=outlier, Blue dot=mean, Red=99% confidence interval",
caption = "No Major obvious difference in mean is noted") +
guides(fill=FALSE) +
stat_summary(fun.data = "mean_cl_normal", colour = "red", size = 1.5, fun.args = list(conf.int=.99)) +
stat_summary(geom="point", fun.y=mean, color="blue") +
theme_bw()
All_Qt_row <- custA[,-c(1)]
head(All_Qt_row)
summary(All_Qt_row)
## Q1_17 Q1_18 Q2_17 Q2_18
## Min. : 1.000 Min. : 1.00 Min. : 1.000 Min. : 1.000
## 1st Qu.: 1.000 1st Qu.: 1.00 1st Qu.: 1.000 1st Qu.: 1.000
## Median : 1.000 Median : 1.00 Median : 1.000 Median : 1.000
## Mean : 3.494 Mean : 4.12 Mean : 3.331 Mean : 3.193
## 3rd Qu.: 1.000 3rd Qu.: 1.00 3rd Qu.: 1.000 3rd Qu.: 1.000
## Max. :85.000 Max. :156.00 Max. :260.000 Max. :101.000
## Q3_17 Q3_18 Q4_17 Q4_18
## Min. : 1.000 Min. : 1.000 Min. : 1.000 Min. : 1.000
## 1st Qu.: 1.000 1st Qu.: 1.000 1st Qu.: 1.000 1st Qu.: 1.000
## Median : 1.000 Median : 1.000 Median : 1.000 Median : 1.000
## Mean : 3.176 Mean : 2.928 Mean : 2.522 Mean : 2.719
## 3rd Qu.: 1.000 3rd Qu.: 1.000 3rd Qu.: 1.000 3rd Qu.: 1.000
## Max. :160.000 Max. :81.000 Max. :87.000 Max. :64.000
# Creating stacked quarter data.
# Q1
# Q2
# Q3
All_Qt_stack <- custAG[,c(3,2)]
head(All_Qt_stack,n=10)
print(t(describe.by(All_Qt_stack)))
## order_unit Qt*
## vars 1.000000e+00 2.00000000
## n 8.000000e+03 8000.00000000
## mean 3.185375e+00 4.50000000
## sd 8.371232e+00 2.29143107
## median 1.000000e+00 4.50000000
## trimmed 1.222656e+00 4.50000000
## mad 0.000000e+00 2.96520000
## min 1.000000e+00 1.00000000
## max 2.600000e+02 8.00000000
## range 2.590000e+02 7.00000000
## skew 9.792949e+00 0.00000000
## kurtosis 1.801081e+02 -1.23853569
## se 9.359322e-02 0.02561898
head(All_Qt_stack)
AOV_RESULT <- aov(order_unit~Qt,All_Qt_stack) # Qt is predictor
class(AOV_RESULT)
## [1] "aov" "lm"
# The names command will give you some sense of all the information contained in the list object.
names(AOV_RESULT)
## [1] "coefficients" "residuals" "effects" "rank"
## [5] "fitted.values" "assign" "qr" "df.residual"
## [9] "contrasts" "xlevels" "call" "terms"
## [13] "model"
# The summary command gives us the key ANOVA data we need and produces a classic ANOVA table
summary(AOV_RESULT)
## Df Sum Sq Mean Sq F value Pr(>F)
## Qt 7 1714 244.85 3.502 0.000937 ***
## Residuals 7992 558836 69.92
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# One-way ANOVA showed a no significant effect of Quarter on Order Quantity gain (F(7, 7992) = 1.504 , , p a .001).
print( AOV_RESULT )
## Call:
## aov(formula = order_unit ~ Qt, data = All_Qt_stack)
##
## Terms:
## Qt Residuals
## Sum of Squares 1713.9 558836.1
## Deg. of Freedom 7 7992
##
## Residual standard error: 8.362084
## Estimated effects may be unbalanced
F-test is always one sided And that we only reject the null hypothesis for very large F-values That means we’re only interested in the upper tail of the F-distribution
pf( 1.504, 7, 7992,lower.tail=FALSE)
## [1] 0.1607537
# R doesn't use the names "between-group"
# and "within-group". Instead, it tries to assign more meaningful names: in our case # "between groups" variance corresponds to the effect that the "Qt" has on the outcome variable; "within groups" variance is corresponds to the "leftover" variability, so it calls that the residuals
# There's a few different ways you could measure the effect size in an ANOVA, but the most commonly
# used measures are ??2 (eta squared) and partial ??2. For a one way analysis of variance they're identical
# to each other, so for the moment I'll just explain ??2. The definition of ??2 is actually really simple
SSb <- 3473
SSt <- (3473+2636684) # total sums of squares
# eta squared
# The interpretation of ??2 (eta squared) is equally straightforward: it refers to the proportion of the variability in the
# outcome variable (Order_Quantity) that can be explained in terms of the predictor (Quarter).
# A value of ??2 ((eta squared) = 0
# means that there is no relationship at all between the two,
# whereas a value of ??2 (eta squared) = 1 means that the relationship is perfect.
# eta_Sqrd <- sqrt(SSb / SSt)
eta_Sqrd <- sqrt(SSb / SSt) # eta-squared value
eta_Sqrd
## [1] 0.03626916
###
Here we can conclude that there is no strong relation between the order Qty over Quarter.
We have assumed 3 things; independence, homogeneity of variance (homoscedasticity) and normality for considering ANOVA result for our probelm. Lets see if our result meets these conditions.
Independence : Eacu customer is indendent and buying pattern is too.
our errors or residuals are normally distributed : Our Residual is Right Skewed as its just the promotion sales data.
The final is homogeneity of variance also known as (homoscedasticity). : Due to some big outlier the sample is not showing the plot , but we can asumet this based on small sample size .
# Plot each one by one
par(mfrow=c(2,2))
plot(AOV_RESULT)
#PLotting Residual only
hist(AOV_RESULT$residuals)
# homoscedasticity
plot(AOV_RESULT$residuals)
print(t(psych::describe(AOV_RESULT$residuals) ))# skew kurtosis are very high , which shows that data is not fully normalised , given the sample size we will
## X1
## vars 1.000000e+00
## n 8.000000e+03
## mean 5.771812e-16
## sd 8.358424e+00
## median -2.176000e+00
## trimmed -1.838967e+00
## mad 4.714668e-01
## min -3.120000e+00
## max 2.566690e+02
## range 2.597890e+02
## skew 9.769740e+00
## kurtosis 1.799567e+02
## se 9.345002e-02
#using sample of size 500 to see data.
par(mfrow=c(2,2))
for (i in 1:10)
{
AOV_RESULT_Sam <- aov(order_unit~Qt,(Dt_ANOVA[sample(nrow(Dt_ANOVA),500),]))
plot(AOV_RESULT_Sam$residuals)
}
It’s tempting to conclude that Q1 is better than the other Quarters. Afetr running multiple T test , it was clear that the pvalue 0.0178 < 0.05 , so we can reject null hypothesis. Suport atlernate hypothesis that there is evidence of a difference in sleas of Quarter 1 and Quarter 2.
Please Note : I have done pairewise t test using function but not sure how to iterpret the result . Including it for future study.
# How we can say which quarter is more or less in terms of data
library(gplots)
plotmeans( formula = order_unit~Qt, # plot Order Qty by Quarter
data = All_Qt_stack, # the data frame
xlab = "Quarter", # x-axis label
ylab = "Order Qty", # y-axis label
n.label = FALSE # don't display sample size
)
plotmeans( formula = order_unit~seq, # plot Order Qty by Quarter
data = custAG[,c(3,4,2)], # the data frame
xlab = "Quarter", # x-axis label
ylab = "Order Qty", # y-axis label
n.label = FALSE # don't display sample size,
)
# it's tempting to conclude that Q1 is better than the other Quarters excpet Q2 and better than Anxifree,
# but there's no real difference between each quarter. However, if we want to get a clearer
# answer about this, it might help to run some tests.
#Running "pairwise" t-tests
# set p.adjust.method = "none" since we're not doing any adjustments.
pairwise.t.test(x = Dt_ANOVA$order_unit,
g = Dt_ANOVA$Qt,
p.adjust.method = "none")
##
## Pairwise comparisons using t tests with pooled SD
##
## data: Dt_ANOVA$order_unit and Dt_ANOVA$Qt
##
## Q1_17 Q1_18 Q2_17 Q2_18 Q3_17 Q3_18 Q4_17
## Q1_18 0.09418 - - - - - -
## Q2_17 0.66294 0.03490 - - - - -
## Q2_18 0.42091 0.01320 0.71212 - - - -
## Q3_17 0.39516 0.01161 0.67853 0.96374 - - -
## Q3_18 0.13019 0.00144 0.28122 0.47858 0.50724 - -
## Q4_17 0.00936 1.9e-05 0.03055 0.07280 0.08036 0.27766 -
## Q4_18 0.03826 0.00018 0.10177 0.20501 0.22173 0.57626 0.59835
##
## P value adjustment method: none
library(DATA606)
##
## Welcome to CUNY DATA606 Statistics and Probability for Data Analytics
## This package is designed to support this course. The text book used
## is OpenIntro Statistics, 3rd Edition. You can read this by typing
## vignette('os3') or visit www.OpenIntro.org.
##
## The getLabs() function will return a list of the labs available.
##
## The demo(package='DATA606') will list the demos that are available.
Dt_ANOVA2017_q12 <- Dt_ANOVA2017[which(Dt_ANOVA2017$Qt %in% c("Q1_17","Q2_17")),]
Dt_ANOVA2017_q12$Qt <- factor(Dt_ANOVA2017_q12$Qt)
inference(y = as.numeric(Dt_ANOVA2017_q12$order_unit),
x = Dt_ANOVA2017_q12$Qt, est = "mean", type = "ht", null = 0,
alternative = "greater", method = "theoretical")
## Response variable: numerical, Explanatory variable: categorical
## Difference between two means
## Summary statistics:
## n_Q1_17 = 1000, mean_Q1_17 = 3.494, sd_Q1_17 = 7.6124
## n_Q2_17 = 1000, mean_Q2_17 = 3.331, sd_Q2_17 = 11.4136
## Observed difference between means (Q1_17-Q2_17) = 0.163
##
## H0: mu_Q1_17 - mu_Q2_17 = 0
## HA: mu_Q1_17 - mu_Q2_17 > 0
## Standard error = 0.434
## Test statistic: Z = 0.376
## p-value = 0.3536
Dt_ANOVA2017_q23 <- Dt_ANOVA2017[which(Dt_ANOVA2017$Qt %in% c("Q2_17","Q3_17")),]
Dt_ANOVA2017_q23$Qt <- factor(Dt_ANOVA2017_q23$Qt)
inference(y = as.numeric(Dt_ANOVA2017_q23$order_unit),
x = Dt_ANOVA2017_q23$Qt, est = "mean", type = "ht", null = 0,
alternative = "greater", method = "theoretical")
## Response variable: numerical, Explanatory variable: categorical
## Difference between two means
## Summary statistics:
## n_Q2_17 = 1000, mean_Q2_17 = 3.331, sd_Q2_17 = 11.4136
## n_Q3_17 = 1000, mean_Q3_17 = 3.176, sd_Q3_17 = 8.692
## Observed difference between means (Q2_17-Q3_17) = 0.155
##
## H0: mu_Q2_17 - mu_Q3_17 = 0
## HA: mu_Q2_17 - mu_Q3_17 > 0
## Standard error = 0.454
## Test statistic: Z = 0.342
## p-value = 0.3663
Dt_ANOVA2017_q34 <- Dt_ANOVA2017[which(Dt_ANOVA2017$Qt %in% c("Q3_17","Q4_17")),]
Dt_ANOVA2017_q34$Qt <- factor(Dt_ANOVA2017_q34$Qt)
inference(y = as.numeric(Dt_ANOVA2017_q34$order_unit),
x = Dt_ANOVA2017_q34$Qt, est = "mean", type = "ht", null = 0,
alternative = "greater", method = "theoretical")
## Response variable: numerical, Explanatory variable: categorical
## Difference between two means
## Summary statistics:
## n_Q3_17 = 1000, mean_Q3_17 = 3.176, sd_Q3_17 = 8.692
## n_Q4_17 = 1000, mean_Q4_17 = 2.522, sd_Q4_17 = 5.7909
## Observed difference between means (Q3_17-Q4_17) = 0.654
##
## H0: mu_Q3_17 - mu_Q4_17 = 0
## HA: mu_Q3_17 - mu_Q4_17 > 0
## Standard error = 0.33
## Test statistic: Z = 1.98
## p-value = 0.0238
# (t.test( formula = Dt_ANOVA2017_q12$order_unit ~ Dt_ANOVA2017_q12$Qt,
# data = Dt_ANOVA2017,
# subset = Qt %in% c("Q1_17","Q2_17"),
# var.equal = TRUE
# ))
# Suppose that my post hoc analysis consists of m separate tests, and I want to ensure
# that the total probability of making any Type I errors at all is at most ??.9 If so, then the Bonferroni
# correction just says "multiply all your raw p-values by m". If we let p denote the original p-value, and
# let p1
# j be the corrected value, then the Bonferroni correction tells that:
# p1 " m ^ p
# And therefore, if you're using the Bonferroni correction, you would reject the null hypothesis if p1 a ??.
# The logic behind this correction is very straightforward. We're doing m different tests; so if we arrange
# it so that each test has a Type I error rate of at most ??{m, then the total Type I error rate across these
# tests cannot be larger than ??.
# here we have 8 Quaters data so comb(8,2) = 28 , with this method all the results were multiplied by 28
pairwise.t.test(x = Dt_ANOVA$order_unit,
g = Dt_ANOVA$Qt,
p.adjust.method = "bonferroni")
##
## Pairwise comparisons using t tests with pooled SD
##
## data: Dt_ANOVA$order_unit and Dt_ANOVA$Qt
##
## Q1_17 Q1_18 Q2_17 Q2_18 Q3_17 Q3_18 Q4_17
## Q1_18 1.00000 - - - - - -
## Q2_17 1.00000 0.97731 - - - - -
## Q2_18 1.00000 0.36963 1.00000 - - - -
## Q3_17 1.00000 0.32513 1.00000 1.00000 - - -
## Q3_18 1.00000 0.04034 1.00000 1.00000 1.00000 - -
## Q4_17 0.26213 0.00055 0.85531 1.00000 1.00000 1.00000 -
## Q4_18 1.00000 0.00506 1.00000 1.00000 1.00000 1.00000 1.00000
##
## P value adjustment method: bonferroni
Test method. Use the chi-square goodness of fit test to determine whether observed sample frequencies differ significantly from expected frequencies specified in the null hypothesis.
This approach consists of four steps: ##### (1) state the hypotheses :
The hypotheses for the Chi-squared test are as follows.
H0: There is no association between qunatity of Q1_17,Q2_17 and so on and so forth. pq1 = pq2 = pq3 …
HA: There is an association between qunatity of Q1_17,Q2_17 and so on and so forth.
Assumptions* The chi-squared test, when used with the standard approximation that a chi-squared distribution is applicable, has the following assumptions:
Simple random sample The sample data is a random sampling from a fixed distribution or population where every collection of members of the population of the given sample size has an equal probability of selection. Variants of the test have been developed for complex samples, such as where the data is weighted. Other forms can be used such as purposive sampling.
n= 50 and 500, selcted randomly from sample . satisfying Simple Random sample
Sample size (whole table) A sample with a sufficiently large size is assumed. If a chi squared test is conducted on a sample with a smaller size, then the chi squared test will yield an inaccurate inference. The researcher, by using chi squared test on small samples, might end up committing a Type II error.
sample size is big enough and with multiple itration I have tried to get possible result.
Expected cell count Adequate expected cell counts. Some require 5 or more, and others require 10 or more. A common rule is 5 or more in all cells of a 2-by-2 table, and 5 or more in 80% of cells in larger tables, but no cells with zero expected count. When this assumption is not met, Yates’s correction is applied.
Cell count is more that 2 X 2 matrix dat value.
Independence The observations are always assumed to be independent of each other. This means chi-squared cannot be used to test correlated data.
- Each sample is choosen randonmly from the Population. We can say that they are meeting the condition on Indepenence
- Then sample of 50 and 500 was created to run the chi-test.
We will create Sample of 1000 datapoints where records are spread in column for each quarter. we would be doing regular chi square test and then we would switch to Multiple simulation
Significance level. significance levels 0.05, or 0.10; but any value between 0 and 1 can be used.
custA$KUNNR_NEW <- as.character(custA$KUNNR_NEW )
summary(custA)
## KUNNR_NEW Q1_17 Q1_18 Q2_17
## Length:1000 Min. : 1.000 Min. : 1.00 Min. : 1.000
## Class :character 1st Qu.: 1.000 1st Qu.: 1.00 1st Qu.: 1.000
## Mode :character Median : 1.000 Median : 1.00 Median : 1.000
## Mean : 3.494 Mean : 4.12 Mean : 3.331
## 3rd Qu.: 1.000 3rd Qu.: 1.00 3rd Qu.: 1.000
## Max. :85.000 Max. :156.00 Max. :260.000
## Q2_18 Q3_17 Q3_18 Q4_17
## Min. : 1.000 Min. : 1.000 Min. : 1.000 Min. : 1.000
## 1st Qu.: 1.000 1st Qu.: 1.000 1st Qu.: 1.000 1st Qu.: 1.000
## Median : 1.000 Median : 1.000 Median : 1.000 Median : 1.000
## Mean : 3.193 Mean : 3.176 Mean : 2.928 Mean : 2.522
## 3rd Qu.: 1.000 3rd Qu.: 1.000 3rd Qu.: 1.000 3rd Qu.: 1.000
## Max. :101.000 Max. :160.000 Max. :81.000 Max. :87.000
## Q4_18
## Min. : 1.000
## 1st Qu.: 1.000
## Median : 1.000
## Mean : 2.719
## 3rd Qu.: 1.000
## Max. :64.000
head(custA)
# List test condtion for CHi-Square
# 1. Are the value independent for each Quarter :
# 2.
# Ho : Customer are not baised on speding over Quarter . pq1 = pq2 = pq3 ...
# Ha : Customer are spending less or more compared to last quarter.
# 1. convert the data as a table with only Quater data .
dt <- as.table(as.matrix(custA[,]))
# Test 1
chi_custA <- custA[1:50,c(2,4,6,8,3,5,7,9)] %>%
chisq.test(test_custA)
chi_custA
##
## Pearson's Chi-squared test
##
## data: .
## X-squared = 5112.2, df = 343, p-value < 2.2e-16
head(chi_custA$observed)
## Q1_17 Q2_17 Q3_17 Q4_17 Q1_18 Q2_18 Q3_18 Q4_18
## [1,] 3 1 1 1 1 1 1 1
## [2,] 1 1 1 1 1 1 2 1
## [3,] 1 1 6 1 1 5 1 1
## [4,] 1 19 1 1 1 1 1 1
## [5,] 1 1 1 15 1 1 1 1
## [6,] 1 1 1 6 1 1 1 1
head(chi_custA$expected)
## Q1_17 Q2_17 Q3_17 Q4_17 Q1_18 Q2_18 Q3_18
## [1,] 0.6643151 1.787184 1.904762 0.8877131 1.528513 0.8406820 1.069959
## [2,] 0.5978836 1.608466 1.714286 0.7989418 1.375661 0.7566138 0.962963
## [3,] 1.1293357 3.038213 3.238095 1.5091123 2.598471 1.4291593 1.818930
## [4,] 1.7272193 4.646678 4.952381 2.3080541 3.974133 2.1857731 2.781893
## [5,] 1.4614932 3.931805 4.190476 1.9529688 3.362728 1.8495003 2.353909
## [6,] 0.8636096 2.323339 2.476190 1.1540270 1.987066 1.0928865 1.390947
## Q4_18
## [1,] 1.316872
## [2,] 1.185185
## [3,] 2.238683
## [4,] 3.423868
## [5,] 2.897119
## [6,] 1.711934
plot(chi_custA$residuals)
chi_custA <- custA[1:50,c(2,4,6,8,3)] %>%
chisq.test()
chi_custA
##
## Pearson's Chi-squared test
##
## data: .
## X-squared = 2496.8, df = 196, p-value < 2.2e-16
head(chi_custA$observed)
## Q1_17 Q2_17 Q3_17 Q4_17 Q1_18
## [1,] 3 1 1 1 1
## [2,] 1 1 1 1 1
## [3,] 1 1 6 1 1
## [4,] 1 19 1 1 1
## [5,] 1 1 1 15 1
## [6,] 1 1 1 6 1
head(chi_custA$expected)
## Q1_17 Q2_17 Q3_17 Q4_17 Q1_18
## [1,] 0.6866319 1.847222 1.96875 0.9175347 1.579861
## [2,] 0.4904514 1.319444 1.40625 0.6553819 1.128472
## [3,] 0.9809028 2.638889 2.81250 1.3107639 2.256944
## [4,] 2.2560764 6.069444 6.46875 3.0147569 5.190972
## [5,] 1.8637153 5.013889 5.34375 2.4904514 4.288194
## [6,] 0.9809028 2.638889 2.81250 1.3107639 2.256944
plot(chi_custA$residuals)
(gather((as.data.frame(chi_custA$residuals)),"Qt","Val")) %>% ggplot(mapping = aes(x=Qt,y= Val))+
geom_col()
# Test 2
chi_custA <- custA[sample(1:nrow(custA),500),c(2,4,6,8,3,5,7,9)] %>%
chisq.test(simulate.p.value = TRUE)
chi_custA
##
## Pearson's Chi-squared test with simulated p-value (based on 2000
## replicates)
##
## data: .
## X-squared = 37353, df = NA, p-value = 0.0004998
head(chi_custA$observed)
## Q1_17 Q2_17 Q3_17 Q4_17 Q1_18 Q2_18 Q3_18 Q4_18
## [1,] 1 1 1 1 4 1 1 1
## [2,] 1 1 1 1 3 1 1 1
## [3,] 1 1 1 1 1 2 1 1
## [4,] 1 1 1 1 1 1 1 6
## [5,] 1 1 10 1 1 5 1 1
## [6,] 1 1 1 1 10 1 1 1
head(chi_custA$expected)
## Q1_17 Q2_17 Q3_17 Q4_17 Q1_18 Q2_18 Q3_18
## [1,] 1.625146 1.396785 1.473191 1.0636853 1.801998 1.292047 1.327246
## [2,] 1.477406 1.269804 1.339265 0.9669867 1.638180 1.174588 1.206587
## [3,] 1.329665 1.142824 1.205338 0.8702880 1.474362 1.057129 1.085928
## [4,] 1.920627 1.650745 1.741044 1.2570827 2.129634 1.526965 1.568563
## [5,] 3.102552 2.666589 2.812456 2.0306720 3.440178 2.466635 2.533833
## [6,] 2.511590 2.158667 2.276750 1.6438773 2.784906 1.996800 2.051198
## Q4_18
## [1,] 1.0199017
## [2,] 0.9271833
## [3,] 0.8344650
## [4,] 1.2053383
## [5,] 1.9470850
## [6,] 1.5762117
round(chi_custA$residuals, 3)
## Q1_17 Q2_17 Q3_17 Q4_17 Q1_18 Q2_18 Q3_18 Q4_18
## [1,] -0.490 -0.336 -0.390 -0.062 1.637 -0.257 -0.284 -0.020
## [2,] -0.393 -0.239 -0.293 0.034 1.064 -0.161 -0.188 0.076
## [3,] -0.286 -0.134 -0.187 0.139 -0.391 0.917 -0.082 0.181
## [4,] -0.664 -0.506 -0.562 -0.229 -0.774 -0.426 -0.454 4.367
## [5,] -1.194 -1.021 4.286 -0.723 -1.316 1.613 -0.964 -0.679
## [6,] -0.954 -0.789 -0.846 -0.502 4.324 -0.705 -0.734 -0.459
## [7,] -0.286 -0.134 -0.187 0.139 -0.391 0.917 -0.082 0.181
## [8,] -0.393 -0.239 -0.293 0.034 -0.499 -0.161 -0.188 2.153
## [9,] -2.055 -1.843 -1.917 -1.489 10.528 -1.739 -1.775 -1.437
## [10,] -2.124 -1.909 12.602 -1.549 -2.277 -1.802 -1.839 -1.496
## [11,] 3.885 -0.656 -0.712 -0.374 -0.930 -0.574 -0.602 -0.331
## [12,] -2.500 -2.264 -2.346 -1.873 -2.669 -2.148 -2.188 18.998
## [13,] -0.167 -0.016 -0.069 0.257 -0.271 0.062 0.035 0.300
## [14,] -1.714 -1.520 -1.587 -1.191 -1.853 4.767 -1.456 5.825
## [15,] -1.947 -1.741 -1.813 7.995 -2.094 -1.639 -1.674 5.049
## [16,] -0.580 -0.424 -0.479 -0.149 2.164 -0.345 -0.372 -0.107
## [17,] 5.844 -0.966 -1.026 -0.672 -1.258 -0.880 -0.910 -0.627
## [18,] -1.450 -1.267 -1.330 -0.955 7.143 -1.175 -1.207 -0.909
## [19,] -0.580 -0.424 -0.479 -0.149 2.164 -0.345 -0.372 -0.107
## [20,] -2.641 -2.398 -2.482 -1.994 13.770 -2.278 -2.319 -1.935
## [21,] -0.286 -0.134 -0.187 0.139 -0.391 -0.056 0.877 0.181
## [22,] -0.817 -0.656 -0.712 5.438 -0.930 -0.574 -0.602 -0.331
## [23,] -0.817 -0.656 -0.712 -0.374 -0.930 4.700 -0.602 -0.331
## [24,] -0.887 -0.724 -0.781 -0.440 -1.001 -0.641 5.088 -0.397
## [25,] -1.079 -0.909 5.927 -0.618 -1.197 -0.825 -0.854 -0.574
## [26,] -0.580 -0.424 -0.479 3.564 -0.689 -0.345 -0.372 -0.107
## [27,] -1.018 -0.850 -0.909 7.018 -1.135 -0.766 -0.795 -0.518
## [28,] -2.020 4.402 3.734 -1.458 -2.169 -1.706 -1.742 1.190
## [29,] -0.393 -0.239 -0.293 0.034 -0.499 -0.161 -0.188 2.153
## [30,] -1.402 -1.220 -1.283 -0.912 -1.530 -1.130 8.627 -0.866
## [31,] -1.402 -1.220 -1.283 -0.912 -1.530 8.791 -1.161 -0.866
## [32,] -0.954 -0.789 -0.846 -0.502 -1.070 -0.705 -0.734 6.710
## [33,] -0.664 -0.506 3.228 -0.229 -0.774 -0.426 -0.454 -0.187
## [34,] -3.147 7.480 -2.968 -2.422 -3.344 -2.739 -2.785 11.963
## [35,] 1.965 -1.520 -1.587 -1.191 5.135 -1.423 -1.456 -1.142
## [36,] 7.145 -1.173 -1.235 -0.867 -1.479 -1.083 -1.114 -0.821
## [37,] 5.955 -2.345 6.542 -1.946 -2.758 -2.227 -2.267 -1.888
## [38,] -1.018 -0.850 -0.909 -0.561 4.689 -0.766 -0.795 -0.518
## [39,] -0.743 -0.583 -0.639 -0.304 -0.854 -0.503 4.086 -0.262
## [40,] -0.167 -0.016 -0.069 0.257 -0.271 0.062 0.035 0.300
## [41,] -1.910 -1.706 -1.777 -1.363 -2.056 12.306 -1.640 -1.312
## [42,] -0.664 -0.506 2.470 -0.229 -0.089 -0.426 -0.454 -0.187
## [43,] -1.714 -1.520 -1.587 -1.191 8.629 -1.423 -1.456 -1.142
## [44,] 6.682 1.291 -1.665 -1.262 -1.936 -1.498 -1.038 -1.212
## [45,] 7.592 -1.398 -1.463 -1.077 -1.721 -1.304 -0.267 -1.030
## [46,] -0.580 -0.424 -0.479 -0.149 2.164 -0.345 -0.372 -0.107
## [47,] -0.817 -0.656 -0.712 -0.374 -0.930 -0.574 4.601 -0.331
## [48,] -1.873 -1.670 -1.740 -1.330 -2.017 -1.570 11.830 -1.280
## [49,] -0.167 -0.016 -0.069 0.257 -0.271 0.062 0.035 0.300
## [50,] -1.018 -0.850 -0.909 -0.561 4.689 -0.766 -0.795 -0.518
## [51,] -1.079 -0.909 -0.968 -0.618 5.038 -0.825 -0.854 -0.574
## [52,] -0.393 -0.239 1.435 0.034 -0.499 -0.161 -0.188 0.076
## [53,] -0.743 -0.583 -0.639 -0.304 -0.854 4.176 -0.530 -0.262
## [54,] -1.079 -0.909 -0.968 -0.618 -1.197 -0.825 6.411 -0.574
## [55,] -1.587 -1.398 -1.463 -1.077 -1.721 10.075 -1.336 -1.030
## [56,] 7.125 -2.550 -2.637 -2.130 5.227 -2.425 -2.468 -2.069
## [57,] -0.286 -0.134 -0.187 1.211 -0.391 -0.056 -0.082 0.181
## [58,] 7.444 -1.220 -1.283 -0.912 -1.530 -1.130 -1.161 -0.866
## [59,] -0.286 -0.134 -0.187 0.139 -0.391 -0.056 0.877 0.181
## [60,] 10.493 -1.706 -1.777 -1.363 -2.056 -1.605 -1.640 -1.312
## [61,] -0.490 -0.336 -0.390 -0.062 1.637 -0.257 -0.284 -0.020
## [62,] -0.887 4.889 -0.781 -0.440 -1.001 -0.641 -0.670 -0.397
## [63,] -1.137 -0.966 -1.026 -0.672 -1.258 -0.880 -0.910 8.185
## [64,] -1.947 -1.741 11.486 -1.395 -2.094 -1.639 -1.674 -1.344
## [65,] -3.306 -3.023 -3.120 -2.556 17.416 -2.884 -2.931 -2.488
## [66,] -0.817 -0.656 -0.712 -0.374 -0.930 -0.574 4.601 -0.331
## [67,] -0.954 -0.789 -0.846 -0.502 -1.070 -0.705 -0.734 6.710
## [68,] -2.090 -1.876 -1.950 15.352 -2.242 -1.771 -1.807 -1.467
## [69,] 8.820 -1.439 -1.506 -1.116 -1.766 -1.344 -1.377 -1.068
## [70,] -0.887 -0.724 -0.781 -0.440 3.940 -0.641 -0.670 -0.397
## [71,] -0.490 -0.336 -0.390 -0.062 -0.597 -0.257 2.320 -0.020
## [72,] -2.055 -1.843 -1.490 -1.489 -2.206 4.185 6.768 -1.437
## [73,] -0.817 -0.656 -0.712 5.438 -0.930 -0.574 -0.602 -0.331
## [74,] 5.115 -0.850 -0.909 -0.561 -1.135 -0.766 -0.795 -0.518
## [75,] -0.393 -0.239 1.435 0.034 -0.499 -0.161 -0.188 0.076
## [76,] -1.194 -1.021 -1.081 8.399 -1.316 -0.934 -0.964 -0.679
## [77,] -1.497 -1.312 -1.376 -0.997 -1.628 -1.219 -1.251 11.058
## [78,] -1.873 -1.670 -1.740 -1.330 -2.017 -1.570 7.512 3.647
## [79,] -1.497 -1.312 -1.376 -0.997 -1.628 -1.219 9.276 -0.950
## [80,] -1.587 -1.398 6.148 -1.077 -1.721 1.947 -1.336 -1.030
## [81,] 5.844 -0.966 -1.026 -0.672 -1.258 -0.880 -0.910 -0.627
## [82,] -1.714 -1.520 10.006 -1.191 -1.853 -1.423 -1.456 -1.142
## [83,] -0.490 -0.336 -0.390 -0.062 1.637 -0.257 -0.284 -0.020
## [84,] -0.167 -0.016 -0.069 0.257 -0.271 0.062 0.035 0.300
## [85,] 0.581 -0.134 -0.187 0.139 -0.391 -0.056 -0.082 0.181
## [86,] -1.673 -1.480 -1.547 1.734 -1.810 -0.336 6.856 -1.106
## [87,] -1.714 10.386 -1.587 -1.191 -1.853 -1.423 -1.456 -1.142
## [88,] -1.194 -1.021 -1.081 2.084 -1.316 -0.934 4.690 -0.679
## [89,] -1.137 -0.966 -1.026 -0.672 -1.258 -0.880 -0.910 8.185
## [90,] -1.137 4.681 0.807 -0.672 -1.258 -0.880 -0.910 -0.627
## [91,] -1.301 -1.124 -1.185 -0.821 -1.426 3.224 3.737 -0.776
## [92,] -0.664 -0.506 -0.562 -0.229 -0.774 3.620 -0.454 -0.187
## [93,] -1.910 11.673 -1.777 -1.363 -2.056 -1.605 -1.640 -1.312
## [94,] -1.248 7.303 -1.134 -0.773 -1.372 -0.985 -1.015 -0.728
## [95,] -1.795 -1.597 -1.665 13.077 -1.936 -1.498 -1.532 -1.212
## [96,] -2.256 -2.034 -2.110 16.631 -2.414 -1.924 -1.961 -1.608
## [97,] -1.630 -1.439 -1.506 -1.116 -1.766 -1.344 10.186 -1.068
## [98,] 8.432 1.867 -2.016 -1.578 -2.312 -1.833 -1.870 -1.525
## [99,] -1.497 -1.312 -1.376 10.762 -1.628 -1.219 -1.251 -0.950
## [100,] -3.052 -2.785 -2.877 19.422 -3.245 -2.653 0.274 -2.278
## [101,] -1.630 -1.439 -1.506 -1.116 8.158 -1.344 -1.377 -1.068
## [102,] 3.015 -0.724 0.586 -0.440 -1.001 -0.641 -0.670 -0.397
## [103,] 4.725 -0.789 -0.846 -0.502 -1.070 -0.705 -0.734 -0.459
## [104,] -0.580 -0.424 -0.479 -0.149 2.164 -0.345 -0.372 -0.107
## [105,] -1.301 -1.124 1.664 -0.821 -1.426 5.049 -1.066 -0.776
## [106,] 5.491 -1.559 2.654 -1.227 -1.895 -1.461 -1.494 -1.178
## [107,] -0.664 -0.506 3.228 -0.229 -0.774 -0.426 -0.454 -0.187
## [108,] -1.587 -1.398 -1.463 -1.077 7.914 -1.304 -1.336 -1.030
## [109,] 5.513 -1.312 -1.376 2.097 -1.628 -1.219 -1.251 -0.950
## [110,] -1.673 -1.480 9.741 -1.154 -1.810 -1.384 -1.417 -1.106
## [111,] -1.450 -1.267 -1.330 -0.955 7.143 -1.175 -1.207 -0.909
## [112,] -0.954 -0.789 -0.846 -0.502 4.324 -0.705 -0.734 -0.459
## [113,] 9.806 -1.597 -1.665 -1.262 -1.936 -1.498 -1.532 -1.212
## [114,] -1.137 6.564 -1.026 -0.672 -1.258 -0.880 -0.910 -0.627
## [115,] -1.587 7.982 -1.463 -1.077 -1.721 -1.304 -1.336 0.800
## [116,] -0.167 -0.016 -0.069 0.257 -0.271 0.062 0.035 0.300
## [117,] -2.441 -2.209 14.602 -1.822 -2.607 -2.094 -2.133 -1.766
## [118,] -0.954 5.337 -0.846 -0.502 -1.070 -0.705 -0.734 -0.459
## [119,] -0.167 -0.016 -0.069 0.257 -0.271 0.062 0.035 0.300
## [120,] -1.137 -0.966 -1.026 -0.672 -1.258 6.949 -0.910 -0.627
## [121,] -1.673 8.096 -1.547 -1.154 -0.035 -1.384 -1.417 -1.106
## [122,] -1.542 -1.355 -1.420 -1.038 -1.675 -1.262 9.587 -0.991
## [123,] -1.137 -0.966 -1.026 -0.672 -1.258 6.949 -0.910 -0.627
## [124,] -0.817 -0.656 -0.712 -0.374 -0.930 -0.574 -0.602 5.604
## [125,] -1.910 -1.706 11.251 -1.363 -2.056 -1.605 -1.640 -1.312
## [126,] -0.167 -0.016 -0.069 0.257 -0.271 0.062 0.035 0.300
## [127,] -0.490 2.203 -0.390 -0.062 -0.597 -0.257 -0.284 -0.020
## [128,] -0.817 -0.656 -0.712 -0.374 -0.930 -0.574 -0.602 5.604
## [129,] -0.817 -0.656 -0.712 -0.374 -0.930 4.700 -0.602 -0.331
## [130,] 5.487 -0.909 -0.968 -0.618 -1.197 -0.825 -0.854 -0.574
## [131,] 6.187 -1.021 -1.081 -0.723 -1.316 -0.934 -0.964 -0.679
## [132,] -0.286 -0.134 -0.187 0.139 0.433 -0.056 -0.082 0.181
## [133,] -2.319 -2.094 -2.171 12.983 -2.480 -1.982 1.681 -1.662
## [134,] -1.873 -1.670 11.012 -1.330 -2.017 -1.570 -1.604 -1.280
## [135,] -0.664 -0.506 -0.562 -0.229 2.652 -0.426 -0.454 -0.187
## [136,] -0.167 -0.016 -0.069 0.257 -0.271 0.062 0.035 0.300
## [137,] -1.947 -1.741 -1.813 1.735 -2.094 9.721 -1.674 -1.344
## [138,] -1.542 9.252 -1.420 -1.038 -1.675 -1.262 -1.294 -0.991
## [139,] -1.018 -0.850 -0.909 -0.561 3.524 -0.766 0.562 -0.518
## [140,] -1.587 -1.398 -1.463 -1.077 -1.721 -1.304 9.890 -1.030
## [141,] -0.490 -0.336 -0.390 -0.062 1.637 -0.257 -0.284 -0.020
## [142,] -1.542 -1.355 8.908 -1.038 -1.675 -1.262 -1.294 -0.991
## [143,] -1.947 11.916 -1.813 -1.395 -2.094 -1.639 -1.674 -1.344
## [144,] -2.191 -1.972 -2.048 -1.607 -2.347 14.229 -1.901 -1.553
## [145,] -4.065 25.634 -3.847 -3.189 -4.304 -3.571 -3.626 -3.111
## [146,] -2.191 -1.972 -2.048 -1.607 -2.347 14.229 -1.901 -1.553
## [147,] 2.157 7.367 -2.016 -0.123 -2.312 -1.833 -1.870 -1.525
## [148,] -1.497 -1.312 -1.376 10.762 -1.628 -1.219 -1.251 -0.950
## [149,] 5.487 -0.909 -0.968 -0.618 -1.197 -0.825 -0.854 -0.574
## [150,] -1.301 -1.124 -1.185 -0.821 -1.426 -1.035 -1.066 9.496
## [151,] -0.743 3.917 -0.639 -0.304 -0.854 -0.503 -0.530 -0.262
## [152,] -0.580 -0.424 -0.479 -0.149 -0.689 3.024 -0.372 -0.107
## [153,] 6.517 -1.073 -1.134 -0.773 -1.372 -0.985 -1.015 -0.728
## [154,] -1.352 -1.173 -1.235 -0.867 -1.479 3.086 4.175 -0.821
## [155,] -0.167 -0.016 -0.069 0.257 -0.271 0.062 0.035 0.300
## [156,] -0.393 -0.239 -0.293 2.067 -0.499 -0.161 -0.188 0.076
## [157,] -1.194 -1.021 -1.081 -0.723 -1.316 -0.934 -0.964 8.638
## [158,] -1.402 -1.220 -1.283 -0.912 -1.530 8.791 -1.161 -0.866
## [159,] 0.581 -0.134 -0.187 0.139 -0.391 -0.056 -0.082 0.181
## [160,] 9.074 -1.480 -1.547 -1.154 -1.810 -1.384 -1.417 -1.106
## [161,] -0.580 -0.424 -0.479 -0.149 2.164 -0.345 -0.372 -0.107
## [162,] -1.301 7.653 -1.185 -0.821 -1.426 -1.035 -1.066 -0.776
## [163,] -3.479 -3.185 16.618 -2.701 -3.691 -3.041 -1.023 0.402
## [164,] -1.248 7.303 -1.134 -0.773 -1.372 -0.985 -1.015 -0.728
## [165,] -2.124 -1.909 5.934 -1.549 -2.277 -1.802 5.186 -1.496
## [166,] -2.319 6.726 5.246 -1.717 -2.480 -1.982 -2.020 -1.662
## [167,] -0.817 -0.656 -0.712 -0.374 -0.930 4.700 -0.602 -0.331
## [168,] 5.844 -0.966 -1.026 -0.672 -1.258 -0.880 -0.910 -0.627
## [169,] -1.755 -1.559 -1.627 -1.227 4.986 3.110 -1.494 -1.178
## [170,] -1.137 -0.966 -1.026 -0.672 -1.258 -0.880 6.815 -0.627
## [171,] 6.517 -1.073 -1.134 -0.773 -1.372 -0.985 -1.015 -0.728
## [172,] 11.353 -1.843 -1.917 -1.489 -2.206 -1.739 -1.775 -1.437
## [173,] -0.954 -0.789 -0.846 -0.502 -1.070 -0.705 -0.734 6.710
## [174,] -2.223 4.203 -0.870 -1.635 4.905 -1.894 -1.931 -1.581
## [175,] 4.725 -0.789 -0.846 -0.502 -1.070 -0.705 -0.734 -0.459
## [176,] -0.743 -0.583 -0.639 -0.304 -0.854 4.176 -0.530 -0.262
## [177,] -1.248 -1.073 -1.134 -0.773 -1.372 -0.985 7.577 -0.728
## [178,] -1.984 -1.776 -1.848 -1.427 -2.132 -1.673 12.582 -1.376
## [179,] -1.542 -1.355 -1.420 -1.038 -1.675 -1.262 -1.294 11.422
## [180,] -1.587 3.813 -1.463 -1.077 -1.721 4.656 -1.336 -1.030
## [181,] -1.248 -1.073 -1.134 8.826 -1.372 -0.985 -1.015 -0.728
## [182,] -1.194 6.940 -1.081 -0.723 -1.316 -0.934 -0.964 -0.679
## [183,] -0.393 -0.239 1.435 0.034 -0.499 -0.161 -0.188 0.076
## [184,] -0.167 -0.016 -0.069 0.257 -0.271 0.062 0.035 0.300
## [185,] -1.079 -0.909 -0.968 -0.618 -1.197 6.539 -0.854 -0.574
## [186,] -0.167 -0.016 -0.069 0.257 -0.271 0.062 0.035 0.300
## [187,] -0.887 -0.724 -0.781 -0.440 -1.001 5.194 -0.670 -0.397
## [188,] 3.885 -0.656 -0.712 -0.374 -0.930 -0.574 -0.602 -0.331
## [189,] -1.248 -1.073 -1.134 -0.773 -1.372 -0.985 7.577 -0.728
## [190,] 3.885 -0.656 -0.712 -0.374 -0.930 -0.574 -0.602 -0.331
## [191,] -1.834 -1.634 -1.703 -1.296 -1.977 11.782 -1.568 -1.246
## [192,] -0.580 2.816 -0.479 -0.149 -0.689 -0.345 -0.372 -0.107
## [193,] -0.393 -0.239 -0.293 0.034 1.064 -0.161 -0.188 0.076
## [194,] 8.017 -1.312 -1.376 -0.997 -1.628 -1.219 -1.251 -0.950
## [195,] -0.580 2.816 -0.479 -0.149 -0.689 -0.345 -0.372 -0.107
## [196,] -0.393 -0.239 -0.293 0.034 -0.499 1.684 -0.188 0.076
## [197,] -2.020 -1.810 11.943 -1.458 -2.169 -1.706 -1.742 -1.407
## [198,] -1.450 -1.267 -1.330 10.397 -1.579 -1.175 -1.207 -0.909
## [199,] -1.079 -0.909 -0.341 6.760 -1.197 -0.825 -0.854 -0.574
## [200,] -2.319 -2.094 -2.171 -1.717 -2.480 15.108 -2.020 -1.662
## [201,] -0.887 -0.724 -0.781 -0.440 -1.001 -0.641 5.088 -0.397
## [202,] -0.490 -0.336 -0.390 -0.062 -0.597 -0.257 2.320 -0.020
## [203,] -2.055 -1.843 -1.917 15.084 -2.206 -1.739 -1.775 -1.437
## [204,] -1.248 -1.073 -1.134 -0.773 -1.372 -0.985 7.577 -0.728
## [205,] -0.664 3.385 -0.562 -0.229 -0.774 -0.426 -0.454 -0.187
## [206,] -1.194 -1.021 6.671 -0.723 -1.316 -0.934 -0.964 -0.679
## [207,] -0.664 -0.506 3.228 -0.229 -0.774 -0.426 -0.454 -0.187
## [208,] -1.248 -1.073 -1.134 -0.773 -1.372 -0.985 7.577 -0.728
## [209,] -0.743 -0.583 -0.639 4.853 -0.854 -0.503 -0.530 -0.262
## [210,] -2.641 -2.398 -2.482 -1.994 9.623 1.112 -0.832 -1.935
## [211,] 9.323 -1.520 -1.587 -1.191 -1.853 -1.423 -1.456 -1.142
## [212,] 12.545 -2.034 -2.110 -1.663 -2.414 -1.924 -1.961 -1.608
## [213,] -0.817 -0.656 4.227 -0.374 -0.930 -0.574 -0.602 -0.331
## [214,] -0.167 -0.016 -0.069 0.257 -0.271 0.062 0.035 0.300
## [215,] -1.352 -1.173 -1.235 -0.867 -1.479 -1.083 8.288 -0.821
## [216,] -2.124 -1.909 -1.983 12.673 -0.017 -1.802 -1.839 -1.496
## [217,] -0.817 -0.656 -0.712 0.456 2.898 -0.574 -0.602 -0.331
## [218,] -1.450 -1.267 -1.330 -0.955 7.143 -1.175 -1.207 -0.909
## [219,] -0.167 -0.016 -0.069 0.257 -0.271 0.062 0.035 0.300
## [220,] -0.887 -0.724 -0.781 -0.440 3.940 -0.641 -0.670 -0.397
## [221,] -0.887 -0.724 -0.781 -0.440 -1.001 -0.641 5.088 -0.397
## [222,] -1.248 -1.073 -1.134 -0.773 3.896 -0.985 1.440 -0.728
## [223,] -1.079 -0.909 -0.968 -0.618 -1.197 -0.825 6.411 -0.574
## [224,] -2.223 -2.003 -0.870 -1.635 -2.381 -1.894 0.615 12.461
## [225,] -0.286 -0.134 -0.187 0.139 0.433 -0.056 -0.082 0.181
## [226,] 8.661 -1.559 -1.627 -1.227 -1.895 -1.461 -0.492 -1.178
## [227,] -1.497 -1.312 -1.376 -0.997 -1.628 -1.219 -1.251 11.058
## [228,] -1.194 -1.021 -1.081 8.399 -1.316 -0.934 -0.964 -0.679
## [229,] 3.057 -2.034 -2.110 -1.663 6.595 -1.924 -1.961 -1.608
## [230,] -0.580 -0.424 -0.479 -0.149 -0.689 -0.345 2.952 -0.107
## [231,] -0.743 -0.583 -0.639 -0.304 -0.854 -0.503 4.086 -0.262
## [232,] -1.079 6.172 -0.968 -0.618 -1.197 -0.825 -0.854 -0.574
## [233,] 2.170 -1.439 -1.506 7.104 -1.766 -1.344 -1.377 -1.068
## [234,] -0.954 -0.789 5.118 -0.502 -1.070 -0.705 -0.734 -0.459
## [235,] -2.287 -2.064 -2.141 -1.690 -2.448 14.893 -1.991 -1.636
## [236,] -1.352 -1.173 -1.235 -0.867 -1.479 -1.083 -1.114 9.904
## [237,] -3.004 -2.739 -2.830 -2.301 -3.195 14.350 2.701 -2.238
## [238,] -0.167 -0.016 -0.069 0.257 -0.271 0.062 0.035 0.300
## [239,] -0.817 -0.656 -0.712 -0.374 -0.930 -0.574 4.601 -0.331
## [240,] -1.079 6.172 -0.968 -0.618 -1.197 -0.825 -0.854 -0.574
## [241,] 3.885 -0.656 -0.712 -0.374 -0.930 -0.574 -0.602 -0.331
## [242,] 9.074 -1.480 -1.547 -1.154 -1.810 -1.384 -1.417 -1.106
## [243,] -0.580 -0.424 -0.479 -0.149 -0.689 3.024 -0.372 -0.107
## [244,] -2.256 -2.034 -2.110 -1.663 -2.414 14.675 -1.961 -1.608
## [245,] -1.587 -1.398 -1.463 -1.077 -1.721 -1.304 -1.336 11.777
## [246,] -1.497 -1.312 -1.376 -0.997 7.407 -1.219 -1.251 -0.950
## [247,] -0.167 -0.016 -0.069 0.257 -0.271 0.062 0.035 0.300
## [248,] 7.145 -1.173 -1.235 -0.867 -1.479 -1.083 -1.114 -0.821
## [249,] 5.844 -0.966 -1.026 -0.672 -1.258 -0.880 -0.910 -0.627
## [250,] -3.803 -3.488 15.078 -2.971 1.833 -1.672 -3.386 -2.896
## [251,] -1.248 -1.073 7.022 -0.773 -1.372 -0.985 -1.015 -0.728
## [252,] 3.885 -0.656 -0.712 -0.374 -0.930 -0.574 -0.602 -0.331
## [253,] -0.490 -0.336 -0.390 -0.062 1.637 -0.257 -0.284 -0.020
## [254,] -1.497 8.950 -1.376 -0.997 -1.628 -1.219 -1.251 -0.950
## [255,] -1.402 -1.220 -1.283 10.022 -1.530 -1.130 -1.161 -0.866
## [256,] -0.664 -0.506 -0.562 -0.229 -0.774 -0.426 -0.454 4.367
## [257,] -2.500 -2.264 -2.346 -1.873 1.662 -0.181 9.069 -1.815
## [258,] -2.381 -2.152 -2.231 12.639 -0.469 -2.039 -2.078 0.585
## [259,] -1.194 -1.021 -1.081 -0.723 -1.316 7.344 -0.964 -0.679
## [260,] -1.248 -1.073 -1.134 -0.773 6.003 -0.985 -1.015 -0.728
## [261,] -1.497 -1.312 8.616 -0.997 -1.628 -1.219 -1.251 -0.950
## [262,] 10.039 -1.634 -1.703 -1.296 -1.977 -1.534 -1.568 -1.246
## [263,] 10.493 -1.706 -1.777 -1.363 -2.056 -1.605 -1.640 -1.312
## [264,] -0.954 -0.789 -0.846 -0.502 -1.070 5.664 -0.734 -0.459
## [265,] -0.887 4.889 -0.781 -0.440 -1.001 -0.641 -0.670 -0.397
## [266,] -1.947 -1.741 -1.813 -1.395 9.930 -1.639 -1.674 -1.344
## [267,] -1.630 9.832 -1.506 -1.116 -1.766 -1.344 -1.377 -1.068
## [268,] -1.248 -1.073 -1.134 -0.773 -1.372 -0.985 7.577 -0.728
## [269,] -0.490 1.357 -0.390 -0.062 -0.597 -0.257 -0.284 0.970
## [270,] -0.490 -0.336 -0.390 2.847 -0.597 -0.257 -0.284 -0.020
## [271,] -1.402 -1.220 -1.283 -0.912 -1.530 -1.130 8.627 -0.866
## [272,] -0.817 -0.656 -0.712 -0.374 -0.930 -0.574 -0.602 5.604
## [273,] -1.018 -0.850 5.532 -0.561 -1.135 -0.766 -0.795 -0.518
## [274,] -0.286 -0.134 -0.187 0.139 -0.391 -0.056 0.877 0.181
## [275,] -0.167 -0.016 -0.069 0.257 -0.271 0.062 0.035 0.300
## [276,] -0.954 -0.789 -0.846 -0.502 4.324 -0.705 -0.734 -0.459
## [277,] -0.393 1.535 -0.293 0.034 -0.499 -0.161 -0.188 0.076
## [278,] 6.836 -1.124 -1.185 -0.821 -1.426 -1.035 -1.066 -0.776
## [279,] -1.673 -1.480 -1.547 12.130 -1.810 -1.384 -1.417 -1.106
## [280,] -1.673 -1.480 -1.547 -1.154 -1.810 -1.384 10.475 -1.106
## [281,] -0.817 2.967 -0.712 1.287 -0.930 -0.574 -0.602 -0.331
## [282,] -1.834 -1.634 -1.703 -1.296 9.299 -1.534 -1.568 -1.246
## [283,] -1.630 -1.439 -1.506 11.801 -1.766 -1.344 -1.377 -1.068
## [284,] 8.404 -1.520 -0.621 -1.191 -1.853 -1.423 -1.456 -1.142
## [285,] -0.393 -0.239 -0.293 0.034 -0.499 -0.161 -0.188 2.153
## [286,] 4.316 -0.724 -0.781 -0.440 -1.001 -0.641 -0.670 -0.397
## [287,] 7.444 -1.220 -1.283 -0.912 -1.530 -1.130 -1.161 -0.866
## [288,] -1.450 -1.267 -1.330 -0.955 -1.579 -1.175 8.956 -0.909
## [289,] -0.393 -0.239 -0.293 0.034 -0.499 -0.161 1.633 0.076
## [290,] -3.328 -3.044 -3.142 -2.574 -3.533 -2.904 21.599 -2.506
## [291,] 0.430 -0.239 0.571 0.034 -0.499 -0.161 -0.188 0.076
## [292,] -0.286 -0.134 -0.187 0.139 -0.391 0.917 -0.082 0.181
## [293,] 4.334 -1.876 -1.950 -1.519 -2.242 -1.771 6.189 -1.467
## [294,] -0.664 -0.506 -0.562 -0.229 -0.774 -0.426 3.538 -0.187
## [295,] -1.194 -1.021 -1.081 -0.723 5.693 -0.934 -0.964 -0.679
## [296,] 9.074 -1.480 -1.547 -1.154 -1.810 -1.384 -1.417 -1.106
## [297,] -1.542 -1.355 -1.420 -1.038 -1.675 -1.262 -1.294 11.422
## [298,] -0.743 -0.583 -0.639 -0.304 3.108 -0.503 -0.530 -0.262
## [299,] -0.664 -0.506 3.228 -0.229 -0.774 -0.426 -0.454 -0.187
## [300,] -0.490 -0.336 2.082 -0.062 -0.597 -0.257 -0.284 -0.020
## [301,] -0.743 -0.583 -0.639 -0.304 3.108 -0.503 -0.530 -0.262
## [302,] -2.696 8.243 -2.535 -2.040 1.833 -2.328 0.921 -1.981
## [303,] -0.817 -0.656 -0.712 5.438 -0.930 -0.574 -0.602 -0.331
## [304,] -1.194 -1.021 -1.081 -0.723 -1.316 -0.934 2.806 4.338
## [305,] -0.743 -0.583 -0.639 -0.304 3.108 -0.503 -0.530 -0.262
## [306,] -1.137 -0.966 -1.026 -0.672 -1.258 6.949 -0.910 -0.627
## [307,] 3.429 -0.583 -0.639 -0.304 -0.854 -0.503 -0.530 -0.262
## [308,] 8.291 -1.355 -1.420 -1.038 -1.675 -1.262 -1.294 -0.991
## [309,] -0.817 -0.656 -0.712 5.438 -0.930 -0.574 -0.602 -0.331
## [310,] -0.954 -0.789 5.118 -0.502 -1.070 -0.705 -0.734 -0.459
## [311,] -0.286 -0.134 -0.187 0.139 -0.391 0.917 -0.082 0.181
## [312,] -1.137 -0.966 6.307 -0.672 -1.258 -0.880 -0.910 -0.627
## [313,] -2.557 -2.319 -2.401 -1.922 -2.729 9.393 -2.241 6.401
## [314,] -0.954 -0.789 -0.846 6.517 -1.070 -0.705 -0.734 -0.459
## [315,] -1.834 -1.634 0.606 -1.296 3.035 -1.534 3.298 -1.246
## [316,] -1.450 8.640 -1.330 -0.955 -1.579 -1.175 -1.207 -0.909
## [317,] -1.910 11.673 -1.777 -1.363 -2.056 -1.605 -1.640 -1.312
## [318,] -1.630 -0.415 3.483 -1.116 -1.766 -1.344 2.828 0.131
## [319,] -0.664 -0.506 -0.562 -0.229 2.652 -0.426 -0.454 -0.187
## [320,] -0.580 2.006 -0.479 -0.149 0.024 -0.345 -0.372 -0.107
## [321,] -4.766 -4.388 29.103 -3.770 -5.039 -4.203 -4.266 -3.681
## [322,] -2.381 -2.152 -2.231 -1.770 12.332 -2.039 -2.078 -1.715
## [323,] -0.393 -0.239 -0.293 0.034 -0.499 1.684 -0.188 0.076
## [324,] -0.580 -0.424 -0.479 -0.149 -0.689 3.024 -0.372 -0.107
## [325,] -0.580 -0.424 2.676 -0.149 -0.689 -0.345 -0.372 -0.107
## [326,] -1.402 -1.220 8.007 -0.912 -1.530 -1.130 -1.161 -0.866
## [327,] -2.157 -1.941 12.815 -1.578 -2.312 -1.833 -1.870 -1.525
## [328,] -1.079 -0.909 -0.968 7.498 -1.197 -0.825 -0.854 -0.574
## [329,] -1.910 -1.706 -1.777 -1.363 -2.056 -1.605 -1.640 14.345
## [330,] -0.490 -0.336 -0.390 2.847 -0.597 -0.257 -0.284 -0.020
## [331,] -2.529 -2.292 -2.373 -1.897 -2.699 -2.175 16.251 -1.840
## [332,] -2.020 0.852 -1.882 -1.458 4.472 2.446 -1.742 -1.407
## [333,] -0.286 -0.134 0.724 0.139 -0.391 -0.056 -0.082 0.181
## [334,] -0.664 -0.506 -0.562 -0.229 2.652 -0.426 -0.454 -0.187
## [335,] -1.137 -0.966 3.251 -0.672 -1.258 -0.880 -0.910 3.044
## [336,] -2.124 -1.909 -1.983 -1.549 -0.017 -1.802 10.893 -1.496
## [337,] -2.090 12.846 -1.950 -1.519 -2.242 -1.771 -1.807 -1.467
## [338,] -1.352 -1.173 -1.235 -0.867 6.591 -1.083 -1.114 -0.821
## [339,] -1.194 6.940 -1.081 -0.723 -1.316 -0.934 -0.964 -0.679
## [340,] -2.441 -2.209 -2.289 -1.822 12.665 -2.094 -2.133 -1.766
## [341,] -2.470 9.602 -2.317 -1.847 -2.638 -2.121 3.716 -1.791
## [342,] -0.393 -0.239 -0.293 0.034 1.064 -0.161 -0.188 0.076
## [343,] -1.947 -1.741 -1.813 2.256 7.124 -1.639 -1.674 -1.344
## [344,] -1.497 -1.312 -1.376 -0.997 -1.628 -1.219 -1.251 11.058
## [345,] -1.587 9.546 -1.463 -1.077 -1.721 -1.304 -1.336 -1.030
## [346,] -0.393 -0.239 -0.293 0.034 -0.499 1.684 -0.188 0.076
## [347,] -1.248 -1.073 7.022 -0.773 -1.372 -0.985 -1.015 -0.728
## [348,] -1.630 9.832 -1.506 -1.116 -1.766 -1.344 -1.377 -1.068
## [349,] -2.557 -2.319 -2.401 2.338 10.034 -2.201 -2.241 -1.864
## [350,] -2.614 16.261 -2.455 -1.970 -2.787 -2.253 -2.293 -1.911
## [351,] -0.664 -0.506 -0.562 -0.229 -0.774 -0.426 3.538 -0.187
## [352,] -0.286 0.802 -0.187 0.139 -0.391 -0.056 -0.082 0.181
## [353,] -0.393 -0.239 -0.293 0.034 -0.499 -0.161 1.633 0.076
## [354,] -0.887 -0.724 -0.781 -0.440 3.940 -0.641 -0.670 -0.397
## [355,] -1.450 -1.267 -1.330 10.397 -1.579 -1.175 -1.207 -0.909
## [356,] -1.352 -1.173 7.689 -0.867 -1.479 -1.083 -1.114 -0.821
## [357,] -1.079 -0.909 -0.968 -0.618 -1.197 -0.825 -0.854 7.714
## [358,] -1.262 -1.819 15.616 -2.342 -3.245 -2.653 -2.698 -2.278
## [359,] -0.580 -0.424 -0.479 -0.149 2.164 -0.345 -0.372 -0.107
## [360,] 9.806 -1.597 -1.665 -1.262 -1.936 -1.498 -1.532 -1.212
## [361,] -1.352 -1.173 -1.235 -0.867 -1.479 8.446 -1.114 -0.821
## [362,] -1.714 6.914 -1.587 -1.191 -1.853 2.188 -1.456 -1.142
## [363,] -0.664 -0.506 -0.562 4.230 -0.774 -0.426 -0.454 -0.187
## [364,] -0.954 -0.789 -0.846 -0.502 -1.070 -0.705 -0.734 6.710
## [365,] -0.490 -0.336 -0.390 -0.062 -0.597 -0.257 2.320 -0.020
## [366,] 6.187 -1.021 -1.081 -0.723 -1.316 -0.934 -0.964 -0.679
## [367,] -1.194 -1.021 -1.081 -0.723 -1.316 7.344 -0.964 -0.679
## [368,] -0.286 0.802 -0.187 0.139 -0.391 -0.056 -0.082 0.181
## [369,] -0.393 -0.239 1.435 0.034 -0.499 -0.161 -0.188 0.076
## [370,] -1.673 -1.480 -1.547 -1.154 -1.810 -1.384 10.475 -1.106
## [371,] -0.664 -0.506 -0.562 -0.229 -0.774 3.620 -0.454 -0.187
## [372,] -2.287 -2.064 3.381 10.378 -2.448 -1.953 -1.991 -1.636
## [373,] -1.079 -0.909 -0.968 -0.618 -1.197 -0.825 -0.854 7.714
## [374,] -1.450 -0.166 -1.330 -0.955 -1.579 4.547 2.181 -0.909
## [375,] -0.167 -0.016 -0.069 0.257 -0.271 0.062 0.035 0.300
## [376,] -1.542 -1.355 -1.420 -1.038 -1.675 -1.262 9.587 -0.991
## [377,] -0.286 -0.134 0.724 0.139 -0.391 -0.056 -0.082 0.181
## [378,] -0.743 -0.583 -0.639 4.853 -0.854 -0.503 -0.530 -0.262
## [379,] -3.004 -2.739 -2.830 -2.301 2.263 13.333 -2.653 -2.238
## [380,] -1.673 10.113 -1.547 -1.154 -1.810 -1.384 -1.417 -1.106
## [381,] -2.223 -2.003 13.231 -1.635 -2.381 -1.894 -1.931 -1.581
## [382,] -1.714 -1.520 3.726 -1.191 3.825 -1.423 -1.456 -1.142
## [383,] -2.641 -2.398 -2.482 -1.994 -2.816 -2.278 17.007 -1.935
## [384,] 0.581 -0.134 -0.187 0.139 -0.391 -0.056 -0.082 0.181
## [385,] -0.286 -0.134 0.724 0.139 -0.391 -0.056 -0.082 0.181
## [386,] -1.834 -1.634 -1.703 -1.296 9.299 -1.534 -1.568 -1.246
## [387,] 3.885 -0.656 -0.712 -0.374 -0.930 -0.574 -0.602 -0.331
## [388,] -0.580 -0.424 -0.479 -0.149 2.164 -0.345 -0.372 -0.107
## [389,] -1.497 -1.312 -1.376 2.716 -1.628 -1.219 5.952 -0.950
## [390,] -0.664 -0.506 3.228 -0.229 -0.774 -0.426 -0.454 -0.187
## [391,] -0.286 -0.134 -0.187 0.139 -0.391 -0.056 0.877 0.181
## [392,] -0.664 -0.506 -0.562 -0.229 -0.774 -0.426 3.538 -0.187
## [393,] -0.580 -0.424 -0.479 -0.149 -0.689 -0.345 -0.372 3.685
## [394,] 10.493 -1.706 -1.777 -1.363 -2.056 -1.605 -1.640 -1.312
## [395,] 2.424 -0.424 -0.479 -0.149 -0.689 -0.345 -0.372 -0.107
## [396,] -0.817 4.417 -0.712 -0.374 -0.930 -0.574 -0.602 -0.331
## [397,] 8.669 -1.972 1.619 -1.607 -2.347 -1.864 -1.901 -1.553
## [398,] -0.664 -0.506 -0.562 -0.229 2.652 -0.426 -0.454 -0.187
## [399,] -0.167 -0.016 -0.069 0.257 -0.271 0.062 0.035 0.300
## [400,] -1.873 -1.670 -1.740 -1.330 -2.017 -1.570 -1.604 14.046
## [401,] -4.462 -4.104 -4.227 -3.519 23.712 -3.930 -3.989 -3.434
## [402,] 10.454 -0.784 0.100 -2.108 -2.957 -2.401 -2.443 -0.826
## [403,] -1.984 -1.776 -1.848 -1.427 10.132 -1.673 -1.708 -1.376
## [404,] -1.587 -1.398 -1.463 -1.077 6.079 0.864 -1.336 -1.030
## [405,] 2.353 -0.966 -1.026 -0.672 -1.258 -0.880 -0.910 3.779
## [406,] -2.723 -2.475 -2.560 -2.063 -2.901 17.866 -2.394 -2.003
## [407,] -1.079 6.172 -0.968 -0.618 -1.197 -0.825 -0.854 -0.574
## [408,] -0.010 8.991 -1.665 -1.262 -1.936 -1.498 -1.532 -1.212
## [409,] -1.301 -1.124 -1.185 -0.821 6.302 -1.035 -1.066 -0.776
## [410,] -0.286 -0.134 -0.187 1.211 -0.391 -0.056 -0.082 0.181
## [411,] -0.286 -0.134 -0.187 1.211 -0.391 -0.056 -0.082 0.181
## [412,] -1.402 -1.220 -1.283 -0.912 6.871 -1.130 -1.161 -0.866
## [413,] -1.194 -1.021 5.478 -0.723 -0.237 -0.934 -0.964 -0.679
## [414,] -0.167 -0.016 -0.069 0.257 -0.271 0.062 0.035 0.300
## [415,] -0.167 -0.016 -0.069 0.257 -0.271 0.062 0.035 0.300
## [416,] -1.714 -1.520 -1.587 -1.191 -1.853 -1.423 -1.456 12.791
## [417,] -1.079 -0.909 -0.968 -0.618 -1.197 -0.825 6.411 -0.574
## [418,] -1.402 -1.220 -1.283 -0.912 -1.530 -1.130 8.627 -0.866
## [419,] -0.286 -0.134 -0.187 0.139 -0.391 -0.056 0.877 0.181
## [420,] 7.303 -1.559 -1.627 -1.227 0.255 -1.461 -1.494 -1.178
## [421,] 0.581 -0.134 -0.187 0.139 -0.391 -0.056 -0.082 0.181
## [422,] -1.497 8.950 -1.376 -0.997 -1.628 -1.219 -1.251 -0.950
## [423,] -1.402 -1.220 8.007 -0.912 -1.530 -1.130 -1.161 -0.866
## [424,] -1.194 -1.021 -1.081 -0.723 -1.316 7.344 -0.964 -0.679
## [425,] -0.664 -0.506 -0.562 4.230 -0.774 -0.426 -0.454 -0.187
## [426,] -0.490 2.203 -0.390 -0.062 -0.597 -0.257 -0.284 -0.020
## [427,] 8.186 6.721 -2.830 -2.301 -3.195 -2.609 -2.653 -2.238
## [428,] -0.954 -0.789 -0.846 -0.502 -1.070 -0.705 -0.734 6.710
## [429,] 1.863 -0.336 -0.390 -0.062 -0.597 -0.257 -0.284 -0.020
## [430,] -0.817 -0.656 -0.712 -0.374 -0.930 4.700 -0.602 -0.331
## [431,] -0.393 -0.239 -0.293 2.067 -0.499 -0.161 -0.188 0.076
## [432,] -1.079 -0.909 -0.968 -0.618 -1.197 -0.825 -0.854 7.714
## [433,] -1.137 -0.966 -1.026 -0.672 -1.258 -0.880 -0.910 8.185
## [434,] -1.587 9.546 -1.463 -1.077 -1.721 -1.304 -1.336 -1.030
## [435,] -1.450 -1.267 -1.330 7.874 -1.579 -1.175 -1.207 1.668
## [436,] -1.714 -1.520 -1.587 -1.191 -1.853 10.956 -1.456 -1.142
## [437,] -1.079 -0.909 -0.968 -0.618 5.038 -0.825 -0.854 -0.574
## [438,] 3.885 -0.656 -0.712 -0.374 -0.930 -0.574 -0.602 -0.331
## [439,] -0.743 -0.583 -0.639 -0.304 -0.854 4.176 -0.530 -0.262
## [440,] -0.580 -0.424 -0.479 -0.149 2.164 -0.345 -0.372 -0.107
## [441,] 6.187 -1.021 -1.081 -0.723 -1.316 -0.934 -0.964 -0.679
## [442,] -0.954 -0.789 -0.846 -0.502 4.324 -0.705 -0.734 -0.459
## [443,] 9.323 -1.520 -1.587 -1.191 -1.853 -1.423 -1.456 -1.142
## [444,] 6.836 -1.124 -1.185 -0.821 -1.426 -1.035 -1.066 -0.776
## [445,] -1.301 -1.124 -1.185 -0.821 -1.426 8.091 -1.066 -0.776
## [446,] -3.350 -3.064 -3.163 -2.593 17.657 -2.924 -2.972 -2.525
## [447,] -1.301 -1.124 1.664 -0.821 -1.426 5.049 -1.066 -0.776
## [448,] 4.316 -0.724 -0.781 -0.440 -1.001 -0.641 -0.670 -0.397
## [449,] -0.664 -0.506 -0.562 -0.229 -0.774 3.620 -0.454 -0.187
## [450,] -0.490 2.203 -0.390 -0.062 -0.597 -0.257 -0.284 -0.020
## [451,] -0.490 -0.336 2.082 -0.062 -0.597 -0.257 -0.284 -0.020
## [452,] 13.988 -2.264 -2.346 -1.873 -2.669 -2.148 -2.188 -1.815
## [453,] -0.664 -0.506 -0.562 -0.229 2.652 -0.426 -0.454 -0.187
## [454,] -0.457 -1.597 -1.665 -1.262 3.996 3.006 -1.532 -1.212
## [455,] -2.500 7.574 -2.346 -1.873 -2.669 6.114 -2.188 -1.815
## [456,] -1.018 -0.850 -0.909 7.018 -1.135 -0.766 -0.795 -0.518
## [457,] -0.286 -0.134 -0.187 0.139 -0.391 -0.056 0.877 0.181
## [458,] -0.167 -0.016 -0.069 0.257 -0.271 0.062 0.035 0.300
## [459,] -0.887 -0.724 -0.781 -0.440 -1.001 -0.641 5.088 -0.397
## [460,] -1.248 -1.073 -1.134 8.826 -1.372 -0.985 -1.015 -0.728
## [461,] 0.008 -2.237 -2.317 -1.847 10.475 -2.121 -2.161 -1.791
## [462,] -1.079 -0.909 -0.968 -0.618 -1.197 -0.825 -0.854 7.714
## [463,] -0.167 -0.016 -0.069 0.257 -0.271 0.062 0.035 0.300
## [464,] -1.018 -0.850 -0.909 -0.561 -1.135 6.111 -0.795 -0.518
## [465,] 8.017 -1.312 -1.376 -0.997 -1.628 -1.219 -1.251 -0.950
## [466,] -0.490 -0.336 1.258 -0.062 -0.597 -0.257 0.584 -0.020
## [467,] -1.079 6.172 -0.968 -0.618 -1.197 -0.825 -0.854 -0.574
## [468,] -1.587 -1.398 -1.463 11.463 -1.721 -1.304 -1.336 -1.030
## [469,] -1.497 8.950 -1.376 -0.997 -1.628 -1.219 -1.251 -0.950
## [470,] -1.714 -1.520 -1.587 -1.191 8.629 -1.423 -1.456 -1.142
## [471,] 7.444 -1.220 -1.283 -0.912 -1.530 -1.130 -1.161 -0.866
## [472,] -2.191 -1.972 -2.048 -1.607 -2.347 14.229 -1.901 -1.553
## [473,] -1.497 8.950 -1.376 -0.997 -1.628 -1.219 -1.251 -0.950
## [474,] -0.286 -0.134 -0.187 0.139 0.433 -0.056 -0.082 0.181
## [475,] 6.836 -1.124 -1.185 -0.821 -1.426 -1.035 -1.066 -0.776
## [476,] -2.669 -2.424 -2.508 -2.017 -2.845 -2.303 17.191 -1.958
## [477,] -0.664 -0.506 -0.562 -0.229 2.652 -0.426 -0.454 -0.187
## [478,] 11.962 -1.941 -2.016 -1.578 -2.312 -1.833 -1.870 -1.525
## [479,] -1.542 6.600 1.162 -1.038 -1.675 -1.262 -1.294 -0.991
## [480,] -0.490 -0.336 -0.390 2.847 -0.597 -0.257 -0.284 -0.020
## [481,] 1.863 -0.336 -0.390 -0.062 -0.597 -0.257 -0.284 -0.020
## [482,] -0.817 4.417 -0.712 -0.374 -0.930 -0.574 -0.602 -0.331
## [483,] 4.501 -0.850 -0.909 -0.561 -1.135 -0.766 -0.117 -0.518
## [484,] -4.154 -3.817 -3.933 -3.263 22.039 -3.652 -3.708 -3.184
## [485,] -1.301 -1.124 -1.185 -0.821 -1.426 8.091 -1.066 -0.776
## [486,] -0.664 -0.506 -0.562 -0.229 -0.774 -0.426 -0.454 4.367
## [487,] 9.567 -1.559 -1.627 -1.227 -1.895 -1.461 -1.494 -1.178
## [488,] 6.187 -1.021 -1.081 -0.723 -1.316 -0.934 -0.964 -0.679
## [489,] -1.248 -1.073 -1.134 -0.773 -1.372 -0.985 -1.015 9.074
## [490,] -1.542 -1.355 -1.420 -1.038 -1.675 9.766 -1.294 -0.991
## [491,] -0.887 -0.724 4.684 -0.440 -1.001 -0.641 -0.670 -0.397
## [492,] -0.286 -0.134 -0.187 1.211 -0.391 -0.056 -0.082 0.181
## [493,] -1.301 -1.124 -1.185 -0.821 -1.426 -1.035 -1.066 9.496
## [494,] -1.497 8.950 -1.376 -0.997 -1.628 -1.219 -1.251 -0.950
## [495,] -1.910 -1.706 11.251 -1.363 -2.056 -1.605 -1.640 -1.312
## [496,] -0.167 -0.016 -0.069 0.257 -0.271 0.062 0.035 0.300
## [497,] -0.393 -0.239 -0.293 2.067 -0.499 -0.161 -0.188 0.076
## [498,] -0.664 -0.506 -0.562 -0.229 -0.774 -0.426 -0.454 4.367
## [499,] 0.115 -0.909 4.674 -0.618 -1.197 -0.825 -0.854 -0.574
## [500,] 5.715 -3.302 5.839 -2.805 -3.822 -3.154 -3.204 4.783
plot(chi_custA$residuals)
chi_custA$p.value
## [1] 0.0004997501
# Test 3
custA[sample(1:nrow(custA),10),c(2,4)] %>%
chisq.test()
##
## Pearson's Chi-squared test
##
## data: .
## X-squared = 70.085, df = 9, p-value = 1.465e-11
custA[sample(1:nrow(custA),10),c(4,6)] %>%
chisq.test()
##
## Pearson's Chi-squared test
##
## data: .
## X-squared = 11.483, df = 9, p-value = 0.2441
Since p-value =
chi_custA$p.value, which is less than .05 so we can reject the null hypothesis. So we see there is dependancy in the spending over the quarter.
Using Simulation
#Multiple simulation
#Doing multiple check
rm(p_chi)
p_chi <- data.frame(Qt12= rep(0, 50),Qt23= rep(0, 50),Qt34= rep(0, 50))
for(i in 1:50){
chi_test <- custA[sample(1:nrow(custA),10),c(2,4)] %>%
chisq.test()
p_chi$Qt12[i] <- chi_test$p.value
chi_test <- custA[sample(1:nrow(custA),10),c(4,6)] %>%
chisq.test()
p_chi$Qt23[i] <- chi_test$p.value
chi_test <- custA[sample(1:nrow(custA),10),c(6,8)] %>%
chisq.test()
p_chi$Qt34[i] <- chi_test$p.value
# samp <- sample(c("atheist", "non_atheist"), n, replace = TRUE, prob = c(p, 1-p))
# p_hats[i] <- sum(samp == "atheist")/n
}
# "Chi-squared approximation may be incorrectChi-squared " The warning message found in the solution above is due to the small cell values in the contingency table.
#lets check the key
table(gather(p_chi)$key)
##
## Qt12 Qt23 Qt34
## 50 50 50
#Gather the data so that we can plot on it.
#using geom_jitter to add some noise as most of poits would overlap in normal plot.
gather(p_chi) %>% ggplot(mapping = aes(x= key, y= round(value,3))) + geom_point()+geom_jitter()
gather(p_chi)%>% filter(value > 0.05)
#contigency table
rowSums(custA[,-c(1)])
## [1] 10 9 17 26 22 13 26 25 31 27 10 13 13 32 19 182 33
## [18] 30 32 167 18 32 28 38 20 33 86 13 30 46 12 21 40 12
## [35] 31 32 14 19 20 21 27 25 10 17 168 53 28 30 13 27 21
## [52] 21 8 37 16 10 11 17 23 8 43 12 20 10 17 18 20 8
## [69] 23 17 31 55 54 13 21 22 19 19 25 13 84 18 50 10 14
## [86] 13 19 29 11 14 30 17 8 14 41 25 15 22 32 29 9 37
## [103] 13 39 10 9 49 32 8 31 18 22 14 11 16 9 14 34 35
## [120] 13 20 17 15 10 29 19 53 8 34 25 15 41 27 17 19 43
## [137] 22 22 111 18 47 10 19 16 19 37 9 20 23 15 9 29 37
## [154] 9 14 8 42 16 19 16 53 27 44 25 26 37 45 32 26 32
## [171] 15 24 9 9 15 16 22 19 15 12 76 10 17 24 42 43 23
## [188] 17 15 8 74 27 27 95 25 10 13 27 18 13 15 21 19 51
## [205] 23 35 14 25 20 19 28 25 19 34 16 47 58 27 27 9 11
## [222] 20 12 14 24 10 50 8 15 17 94 15 20 19 55 8 8 16
## [239] 23 29 63 8 17 40 43 21 18 30 19 10 37 15 26 66 19
## [256] 47 22 37 8 16 27 19 46 19 24 60 34 46 28 8 27 49
## [273] 22 21 23 23 20 8 12 9 21 21 12 13 57 25 14 41 14
## [290] 20 20 34 14 28 11 40 28 22 28 24 38 8 23 12 13 27
## [307] 8 25 21 65 21 37 87 48 22 17 8 55 32 13 12 16 14
## [324] 17 26 32 23 19 46 12 19 14 11 21 17 26 24 16 76 35
## [341] 27 20 15 15 34 10 21 21 53 19 82 61 27 13 15 37 13
## [358] 9 25 12 20 26 38 17 101 24 15 28 45 34 14 33 34 24
## [375] 23 19 12 23 16 16 23 55 13 26 14 25 35 27 16 10 10
## [392] 15 15 30 27 28 17 22 19 25 22 35 59 40 33 25 27 9
## [409] 33 22 24 24 11 47 148 30 10 21 11 37 13 88 39 13 28
## [426] 17 76 8 19 94 9 44 32 13 23 22 12 49 18 21 16 31
## [443] 28 13 48 30 23 10 9 27 10 23 9 19 23 37 11 21 13
## [460] 22 21 29 21 18 25 10 16 24 10 8 11 12 12 14 12 18
## [477] 19 21 37 25 12 18 10 30 52 51 55 14 19 14 20 13 29
## [494] 29 9 29 26 27 22 52 30 19 15 11 10 17 31 13 13 17
## [511] 24 32 37 27 16 27 17 18 31 13 20 16 38 23 13 22 10
## [528] 10 18 8 27 31 13 19 24 22 25 18 13 10 26 8 16 17
## [545] 10 26 63 36 35 11 8 39 12 30 15 20 27 44 54 25 57
## [562] 57 9 9 25 10 18 9 12 38 10 17 8 9 42 44 27 16
## [579] 16 18 16 18 108 45 16 21 12 22 17 15 10 23 13 12 26
## [596] 29 19 11 19 15 57 15 11 18 55 11 20 18 28 12 125 40
## [613] 8 74 28 17 9 29 48 60 21 30 80 13 17 14 22 12 9
## [630] 39 10 16 30 21 17 13 45 9 9 12 22 17 9 39 28 19
## [647] 32 13 19 9 12 12 19 11 9 163 10 24 14 15 40 48 12
## [664] 17 30 33 15 17 10 15 22 47 29 15 20 47 11 27 38 8
## [681] 28 27 16 21 27 32 8 15 20 24 13 14 27 16 28 9 46
## [698] 37 21 12 47 8 16 34 11 25 19 15 12 27 48 17 17 15
## [715] 88 39 10 15 14 11 130 21 28 11 27 9 16 9 12 22 26
## [732] 17 19 10 22 28 13 10 21 21 16 20 27 36 18 13 16 31
## [749] 11 25 16 13 24 33 19 9 31 12 41 39 38 10 22 35 13
## [766] 12 30 15 18 13 54 20 37 27 12 40 13 28 34 12 29 16
## [783] 16 32 17 11 14 32 17 30 26 10 37 31 13 16 11 17 18
## [800] 24 20 16 40 27 12 17 13 89 26 8 11 35 37 12 31 39
## [817] 12 19 20 47 19 8 43 31 12 14 45 13 13 71 25 13 9
## [834] 29 31 32 59 29 15 10 10 23 27 66 20 42 15 17 45 15
## [851] 40 17 56 14 24 26 19 45 25 27 29 18 13 19 19 27 17
## [868] 21 32 77 18 20 9 19 11 21 31 36 22 15 13 35 15 13
## [885] 17 21 19 32 12 34 34 74 9 22 20 9 20 16 8 14 18
## [902] 27 49 9 29 19 21 12 62 14 8 18 22 25 9 25 17 27
## [919] 67 17 8 24 41 22 62 27 13 10 25 32 29 8 13 37 12
## [936] 30 21 10 38 8 17 25 19 15 13 12 11 17 20 13 23 15
## [953] 15 13 22 92 11 339 20 47 29 46 27 17 31 13 19 17 23
## [970] 34 18 9 17 36 13 37 33 9 32 18 31 31 15 8 38 27
## [987] 12 35 19 16 60 32 14 29 11 8 36 37 27 18
colSums(custA[,-c(1)])
## Q1_17 Q1_18 Q2_17 Q2_18 Q3_17 Q3_18 Q4_17 Q4_18
## 3494 4120 3331 3193 3176 2928 2522 2719
Answer to Business Question A: Does customer who baught more at the Quarter end , how did they perfrom during the followin quarter.
Since p-value =
chi_custA$p.value, which is less than .05 so we can reject the null hypothesis. So we see there is dependancy in the spending over the quarter. Multiple simulation also indicatess pvlaue < 0.05 , for Aplha = 0.5 it indicates that we are 95% confident that spending over each quater is depended on spending over last quarter.
Limitation : We can’t evalaute spending is more or less using Chi-square test , as it is goodness of fittest only.
Lets evaluate Promotion and qty realtion Qt. In this section we will build a regression model to identify which are the predcitors whcih can predict’ Order Quantity’.
Doing some visual data analysis to see how the relation goes by each predictors of Order Unit.
# Creating subset of data
lm_cust <- mkt_Datalean[,c(15,4,1,3,5,7,11,12,13,14)]
lm_cust<- rename(lm_cust , promo = `External Description` )
lm_cust$KUNNR_NEW = as.character(lm_cust$KUNNR_NEW)
lm_cust$Brand = as.factor(lm_cust$Brand)
lm_cust$zip = as.factor(lm_cust$zip)
lm_cust$city = as.factor(lm_cust$city)
lm_cust$state = as.factor(lm_cust$state)
lm_cust$Qt = as.factor(lm_cust$Qt)
# Check data
head(lm_cust)
summary(lm_cust)
## KUNNR_NEW Order Quantity Brand
## Length:5000 Min. : 1.00 RB : 777
## Class :character 1st Qu.: 5.00 RX : 717
## Mode :character Median : 10.00 OX : 351
## Mean : 14.22 OO : 309
## 3rd Qu.: 19.00 HC : 299
## Max. :304.00 RY : 292
## (Other):2255
## Order Date Promotion Order Doll promo
## Min. :2017-01-03 00:00:00 Min. : 0.0 Length:5000
## 1st Qu.:2017-07-03 00:00:00 1st Qu.: 348.3 Class :character
## Median :2018-01-20 00:00:00 Median : 741.5 Mode :character
## Mean :2018-01-03 18:54:08 Mean : 1094.8
## 3rd Qu.:2018-06-26 06:00:00 3rd Qu.: 1383.6
## Max. :2018-12-29 00:00:00 Max. :23339.4
##
## city state zip Qt
## HOUSTON : 68 CA :1005 92683 : 17 Q1_18 : 754
## BROOKLYN : 61 TX : 533 77478 : 12 Q1_17 : 683
## LOS ANGELES: 49 NY : 372 33901 : 11 Q2_18 : 663
## LAS VEGAS : 40 FL : 302 36830 : 11 Q3_18 : 624
## SAN ANTONIO: 40 PA : 200 32084 : 10 Q3_17 : 610
## MIAMI : 32 (Other):2581 40213 : 10 Q4_18 : 598
## (Other) :4710 NA's : 7 (Other):4929 (Other):1068
# lm_cust[which(is.na(lm_cust$state)),]
lm_cust <- lm_cust %>% group_by(KUNNR_NEW,Qt,Brand,`Order Date`,promo,city,state) %>% summarise(Order_Qty = sum(`Order Quantity`),Doll_Val = sum(`Promotion Order Doll`))
#
# lm_cust[which(lm_cust$Brand=="OO"),] %>% ggplot(mapping = aes(x= promo, y= Order_Qty,group= Qt , color = Qt)) + geom_line()+
# geom_point() + geom_jitter()+ facet_grid(year(`Order Date`)~ .)
#
# ggplot(lm_cust,mapping = aes(x= Qt, y= Order_Qty, group= Brand ,color= Brand )) + geom_line()+
# geom_point() + geom_jitter()
# Brand by Year
lm_cust[which(lm_cust$Brand %in% c("RB","RJ")),] %>% group_by(promo,Brand,Qt,year =year(`Order Date`)) %>%summarise(Order_Qty = sum(Order_Qty)) %>%
ggplot(mapping = aes(x=Brand, y = Order_Qty,fill = Qt)) +
geom_col()+facet_grid(year~ .)+
theme(axis.text.x = element_text(angle = 70, hjust = 1)) +
scale_y_continuous( labels = scales::number)+
ggtitle("Brand by Year ") +ylab("Ordered Unit")
# promo by year and Brand
plotly::ggplotly( lm_cust[which(lm_cust$Brand %in% c("RB")),] %>% group_by(promo,Brand,Qt,year =year(`Order Date`)) %>%summarise(Order_Qty = sum(Order_Qty)) %>%
ggplot(mapping = aes(x=promo, y = Order_Qty,fill = Qt)) +
geom_col( position = "dodge")+facet_grid(Brand+year~ .,scales="free")+
theme(axis.text.x = element_text(angle = 70, hjust = 1)) +
scale_y_continuous( labels = scales::number)+
ggtitle("Promo by year and Brand ") +ylab("Ordered Unit"))
#Plotly check
plotData <- lm_cust[which(lm_cust$Brand %in% c("RB")),] %>% group_by(promo,Brand,Qt,month =month(`Order Date`)) %>%summarise(Order_Qty = sum(Order_Qty))
plot_ly(x = plotData$promo, y = plotData$Order_Qty, mode= "marker", type = "bar", data= plotData, color= plotData$Qt) %>% layout(title="RB Brand Order ")
lm_cust[which(lm_cust$Brand %in% c("RB")),] %>% group_by(promo,Brand,Qt,month =month(`Order Date`)) %>%summarise(Order_Qty = sum(Order_Qty))
linPlot <- lm_cust[which(lm_cust$Brand %in% c("RB","OO")),] %>% group_by(Brand,date = month(`Order Date`) )%>%summarise(OrderQty = sum(Order_Qty))
linPlot <- lm_cust[which(lm_cust$Brand %in% c("RB","OO")),] %>% group_by(Brand,date = (format(`Order Date`, "%Y-%m")) )%>%summarise(OrderQty = sum(Order_Qty))
linPlot <- lm_cust[which(lm_cust$Brand %in% c("RB","OO")),] %>% group_by(Brand,date = (month(`Order Date`)) , year = year(`Order Date`))%>%summarise(OrderQty = sum(Order_Qty))
plot_ly(x= linPlot$date,y= linPlot$OrderQty, color = as.factor(linPlot$Brand) , data = linPlot[which(linPlot$year==2017),], linetype = I("Brand")) %>% layout(title= "Two Brand Order Unit By Quarter")
linPlot$year <- as.factor(linPlot$year)
#
# plot_ly(x= linPlot$date,y= linPlot$OrderQty, group_by = linPlot$year,color = as.factor(linPlot$year) , data = linPlot[which(linPlot$brand=="RB"),], linetype = "solid")
# linPlot <- lm_cust[which(lm_cust$Brand %in% c("RB","OO","TY")),] %>% group_by(Brand,dateL = `Order Date`)%>%summarise(OrderQty = sum(Order_Qty))
# plot_ly(data= linPlot,x= month(linPlot$dateL), y = linPlot$OrderQty,color = linPlot$Brand , linetype = 'dot' )
# str_replace(str_extract(linPlot$dateL[1],"\\d+_\\d{2}"),"_","")
linPlot <- lm_cust[which(lm_cust$Brand %in% c("RB","OO","TY")),] %>% group_by(Brand,
dateL = Qt
)%>%summarise(OrderQty = sum(Order_Qty))
linPlot$Qt <- as.numeric(str_replace_all(str_extract_all(linPlot$dateL,"\\d+_\\d{2}"),"_",""))
plot_ly(data= linPlot,x= linPlot$Qt, y = linPlot$OrderQty,color = linPlot$Brand , linetype = 'dot' ) %>% layout(title = " Sales by Brand by Quarter") %>% layout(title= " 3 Brand Order Unit By Quarter", scene = list(
xaxis = list(title = "Quarter"),
yaxis = list(title = "Order Unit")
))
# check if all promotions are running every year
head(table(year(lm_cust$`Order Date`),lm_cust$promo))
##
## ANB AND CHANEL PRE CHROME8 CODE F H15 HC18 LUX40 MVE150 MVENB
## 2017 1 7 5 2 21 237 16 282 3 3
## 2018 0 0 0 0 0 0 0 0 0 0
##
## NASC150 NASC75 NB NB20 NB40 OOX40 OOX60 Other OY12 PB1 PB3
## 2017 25 19 18 4 1 18 3 762 14 6 2
## 2018 0 0 0 0 0 0 0 2008 0 0 0
##
## PRE-SELL B PRE-SELL T PRE SELL T RB15 RSD SUN1 SUN2 SY1 SY100
## 2017 3 6 1 20 4 8 13 0 302
## 2018 0 0 0 0 6 0 0 234 0
##
## SY1000 SY2 SY200 SY250 SY5 SYNERGY54 SYVE UP1 UP3 VIP VP1200
## 2017 0 0 62 6 0 0 0 207 108 0 22
## 2018 16 45 0 97 29 29 99 0 0 22 0
##
## VPFP150 VPFP200 VPNB WC1 WC2 Wild Card
## 2017 9 50 11 78 1 0
## 2018 0 0 0 21 1 30
Try Predicting Quantity based on Known informaiton . Identifying Best model to predict Quantity .
I have create many regression model using ‘lm’ and stored the result in ‘result’ . I noted few models meeting the expected result. I will discuss them in next tab. example:" lm_pbm which is model for promotion + brand + month would predict order Quanity."
# pairs.panels(lm_cust[,c(2,3)])
# Try Predicting Quantity based on Known informaiton .
# Identifying Best model to predict Quantity
head(lm_cust)
result <- data.frame(var = 1:10,pval = 1:10, comment=1:10)
result$var <- "A"
result$pval <- "A"
result$comment <- "A"
# Working With Sample
set.seed(42672)
lm_cust_s1 <- lm_cust[sample(nrow(lm_cust),200),]
lm_cust_s1$month <- month(lm_cust_s1$`Order Date`)
lm_cust_s1$month <- as.factor(lm_cust_s1$month )
names(lm_cust_s1)
## [1] "KUNNR_NEW" "Qt" "Brand" "Order Date" "promo"
## [6] "city" "state" "Order_Qty" "Doll_Val" "month"
lm1 <- lm(Order_Qty ~ Qt + Brand + promo + month + state,lm_cust_s1)
summary(lm1)
##
## Call:
## lm(formula = Order_Qty ~ Qt + Brand + promo + month + state,
## data = lm_cust_s1)
##
## Residuals:
## Min 1Q Median 3Q Max
## -16.550 -4.241 0.000 3.479 32.806
##
## Coefficients: (4 not defined because of singularities)
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -1.9078 21.6089 -0.088 0.9298
## QtQ1_18 0.9060 17.1804 0.053 0.9581
## QtQ2_17 -10.6690 6.7652 -1.577 0.1181
## QtQ2_18 4.4088 16.8263 0.262 0.7939
## QtQ3_17 4.2890 18.8786 0.227 0.8208
## QtQ3_18 0.2220 18.6653 0.012 0.9905
## QtQ4_17 -2.2830 17.5834 -0.130 0.8970
## QtQ4_18 -0.7737 17.6637 -0.044 0.9652
## BrandAX 18.3458 22.3044 0.823 0.4128
## BrandBB 2.3696 19.4477 0.122 0.9033
## BrandBE 4.8108 17.0912 0.281 0.7790
## BrandBV 12.8512 18.2565 0.704 0.4832
## BrandCH 20.3679 18.4397 1.105 0.2721
## BrandDG 16.9778 19.2512 0.882 0.3800
## BrandDY 0.7952 18.4361 0.043 0.9657
## BrandEA 17.7019 17.2015 1.029 0.3060
## BrandHC 11.0212 15.3629 0.717 0.4749
## BrandMK 12.2266 16.2524 0.752 0.4537
## BrandMU 5.1632 19.3904 0.266 0.7906
## BrandOJ 8.0469 24.5189 0.328 0.7435
## BrandOO 12.0027 16.3069 0.736 0.4635
## BrandOX 16.9387 16.0352 1.056 0.2935
## BrandOY 4.6321 16.9397 0.273 0.7851
## BrandPH 0.1814 16.1386 0.011 0.9911
## BrandPO -6.6710 20.5100 -0.325 0.7457
## BrandPR 13.6841 16.1577 0.847 0.3992
## BrandPS -1.4118 19.6018 -0.072 0.9427
## BrandRB 11.3283 16.1044 0.703 0.4835
## BrandRJ -1.4976 17.3495 -0.086 0.9314
## BrandRL 0.2288 18.2880 0.013 0.9900
## BrandRX 11.1098 16.0246 0.693 0.4898
## BrandRY 2.2306 16.3775 0.136 0.8919
## BrandTF 8.5103 16.3253 0.521 0.6034
## BrandTY 6.2068 16.5061 0.376 0.7077
## BrandVA -3.8398 19.1370 -0.201 0.8414
## BrandVE 9.0235 16.2144 0.557 0.5792
## BrandVO 11.9972 17.4822 0.686 0.4942
## promoH15 9.6017 13.9029 0.691 0.4915
## promoHC18 19.2841 15.2727 1.263 0.2098
## promoLUX40 21.9169 14.8400 1.477 0.1430
## promoMVE150 17.2033 25.5096 0.674 0.5017
## promoNB 21.1233 21.4209 0.986 0.3266
## promoOther 6.9515 20.5648 0.338 0.7361
## promoPB3 NA NA NA NA
## promoRSD 5.7801 22.6733 0.255 0.7993
## promoSUN2 32.3281 17.4618 1.851 0.0672 .
## promoSY1 9.6893 20.4632 0.473 0.6369
## promoSY100 14.1988 21.3098 0.666 0.5068
## promoSY1000 19.7310 23.8682 0.827 0.4105
## promoSY2 -6.9960 25.9335 -0.270 0.7879
## promoSY200 38.9640 25.2710 1.542 0.1264
## promoSY250 18.7303 21.4514 0.873 0.3848
## promoSY5 -4.9719 23.1484 -0.215 0.8304
## promoSYNERGY54 8.2911 22.2721 0.372 0.7105
## promoSYVE 7.7185 22.2776 0.346 0.7297
## promoUP1 19.0150 14.2490 1.334 0.1852
## promoUP3 11.5593 16.8913 0.684 0.4954
## promoVIP 49.2421 23.6627 2.081 0.0401 *
## promoVPFP200 1.1052 17.1949 0.064 0.9489
## promoWC1 13.7854 14.3078 0.963 0.3377
## promoWild Card 0.6250 23.6542 0.026 0.9790
## month2 -4.0531 4.5852 -0.884 0.3789
## month3 -4.1391 4.8446 -0.854 0.3950
## month4 1.9585 4.8677 0.402 0.6883
## month5 -0.3939 5.9585 -0.066 0.9474
## month6 NA NA NA NA
## month7 -5.0892 6.4939 -0.784 0.4352
## month8 2.4540 4.3761 0.561 0.5763
## month9 NA NA NA NA
## month10 4.5085 4.3857 1.028 0.3065
## month11 3.0711 4.5898 0.669 0.5050
## month12 NA NA NA NA
## stateAR 4.9067 13.5503 0.362 0.7181
## stateAZ -12.6404 9.1172 -1.386 0.1688
## stateCA -3.1682 6.8239 -0.464 0.6435
## stateCO -7.3438 13.2637 -0.554 0.5811
## stateCT -15.9275 9.3699 -1.700 0.0924 .
## stateFL -1.0817 7.6681 -0.141 0.8881
## stateGA -14.0750 10.1232 -1.390 0.1676
## stateIA -11.6502 11.5498 -1.009 0.3157
## stateIL 5.5588 8.2697 0.672 0.5031
## stateIN -2.1564 10.5735 -0.204 0.8388
## stateKS -11.9797 11.1076 -1.079 0.2835
## stateKY -0.8319 13.1444 -0.063 0.9497
## stateLA -19.7563 12.3596 -1.598 0.1132
## stateMA 3.8609 9.5001 0.406 0.6854
## stateME 5.5262 12.3303 0.448 0.6550
## stateMI -2.8545 9.2395 -0.309 0.7580
## stateMN 2.4257 10.0699 0.241 0.8102
## stateMO -19.8191 13.5869 -1.459 0.1479
## stateMS -16.2905 13.0349 -1.250 0.2144
## stateNC -6.0919 10.8236 -0.563 0.5749
## stateND -3.1519 14.4050 -0.219 0.8273
## stateNH -5.5647 10.7039 -0.520 0.6044
## stateNJ -4.4015 8.2831 -0.531 0.5964
## stateNV 2.2659 10.5634 0.215 0.8306
## stateNY -3.9499 7.5107 -0.526 0.6002
## stateOH -3.9169 8.4383 -0.464 0.6436
## stateOK -11.1089 9.1041 -1.220 0.2254
## stateOR -3.1731 9.9453 -0.319 0.7504
## statePA -5.7108 8.4292 -0.677 0.4997
## statePR -16.4884 10.2060 -1.616 0.1095
## stateSC -11.6695 10.7825 -1.082 0.2818
## stateTN -7.6426 14.5518 -0.525 0.6007
## stateTX -3.9184 6.9454 -0.564 0.5740
## stateUT -11.2160 10.3562 -1.083 0.2815
## stateVA 11.3389 10.1637 1.116 0.2674
## stateWA -13.5126 10.2216 -1.322 0.1893
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 10.09 on 96 degrees of freedom
## Multiple R-squared: 0.5671, Adjusted R-squared: 0.1027
## F-statistic: 1.221 on 103 and 96 DF, p-value: 0.1613
anova(lm1)
result$var[1] <- "lm(formula = Order_Qty ~ Qt + Brand + promo + month + state,
data = lm_cust_s1)"
result$pval[1] <- "Adjusted R-squared: 0.2356 F-statistic: 1.568 on 108 and 91 DF, p-value: 0.01388"
result$comment[1] <- "(Month , State ) Qt,Promo codes are significant,state is not "
#Dropping State
lm2 <- lm(Order_Qty ~ Qt + Brand + promo + month,lm_cust_s1)
summary(lm2)
##
## Call:
## lm(formula = Order_Qty ~ Qt + Brand + promo + month, data = lm_cust_s1)
##
## Residuals:
## Min 1Q Median 3Q Max
## -16.961 -4.673 -0.497 3.248 35.929
##
## Coefficients: (4 not defined because of singularities)
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1.76646 15.85513 0.111 0.9115
## QtQ1_18 8.19326 15.10309 0.542 0.5884
## QtQ2_17 -8.45412 5.56060 -1.520 0.1308
## QtQ2_18 8.26195 14.70668 0.562 0.5752
## QtQ3_17 9.13929 16.42153 0.557 0.5788
## QtQ3_18 4.85130 16.32582 0.297 0.7668
## QtQ4_17 5.16805 15.40193 0.336 0.7377
## QtQ4_18 6.02604 15.43343 0.390 0.6968
## BrandAX 13.47419 14.92339 0.903 0.3682
## BrandBB -1.85800 14.56726 -0.128 0.8987
## BrandBE 0.84478 11.24694 0.075 0.9402
## BrandBV 2.46199 13.09288 0.188 0.8511
## BrandCH 10.16419 13.25922 0.767 0.4447
## BrandDG 15.77592 15.14897 1.041 0.2996
## BrandDY -2.40774 13.09982 -0.184 0.8545
## BrandEA 9.51967 11.71647 0.813 0.4180
## BrandHC 8.00163 10.83654 0.738 0.4616
## BrandMK 9.78688 11.22669 0.872 0.3849
## BrandMU -0.12788 14.74098 -0.009 0.9931
## BrandOJ 3.66944 18.80247 0.195 0.8456
## BrandOO 8.97486 10.80145 0.831 0.4075
## BrandOX 13.51180 10.78819 1.252 0.2126
## BrandOY -1.75425 11.59509 -0.151 0.8800
## BrandPH -2.08049 11.16732 -0.186 0.8525
## BrandPO -15.82037 15.52513 -1.019 0.3101
## BrandPR 6.24358 10.87677 0.574 0.5669
## BrandPS -2.75859 15.29122 -0.180 0.8571
## BrandRB 5.17785 10.71694 0.483 0.6298
## BrandRJ -5.56978 12.09695 -0.460 0.6460
## BrandRL -0.40758 13.20894 -0.031 0.9754
## BrandRX 6.84940 10.75139 0.637 0.5252
## BrandRY -3.06439 11.08068 -0.277 0.7826
## BrandTF 5.68303 11.06348 0.514 0.6083
## BrandTY 3.27404 11.37846 0.288 0.7740
## BrandVA -7.78735 15.01296 -0.519 0.6048
## BrandVE 6.43716 11.16435 0.577 0.5652
## BrandVO 10.41475 12.85835 0.810 0.4194
## promoH15 7.75470 11.45441 0.677 0.4996
## promoHC18 17.88883 12.80711 1.397 0.1648
## promoLUX40 13.38640 12.53006 1.068 0.2873
## promoMVE150 10.66944 18.80247 0.567 0.5714
## promoNB 13.05855 16.03867 0.814 0.4170
## promoOther -1.99801 17.76144 -0.112 0.9106
## promoPB3 NA NA NA NA
## promoRSD -1.29378 19.37013 -0.067 0.9468
## promoSUN2 25.00462 15.13055 1.653 0.1008
## promoSY1 0.19567 17.86870 0.011 0.9913
## promoSY100 3.85284 18.28232 0.211 0.8334
## promoSY1000 10.29834 20.80866 0.495 0.6215
## promoSY2 -13.57687 21.18255 -0.641 0.5227
## promoSY200 22.06638 21.20608 1.041 0.3000
## promoSY250 12.29655 18.50514 0.664 0.5075
## promoSY5 -9.92659 20.77319 -0.478 0.6335
## promoSYNERGY54 -1.14395 19.23230 -0.059 0.9527
## promoSYVE 2.88566 19.02076 0.152 0.8796
## promoUP1 11.09237 11.97327 0.926 0.3559
## promoUP3 5.67156 14.53816 0.390 0.6971
## promoVIP 40.69755 20.62294 1.973 0.0505 .
## promoVPFP200 -2.17996 15.41726 -0.141 0.8878
## promoWC1 8.37933 12.06755 0.694 0.4887
## promoWild Card -6.76739 20.93979 -0.323 0.7471
## month2 -4.74452 4.06230 -1.168 0.2449
## month3 -3.43590 4.12213 -0.834 0.4061
## month4 0.53474 4.14536 0.129 0.8976
## month5 1.83826 4.72189 0.389 0.6977
## month6 NA NA NA NA
## month7 -3.50092 5.28964 -0.662 0.5092
## month8 4.22014 3.83925 1.099 0.2737
## month9 NA NA NA NA
## month10 0.34721 3.82871 0.091 0.9279
## month11 0.06351 3.46890 0.018 0.9854
## month12 NA NA NA NA
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 10.04 on 132 degrees of freedom
## Multiple R-squared: 0.4109, Adjusted R-squared: 0.1118
## F-statistic: 1.374 on 67 and 132 DF, p-value: 0.06178
anova(lm2)
result$var[2] <- "lm(formula = Order_Qty ~ Qt + Brand + promo + month, data = lm_cust_s1)"
result$pval[2] <- "Adjusted R-squared: 0.3198 F-statistic: 2.396 on 67 and 132 DF, p-value: 9.788e-06"
result$comment[2] <- "(Month)Brand is not significant"
#Promo promoVPFP200 turns out to more significant here.
#3 Dropping brand info
lm3 <- lm(Order_Qty ~ Qt + promo + month,lm_cust_s1)
summary(lm3)
##
## Call:
## lm(formula = Order_Qty ~ Qt + promo + month, data = lm_cust_s1)
##
## Residuals:
## Min 1Q Median 3Q Max
## -17.866 -5.922 -1.888 5.804 38.720
##
## Coefficients: (3 not defined because of singularities)
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 7.0142 11.8946 0.590 0.5562
## QtQ1_18 1.0985 12.8603 0.085 0.9320
## QtQ2_17 -6.6454 5.3531 -1.241 0.2163
## QtQ2_18 2.2094 12.4434 0.178 0.8593
## QtQ3_17 0.3547 13.2444 0.027 0.9787
## QtQ3_18 -4.1745 13.4272 -0.311 0.7563
## QtQ4_17 -1.3696 13.1970 -0.104 0.9175
## QtQ4_18 -0.2888 13.1282 -0.022 0.9825
## promoH15 6.6873 11.5699 0.578 0.5641
## promoHC18 14.0000 12.7914 1.094 0.2754
## promoLUX40 11.3344 12.4090 0.913 0.3624
## promoMVE150 3.4745 15.8602 0.219 0.8269
## promoNB 3.5945 15.9481 0.225 0.8220
## promoOther 4.5661 16.0019 0.285 0.7757
## promoPB3 -3.5255 15.8602 -0.222 0.8244
## promoRSD 2.7159 17.5790 0.154 0.8774
## promoSUN2 19.0000 14.7702 1.286 0.2002
## promoSY1 8.1008 16.1166 0.503 0.6159
## promoSY100 10.1683 16.3313 0.623 0.5344
## promoSY1000 15.3760 19.4517 0.790 0.4304
## promoSY2 -7.7943 19.3216 -0.403 0.6872
## promoSY200 19.1929 19.3130 0.994 0.3218
## promoSY250 13.7531 16.7025 0.823 0.4115
## promoSY5 -0.7943 19.3216 -0.041 0.9673
## promoSYNERGY54 4.2402 17.7321 0.239 0.8113
## promoSYVE 13.7861 17.0650 0.808 0.4204
## promoUP1 9.0155 12.0499 0.748 0.4555
## promoUP3 4.0000 14.7702 0.271 0.7869
## promoVIP 44.7764 18.9571 2.362 0.0194 *
## promoVPFP200 -2.5255 15.8602 -0.159 0.8737
## promoWC1 6.7764 11.8833 0.570 0.5693
## promoWild Card -0.6240 19.4517 -0.032 0.9745
## month2 -2.6087 3.9068 -0.668 0.5053
## month3 -1.4887 3.8859 -0.383 0.7021
## month4 0.5578 4.1556 0.134 0.8934
## month5 1.6312 4.5462 0.359 0.7202
## month6 NA NA NA NA
## month7 -1.4957 4.7273 -0.316 0.7521
## month8 5.4989 3.5054 1.569 0.1187
## month9 NA NA NA NA
## month10 2.0689 3.7185 0.556 0.5787
## month11 1.1625 3.2653 0.356 0.7223
## month12 NA NA NA NA
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 10.44 on 160 degrees of freedom
## Multiple R-squared: 0.2265, Adjusted R-squared: 0.03798
## F-statistic: 1.201 on 39 and 160 DF, p-value: 0.2151
anova(lm3)
result$var[3] <- "lm(formula = Order_Qty ~ Qt + promo + month, data = lm_cust_s1)"
result$pval[3] <- "Adjusted R-squared: 0.2799 F-statistic: 3.09 on 37 and 162 DF, p-value: 4.911e-07"
result$comment[3] <- "(Month) least significant"
#4 Dropping Month
lm4 <- lm(Order_Qty ~ Qt + promo ,lm_cust_s1)
summary(lm4)
##
## Call:
## lm(formula = Order_Qty ~ Qt + promo, data = lm_cust_s1)
##
## Residuals:
## Min 1Q Median 3Q Max
## -17.500 -6.170 -1.375 5.923 40.099
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 6.86722 11.25286 0.610 0.5425
## QtQ1_18 0.07737 12.43278 0.006 0.9950
## QtQ2_17 -4.86722 4.42147 -1.101 0.2726
## QtQ2_18 3.09959 12.03509 0.258 0.7971
## QtQ3_17 3.24186 12.44002 0.261 0.7947
## QtQ3_18 -1.17263 12.52218 -0.094 0.9255
## QtQ4_17 -0.19445 12.44455 -0.016 0.9876
## QtQ4_18 1.03282 12.36837 0.084 0.9335
## promoH15 5.60581 10.99322 0.510 0.6108
## promoHC18 14.00000 12.67344 1.105 0.2709
## promoLUX40 10.30622 11.87453 0.868 0.3867
## promoMVE150 2.13278 15.28739 0.140 0.8892
## promoNB 1.13278 15.28739 0.074 0.9410
## promoOther 4.43041 15.72944 0.282 0.7785
## promoPB3 -4.86722 15.28739 -0.318 0.7506
## promoRSD 3.68021 17.26820 0.213 0.8315
## promoSUN2 19.00000 14.63403 1.298 0.1959
## promoSY1 7.83324 15.87814 0.493 0.6224
## promoSY100 9.79220 16.05434 0.610 0.5427
## promoSY1000 15.05541 18.94609 0.795 0.4279
## promoSY2 -6.90004 18.90388 -0.365 0.7156
## promoSY200 19.32723 18.95381 1.020 0.3093
## promoSY250 13.55541 16.42325 0.825 0.4103
## promoSY5 0.09996 18.90388 0.005 0.9958
## promoSYNERGY54 4.09996 17.43038 0.235 0.8143
## promoSYVE 15.05541 16.75938 0.898 0.3703
## promoUP1 8.47967 11.64176 0.728 0.4674
## promoUP3 4.00000 14.63403 0.273 0.7849
## promoVIP 44.03320 18.68752 2.356 0.0196 *
## promoVPFP200 -3.86722 15.28739 -0.253 0.8006
## promoWC1 6.03320 11.62190 0.519 0.6044
## promoWild Card -0.94459 18.94609 -0.050 0.9603
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 10.35 on 168 degrees of freedom
## Multiple R-squared: 0.2028, Adjusted R-squared: 0.05564
## F-statistic: 1.378 on 31 and 168 DF, p-value: 0.1034
anova(lm4)
result$var[4] <- "lm(formula = Order_Qty ~ Qt + promo, data = lm_cust_s1)"
result$pval[4] <- "Adjusted R-squared: -0.003147 F-statistic: 0.9799 on 31 and 168 DF, p-value: 0.5038"
result$comment[4] <- "not much significant"
# 5 Increase Sample Size
rm(lm_cust_s1)
# SInce I see no major significance increasing the sample size to 500
set.seed(12121)
lm_cust_s2 <- lm_cust[sample(nrow(lm_cust),500),]
lm_cust_s2$month <- month(lm_cust_s2$`Order Date`)
lm_cust_s2$month <- as.factor(lm_cust_s2$month )
names(lm_cust_s2)
## [1] "KUNNR_NEW" "Qt" "Brand" "Order Date" "promo"
## [6] "city" "state" "Order_Qty" "Doll_Val" "month"
lm5 <- lm(Order_Qty ~ Qt + Brand + promo + month + state,lm_cust_s2)
summary(lm5)
##
## Call:
## lm(formula = Order_Qty ~ Qt + Brand + promo + month + state,
## data = lm_cust_s2)
##
## Residuals:
## Min 1Q Median 3Q Max
## -58.622 -6.576 -0.564 4.571 96.370
##
## Coefficients: (3 not defined because of singularities)
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -2.23836 24.91771 -0.090 0.928471
## QtQ1_18 5.68596 7.62788 0.745 0.456493
## QtQ2_17 4.90074 4.33482 1.131 0.258978
## QtQ2_18 9.77888 7.96075 1.228 0.220085
## QtQ3_17 9.26640 7.94036 1.167 0.243964
## QtQ3_18 6.23512 8.12498 0.767 0.443334
## QtQ4_17 10.98159 8.02317 1.369 0.171915
## QtQ4_18 7.87855 8.17353 0.964 0.335722
## BrandAX 6.28736 9.54950 0.658 0.510694
## BrandBB 2.30396 10.36390 0.222 0.824198
## BrandBE 25.20950 9.20688 2.738 0.006479 **
## BrandBV 6.23365 9.93958 0.627 0.530946
## BrandCH 18.36577 12.41099 1.480 0.139780
## BrandDG 9.22986 9.48157 0.973 0.330966
## BrandDY -2.43066 8.92135 -0.272 0.785425
## BrandEA 4.22087 8.21652 0.514 0.607765
## BrandHC 17.56763 7.28464 2.412 0.016370 *
## BrandMK 15.26507 7.34155 2.079 0.038283 *
## BrandMU 28.37507 16.41629 1.728 0.084741 .
## BrandOJ 0.28410 9.39984 0.030 0.975905
## BrandOO 18.05318 7.12518 2.534 0.011699 *
## BrandOX 16.29683 7.31304 2.228 0.026452 *
## BrandOY 13.78368 8.12854 1.696 0.090783 .
## BrandPH 16.20134 8.73146 1.856 0.064320 .
## BrandPO 41.37726 10.32638 4.007 7.44e-05 ***
## BrandPP 9.44181 13.11977 0.720 0.472188
## BrandPR 17.81589 7.33210 2.430 0.015581 *
## BrandPS 8.62006 9.21071 0.936 0.349950
## BrandRA -101.12802 22.07255 -4.582 6.32e-06 ***
## BrandRB 19.20374 6.87953 2.791 0.005520 **
## BrandRJ 7.60922 13.77483 0.552 0.581009
## BrandRL 9.40933 9.68586 0.971 0.331961
## BrandRX 17.98048 6.92617 2.596 0.009808 **
## BrandRY 3.57624 7.19166 0.497 0.619291
## BrandSF -2.41412 13.26180 -0.182 0.855655
## BrandTF 13.30561 7.87569 1.689 0.091977 .
## BrandTY 12.26509 8.09756 1.515 0.130713
## BrandVA -9.65624 13.05699 -0.740 0.460046
## BrandVE 13.16022 7.84219 1.678 0.094168 .
## BrandVO 12.33400 7.86830 1.568 0.117842
## promoCODE F -7.66331 21.77963 -0.352 0.725147
## promoH15 -11.02374 18.64078 -0.591 0.554630
## promoLUX40 2.01094 18.56484 0.108 0.913801
## promoMVE150 -16.92342 20.92357 -0.809 0.419139
## promoMVENB -24.45911 23.95361 -1.021 0.307874
## promoNASC75 -17.31631 20.35928 -0.851 0.395578
## promoNB 2.27980 21.45877 0.106 0.915449
## promoOOX40 -13.05094 20.60380 -0.633 0.526849
## promoOOX60 -2.75317 24.34163 -0.113 0.910008
## promoOther -15.02685 19.72704 -0.762 0.446702
## promoOY12 -12.91125 21.77023 -0.593 0.553498
## promoPRE-SELL B -14.21934 27.05889 -0.525 0.599554
## promoPRE-SELL T -15.02483 25.20373 -0.596 0.551450
## promoRB15 -7.71640 19.39064 -0.398 0.690901
## promoRSD -13.01034 25.53166 -0.510 0.610653
## promoSUN1 -14.23245 26.54096 -0.536 0.592112
## promoSY1 -9.48118 20.23297 -0.469 0.639632
## promoSY100 -13.89471 19.91631 -0.698 0.485833
## promoSY1000 87.81025 24.64570 3.563 0.000415 ***
## promoSY2 6.64700 20.81949 0.319 0.749704
## promoSY200 0.60032 19.31584 0.031 0.975223
## promoSY250 9.70349 20.85748 0.465 0.642042
## promoSY5 -11.05189 21.54875 -0.513 0.608343
## promoSYNERGY54 -17.91337 24.88359 -0.720 0.472051
## promoSYVE -7.84596 20.86777 -0.376 0.707144
## promoUP1 -6.74887 18.90346 -0.357 0.721283
## promoUP3 -5.34776 19.01536 -0.281 0.778689
## promoVIP -16.80078 25.26275 -0.665 0.506439
## promoVP1200 -14.77289 20.05127 -0.737 0.461739
## promoVPFP150 -27.72705 23.43836 -1.183 0.237580
## promoVPFP200 38.96072 19.18009 2.031 0.042940 *
## promoVPNB 3.12551 24.90540 0.125 0.900200
## promoWC1 3.86447 19.03659 0.203 0.839245
## promoWC2 -26.74522 25.63692 -1.043 0.297525
## promoWild Card -7.32750 20.76494 -0.353 0.724381
## month2 7.20628 3.20305 2.250 0.025049 *
## month3 5.80081 3.42283 1.695 0.090968 .
## month4 -4.29734 3.89805 -1.102 0.270992
## month5 -5.83098 3.87120 -1.506 0.132859
## month6 NA NA NA NA
## month7 -0.90008 3.68034 -0.245 0.806930
## month8 4.65983 3.76886 1.236 0.217096
## month9 NA NA NA NA
## month10 -0.15770 3.99211 -0.040 0.968510
## month11 1.49643 3.81906 0.392 0.695408
## month12 NA NA NA NA
## stateAL 9.50445 18.76959 0.506 0.612896
## stateAR 4.25873 17.50037 0.243 0.807869
## stateAZ 8.75412 15.96340 0.548 0.583758
## stateCA 5.96085 15.56816 0.383 0.702024
## stateCO 6.89773 16.34269 0.422 0.673221
## stateCT 8.87272 17.47015 0.508 0.611842
## stateDE 2.94917 18.67069 0.158 0.874577
## stateFL 5.07178 15.78812 0.321 0.748210
## stateGA 5.08077 16.15192 0.315 0.753273
## stateHI -3.27474 21.54100 -0.152 0.879251
## stateIA -2.92012 21.57278 -0.135 0.892400
## stateID -0.50943 18.88718 -0.027 0.978497
## stateIL -0.10485 16.10398 -0.007 0.994809
## stateIN 13.93032 16.31788 0.854 0.393834
## stateKS -0.24870 17.33186 -0.014 0.988559
## stateKY 3.56168 16.30882 0.218 0.827246
## stateLA 0.73917 16.61934 0.044 0.964549
## stateMA 0.18353 16.46690 0.011 0.991113
## stateMD 19.31106 16.35617 1.181 0.238499
## stateME -2.02199 21.92339 -0.092 0.926566
## stateMI 7.34720 16.06901 0.457 0.647776
## stateMN 3.27208 17.81806 0.184 0.854398
## stateMO -0.05557 16.95513 -0.003 0.997387
## stateMS -0.01067 17.85912 -0.001 0.999524
## stateNC 0.75692 16.76942 0.045 0.964023
## stateND -8.31927 22.32342 -0.373 0.709608
## stateNE 1.81415 17.71895 0.102 0.918507
## stateNH -29.26246 19.28305 -1.518 0.129991
## stateNJ 20.06935 16.02458 1.252 0.211214
## stateNM 3.80066 19.03693 0.200 0.841867
## stateNV -1.60254 16.24832 -0.099 0.921487
## stateNY 3.99519 15.71092 0.254 0.799410
## stateOH 9.43637 15.92247 0.593 0.553782
## stateOK 12.39685 16.83889 0.736 0.462075
## stateOR 0.48465 16.33196 0.030 0.976342
## statePA 2.76725 15.76791 0.175 0.860784
## statePR 9.11070 16.83870 0.541 0.588795
## stateRI 4.01777 18.73917 0.214 0.830350
## stateSC 5.09637 16.51896 0.309 0.757864
## stateSD -1.17365 21.59044 -0.054 0.956678
## stateTN 0.23167 18.01229 0.013 0.989745
## stateTX 8.62790 15.52548 0.556 0.578735
## stateUT -0.84388 17.26070 -0.049 0.961033
## stateVA 11.47599 16.28521 0.705 0.481449
## stateVT 1.88275 21.95387 0.086 0.931704
## stateWA 3.68880 17.23079 0.214 0.830601
## stateWI 3.55623 21.82413 0.163 0.870647
## stateWY 0.82148 17.90189 0.046 0.963425
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 14.5 on 369 degrees of freedom
## Multiple R-squared: 0.4578, Adjusted R-squared: 0.2667
## F-statistic: 2.396 on 130 and 369 DF, p-value: 6.195e-11
anova(lm5)
result$var[5] <- "500: lm(formula = Order_Qty ~ Qt + Brand + promo + month + state, data = lm_cust_s2)"
result$pval[5] <- " Adjusted R-squared: 0.05218 F-statistic: 1.214 on 128 and 370 DF, p-value: 0.08366"
result$comment[5] <- "(Sig: Promo) "
#6 Dropping Month, I want to keep state for now.
lm6 <- lm(Order_Qty ~ Qt + Brand + promo + state,lm_cust_s2)
summary(lm6)
##
## Call:
## lm(formula = Order_Qty ~ Qt + Brand + promo + state, data = lm_cust_s2)
##
## Residuals:
## Min 1Q Median 3Q Max
## -59.496 -6.406 -0.601 4.280 99.577
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1.52877 24.63637 0.062 0.950553
## QtQ1_18 5.06436 7.54958 0.671 0.502750
## QtQ2_17 -3.00991 3.09533 -0.972 0.331474
## QtQ2_18 1.72419 7.27105 0.237 0.812684
## QtQ3_17 5.18133 7.47685 0.693 0.488747
## QtQ3_18 2.86289 7.65075 0.374 0.708467
## QtQ4_17 6.41013 7.33828 0.874 0.382936
## QtQ4_18 3.55857 7.65293 0.465 0.642204
## BrandAX 7.04313 9.49117 0.742 0.458505
## BrandBB 4.53298 10.31383 0.440 0.660548
## BrandBE 27.21911 9.14236 2.977 0.003096 **
## BrandBV 7.42837 9.90625 0.750 0.453802
## BrandCH 20.06635 12.34992 1.625 0.105037
## BrandDG 12.06067 9.33964 1.291 0.197376
## BrandDY 0.08956 8.85609 0.010 0.991937
## BrandEA 5.49184 8.20344 0.669 0.503615
## BrandHC 18.99537 7.21785 2.632 0.008844 **
## BrandMK 16.48295 7.29505 2.259 0.024424 *
## BrandMU 33.19880 16.32795 2.033 0.042727 *
## BrandOJ 4.73391 9.19500 0.515 0.606970
## BrandOO 19.56637 7.06140 2.771 0.005867 **
## BrandOX 18.13895 7.26779 2.496 0.012994 *
## BrandOY 15.12124 8.06852 1.874 0.061690 .
## BrandPH 17.48872 8.67507 2.016 0.044512 *
## BrandPO 41.13267 10.30461 3.992 7.89e-05 ***
## BrandPP 8.15352 13.13639 0.621 0.535184
## BrandPR 18.68787 7.30897 2.557 0.010954 *
## BrandPS 10.79240 9.16730 1.177 0.239830
## BrandRA -99.18107 22.09677 -4.488 9.54e-06 ***
## BrandRB 20.36236 6.81353 2.989 0.002987 **
## BrandRJ 6.15807 13.71160 0.449 0.653607
## BrandRL 10.66471 9.66073 1.104 0.270330
## BrandRX 19.85388 6.84985 2.898 0.003969 **
## BrandRY 4.16747 7.16701 0.581 0.561264
## BrandSF -1.07966 13.21749 -0.082 0.934941
## BrandTF 14.93447 7.77970 1.920 0.055654 .
## BrandTY 13.68924 7.98476 1.714 0.087273 .
## BrandVA -5.67434 12.85949 -0.441 0.659280
## BrandVE 15.09650 7.75827 1.946 0.052415 .
## BrandVO 14.01905 7.82057 1.793 0.073841 .
## promoCODE F -12.74067 21.59668 -0.590 0.555587
## promoH15 -13.10862 18.49679 -0.709 0.478950
## promoLUX40 -0.08512 18.39459 -0.005 0.996310
## promoMVE150 -17.37885 20.99411 -0.828 0.408309
## promoMVENB -24.83259 23.98568 -1.035 0.301188
## promoNASC75 -19.86089 20.22305 -0.982 0.326684
## promoNB -2.23223 21.28790 -0.105 0.916543
## promoOOX40 -13.04779 20.54753 -0.635 0.525810
## promoOOX60 -4.77677 24.35194 -0.196 0.844594
## promoOther -16.37420 19.68875 -0.832 0.406132
## promoOY12 -13.00063 21.71437 -0.599 0.549725
## promoPRE-SELL B -13.45720 26.63859 -0.505 0.613730
## promoPRE-SELL T -12.32346 24.96930 -0.494 0.621915
## promoRB15 -8.75614 19.35548 -0.452 0.651251
## promoRSD -16.97116 25.29161 -0.671 0.502619
## promoSUN1 -9.86427 26.39147 -0.374 0.708788
## promoSY1 -10.77403 20.18025 -0.534 0.593732
## promoSY100 -15.32144 19.90025 -0.770 0.441834
## promoSY1000 87.36566 24.67576 3.541 0.000449 ***
## promoSY2 5.12432 20.75449 0.247 0.805119
## promoSY200 1.95062 19.21182 0.102 0.919182
## promoSY250 8.24511 20.76480 0.397 0.691539
## promoSY5 -11.28542 21.53484 -0.524 0.600549
## promoSYNERGY54 -17.96254 24.83461 -0.723 0.469952
## promoSYVE -10.46337 20.82454 -0.502 0.615642
## promoUP1 -10.07883 18.70540 -0.539 0.590330
## promoUP3 -7.48757 18.89459 -0.396 0.692122
## promoVIP -14.51965 25.20483 -0.576 0.564914
## promoVP1200 -17.82344 19.92407 -0.895 0.371589
## promoVPFP150 -28.07846 23.44161 -1.198 0.231746
## promoVPFP200 39.59204 19.16920 2.065 0.039568 *
## promoVPNB 3.11183 24.85811 0.125 0.900445
## promoWC1 2.28277 18.98140 0.120 0.904339
## promoWC2 -25.25581 25.61904 -0.986 0.324853
## promoWild Card -7.92439 20.77213 -0.381 0.703054
## stateAL 12.09751 18.67516 0.648 0.517518
## stateAR 6.06923 17.42167 0.348 0.727755
## stateAZ 9.14826 15.91024 0.575 0.565639
## stateCA 7.18733 15.51088 0.463 0.643364
## stateCO 7.89525 16.30694 0.484 0.628550
## stateCT 10.87731 17.36564 0.626 0.531452
## stateDE 6.59727 18.49572 0.357 0.721522
## stateFL 5.40488 15.71230 0.344 0.731045
## stateGA 6.61596 16.05348 0.412 0.680486
## stateHI -0.78531 21.46796 -0.037 0.970839
## stateIA -1.92706 21.44819 -0.090 0.928456
## stateID -3.73818 18.74433 -0.199 0.842034
## stateIL 1.01288 16.03717 0.063 0.949674
## stateIN 14.41846 16.18538 0.891 0.373587
## stateKS -1.13977 17.23663 -0.066 0.947313
## stateKY 5.03695 16.23614 0.310 0.756557
## stateLA 0.45227 16.52306 0.027 0.978177
## stateMA 2.22960 16.36496 0.136 0.891702
## stateMD 19.09073 16.31033 1.170 0.242552
## stateME -1.49917 21.80032 -0.069 0.945211
## stateMI 8.89246 16.02217 0.555 0.579217
## stateMN 5.56969 17.73045 0.314 0.753595
## stateMO 1.88272 16.83366 0.112 0.911008
## stateMS -0.12679 17.82427 -0.007 0.994328
## stateNC 0.52579 16.69392 0.031 0.974891
## stateND -6.93225 22.25168 -0.312 0.755564
## stateNE 3.48953 17.59910 0.198 0.842934
## stateNH -29.91738 19.23082 -1.556 0.120618
## stateNJ 21.22228 15.93093 1.332 0.183618
## stateNM 6.33967 18.84572 0.336 0.736758
## stateNV -0.80598 16.16271 -0.050 0.960255
## stateNY 4.78374 15.61806 0.306 0.759549
## stateOH 10.35219 15.84978 0.653 0.514062
## stateOK 14.75048 16.75936 0.880 0.379348
## stateOR 2.61633 16.21158 0.161 0.871876
## statePA 3.19331 15.71870 0.203 0.839125
## statePR 9.87068 16.80498 0.587 0.557309
## stateRI 5.50006 18.63505 0.295 0.768045
## stateSC 6.51450 16.42027 0.397 0.691787
## stateSD -1.37982 21.47017 -0.064 0.948792
## stateTN -0.67807 17.91974 -0.038 0.969836
## stateTX 9.39156 15.48293 0.607 0.544498
## stateUT -1.20692 17.13130 -0.070 0.943872
## stateVA 12.57227 16.19860 0.776 0.438157
## stateVT 8.19761 21.67719 0.378 0.705519
## stateWA 5.65411 17.19492 0.329 0.742471
## stateWI 5.26781 21.73125 0.242 0.808596
## stateWY 1.21667 17.82631 0.068 0.945622
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 14.55 on 377 degrees of freedom
## Multiple R-squared: 0.4421, Adjusted R-squared: 0.2616
## F-statistic: 2.449 on 122 and 377 DF, p-value: 3.965e-11
anova(lm6)
result$var[6] <- "lm(formula = Order_Qty ~ Qt + Brand + promo + state, data = lm_cust_s2)"
result$pval[6] <- "Adjusted R-squared: 0.04593 F-statistic: 1.2 on 120 and 378 DF, p-value: 0.1016"
result$comment[6] <- "promo is very less significant now, nothing else is significant"
#7 Drop Brand
set.seed(12123)
lm7 <- lm(Order_Qty ~ Qt + promo + state,lm_cust_s2)
summary(lm7)
##
## Call:
## lm(formula = Order_Qty ~ Qt + promo + state, data = lm_cust_s2)
##
## Residuals:
## Min 1Q Median 3Q Max
## -59.897 -7.220 -1.751 4.574 118.831
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 17.82699 22.77007 0.783 0.4341
## QtQ1_18 9.60323 7.94634 1.209 0.2275
## QtQ2_17 -1.91410 3.24532 -0.590 0.5556
## QtQ2_18 6.37288 7.66468 0.831 0.4062
## QtQ3_17 9.74091 7.92989 1.228 0.2200
## QtQ3_18 6.55771 8.06986 0.813 0.4169
## QtQ4_17 9.28270 7.82815 1.186 0.2364
## QtQ4_18 6.49315 8.07874 0.804 0.4220
## promoCODE F -21.30117 20.15356 -1.057 0.2912
## promoH15 -16.22210 16.49983 -0.983 0.3261
## promoLUX40 -5.98859 16.38959 -0.365 0.7150
## promoMVE150 -16.49235 22.80517 -0.723 0.4700
## promoMVENB -24.58051 23.12634 -1.063 0.2885
## promoNASC75 -18.45159 18.71766 -0.986 0.3248
## promoNB -6.10572 19.96944 -0.306 0.7599
## promoOOX40 -20.10862 19.03007 -1.057 0.2913
## promoOOX60 -11.93311 22.68317 -0.526 0.5991
## promoOther -22.19987 18.06058 -1.229 0.2197
## promoOY12 -13.99418 20.50940 -0.682 0.4954
## promoPRE-SELL B -28.25690 25.30282 -1.117 0.2648
## promoPRE-SELL T -14.99829 24.01635 -0.625 0.5326
## promoRB15 -8.81141 17.58271 -0.501 0.6165
## promoRSD -25.86523 24.25123 -1.067 0.2868
## promoSUN1 -24.01901 22.90203 -1.049 0.2949
## promoSY1 -18.84227 18.51470 -1.018 0.3094
## promoSY100 -19.76133 18.31480 -1.079 0.2812
## promoSY1000 27.34825 21.40559 1.278 0.2021
## promoSY2 -6.17294 19.15482 -0.322 0.7474
## promoSY200 -6.45183 17.32059 -0.372 0.7097
## promoSY250 -7.59815 19.07136 -0.398 0.6905
## promoSY5 -20.75396 20.20567 -1.027 0.3050
## promoSYNERGY54 -21.42626 24.18976 -0.886 0.3763
## promoSYVE -15.85038 19.33258 -0.820 0.4128
## promoUP1 -13.09966 16.80322 -0.780 0.4361
## promoUP3 -10.10114 16.98647 -0.595 0.5524
## promoVIP -21.86523 24.25123 -0.902 0.3678
## promoVP1200 -19.81277 18.28019 -1.084 0.2791
## promoVPFP150 -26.93311 22.68317 -1.187 0.2358
## promoVPFP200 40.45007 17.39671 2.325 0.0206 *
## promoVPNB -1.26706 23.74306 -0.053 0.9575
## promoWC1 -2.23708 17.04531 -0.131 0.8956
## promoWC2 -21.86523 24.25123 -0.902 0.3678
## promoWild Card -17.18915 19.38265 -0.887 0.3757
## stateAL 9.92992 19.62458 0.506 0.6131
## stateAR 4.21711 17.92803 0.235 0.8142
## stateAZ 11.78135 16.64629 0.708 0.4795
## stateCA 10.10612 16.13699 0.626 0.5315
## stateCO 13.39658 16.98687 0.789 0.4308
## stateCT 15.71661 17.99018 0.874 0.3828
## stateDE 11.38483 19.46232 0.585 0.5589
## stateFL 9.17301 16.36422 0.561 0.5754
## stateGA 8.75352 16.71646 0.524 0.6008
## stateHI 3.76965 22.63566 0.167 0.8678
## stateIA 5.09018 22.66199 0.225 0.8224
## stateID 2.02190 19.76866 0.102 0.9186
## stateIL 4.61969 16.85942 0.274 0.7842
## stateIN 12.93396 16.92027 0.764 0.4451
## stateKS 0.17131 17.93655 0.010 0.9924
## stateKY 7.78882 16.92252 0.460 0.6456
## stateLA 4.71040 17.24343 0.273 0.7849
## stateMA 9.65741 17.03375 0.567 0.5711
## stateMD 20.85035 16.89661 1.234 0.2179
## stateME 0.09018 22.66199 0.004 0.9968
## stateMI 10.16827 16.66883 0.610 0.5422
## stateMN 1.89110 18.51469 0.102 0.9187
## stateMO 4.23787 17.52649 0.242 0.8091
## stateMS -1.91202 18.45235 -0.104 0.9175
## stateNC 5.53496 17.33964 0.319 0.7497
## stateND 6.87973 22.65604 0.304 0.7615
## stateNE 5.04570 18.96670 0.266 0.7904
## stateNH -15.25370 19.90810 -0.766 0.4440
## stateNJ 17.33696 16.56044 1.047 0.2958
## stateNM 5.19970 19.68206 0.264 0.7918
## stateNV 0.28869 16.83305 0.017 0.9863
## stateNY 7.66536 16.25692 0.472 0.6375
## stateOH 13.30330 16.47950 0.807 0.4200
## stateOK 15.07647 17.44027 0.864 0.3878
## stateOR 3.20506 16.87591 0.190 0.8495
## statePA 5.30031 16.44689 0.322 0.7474
## statePR 15.44008 17.51342 0.882 0.3785
## stateRI 11.42992 19.62458 0.582 0.5606
## stateSC 7.98442 17.05499 0.468 0.6399
## stateSD 4.81517 22.66903 0.212 0.8319
## stateTN 1.02774 18.70072 0.055 0.9562
## stateTX 10.95956 16.18455 0.677 0.4987
## stateUT 5.22434 17.92671 0.291 0.7709
## stateVA 12.53188 16.86834 0.743 0.4580
## stateVT 14.18677 22.96257 0.618 0.5370
## stateWA 3.36819 17.97034 0.187 0.8514
## stateWI 5.87973 22.65604 0.260 0.7954
## stateWY 3.15485 18.50057 0.171 0.8647
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 15.83 on 409 degrees of freedom
## Multiple R-squared: 0.283, Adjusted R-squared: 0.1252
## F-statistic: 1.794 on 90 and 409 DF, p-value: 7.364e-05
anova(lm7)
result$var[7] <- "lm(formula = Order_Qty ~ Qt + promo + state, data = lm_cust_s2)"
result$pval[7] <- "Adjusted R-squared: 0.04285 F-statistic: 1.251 on 89 and 409 DF, p-value: 0.07818"
result$comment[7] <- "not much. sig "
#8 Drop state and Brand
set.seed(12126)
lm8 <- lm(Order_Qty ~ Qt + promo + Brand,lm_cust_s2)
summary(lm8)
##
## Call:
## lm(formula = Order_Qty ~ Qt + promo + Brand, data = lm_cust_s2)
##
## Residuals:
## Min 1Q Median 3Q Max
## -59.996 -7.220 -1.227 4.521 112.894
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 10.91788 19.09197 0.572 0.567721
## QtQ1_18 7.06051 7.25004 0.974 0.330681
## QtQ2_17 -0.05754 2.94410 -0.020 0.984417
## QtQ2_18 5.66405 6.97502 0.812 0.417219
## QtQ3_17 6.95078 7.18832 0.967 0.334117
## QtQ3_18 6.47498 7.27275 0.890 0.373805
## QtQ4_17 9.15344 7.03005 1.302 0.193606
## QtQ4_18 6.83850 7.35370 0.930 0.352930
## promoCODE F -19.32242 20.99467 -0.920 0.357913
## promoH15 -14.90217 18.25338 -0.816 0.414725
## promoLUX40 -0.38336 18.19446 -0.021 0.983200
## promoMVE150 -18.00000 20.67632 -0.871 0.384485
## promoMVENB -24.18558 23.39922 -1.034 0.301908
## promoNASC75 -18.60921 20.09430 -0.926 0.354923
## promoNB -0.55462 20.92204 -0.027 0.978864
## promoOOX40 -9.38359 20.08931 -0.467 0.640672
## promoOOX60 -4.36790 24.14594 -0.181 0.856535
## promoOther -19.56951 19.20950 -1.019 0.308905
## promoOY12 -18.68670 20.86216 -0.896 0.370908
## promoPRE-SELL B -14.45229 24.36992 -0.593 0.553471
## promoPRE-SELL T -21.19629 23.51011 -0.902 0.367790
## promoRB15 -10.69289 19.24500 -0.556 0.578763
## promoRSD -23.86034 24.48004 -0.975 0.330271
## promoSUN1 -6.71018 25.46497 -0.264 0.792288
## promoSY1 -15.86576 19.61723 -0.809 0.419102
## promoSY100 -15.81382 19.40307 -0.815 0.415519
## promoSY1000 85.36565 24.27172 3.517 0.000483 ***
## promoSY2 -0.17745 20.28992 -0.009 0.993026
## promoSY200 -2.30075 18.99052 -0.121 0.903627
## promoSY250 7.88248 20.26298 0.389 0.697465
## promoSY5 -19.02459 20.74543 -0.917 0.359637
## promoSYNERGY54 -20.02408 24.42109 -0.820 0.412704
## promoSYVE -14.99847 20.36204 -0.737 0.461778
## promoUP1 -10.87043 18.42731 -0.590 0.555565
## promoUP3 -8.68283 18.54037 -0.468 0.639796
## promoVIP -21.11033 24.43453 -0.864 0.388100
## promoVP1200 -15.66941 19.51538 -0.803 0.422466
## promoVPFP150 -27.16314 23.23322 -1.169 0.242998
## promoVPFP200 34.83268 18.99865 1.833 0.067438 .
## promoVPNB 7.03219 23.73477 0.296 0.767159
## promoWC1 -0.20502 18.68815 -0.011 0.991252
## promoWC2 -29.37264 24.73669 -1.187 0.235729
## promoWild Card -9.71568 20.40087 -0.476 0.634149
## BrandAX 8.09437 9.27029 0.873 0.383073
## BrandBB 4.40083 9.78474 0.450 0.653110
## BrandBE 22.79071 8.51049 2.678 0.007694 **
## BrandBV 4.53441 9.79543 0.463 0.643665
## BrandCH 16.08212 12.27795 1.310 0.190958
## BrandDG 9.45003 9.09381 1.039 0.299316
## BrandDY -1.10752 8.64108 -0.128 0.898075
## BrandEA 7.20300 7.90716 0.911 0.362839
## BrandHC 17.34540 7.00349 2.477 0.013649 *
## BrandMK 14.52840 7.09902 2.047 0.041318 *
## BrandMU 28.17666 16.12137 1.748 0.081224 .
## BrandOJ 3.21066 8.78855 0.365 0.715052
## BrandOO 16.49300 6.88708 2.395 0.017063 *
## BrandOX 16.72909 7.04730 2.374 0.018048 *
## BrandOY 11.80856 7.64626 1.544 0.123246
## BrandPH 14.04994 8.35522 1.682 0.093386 .
## BrandPO 30.19333 9.87588 3.057 0.002375 **
## BrandPP 1.55707 12.23662 0.127 0.898805
## BrandPR 15.26770 7.09767 2.151 0.032033 *
## BrandPS 5.72306 8.91862 0.642 0.521415
## BrandRA -87.34404 21.71560 -4.022 6.82e-05 ***
## BrandRB 17.24526 6.64785 2.594 0.009811 **
## BrandRJ -2.15016 12.25389 -0.175 0.860796
## BrandRL 10.55406 9.33896 1.130 0.259067
## BrandRX 17.65596 6.63757 2.660 0.008109 **
## BrandRY 2.07458 6.95340 0.298 0.765578
## BrandSF 0.06096 12.60019 0.005 0.996142
## BrandTF 13.27841 7.48407 1.774 0.076742 .
## BrandTY 9.80262 7.69471 1.274 0.203380
## BrandVA -1.63487 12.07466 -0.135 0.892362
## BrandVE 13.33501 7.54497 1.767 0.077878 .
## BrandVO 12.43224 7.38455 1.684 0.093003 .
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 14.62 on 425 degrees of freedom
## Multiple R-squared: 0.3647, Adjusted R-squared: 0.2541
## F-statistic: 3.297 on 74 and 425 DF, p-value: 1.028e-14
anova(lm8)
result$var[8] <- "lm(formula = Order_Qty ~ Qt + promo + Brand, data = lm_cust_s2)"
result$pval[8] <- "Adjusted R-squared: 0.04555 F-statistic: 1.34 on 70 and 429 DF, p-value: 0.04416"
result$comment[8] <- "not much sig."
lm9 <- lm(formula = Order_Qty ~ Qt + Brand + promo + month, data = lm_cust_s2)
summary(lm9)
##
## Call:
## lm(formula = Order_Qty ~ Qt + Brand + promo + month, data = lm_cust_s2)
##
## Residuals:
## Min 1Q Median 3Q Max
## -59.750 -7.022 -1.354 4.585 109.021
##
## Coefficients: (3 not defined because of singularities)
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 6.181159 19.234168 0.321 0.748096
## QtQ1_18 7.576366 7.288913 1.039 0.299204
## QtQ2_17 6.971625 4.061219 1.717 0.086789 .
## QtQ2_18 13.110317 7.576606 1.730 0.084304 .
## QtQ3_17 10.859031 7.562334 1.436 0.151770
## QtQ3_18 9.437978 7.674453 1.230 0.219469
## QtQ4_17 14.695165 7.648736 1.921 0.055381 .
## QtQ4_18 11.955958 7.857497 1.522 0.128868
## BrandAX 7.161199 9.309875 0.769 0.442207
## BrandBB 3.163395 9.832283 0.322 0.747814
## BrandBE 21.289024 8.559222 2.487 0.013263 *
## BrandBV 4.306264 9.808624 0.439 0.660868
## BrandCH 13.615238 12.280327 1.109 0.268197
## BrandDG 6.527993 9.189764 0.710 0.477881
## BrandDY -3.075941 8.673155 -0.355 0.723031
## BrandEA 6.097335 7.900319 0.772 0.440680
## BrandHC 16.461769 7.044462 2.337 0.019920 *
## BrandMK 13.242229 7.129100 1.857 0.063946 .
## BrandMU 23.321242 16.118782 1.447 0.148694
## BrandOJ 0.297105 8.930357 0.033 0.973476
## BrandOO 15.286678 6.932210 2.205 0.027988 *
## BrandOX 15.016663 7.082081 2.120 0.034564 *
## BrandOY 11.164944 7.687309 1.452 0.147146
## BrandPH 13.325576 8.408063 1.585 0.113757
## BrandPO 31.029831 9.870574 3.144 0.001788 **
## BrandPP 3.293757 12.202494 0.270 0.787352
## BrandPR 14.886553 7.105670 2.095 0.036772 *
## BrandPS 4.155378 8.918288 0.466 0.641502
## BrandRA -88.924971 21.607401 -4.115 4.66e-05 ***
## BrandRB 16.552876 6.690870 2.474 0.013760 *
## BrandRJ -1.637048 12.292957 -0.133 0.894123
## BrandRL 9.768585 9.307913 1.049 0.294559
## BrandRX 16.075029 6.688829 2.403 0.016685 *
## BrandRY 1.844805 6.966909 0.265 0.791298
## BrandSF 0.314770 12.634630 0.025 0.980136
## BrandTF 12.118302 7.567280 1.601 0.110044
## BrandTY 8.725250 7.757849 1.125 0.261363
## BrandVA -6.085671 12.201965 -0.499 0.618222
## BrandVE 11.609611 7.606555 1.526 0.127702
## BrandVO 11.373074 7.401579 1.537 0.125156
## promoCODE F -17.884516 21.082302 -0.848 0.396747
## promoH15 -13.772933 18.309700 -0.752 0.452343
## promoLUX40 0.702886 18.275956 0.038 0.969340
## promoMVE150 -18.000000 20.546030 -0.876 0.381490
## promoMVENB -26.271315 23.310316 -1.127 0.260380
## promoNASC75 -16.569757 20.157356 -0.822 0.411535
## promoNB 3.489081 20.994132 0.166 0.868085
## promoOOX40 -10.146352 20.070234 -0.506 0.613445
## promoOOX60 -3.912756 24.049823 -0.163 0.870838
## promoOther -19.060061 19.188540 -0.993 0.321138
## promoOY12 -20.397441 20.848811 -0.978 0.328468
## promoPRE-SELL B -17.534777 24.515590 -0.715 0.474855
## promoPRE-SELL T -23.346814 23.681710 -0.986 0.324774
## promoRB15 -10.723265 19.208508 -0.558 0.576969
## promoRSD -22.269129 24.612582 -0.905 0.366101
## promoSUN1 -9.515735 25.530055 -0.373 0.709541
## promoSY1 -15.373870 19.600746 -0.784 0.433279
## promoSY100 -15.144423 19.366255 -0.782 0.434658
## promoSY1000 83.963843 24.164782 3.475 0.000565 ***
## promoSY2 0.525059 20.289440 0.026 0.979367
## promoSY200 -3.446806 19.037747 -0.181 0.856415
## promoSY250 8.621645 20.290303 0.425 0.671118
## promoSY5 -19.400331 20.703050 -0.937 0.349262
## promoSYNERGY54 -21.224502 24.379222 -0.871 0.384475
## promoSYVE -11.979047 20.336611 -0.589 0.556154
## promoUP1 -9.382130 18.506440 -0.507 0.612447
## promoUP3 -7.537797 18.593049 -0.405 0.685385
## promoVIP -22.533705 24.431281 -0.922 0.356890
## promoVP1200 -13.736997 19.548343 -0.703 0.482623
## promoVPFP150 -28.937638 23.148551 -1.250 0.211970
## promoVPFP200 32.811914 18.946381 1.732 0.084043 .
## promoVPNB 5.289662 23.660668 0.224 0.823206
## promoWC1 0.531093 18.676424 0.028 0.977328
## promoWC2 -30.580500 24.709737 -1.238 0.216565
## promoWild Card -10.481975 20.330390 -0.516 0.606420
## month2 8.047354 3.030940 2.655 0.008233 **
## month3 7.203604 3.156798 2.282 0.022996 *
## month4 -3.279584 3.710154 -0.884 0.377234
## month5 -3.140648 3.652239 -0.860 0.390325
## month6 NA NA NA NA
## month7 0.001712 3.539126 0.000 0.999614
## month8 6.119683 3.638560 1.682 0.093338 .
## month9 NA NA NA NA
## month10 -1.271845 3.749527 -0.339 0.734629
## month11 1.200833 3.534208 0.340 0.734198
## month12 NA NA NA NA
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 14.53 on 417 degrees of freedom
## Multiple R-squared: 0.3845, Adjusted R-squared: 0.2635
## F-statistic: 3.177 on 82 and 417 DF, p-value: 1.158e-14
anova(lm9)
result$var[9] <- "lm(formula = Order_Qty ~ Qt + Brand + promo + month, data = lm_cust_s2)"
result$pval[9] <- "Adjusted R-squared: 0.05115 F-statistic: 1.345 on 78 and 421 DF, p-value: 0.03633"
result$comment[9] <- "Pvalue looks less than to .05"
## 10
lm10 <- lm(formula = Order_Qty ~ Qt + promo + month, data = lm_cust_s2)
summary(lm10)
##
## Call:
## lm(formula = Order_Qty ~ Qt + promo + month, data = lm_cust_s2)
##
## Residuals:
## Min 1Q Median 3Q Max
## -59.500 -7.557 -1.736 4.402 122.450
##
## Coefficients: (3 not defined because of singularities)
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 19.0988 15.7928 1.209 0.2272
## QtQ1_18 10.9097 7.5123 1.452 0.1471
## QtQ2_17 6.0304 4.1704 1.446 0.1489
## QtQ2_18 15.5235 7.8028 1.989 0.0473 *
## QtQ3_17 12.8233 7.8312 1.637 0.1022
## QtQ3_18 10.9335 7.9773 1.371 0.1712
## QtQ4_17 17.9925 7.9371 2.267 0.0239 *
## QtQ4_18 14.5858 8.0892 1.803 0.0720 .
## promoCODE F -23.0839 19.0287 -1.213 0.2257
## promoH15 -14.2361 15.9386 -0.893 0.3722
## promoLUX40 -2.6157 15.8592 -0.165 0.8691
## promoMVE150 -18.0000 21.8516 -0.824 0.4105
## promoMVENB -25.0000 21.8516 -1.144 0.2532
## promoNASC75 -12.6392 18.3653 -0.688 0.4917
## promoNB 1.7976 19.1932 0.094 0.9254
## promoOOX40 -13.7528 18.0629 -0.761 0.4468
## promoOOX60 -11.0000 21.8516 -0.503 0.6149
## promoOther -21.2966 17.1376 -1.243 0.2146
## promoOY12 -20.4495 18.9982 -1.076 0.2823
## promoPRE-SELL B -25.8990 22.1075 -1.172 0.2420
## promoPRE-SELL T -23.8990 22.1075 -1.081 0.2803
## promoRB15 -7.3206 17.0616 -0.429 0.6681
## promoRSD -26.6610 23.1229 -1.153 0.2495
## promoSUN1 -23.1292 22.2566 -1.039 0.2993
## promoSY1 -18.6139 17.5124 -1.063 0.2884
## promoSY100 -16.1685 17.3743 -0.931 0.3526
## promoSY1000 30.5903 20.3606 1.502 0.1337
## promoSY2 -4.3766 18.2818 -0.239 0.8109
## promoSY200 -6.0972 16.8391 -0.362 0.7175
## promoSY250 -4.2586 18.1881 -0.234 0.8150
## promoSY5 -26.0564 18.9321 -1.376 0.1694
## promoSYNERGY54 -21.4281 23.2410 -0.922 0.3570
## promoSYVE -14.1990 18.4580 -0.769 0.4421
## promoUP1 -9.7744 16.1217 -0.606 0.5446
## promoUP3 -7.5879 16.2651 -0.467 0.6411
## promoVIP -24.6224 23.1671 -1.063 0.2884
## promoVP1200 -13.2742 17.4166 -0.762 0.4464
## promoVPFP150 -26.0000 21.8516 -1.190 0.2347
## promoVPFP200 35.5000 16.6895 2.127 0.0340 *
## promoVPNB 5.0000 21.8516 0.229 0.8191
## promoWC1 -1.1299 16.3643 -0.069 0.9450
## promoWC2 -24.6224 23.1671 -1.063 0.2884
## promoWild Card -15.5092 18.5234 -0.837 0.4029
## month2 7.8002 3.1045 2.513 0.0123 *
## month3 7.9012 3.2656 2.420 0.0159 *
## month4 -2.8233 3.8337 -0.736 0.4618
## month5 -1.9614 3.6842 -0.532 0.5947
## month6 NA NA NA NA
## month7 1.7468 3.6685 0.476 0.6342
## month8 6.7384 3.7294 1.807 0.0715 .
## month9 NA NA NA NA
## month10 -4.4498 3.7932 -1.173 0.2414
## month11 0.7435 3.6338 0.205 0.8380
## month12 NA NA NA NA
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 15.45 on 449 degrees of freedom
## Multiple R-squared: 0.2504, Adjusted R-squared: 0.1669
## F-statistic: 2.999 on 50 and 449 DF, p-value: 6.715e-10
anova(lm10)
result$var[10] <- "lm(formula = Order_Qty ~ Qt + promo + month, data = lm_cust_s2)"
result$pval[10] <- "Adjusted R-squared: 0.0448
F-statistic: 1.498 on 47 and 452 DF, p-value: 0.02147"
result$comment[10] <- "not much sig."
# p-value: 0.02331
lm_pbm <- lm(formula = Order_Qty ~ promo + Brand + month, data = lm_cust_s2)
summary(lm(formula = Order_Qty ~ promo + Brand + month, data = lm_cust_s2))
##
## Call:
## lm(formula = Order_Qty ~ promo + Brand + month, data = lm_cust_s2)
##
## Residuals:
## Min 1Q Median 3Q Max
## -59.900 -7.122 -1.347 4.404 108.734
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 6.4594 19.1440 0.337 0.73597
## promoCODE F -18.4376 21.0272 -0.877 0.38107
## promoH15 -14.2338 18.2601 -0.780 0.43612
## promoLUX40 0.2627 18.2282 0.014 0.98851
## promoMVE150 -18.0000 20.5002 -0.878 0.38042
## promoMVENB -26.9237 23.2311 -1.159 0.24713
## promoNASC75 -16.6401 20.0516 -0.830 0.40709
## promoNB 3.1356 20.9442 0.150 0.88106
## promoOOX40 -10.3352 20.0067 -0.517 0.60571
## promoOOX60 -4.0954 23.9651 -0.171 0.86439
## promoOther -12.6564 18.0043 -0.703 0.48246
## promoOY12 -21.0095 20.7784 -1.011 0.31254
## promoPRE-SELL B -18.6297 24.4131 -0.763 0.44583
## promoPRE-SELL T -24.6383 23.5948 -1.044 0.29698
## promoRB15 -11.1523 19.1511 -0.582 0.56065
## promoRSD -17.0222 23.7796 -0.716 0.47449
## promoSUN1 -9.2637 25.4574 -0.364 0.71612
## promoSY1 -9.8998 18.4399 -0.537 0.59164
## promoSY100 -7.8949 18.2787 -0.432 0.66602
## promoSY1000 90.9055 23.0554 3.943 9.43e-05 ***
## promoSY2 5.3394 19.0799 0.280 0.77973
## promoSY200 -2.7275 18.9362 -0.144 0.88554
## promoSY250 15.5501 19.0269 0.817 0.41424
## promoSY5 -14.3404 19.5531 -0.733 0.46372
## promoSYNERGY54 -16.3377 23.4664 -0.696 0.48668
## promoSYVE -6.3770 19.1916 -0.332 0.73984
## promoUP1 -9.8059 18.4535 -0.531 0.59543
## promoUP3 -8.1234 18.5388 -0.438 0.66148
## promoVIP -16.4256 23.4458 -0.701 0.48395
## promoVP1200 -14.5300 19.4735 -0.746 0.45600
## promoVPFP150 -29.6386 23.0746 -1.284 0.19968
## promoVPFP200 32.2610 18.8836 1.708 0.08830 .
## promoVPNB 5.2297 23.5957 0.222 0.82470
## promoWC1 3.4220 18.4043 0.186 0.85259
## promoWC2 -24.6812 23.9193 -1.032 0.30273
## promoWild Card -3.6196 19.0762 -0.190 0.84960
## BrandAX 7.3029 9.2693 0.788 0.43123
## BrandBB 3.7440 9.7932 0.382 0.70243
## BrandBE 21.9211 8.5025 2.578 0.01027 *
## BrandBV 5.1027 9.7177 0.525 0.59980
## BrandCH 13.5505 12.1828 1.112 0.26666
## BrandDG 6.6459 9.0846 0.732 0.46485
## BrandDY -2.6249 8.6188 -0.305 0.76086
## BrandEA 5.9863 7.8611 0.762 0.44678
## BrandHC 17.0837 7.0012 2.440 0.01509 *
## BrandMK 13.6655 7.0639 1.935 0.05372 .
## BrandMU 23.3555 16.0212 1.458 0.14565
## BrandOJ 0.8699 8.8906 0.098 0.92211
## BrandOO 15.6215 6.8855 2.269 0.02379 *
## BrandOX 15.4978 7.0464 2.199 0.02839 *
## BrandOY 11.5447 7.6402 1.511 0.13153
## BrandPH 13.3208 8.3141 1.602 0.10986
## BrandPO 31.4128 9.8303 3.196 0.00150 **
## BrandPP 4.0117 12.1392 0.330 0.74120
## BrandPR 15.4742 7.0633 2.191 0.02901 *
## BrandPS 4.7080 8.8569 0.532 0.59531
## BrandRA -88.3550 21.5473 -4.101 4.95e-05 ***
## BrandRB 17.1891 6.6340 2.591 0.00990 **
## BrandRJ -1.4965 12.2085 -0.123 0.90250
## BrandRL 10.4400 9.2607 1.127 0.26024
## BrandRX 16.6450 6.6352 2.509 0.01250 *
## BrandRY 2.1357 6.9128 0.309 0.75751
## BrandSF 0.9081 12.5728 0.072 0.94246
## BrandTF 13.1113 7.5031 1.747 0.08129 .
## BrandTY 9.2698 7.7089 1.202 0.22986
## BrandVA -5.4738 12.1610 -0.450 0.65286
## BrandVE 11.7638 7.5700 1.554 0.12093
## BrandVO 11.6822 7.3574 1.588 0.11308
## month2 8.0676 3.0220 2.670 0.00789 **
## month3 6.9900 3.1444 2.223 0.02674 *
## month4 2.8747 3.4278 0.839 0.40215
## month5 3.4515 3.3683 1.025 0.30610
## month6 6.3007 3.4371 1.833 0.06749 .
## month7 2.8340 3.6265 0.781 0.43497
## month8 8.8415 3.5805 2.469 0.01393 *
## month9 3.0164 3.3874 0.890 0.37373
## month10 5.5656 3.5247 1.579 0.11508
## month11 7.4041 3.4243 2.162 0.03117 *
## month12 6.1625 3.5228 1.749 0.08096 .
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 14.5 on 421 degrees of freedom
## Multiple R-squared: 0.3814, Adjusted R-squared: 0.2668
## F-statistic: 3.328 on 78 and 421 DF, p-value: 2.198e-15
anova(lm(formula = Order_Qty ~ promo + Brand + month, data = lm_cust_s2))
# p-value: 0.0177
lm_pd <- lm(formula = Order_Qty ~ promo + `Order Date`, data = lm_cust_s2)
anova(lm(formula = Order_Qty ~ promo + `Order Date`, data = lm_cust_s2))
summary(lm(formula = Order_Qty ~ promo + `Order Date`, data = lm_cust_s2))
##
## Call:
## lm(formula = Order_Qty ~ promo + `Order Date`, data = lm_cust_s2)
##
## Residuals:
## Min 1Q Median 3Q Max
## -59.499 -7.737 -2.688 4.403 125.378
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 3.034e+01 1.039e+02 0.292 0.7703
## promoCODE F -2.499e+01 1.900e+01 -1.315 0.1891
## promoH15 -1.737e+01 1.580e+01 -1.099 0.2722
## promoLUX40 -6.105e+00 1.572e+01 -0.388 0.6979
## promoMVE150 -1.800e+01 2.194e+01 -0.821 0.4123
## promoMVENB -2.500e+01 2.194e+01 -1.140 0.2550
## promoNASC75 -1.732e+01 1.791e+01 -0.967 0.3340
## promoNB -4.502e+00 1.900e+01 -0.237 0.8128
## promoOOX40 -1.498e+01 1.792e+01 -0.836 0.4034
## promoOOX60 -1.100e+01 2.194e+01 -0.501 0.6163
## promoOther -1.420e+01 1.572e+01 -0.903 0.3669
## promoOY12 -2.050e+01 1.900e+01 -1.079 0.2811
## promoPRE-SELL B -2.600e+01 2.194e+01 -1.185 0.2365
## promoPRE-SELL T -2.401e+01 2.194e+01 -1.094 0.2744
## promoRB15 -9.391e+00 1.699e+01 -0.553 0.5808
## promoRSD -2.091e+01 2.209e+01 -0.947 0.3443
## promoSUN1 -2.498e+01 2.195e+01 -1.138 0.2557
## promoSY1 -1.257e+01 1.624e+01 -0.774 0.4395
## promoSY100 -8.962e+00 1.579e+01 -0.567 0.5707
## promoSY1000 4.157e+01 1.913e+01 2.173 0.0303 *
## promoSY2 1.264e+00 1.700e+01 0.074 0.9407
## promoSY200 -6.602e+00 1.647e+01 -0.401 0.6887
## promoSY250 3.691e+00 1.658e+01 0.223 0.8239
## promoSY5 -1.888e+01 1.776e+01 -1.063 0.2883
## promoSYNERGY54 -1.388e+01 2.226e+01 -0.623 0.5334
## promoSYVE -1.106e+01 1.709e+01 -0.647 0.5181
## promoUP1 -1.334e+01 1.596e+01 -0.836 0.4036
## promoUP3 -1.055e+01 1.620e+01 -0.651 0.5154
## promoVIP -1.691e+01 2.212e+01 -0.764 0.4451
## promoVP1200 -1.726e+01 1.734e+01 -0.995 0.3203
## promoVPFP150 -2.600e+01 2.194e+01 -1.185 0.2365
## promoVPFP200 3.550e+01 1.675e+01 2.119 0.0346 *
## promoVPNB 5.003e+00 2.194e+01 0.228 0.8197
## promoWC1 5.657e-01 1.600e+01 0.035 0.9718
## promoWC2 -1.691e+01 2.211e+01 -0.765 0.4448
## promoWild Card -6.129e+00 1.713e+01 -0.358 0.7206
## `Order Date` -2.245e-09 6.901e-08 -0.033 0.9741
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 15.51 on 463 degrees of freedom
## Multiple R-squared: 0.221, Adjusted R-squared: 0.1605
## F-statistic: 3.65 on 36 and 463 DF, p-value: 6.218e-11
#p-value: 0.0169
lm_py <- lm(formula = Order_Qty ~ promo + year(`Order Date`), data = lm_cust_s2)
summary(lm(formula = Order_Qty ~ promo + year(`Order Date`), data = lm_cust_s2))
##
## Call:
## lm(formula = Order_Qty ~ promo + year(`Order Date`), data = lm_cust_s2)
##
## Residuals:
## Min 1Q Median 3Q Max
## -59.500 -7.731 -2.567 4.491 125.375
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1177.2421 4227.6508 0.278 0.7808
## promoCODE F -25.0000 18.9955 -1.316 0.1888
## promoH15 -17.3704 15.7943 -1.100 0.2720
## promoLUX40 -6.1081 15.7179 -0.389 0.6977
## promoMVE150 -18.0000 21.9341 -0.821 0.4123
## promoMVENB -25.0000 21.9341 -1.140 0.2550
## promoNASC75 -17.3333 17.9091 -0.968 0.3336
## promoNB -4.5000 18.9955 -0.237 0.8128
## promoOOX40 -15.0000 17.9091 -0.838 0.4027
## promoOOX60 -11.0000 21.9341 -0.502 0.6163
## promoOther -13.8624 15.6149 -0.888 0.3751
## promoOY12 -20.5000 18.9955 -1.079 0.2811
## promoPRE-SELL B -26.0000 21.9341 -1.185 0.2365
## promoPRE-SELL T -24.0000 21.9341 -1.094 0.2744
## promoRB15 -9.4000 16.9900 -0.553 0.5803
## promoRSD -20.4297 22.0340 -0.927 0.3543
## promoSUN1 -25.0000 21.9341 -1.140 0.2550
## promoSY1 -12.0964 16.0720 -0.753 0.4520
## promoSY100 -9.0000 15.7502 -0.571 0.5680
## promoSY1000 42.0703 19.1107 2.201 0.0282 *
## promoSY2 1.7131 16.7125 0.103 0.9184
## promoSY200 -6.6250 16.4505 -0.403 0.6873
## promoSY250 4.1953 16.5835 0.253 0.8004
## promoSY5 -18.4297 17.4666 -1.055 0.2919
## promoSYNERGY54 -13.4297 22.0340 -0.610 0.5425
## promoSYVE -10.5964 16.8830 -0.628 0.5306
## promoUP1 -13.3529 15.9594 -0.837 0.4032
## promoUP3 -10.5455 16.1994 -0.651 0.5154
## promoVIP -16.4297 22.0340 -0.746 0.4563
## promoVP1200 -17.2500 17.3404 -0.995 0.3204
## promoVPFP150 -26.0000 21.9341 -1.185 0.2365
## promoVPFP200 35.5000 16.7524 2.119 0.0346 *
## promoVPNB 5.0000 21.9341 0.228 0.8198
## promoWC1 0.6971 15.9713 0.044 0.9652
## promoWC2 -16.4297 22.0340 -0.746 0.4563
## promoWild Card -5.6297 17.1188 -0.329 0.7424
## year(`Order Date`) -0.5703 2.0960 -0.272 0.7857
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 15.51 on 463 degrees of freedom
## Multiple R-squared: 0.2212, Adjusted R-squared: 0.1606
## F-statistic: 3.652 on 36 and 463 DF, p-value: 6.05e-11
anova(lm(formula = Order_Qty ~ promo + year(`Order Date`), data = lm_cust_s2))
#p-value: 0.4186 Not considering
summary(lm(formula = Order_Qty ~ month + Brand + Qt , data = lm_cust_s2))
##
## Call:
## lm(formula = Order_Qty ~ month + Brand + Qt, data = lm_cust_s2)
##
## Residuals:
## Min 1Q Median 3Q Max
## -29.096 -7.671 -2.384 4.219 135.632
##
## Coefficients: (3 not defined because of singularities)
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 9.55179 7.20768 1.325 0.185766
## month2 8.26770 3.34414 2.472 0.013792 *
## month3 11.47808 3.24462 3.538 0.000446 ***
## month4 -1.24341 4.20529 -0.296 0.767612
## month5 -0.02701 4.34391 -0.006 0.995041
## month6 3.33782 4.11187 0.812 0.417362
## month7 -2.21626 4.50009 -0.492 0.622611
## month8 3.78240 4.25074 0.890 0.374035
## month9 -0.96426 4.00482 -0.241 0.809839
## month10 0.44848 4.59902 0.098 0.922359
## month11 2.24251 4.09957 0.547 0.584641
## month12 3.22126 4.13088 0.780 0.435917
## BrandAX -0.55422 10.09759 -0.055 0.956253
## BrandBB -9.70195 10.72204 -0.905 0.366021
## BrandBE 11.51707 9.03659 1.274 0.203144
## BrandBV -8.64616 10.09153 -0.857 0.392024
## BrandCH -0.47967 10.81382 -0.044 0.964639
## BrandDG 0.36055 9.64851 0.037 0.970208
## BrandDY -0.82685 9.60699 -0.086 0.931451
## BrandEA -0.42653 8.45039 -0.050 0.959766
## BrandHC 6.21782 7.49232 0.830 0.407038
## BrandMK 1.44245 7.53605 0.191 0.848293
## BrandMU 12.66581 18.00761 0.703 0.482194
## BrandOJ -14.21209 9.33267 -1.523 0.128500
## BrandOO 6.06612 7.37329 0.823 0.411104
## BrandOX 1.19909 7.49510 0.160 0.872965
## BrandOY -1.48787 8.16462 -0.182 0.855481
## BrandPH 3.08764 8.85312 0.349 0.727430
## BrandPO 28.71730 10.70881 2.682 0.007594 **
## BrandPP -4.42259 13.46163 -0.329 0.742661
## BrandPR 5.79856 7.56799 0.766 0.443960
## BrandPS -5.60724 9.61817 -0.583 0.560194
## BrandRA -2.85636 17.94420 -0.159 0.873598
## BrandRB 6.33812 7.10467 0.892 0.372811
## BrandRJ -10.96205 11.74599 -0.933 0.351185
## BrandRL -3.57699 10.01874 -0.357 0.721236
## BrandRX 5.86175 7.06205 0.830 0.406957
## BrandRY -6.46912 7.42940 -0.871 0.384355
## BrandSF -2.59908 13.57246 -0.191 0.848222
## BrandTF 2.68708 7.95910 0.338 0.735813
## BrandTY -1.50482 8.23192 -0.183 0.855035
## BrandVA -5.14599 13.69580 -0.376 0.707291
## BrandVE -0.37324 8.18324 -0.046 0.963641
## BrandVO 0.65988 7.88283 0.084 0.933323
## QtQ1_18 -2.17350 2.71350 -0.801 0.423555
## QtQ2_17 3.94211 3.17030 1.243 0.214345
## QtQ2_18 NA NA NA NA
## QtQ3_17 2.61036 3.28104 0.796 0.426687
## QtQ3_18 NA NA NA NA
## QtQ4_17 2.19058 3.38054 0.648 0.517316
## QtQ4_18 NA NA NA NA
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 16.4 on 452 degrees of freedom
## Multiple R-squared: 0.1504, Adjusted R-squared: 0.06202
## F-statistic: 1.702 on 47 and 452 DF, p-value: 0.003565
#p-value: 0.0569
lm_pbms <- lm(formula = Order_Qty ~ Brand + promo + month + state, data = lm_cust_s2)
summary(lm(formula = Order_Qty ~ Brand + promo + month + state, data = lm_cust_s2))
##
## Call:
## lm(formula = Order_Qty ~ Brand + promo + month + state, data = lm_cust_s2)
##
## Residuals:
## Min 1Q Median 3Q Max
## -58.650 -6.873 -0.527 4.599 96.230
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -2.0271 24.8380 -0.082 0.93500
## BrandAX 6.1276 9.5040 0.645 0.51949
## BrandBB 2.5712 10.3337 0.249 0.80364
## BrandBE 25.7510 9.1478 2.815 0.00514 **
## BrandBV 7.2538 9.8473 0.737 0.46181
## BrandCH 18.2210 12.3096 1.480 0.13966
## BrandDG 9.2969 9.3754 0.992 0.32202
## BrandDY -2.0602 8.8505 -0.233 0.81606
## BrandEA 3.8759 8.1655 0.475 0.63530
## BrandHC 17.9172 7.2400 2.475 0.01378 *
## BrandMK 15.4007 7.2740 2.117 0.03490 *
## BrandMU 28.2075 16.2832 1.732 0.08404 .
## BrandOJ 0.6368 9.3583 0.068 0.94579
## BrandOO 18.2497 7.0704 2.581 0.01023 *
## BrandOX 16.6811 7.2802 2.291 0.02250 *
## BrandOY 13.9625 8.0759 1.729 0.08465 .
## BrandPH 15.8409 8.6224 1.837 0.06698 .
## BrandPO 41.5900 10.2797 4.046 6.34e-05 ***
## BrandPP 9.9690 13.0342 0.765 0.44485
## BrandPR 18.0645 7.2789 2.482 0.01351 *
## BrandPS 8.9873 9.1256 0.985 0.32534
## BrandRA -100.7532 21.9942 -4.581 6.32e-06 ***
## BrandRB 19.7317 6.8262 2.891 0.00407 **
## BrandRJ 6.8061 13.6416 0.499 0.61813
## BrandRL 9.9506 9.6307 1.033 0.30217
## BrandRX 18.2438 6.8730 2.654 0.00829 **
## BrandRY 3.5478 7.1285 0.498 0.61900
## BrandSF -1.9104 13.1964 -0.145 0.88497
## BrandTF 13.8926 7.8195 1.777 0.07644 .
## BrandTY 12.3365 8.0353 1.535 0.12556
## BrandVA -9.1514 13.0143 -0.703 0.48238
## BrandVE 13.0826 7.7991 1.677 0.09429 .
## BrandVO 12.2923 7.8071 1.575 0.11622
## promoCODE F -7.9624 21.7205 -0.367 0.71414
## promoH15 -11.3711 18.5888 -0.612 0.54110
## promoLUX40 1.7894 18.5178 0.097 0.92307
## promoMVE150 -16.2101 20.8636 -0.777 0.43768
## promoMVENB -24.1914 23.8723 -1.013 0.31154
## promoNASC75 -17.4953 20.2637 -0.863 0.38848
## promoNB 1.9541 21.3986 0.091 0.92729
## promoOOX40 -12.9253 20.5342 -0.629 0.52944
## promoOOX60 -2.8152 24.2318 -0.116 0.90757
## promoOther -10.1106 18.3122 -0.552 0.58119
## promoOY12 -13.3079 21.6869 -0.614 0.53983
## promoPRE-SELL B -16.0857 26.9046 -0.598 0.55028
## promoPRE-SELL T -16.8819 25.0731 -0.673 0.50117
## promoRB15 -8.1403 19.3365 -0.421 0.67401
## promoRSD -8.2395 24.4661 -0.337 0.73648
## promoSUN1 -13.2789 26.4509 -0.502 0.61595
## promoSY1 -5.3353 18.8383 -0.283 0.77717
## promoSY100 -7.3306 18.6147 -0.394 0.69395
## promoSY1000 93.2378 23.3622 3.991 7.92e-05 ***
## promoSY2 9.9058 19.4176 0.510 0.61025
## promoSY200 1.1945 19.1970 0.062 0.95042
## promoSY250 14.8518 19.3964 0.766 0.44434
## promoSY5 -7.2125 20.1324 -0.358 0.72036
## promoSYNERGY54 -14.6269 23.8259 -0.614 0.53965
## promoSYVE -4.1964 19.4985 -0.215 0.82972
## promoUP1 -7.0812 18.8553 -0.376 0.70746
## promoUP3 -5.4731 18.9518 -0.289 0.77290
## promoVIP -11.3443 23.9973 -0.473 0.63668
## promoVP1200 -15.4632 19.9470 -0.775 0.43870
## promoVPFP150 -28.2500 23.3572 -1.209 0.22724
## promoVPFP200 38.5838 19.1104 2.019 0.04420 *
## promoVPNB 3.4045 24.8219 0.137 0.89098
## promoWC1 6.3420 18.6847 0.339 0.73448
## promoWC2 -21.6945 24.6035 -0.882 0.37847
## promoWild Card -2.0623 19.3295 -0.107 0.91509
## month2 7.2526 3.1912 2.273 0.02361 *
## month3 5.5817 3.4056 1.639 0.10206
## month4 0.1752 3.6563 0.048 0.96180
## month5 -1.0604 3.6481 -0.291 0.77145
## month6 4.5362 3.6976 1.227 0.22067
## month7 1.2923 3.8150 0.339 0.73499
## month8 6.4958 3.7901 1.714 0.08738 .
## month9 2.2046 3.6545 0.603 0.54671
## month10 4.5054 3.7658 1.196 0.23231
## month11 5.6257 3.7434 1.503 0.13373
## month12 3.9367 3.7540 1.049 0.29501
## stateAL 10.6382 18.6311 0.571 0.56835
## stateAR 4.1500 17.4195 0.238 0.81183
## stateAZ 8.6466 15.8856 0.544 0.58656
## stateCA 5.9637 15.4903 0.385 0.70046
## stateCO 6.6513 16.2777 0.409 0.68306
## stateCT 8.4799 17.4160 0.487 0.62661
## stateDE 2.9995 18.6171 0.161 0.87209
## stateFL 5.2243 15.7274 0.332 0.73994
## stateGA 4.5722 16.0808 0.284 0.77632
## stateHI -2.6937 21.3661 -0.126 0.89974
## stateIA -1.5307 21.4072 -0.072 0.94304
## stateID -0.6688 18.8024 -0.036 0.97164
## stateIL -0.2197 16.0442 -0.014 0.98908
## stateIN 14.2527 16.2389 0.878 0.38068
## stateKS 0.7637 17.2332 0.044 0.96467
## stateKY 3.6630 16.2102 0.226 0.82135
## stateLA 0.8786 16.5711 0.053 0.95774
## stateMA -0.2324 16.3958 -0.014 0.98870
## stateMD 18.9103 16.3065 1.160 0.24692
## stateME -0.6916 21.7265 -0.032 0.97462
## stateMI 7.6082 15.9714 0.476 0.63409
## stateMN 3.4418 17.7510 0.194 0.84637
## stateMO 0.1299 16.9033 0.008 0.99387
## stateMS 0.8777 17.7718 0.049 0.96064
## stateNC 0.5107 16.7077 0.031 0.97563
## stateND -10.2389 22.1984 -0.461 0.64489
## stateNE 1.6336 17.6542 0.093 0.92632
## stateNH -29.1612 19.1727 -1.521 0.12911
## stateNJ 19.9607 15.9414 1.252 0.21131
## stateNM 4.6873 18.8954 0.248 0.80422
## stateNV -1.4418 16.1878 -0.089 0.92908
## stateNY 3.4344 15.6451 0.220 0.82637
## stateOH 9.6253 15.8424 0.608 0.54385
## stateOK 12.1529 16.7818 0.724 0.46941
## stateOR 0.8095 16.2716 0.050 0.96035
## statePA 3.1171 15.6808 0.199 0.84254
## statePR 9.1999 16.7608 0.549 0.58340
## stateRI 4.6064 18.6326 0.247 0.80487
## stateSC 4.9871 16.4590 0.303 0.76206
## stateSD -2.7986 21.4359 -0.131 0.89620
## stateTN -0.1352 17.9089 -0.008 0.99398
## stateTX 8.6111 15.4332 0.558 0.57721
## stateUT -0.3484 17.1736 -0.020 0.98382
## stateVA 11.5649 16.2051 0.714 0.47588
## stateVT 1.8404 21.7898 0.084 0.93274
## stateWA 3.4939 17.1316 0.204 0.83851
## stateWI 2.2197 21.7095 0.102 0.91862
## stateWY 0.2215 17.8137 0.012 0.99009
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 14.46 on 373 degrees of freedom
## Multiple R-squared: 0.4545, Adjusted R-squared: 0.2702
## F-statistic: 2.466 on 126 and 373 DF, p-value: 1.961e-11
# p-value: 0.08366
lmdata<-na.omit(lm_cust_s2)
lm_qbpms <-(lm(formula = Order_Qty ~ Qt + Brand + promo + `Order Date`, data = lm_cust_s2))
summary(lm_qbpms)
##
## Call:
## lm(formula = Order_Qty ~ Qt + Brand + promo + `Order Date`, data = lm_cust_s2)
##
## Residuals:
## Min 1Q Median 3Q Max
## -60.309 -7.377 -1.410 4.684 112.184
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -5.957e+02 4.910e+02 -1.213 0.225743
## QtQ1_18 -6.035e+00 1.283e+01 -0.470 0.638393
## QtQ2_17 -3.274e+00 3.927e+00 -0.834 0.404996
## QtQ2_18 -1.047e+01 1.480e+01 -0.708 0.479512
## QtQ3_17 8.222e-02 9.081e+00 0.009 0.992781
## QtQ3_18 -1.332e+01 1.758e+01 -0.757 0.449183
## QtQ4_17 -5.223e-01 1.052e+01 -0.050 0.960418
## QtQ4_18 -1.603e+01 1.990e+01 -0.805 0.421056
## BrandAX 7.969e+00 9.265e+00 0.860 0.390198
## BrandBB 3.667e+00 9.797e+00 0.374 0.708380
## BrandBE 2.203e+01 8.528e+00 2.583 0.010128 *
## BrandBV 4.345e+00 9.791e+00 0.444 0.657445
## BrandCH 1.568e+01 1.227e+01 1.278 0.202043
## BrandDG 8.756e+00 9.105e+00 0.962 0.336772
## BrandDY -1.922e+00 8.661e+00 -0.222 0.824440
## BrandEA 7.193e+00 7.902e+00 0.910 0.363195
## BrandHC 1.727e+01 6.999e+00 2.467 0.014029 *
## BrandMK 1.422e+01 7.099e+00 2.002 0.045877 *
## BrandMU 2.832e+01 1.611e+01 1.758 0.079507 .
## BrandOJ 2.117e+00 8.828e+00 0.240 0.810574
## BrandOO 1.591e+01 6.899e+00 2.307 0.021564 *
## BrandOX 1.611e+01 7.061e+00 2.281 0.023035 *
## BrandOY 1.196e+01 7.642e+00 1.564 0.118470
## BrandPH 1.361e+01 8.357e+00 1.629 0.104076
## BrandPO 2.964e+01 9.880e+00 3.000 0.002862 **
## BrandPP 1.458e+00 1.223e+01 0.119 0.905188
## BrandPR 1.523e+01 7.093e+00 2.147 0.032386 *
## BrandPS 5.409e+00 8.917e+00 0.607 0.544432
## BrandRA -8.853e+01 2.172e+01 -4.075 5.49e-05 ***
## BrandRB 1.693e+01 6.649e+00 2.547 0.011233 *
## BrandRJ -2.724e+00 1.226e+01 -0.222 0.824180
## BrandRL 1.054e+01 9.333e+00 1.129 0.259393
## BrandRX 1.714e+01 6.647e+00 2.579 0.010247 *
## BrandRY 1.837e+00 6.952e+00 0.264 0.791769
## BrandSF -3.040e-01 1.260e+01 -0.024 0.980758
## BrandTF 1.251e+01 7.505e+00 1.667 0.096212 .
## BrandTY 9.736e+00 7.690e+00 1.266 0.206183
## BrandVA -2.182e+00 1.208e+01 -0.181 0.856715
## BrandVE 1.274e+01 7.556e+00 1.685 0.092633 .
## BrandVO 1.204e+01 7.387e+00 1.630 0.103912
## promoCODE F -1.926e+01 2.098e+01 -0.918 0.359065
## promoH15 -1.424e+01 1.825e+01 -0.781 0.435506
## promoLUX40 2.385e-01 1.819e+01 0.013 0.989544
## promoMVE150 -1.818e+01 2.066e+01 -0.880 0.379570
## promoMVENB -2.461e+01 2.339e+01 -1.052 0.293192
## promoNASC75 -1.717e+01 2.012e+01 -0.853 0.393878
## promoNB 1.268e+00 2.096e+01 0.060 0.951810
## promoOOX40 -1.001e+01 2.008e+01 -0.498 0.618556
## promoOOX60 -4.214e+00 2.413e+01 -0.175 0.861467
## promoOther -1.875e+01 1.921e+01 -0.976 0.329612
## promoOY12 -1.872e+01 2.085e+01 -0.898 0.369649
## promoPRE-SELL B -1.410e+01 2.436e+01 -0.579 0.563040
## promoPRE-SELL T -1.981e+01 2.352e+01 -0.842 0.400236
## promoRB15 -1.038e+01 1.923e+01 -0.540 0.589690
## promoRSD -2.283e+01 2.448e+01 -0.933 0.351606
## promoSUN1 -7.547e+00 2.546e+01 -0.296 0.767040
## promoSY1 -1.522e+01 1.961e+01 -0.776 0.438116
## promoSY100 -1.503e+01 1.940e+01 -0.775 0.439066
## promoSY1000 8.547e+01 2.426e+01 3.524 0.000472 ***
## promoSY2 5.511e-01 2.029e+01 0.027 0.978338
## promoSY200 -2.521e+00 1.898e+01 -0.133 0.894410
## promoSY250 9.060e+00 2.027e+01 0.447 0.655187
## promoSY5 -1.881e+01 2.073e+01 -0.907 0.364692
## promoSYNERGY54 -1.993e+01 2.441e+01 -0.816 0.414727
## promoSYVE -1.535e+01 2.035e+01 -0.754 0.450998
## promoUP1 -1.045e+01 1.842e+01 -0.568 0.570625
## promoUP3 -8.070e+00 1.854e+01 -0.435 0.663508
## promoVIP -2.205e+01 2.443e+01 -0.902 0.367390
## promoVP1200 -1.493e+01 1.951e+01 -0.765 0.444571
## promoVPFP150 -2.739e+01 2.322e+01 -1.180 0.238848
## promoVPFP200 3.436e+01 1.899e+01 1.809 0.071139 .
## promoVPNB 6.542e+00 2.372e+01 0.276 0.782881
## promoWC1 9.916e-02 1.868e+01 0.005 0.995767
## promoWC2 -2.926e+01 2.472e+01 -1.183 0.237277
## promoWild Card -9.420e+00 2.039e+01 -0.462 0.644306
## `Order Date` 4.078e-07 3.299e-07 1.236 0.217020
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 14.61 on 424 degrees of freedom
## Multiple R-squared: 0.367, Adjusted R-squared: 0.255
## F-statistic: 3.278 on 75 and 424 DF, p-value: 1.1e-14
print("Result of Few models:")
## [1] "Result of Few models:"
DT::datatable(result)
From above analyis I would use differnt model to valdiate the result. Lets take model lm_pbm which is model for promotion + brand + month would predict order Quanity.
To assess whether the linear model is reliable, we need to check for
(1) linearity, (2) nearly normal residuals, and (3) constant variability. (4) Residuals are independent
Residual = Observed value - Predicted value
# From above analyis I would use differnt model to valdiate the result. Lets take model lm_pbm which is model for promotion + brand + month would predict order Quanity .
# To assess whether the linear model is reliable, we need to check for
#(1) linearity,
#(2) nearly normal residuals, and
#(3) constant variability.
#(4) Residuals are independent
# Residual = Observed value - Predicted value
library(DATA606)
plot_ss(x = lm_cust_s2$Order_Qty, y = lm_pbm$residuals,showSquares = TRUE)
## Click two points to make a line.
## Call:
## lm(formula = y ~ x, data = pts)
##
## Coefficients:
## (Intercept) x
## -9.6529 0.6186
##
## Sum of Squares: 33738.77
# # (1) Linear association: The residuals plot shows a random scatter.
#Based on the plot we can clearly say that there is apparent pattern in the distribution as the numbers appear to be group and outlier are close to the regression line, so it can be treated as strong corelation and can be considered as a linear relationship.
# # (2) Nearly normal residuals: To check this condition, we can look at a histogram
hist(lm_pbm$residuals)
# or a normal probability plot of the residuals.
#It seems the plot is slightly skewed left,
qqnorm(lm_pbm$residuals)
qqline(lm_pbm$residuals) # adds diagonal line to the normal prob plot
# (3) we can say that its also Nearly normal residuals even though its right skewed with few outliers .
# (4)Residuals can be treated as independent as sample is drawn from independent .
# plot on sample
ggplot(data = lm_cust_s2,mapping = aes(y=lm_cust_s2$Order_Qty ,x= lm_cust_s2$promo))+ geom_point() + geom_smooth(method = "lm",se=FALSE) + geom_abline(slope = lm_pbm$coefficients[8], intercept = lm_pbm$coefficients[1], color="red")
# regression Line population data of 2 year.
(ggplot(data = mkt_Data,mapping = aes(y=mkt_Data$`Order Quantity` ,x= mkt_Data$`External Description`))+ geom_point() + geom_smooth(method = "lm",se=FALSE) + geom_abline(slope = lm_pbm$coefficients[8], intercept = lm_pbm$coefficients[1], color="red") )
# Lets plot on by Order Date
# To assess whether the linear model is reliable, we need to check for
#(1) linearity,
#(2) nearly normal residuals, and
#(3) constant variability.
#(4) Residuals are independent
#
plot_ss(x = lm_cust_s2$Order_Qty, y = lm_pd$residuals,showSquares = TRUE) # Linear association
## Click two points to make a line.
## Call:
## lm(formula = y ~ x, data = pts)
##
## Coefficients:
## (Intercept) x
## -12.155 0.779
##
## Sum of Squares: 24623.21
hist(lm_pd$residuals) # Right skewed
qqnorm(lm_pd$residuals)
qqline(lm_pd$residuals) # very much on the regression line, Nearly normal residuals even though its right skewed
# On Sample
ggplot(data = lm_cust_s2,mapping = aes(y=lm_cust_s2$Order_Qty ,x= lm_cust_s2$`Order Date`))+ geom_point() + geom_smooth(method = "lm",se=FALSE) +
geom_abline(slope = lm_pd$coefficients[8], intercept = lm_pd$coefficients[1], color="green")+
geom_abline(slope = lm_pbm$coefficients[8], intercept = lm_pbm$coefficients[1], color="red")
# On Population
ggplot(data = mkt_Data,mapping = aes(y = mkt_Data$`Order Quantity`,x= mkt_Data$Brand))+ geom_point() + geom_smooth(method = "lm",se=FALSE) + geom_abline(slope = lm_pd$coefficients[8], intercept = lm_pd$coefficients[1], color="red") +
geom_abline(slope = lm_pbm$coefficients[8], intercept = lm_pbm$coefficients[1], color="green")
plot(lm_pbm)
plot(lm_pd)
Residuals: We can see that the multiple regression model1 has a smaller range for the residuals as compared with Model 2: (Model 1) -59 to 339 vs.(model 2) -62.02 to 356.44. Secondly the median of the multiple regression model 1 is much closer to 0 than the model 2 regression model.
Coefficients: (Intercept): The intercept is the left over when you average the independent and dependent variable. In the simple regression Model 1 we see that the intercept is 20.02172 which is close tp ZERO, and Model 2 has much larger intercept ie. 266.9 (format( 2.669e+02, scientific = FALSE)) meaning there’s a fair amount left over. Model 1 looks close fit with nearrest to ZERO intercept.
promo: Both multiple regression model shows that when we add promo variable it’s multiplying this variable times the numeric (ordinal) value of the Promotion code.So for every promocode in the year, you add an additional estimated column unit value in sales. For example : promoRSD will add 130 Unit each MOnth.promoWild Card will add 53 Unit
Brand : So far every brand addition would add resepctive value in the sales unit by multiplying the brand intercept with its ordinal vlaue. FOr example addition of brand AX would add 3 unit each month.
Month: When we add in the Month variable it’s multiplying this variable times the numeric (ordinal) value of the month. For example July and August
##
## Call:
## lm(formula = Order_Qty ~ promo + Brand + month, data = lm_cust_s2)
##
## Residuals:
## Min 1Q Median 3Q Max
## -59.900 -7.122 -1.347 4.404 108.734
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 6.4594 19.1440 0.337 0.73597
## promoCODE F -18.4376 21.0272 -0.877 0.38107
## promoH15 -14.2338 18.2601 -0.780 0.43612
## promoLUX40 0.2627 18.2282 0.014 0.98851
## promoMVE150 -18.0000 20.5002 -0.878 0.38042
## promoMVENB -26.9237 23.2311 -1.159 0.24713
## promoNASC75 -16.6401 20.0516 -0.830 0.40709
## promoNB 3.1356 20.9442 0.150 0.88106
## promoOOX40 -10.3352 20.0067 -0.517 0.60571
## promoOOX60 -4.0954 23.9651 -0.171 0.86439
## promoOther -12.6564 18.0043 -0.703 0.48246
## promoOY12 -21.0095 20.7784 -1.011 0.31254
## promoPRE-SELL B -18.6297 24.4131 -0.763 0.44583
## promoPRE-SELL T -24.6383 23.5948 -1.044 0.29698
## promoRB15 -11.1523 19.1511 -0.582 0.56065
## promoRSD -17.0222 23.7796 -0.716 0.47449
## promoSUN1 -9.2637 25.4574 -0.364 0.71612
## promoSY1 -9.8998 18.4399 -0.537 0.59164
## promoSY100 -7.8949 18.2787 -0.432 0.66602
## promoSY1000 90.9055 23.0554 3.943 9.43e-05 ***
## promoSY2 5.3394 19.0799 0.280 0.77973
## promoSY200 -2.7275 18.9362 -0.144 0.88554
## promoSY250 15.5501 19.0269 0.817 0.41424
## promoSY5 -14.3404 19.5531 -0.733 0.46372
## promoSYNERGY54 -16.3377 23.4664 -0.696 0.48668
## promoSYVE -6.3770 19.1916 -0.332 0.73984
## promoUP1 -9.8059 18.4535 -0.531 0.59543
## promoUP3 -8.1234 18.5388 -0.438 0.66148
## promoVIP -16.4256 23.4458 -0.701 0.48395
## promoVP1200 -14.5300 19.4735 -0.746 0.45600
## promoVPFP150 -29.6386 23.0746 -1.284 0.19968
## promoVPFP200 32.2610 18.8836 1.708 0.08830 .
## promoVPNB 5.2297 23.5957 0.222 0.82470
## promoWC1 3.4220 18.4043 0.186 0.85259
## promoWC2 -24.6812 23.9193 -1.032 0.30273
## promoWild Card -3.6196 19.0762 -0.190 0.84960
## BrandAX 7.3029 9.2693 0.788 0.43123
## BrandBB 3.7440 9.7932 0.382 0.70243
## BrandBE 21.9211 8.5025 2.578 0.01027 *
## BrandBV 5.1027 9.7177 0.525 0.59980
## BrandCH 13.5505 12.1828 1.112 0.26666
## BrandDG 6.6459 9.0846 0.732 0.46485
## BrandDY -2.6249 8.6188 -0.305 0.76086
## BrandEA 5.9863 7.8611 0.762 0.44678
## BrandHC 17.0837 7.0012 2.440 0.01509 *
## BrandMK 13.6655 7.0639 1.935 0.05372 .
## BrandMU 23.3555 16.0212 1.458 0.14565
## BrandOJ 0.8699 8.8906 0.098 0.92211
## BrandOO 15.6215 6.8855 2.269 0.02379 *
## BrandOX 15.4978 7.0464 2.199 0.02839 *
## BrandOY 11.5447 7.6402 1.511 0.13153
## BrandPH 13.3208 8.3141 1.602 0.10986
## BrandPO 31.4128 9.8303 3.196 0.00150 **
## BrandPP 4.0117 12.1392 0.330 0.74120
## BrandPR 15.4742 7.0633 2.191 0.02901 *
## BrandPS 4.7080 8.8569 0.532 0.59531
## BrandRA -88.3550 21.5473 -4.101 4.95e-05 ***
## BrandRB 17.1891 6.6340 2.591 0.00990 **
## BrandRJ -1.4965 12.2085 -0.123 0.90250
## BrandRL 10.4400 9.2607 1.127 0.26024
## BrandRX 16.6450 6.6352 2.509 0.01250 *
## BrandRY 2.1357 6.9128 0.309 0.75751
## BrandSF 0.9081 12.5728 0.072 0.94246
## BrandTF 13.1113 7.5031 1.747 0.08129 .
## BrandTY 9.2698 7.7089 1.202 0.22986
## BrandVA -5.4738 12.1610 -0.450 0.65286
## BrandVE 11.7638 7.5700 1.554 0.12093
## BrandVO 11.6822 7.3574 1.588 0.11308
## month2 8.0676 3.0220 2.670 0.00789 **
## month3 6.9900 3.1444 2.223 0.02674 *
## month4 2.8747 3.4278 0.839 0.40215
## month5 3.4515 3.3683 1.025 0.30610
## month6 6.3007 3.4371 1.833 0.06749 .
## month7 2.8340 3.6265 0.781 0.43497
## month8 8.8415 3.5805 2.469 0.01393 *
## month9 3.0164 3.3874 0.890 0.37373
## month10 5.5656 3.5247 1.579 0.11508
## month11 7.4041 3.4243 2.162 0.03117 *
## month12 6.1625 3.5228 1.749 0.08096 .
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 14.5 on 421 degrees of freedom
## Multiple R-squared: 0.3814, Adjusted R-squared: 0.2668
## F-statistic: 3.328 on 78 and 421 DF, p-value: 2.198e-15
## $promo
## [1] "CHANEL PRE" "CODE F" "H15" "LUX40" "MVE150"
## [6] "MVENB" "NASC75" "NB" "OOX40" "OOX60"
## [11] "Other" "OY12" "PRE-SELL B" "PRE-SELL T" "RB15"
## [16] "RSD" "SUN1" "SY1" "SY100" "SY1000"
## [21] "SY2" "SY200" "SY250" "SY5" "SYNERGY54"
## [26] "SYVE" "UP1" "UP3" "VIP" "VP1200"
## [31] "VPFP150" "VPFP200" "VPNB" "WC1" "WC2"
## [36] "Wild Card"
##
## $Brand
## [1] "AR" "AX" "BB" "BE" "BV" "CH" "DG" "DY" "EA" "HC" "MK" "MU" "OJ" "OO"
## [15] "OX" "OY" "PH" "PO" "PP" "PR" "PS" "RA" "RB" "RJ" "RL" "RX" "RY" "SF"
## [29] "TF" "TY" "VA" "VE" "VO"
##
## $month
## [1] "1" "2" "3" "4" "5" "6" "7" "8" "9" "10" "11" "12"
## [1] "Regression Formula Y = 6.46 + -18.44 * promoCODE F + -14.23 * promoH15 + 0.26 * promoLUX40 + -18 * promoMVE150 + -26.92 * promoMVENB + -16.64 * promoNASC75 + 3.14 * promoNB + -10.34 * promoOOX40 + -4.1 * promoOOX60 + -12.66 * promoOther + -21.01 * promoOY12 + -18.63 * promoPRE-SELL B + -24.64 * promoPRE-SELL T + -11.15 * promoRB15 + -17.02 * promoRSD + -9.26 * promoSUN1 + -9.9 * promoSY1 + -7.89 * promoSY100 + 90.91 * promoSY1000 + 5.34 * promoSY2 + -2.73 * promoSY200 + 15.55 * promoSY250 + -14.34 * promoSY5 + -16.34 * promoSYNERGY54 + -6.38 * promoSYVE + -9.81 * promoUP1 + -8.12 * promoUP3 + -16.43 * promoVIP + -14.53 * promoVP1200 + -29.64 * promoVPFP150 + 32.26 * promoVPFP200 + 5.23 * promoVPNB + 3.42 * promoWC1 + -24.68 * promoWC2 + -3.62 * promoWild Card + 7.3 * BrandAX + 3.74 * BrandBB + 21.92 * BrandBE + 5.1 * BrandBV + 13.55 * BrandCH + 6.65 * BrandDG + -2.62 * BrandDY + 5.99 * BrandEA + 17.08 * BrandHC + 13.67 * BrandMK + 23.36 * BrandMU + 0.87 * BrandOJ + 15.62 * BrandOO + 15.5 * BrandOX + 11.54 * BrandOY + 13.32 * BrandPH + 31.41 * BrandPO + 4.01 * BrandPP + 15.47 * BrandPR + 4.71 * BrandPS + -88.35 * BrandRA + 17.19 * BrandRB + -1.5 * BrandRJ + 10.44 * BrandRL + 16.65 * BrandRX + 2.14 * BrandRY + 0.91 * BrandSF + 13.11 * BrandTF + 9.27 * BrandTY + -5.47 * BrandVA + 11.76 * BrandVE + 11.68 * BrandVO + 8.07 * month2 + 6.99 * month3 + 2.87 * month4 + 3.45 * month5 + 6.3 * month6 + 2.83 * month7 + 8.84 * month8 + 3.02 * month9 + 5.57 * month10 + 7.4 * month11 + 6.16 * month12 + e"
##
## Call:
## lm(formula = Order_Qty ~ promo + `Order Date`, data = lm_cust_s2)
##
## Residuals:
## Min 1Q Median 3Q Max
## -59.499 -7.737 -2.688 4.403 125.378
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 3.034e+01 1.039e+02 0.292 0.7703
## promoCODE F -2.499e+01 1.900e+01 -1.315 0.1891
## promoH15 -1.737e+01 1.580e+01 -1.099 0.2722
## promoLUX40 -6.105e+00 1.572e+01 -0.388 0.6979
## promoMVE150 -1.800e+01 2.194e+01 -0.821 0.4123
## promoMVENB -2.500e+01 2.194e+01 -1.140 0.2550
## promoNASC75 -1.732e+01 1.791e+01 -0.967 0.3340
## promoNB -4.502e+00 1.900e+01 -0.237 0.8128
## promoOOX40 -1.498e+01 1.792e+01 -0.836 0.4034
## promoOOX60 -1.100e+01 2.194e+01 -0.501 0.6163
## promoOther -1.420e+01 1.572e+01 -0.903 0.3669
## promoOY12 -2.050e+01 1.900e+01 -1.079 0.2811
## promoPRE-SELL B -2.600e+01 2.194e+01 -1.185 0.2365
## promoPRE-SELL T -2.401e+01 2.194e+01 -1.094 0.2744
## promoRB15 -9.391e+00 1.699e+01 -0.553 0.5808
## promoRSD -2.091e+01 2.209e+01 -0.947 0.3443
## promoSUN1 -2.498e+01 2.195e+01 -1.138 0.2557
## promoSY1 -1.257e+01 1.624e+01 -0.774 0.4395
## promoSY100 -8.962e+00 1.579e+01 -0.567 0.5707
## promoSY1000 4.157e+01 1.913e+01 2.173 0.0303 *
## promoSY2 1.264e+00 1.700e+01 0.074 0.9407
## promoSY200 -6.602e+00 1.647e+01 -0.401 0.6887
## promoSY250 3.691e+00 1.658e+01 0.223 0.8239
## promoSY5 -1.888e+01 1.776e+01 -1.063 0.2883
## promoSYNERGY54 -1.388e+01 2.226e+01 -0.623 0.5334
## promoSYVE -1.106e+01 1.709e+01 -0.647 0.5181
## promoUP1 -1.334e+01 1.596e+01 -0.836 0.4036
## promoUP3 -1.055e+01 1.620e+01 -0.651 0.5154
## promoVIP -1.691e+01 2.212e+01 -0.764 0.4451
## promoVP1200 -1.726e+01 1.734e+01 -0.995 0.3203
## promoVPFP150 -2.600e+01 2.194e+01 -1.185 0.2365
## promoVPFP200 3.550e+01 1.675e+01 2.119 0.0346 *
## promoVPNB 5.003e+00 2.194e+01 0.228 0.8197
## promoWC1 5.657e-01 1.600e+01 0.035 0.9718
## promoWC2 -1.691e+01 2.211e+01 -0.765 0.4448
## promoWild Card -6.129e+00 1.713e+01 -0.358 0.7206
## `Order Date` -2.245e-09 6.901e-08 -0.033 0.9741
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 15.51 on 463 degrees of freedom
## Multiple R-squared: 0.221, Adjusted R-squared: 0.1605
## F-statistic: 3.65 on 36 and 463 DF, p-value: 6.218e-11
## $promo
## [1] "CHANEL PRE" "CODE F" "H15" "LUX40" "MVE150"
## [6] "MVENB" "NASC75" "NB" "OOX40" "OOX60"
## [11] "Other" "OY12" "PRE-SELL B" "PRE-SELL T" "RB15"
## [16] "RSD" "SUN1" "SY1" "SY100" "SY1000"
## [21] "SY2" "SY200" "SY250" "SY5" "SYNERGY54"
## [26] "SYVE" "UP1" "UP3" "VIP" "VP1200"
## [31] "VPFP150" "VPFP200" "VPNB" "WC1" "WC2"
## [36] "Wild Card"
Analyis of Variance table
anova(lm_pbm,lm_pd)
Function perfroms an analysis of variance of the two models using an F-test to assess the significanxe of the differences.
We can see Model has decreased the Sum of the Squared error, and the value of 0.1977 says that we can be 80% confidence in saying that they models are different.
Using test and sample data we will see how good our Model is. We wil luse Absolute Mean error of the model and decide which regression models works well for the sample.
# lm_cust_s2
# lm_cust_s2 <- lm_cust[sample(nrow(lm_cust),500),]
# lm_cust_s2$month <- month(lm_cust_s2$`Order Date`)
# lm_cust_s2$month <- as.factor(lm_cust_s2$month )
# names(lm_cust_s2)
#
# Uisng same sample to test lm_cust_s2 , creating sample of 500 more to test.
lm_cust_t1 <- lm_cust_s2
lm_cust_t2 <- lm_cust[sample(nrow(lm_cust),500),]
lm_cust_t2$month <- month(lm_cust_t2$`Order Date`)
lm_cust_t2$month <- as.factor(lm_cust_t2$month )
names(lm_cust_t2)
## [1] "KUNNR_NEW" "Qt" "Brand" "Order Date" "promo"
## [6] "city" "state" "Order_Qty" "Doll_Val" "month"
lm_pbm1 <- update(lm_pbm,lm_cust_s2)
# Predict main train data
lm_pred_pbm <- predict(lm_pbm,lm_cust_t1)
lm_pred_pd <- predict(lm_pd,lm_cust_t1)
lm_pred_qbpms <- predict(lm_qbpms,lm_cust_t1)
mean(abs(lm_cust_t1$Order_Qty- lm_cust_t1$Order_Qty))
## [1] 0
mean(abs(lm_pred_pbm - lm_cust_t1$Order_Qty))
## [1] 8.45356
mean(abs(lm_pred_pd - lm_cust_t1$Order_Qty))
## [1] 9.296146
mean(abs(lm_pred_qbpms - lm_cust_t1$Order_Qty))
## [1] 8.540475
# Using test data of new set
# lm_pbm <- lm(formula = Order_Qty ~ promo + Brand + month, data = lm_cust_t2)
update
## standardGeneric for "update" defined from package "stats"
##
## function (object, ...)
## standardGeneric("update")
## <environment: 0x000000000fdfe3e8>
## Methods may be defined for arguments: object
## Use showMethods("update") for currently available ones.
lm_pred_pbm <- predict(lm(formula = Order_Qty ~ promo + Brand + month, data = lm_cust_t2),lm_cust_t2)
lm_pred_pd <- predict(lm(formula = Order_Qty ~ promo + `Order Date` , data = lm_cust_t2),lm_cust_t2)
lm_pred_qbpms <- predict(lm(formula = Order_Qty ~ Qt + Brand+promo +month+ state , data = lm_cust_t2),lm_cust_t2)
## Warning in predict.lm(lm(formula = Order_Qty ~ Qt + Brand + promo + month
## + : prediction from a rank-deficient fit may be misleading
mean(abs(lm_cust_t2$Order_Qty- lm_cust_t2$Order_Qty))
## [1] 0
mean(abs(lm_pred_pbm - lm_cust_t2$Order_Qty))
## [1] 7.174344
mean(abs(lm_pred_pd - lm_cust_t2$Order_Qty))
## [1] 8.162131
mean(abs(lm_pred_qbpms - lm_cust_t2$Order_Qty))
## [1] 6.90155
From above mean errors we can see that model 1 with regession model with formula lm(formula = Order_Qty ~ promo + Brand + month, data = lm_cust_t2) is well close to zero in terms of mean absulate error.
Write a brief summary of your findings without repeating your statements from earlier. Also include a discussion of what you have learned about your research question and the data you collected. You may also want to include ideas for possible future research.
Basedon chi-square test we can say that there sales of each quarter is not same, some quarter sales are high and some qurter its low. We noted that there is some pattern or other facor that is driving sales each quarter and hence we note the relation between sales over Quarter (By rejecting H0 for Chi-square test).
One side Analysis of Variance also shows that there is diffrence in each quarters number, to answer which qurter is doing better we hav eperfromed paired t test and result inicated that Q1 of 2017 and Q2 of 2018 had major contribution to the sales.
After too many formulation of regression lines we noted that Sales Quantity (Order_Qty) can be better explained by predicotor (promo + Brand + month). Our model shows strong relation with this formula on sample dataset.
https://stats.stackexchange.com/questions/405243/compare-sales-data-over-time-in-sequence https://www.machinelearningplus.com/machine-learning/complete-introduction-linear-regression-r/ https://university.business-science.io/courses/541056/lectures/9826285 https://www.youtube.com/watch?v=SvKv375sacA https://www.youtube.com/watch?v=-yQb_ZJnFXw http://rstudio-pubs-static.s3.amazonaws.com/308410_2ece93ee71a847af9cd12fa750ed8e51.html
NA.