1.

stores <- read.csv("stores.csv")
sales <- read.csv("sales.csv")
products <- read.csv("products.csv")
inventory <- read.csv("inventory.csv")

sp <- 
merge(x = sales, 
      y = products, 
      by = c("Product_ID"))

sp$Product_Cost <- as.numeric(gsub('[$,]', '', sp$Product_Cost))
sp$Product_Price <- as.numeric(gsub('[$,]', '', sp$Product_Price))
sp$Product_ID <- as.character(sp$Product_ID)
sp$Store_ID <- as.character(sp$Store_ID)
sp$Sale_ID <- as.character(sp$Sale_ID)

A.

My dependent variable is units and my independent variable is product price. Unit (Y) is the number of units sold of a particular product. Product price (x) is the price of said particular product.

\[ Y_i \sim \beta_0 + X_i\beta_1 + \epsilon_i \]

B.

reg1 <- lm(data = sp, formula = Units ~ Product_Price)
reg1
## 
## Call:
## lm(formula = Units ~ Product_Price, data = sp)
## 
## Coefficients:
##   (Intercept)  Product_Price  
##      1.442307      -0.009236

C.

The intercept value means that when the price is 0, the average units demanded is 1.44.

The slope expresses the relationship between the two variables. When there is an increase in 1 unit of price, the quantity demanded decreases by -0.009236. This aligns with the basic law of demand assumptions in economics, an increase in price decreases the quantity demanded which can be observed in the negative value of the slope.

D.

#Slope 
covxy <- cov(x = sp$Product_Price, y = sp$Units)
varx <- var(sp$Product_Price)
b1 <- covxy / varx
b1
## [1] -0.009236223
# Intercept 
avx <- mean(sp$Product_Price)
avy <- mean(sp$Units)
int <- avy - avx * b1
int 
## [1] 1.442307