library(dplyr) # for manipulating data (group_by, filter, select, summarise, etc.)
library(ggplot2) # for visualizing data using the ggplot command
# note that dplyr and ggplot2 are part of a larger ecosystem of packages called `tidyverse`
# in the future we can simply run `library(tidyverse)` to load all dplyr and ggplot2
library(jtools) # summ() commands to display regression output
library(stargazer) # stargazer() command for displaying tables and regression output
library(sjPlot) # plot_model() command for visualizing output
# convert scientific notation to numerals throughout the notebook
options(scipen=999)
# change plot size to 6in x 5in to fit the Deepnote window
options(repr.plot.width=6, repr.plot.height=5)

df_store <- read.csv("Data_Class7_Store24_B.csv")

names(df_store)

str(df_store)

head(df_store)

stargazer(df_store, type = "text", digits = 2)

# Insert your own analyses here. You can add more code blocks as needed.

names(df_store)

model_1 <- lm(profit ~ mtenure + ctenure, data = df_store)
summ(model_1)

#What is the relationship between service quality and profit?
model_2 <- lm(profit ~ servqual, data = df_store)
summ(model_2)

#What is the relationship between tenure and service quality?
model_3 <- lm(servqual ~ mtenure + ctenure, data = df_store)
summ(model_3)

#What is the relationship between service quality and other skill metrics?
model_4 <- lm(servqual ~ crewskill + mgrskill, data = df_store)
summ(model_4)

#What is the relationship between service quality and other intrinsic store metrics?
model_5 <- lm(servqual ~ pop + comp + visibility + pedcount + res + hours24, data = df_store)
summ(model_5)

#Last, just for fun, I'm going to run the "kitchen sink" regression.
#What is the relationship between service quality, other variables used previously, and profit?
#I'm hoping that adding servqual to the data we had in part A of the case will improve the predictive power of the regression
model_6 <- lm(profit ~ mtenure + ctenure + pop + comp + visibility + pedcount + res + hours24 + crewskill + mgrskill + servqual, data = df_store)
summ(model_6)