2024-02-04

Table of Contents

  1. Linear Regression: What is it?
  2. Mathematical Foundation
  3. Linear Regression and its Applications
  4. Example 2: Analysing Customer Purchasing Patterns

Linear Regression: What is it?

. Regression analysis is a statistical method that allows us to determine the strength and relationship of two variables.

. When there is a single input variable, the regression is referred to as Simple Linear Regression. We use the single independent variable to model a linear relationship with the dependent target variable.

Mathematical Foundation

In linear regression we usually have many different values of the explanatory variable, and we usually assume that values between the observed values of the explanatory variables are also possible values of the explanatory variables. We postulate a linear relationship between the population mean of the outcome and the value of the explanatory variable.(Chapter 9 simple linear regression - Carnegie Mellon University) \[ E(Y|x) = \beta_0 + \beta_1 x\] Where,

\(E(Y|x)\)is the expected value of \(Y\) given \(x\)

\(\beta_0\) is the intercept parameter

\(\beta_1\) is the slope parameter

Linear Regression and its Applications

*Predicting house prices based on size and other factors.

*Analyzing customer buying behavior based on demographics and purchase history.

*Forecasting sales based on advertising spend and market trends.

*Evaluating the impact of smoking on life expectancy.

*Understanding the relationship between education level and income.

Example 1: Predictions of Housing Rates

Using the Formula: \(Price = \beta_0 +\beta_1(Square footage) +\epsilon\)

Example 2: Analysing Customer Purchasing Patterns

Using the Formula: \(Purchaseamount = \beta_0 +\beta_1(Age) +\beta_2(income)+\epsilon\)

Example 3: Optimizing Crop Production

Using the Formula: \(CropProduction = \beta_0 +\beta_1(Fertilizer)+\epsilon\)

Example R Code

Creating Example Data Frames

set.seed(42)
n_data <- 200
fertilizer <- runif(n_data, min = 50, max = 200)
beta0 <- 2000 
beta1 <- 5
error <- rnorm(n_data, mean = 0, sd = 50)
crop_yield <- beta0 + beta1 * fertilizer + error
data <- data.frame(
  fertilizer = fertilizer,
  crop_yield = crop_yield
)

Citaitons