# Data_frame
price <- c(100, 110, 120, 130, 140, 150, 160, 170, 180, 190)
marketing_cost <- c(20, 25, 22, 30, 35, 40, 42, 45, 50, 55)
stores <- c(50, 52, 55, 58, 60, 62, 65, 67, 70, 72)
income <- c(5000, 5200, 5400, 5600, 5800, 6000, 6200, 6400, 6600, 6800)
sales_volume <- c(200, 220, 210, 230, 240, 250, 260, 270,280,290)

data <- data.frame(price,marketing_cost,stores,income,sales_volume)
# Linear regression model
model <- lm(sales_volume ~ price + marketing_cost + stores + income + sales_volume, data = data)
## Warning in model.matrix.default(mt, mf, contrasts): the response appeared on
## the right-hand side and was dropped
## Warning in model.matrix.default(mt, mf, contrasts): problem with term 5 in
## model.matrix: no columns are assigned
summary(model)
## 
## Call:
## lm(formula = sales_volume ~ price + marketing_cost + stores + 
##     income + sales_volume, data = data)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -3.5778 -1.5081 -0.0229  1.4289  4.4748 
## 
## Coefficients: (1 not defined because of singularities)
##                Estimate Std. Error t value Pr(>|t|)  
## (Intercept)    172.6154    83.1662   2.076   0.0832 .
## price            0.5164     0.9521   0.542   0.6071  
## marketing_cost   1.9689     0.5688   3.462   0.0134 *
## stores          -1.2139     3.4233  -0.355   0.7350  
## income               NA         NA      NA       NA  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 3.059 on 6 degrees of freedom
## Multiple R-squared:  0.9932, Adjusted R-squared:  0.9898 
## F-statistic: 291.8 on 3 and 6 DF,  p-value: 6.882e-07
# Scatter Plot
pairs(data, main="Scatter Plot Matrix", pch = 9)

# Residual Fitted Value
plot(model$residuals, main="Residual", ylab = "Residuals", xlab = "fitted values")

abline(h=0, col = "red", lawd = 2)
## Warning in int_abline(a = a, b = b, h = h, v = v, untf = untf, ...): "lawd" is
## not a graphical parameter

#Predicted value
new_data <- data.frame(price=175, marketing_cost = 48, stores = 68 , income = 6500)

predicted_sales <- predict(model, newdata = new_data)
print(predicted_sales)
##        1 
## 274.9569