-
Notifications
You must be signed in to change notification settings - Fork 0
/
Model6.Rmd
67 lines (61 loc) · 2.03 KB
/
Model6.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
---
title: "Model6"
author: "Venkata babu Aalapati"
date: "11/24/2022"
output: word_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(utf8)
library(ggplot2)
library(aod)
library(outliers)
library(readxl)
library(Hmisc)
```
```{r}
#loading the data set
df_good_belly <- read_excel("Goodbelly_Project_Data.xlsx")
#removing null values from the data set
na.omit(df_good_belly)
```
Model6:
Sales = β0 + β1Sales_Rep+β2ARP + β3Endcap + β4Demo
+ β5Demo1.3 + β6Demo4.5 + β7Sales_Rep ∗ Endcap
```{r}
#Building basic regression model
Model6<-lm(formula = Sales ~ Sales_Rep+Region+ARP+Endcap+Demo+Demo1.3+Demo4.5
+Sales_Rep*Endcap ,
data = df_good_belly)
#Understanding summary results of the model
summary(Model6)
# Plotting fitted residuals model
plot(Model6, which=1, col=c("blue"))
# Plotting residuals and find the variation left by unexplained by the model
df_good_belly$predicted <- predict(Model6) # Save the predicted values
df_good_belly$residuals <- residuals(Model6) # Save the residual values
ggplot(df_good_belly, aes(x = ARP, y = Sales)) +
geom_smooth(method = "lm", se = FALSE, color = "lightgrey") +
geom_segment(aes(xend = ARP, yend = predicted), alpha = .2) +
geom_point(aes(color = abs(residuals), size = abs(residuals))) +
scale_color_continuous(low = "green", high = "red") +
guides(color = FALSE, size = FALSE) +
geom_point(aes(y = predicted), shape = 1) +
theme_bw()
```
```{r}
#Generating CI intervals for coefficients with alpha 0.10
confint(Model6,level = 0.90)
confint.default(Model6)
coef(Model6)
#Doing wald test for further analysis on coefficients
wald.test(b = coef(Model6), Sigma = vcov(Model6), Terms = 1:9)
#Generating CI intervals for odds ratio of coefficients with alpha 0.10
exp(coef(Model6))
exp(cbind(OR = coef(Model6), confint(Model6,level = 0.90)))
```
```{r}
#Further analysis with on residuals with diagnostic plots
opar <- par(mfrow = c(2,2), oma = c(0, 0, 1.1, 0))
plot(Model6, las = 1)
```