Simple Linear Regression can be modeled by the following:
\(y = \beta_0 + \beta_1 \cdot x + \epsilon\)
Where:
- \(y\): Amount spent
- \(x\): Minutes spent on website
- \(\epsilon\): Error term
2025-04-11
\(y = \beta_0 + \beta_1 \cdot x + \epsilon\)
completejourneytransactions)products)demographics)sales_value) from number of items (quantity)
For the purposes of loading the data I limited the dataset to the first 1,000 transactions with qty < 20 and sales_value < 100.
completejourney## # A tibble: 6 × 11 ## household_id store_id basket_id product_id quantity sales_value retail_disc ## <chr> <chr> <chr> <chr> <dbl> <dbl> <dbl> ## 1 900 330 31198570044 1095275 1 0.5 0 ## 2 900 330 31198570047 9878513 1 0.99 0.1 ## 3 1228 406 31198655051 1041453 1 1.43 0.15 ## 4 906 319 31198705046 1020156 1 1.5 0.29 ## 5 906 319 31198705046 1053875 2 2.78 0.8 ## 6 906 319 31198705046 1060312 1 5.49 0.5 ## # ℹ 4 more variables: coupon_disc <dbl>, coupon_match_disc <dbl>, week <int>, ## # transaction_timestamp <dttm>
transactions %>% ggplot(aes(x = quantity, y = sales_value)) + geom_point(alpha = 0.2) + geom_smooth(method = "lm", se = FALSE, color = "pink") + labs(title = "Sales Value vs Quantity", x = "Quantity in Basket", y = "Sales Value ($)")
## `geom_smooth()` using formula = 'y ~ x'
\(\hat{y} = \hat{\beta}_0 + \hat{\beta}_1 \cdot x\)
summary(model) to view:
See the results on the next slide
## ## Call: ## lm(formula = sales_value ~ quantity, data = transactions) ## ## Residuals: ## Min 1Q Median 3Q Max ## -4.3134 -1.3355 -0.5855 0.4145 18.4045 ## ## Coefficients: ## Estimate Std. Error t value Pr(>|t|) ## (Intercept) 1.8199 0.1490 12.214 < 2e-16 *** ## quantity 0.7656 0.1061 7.214 1.08e-12 *** ## --- ## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 ## ## Residual standard error: 2.265 on 998 degrees of freedom ## Multiple R-squared: 0.04956, Adjusted R-squared: 0.04861 ## F-statistic: 52.04 on 1 and 998 DF, p-value: 1.075e-12
Multiple R-squared: 0.04956
Only ~4.96% of the variation in your outcome variable (Y) is explained by your predictor (X).(weak linear relationship)
p-value: 1.075e-12
This is extremely small (almost 0), meaning the relationship between your predictor and the outcome is statistically significant (very unlikely to be due to random chance).
Let’s add more predictors, like income.
From this plot alone, it does not seem that there is any correlation between income and spending or quantity purchased at this grocery store.
Residuals are randomly clustered around the red 0 line.