2024-04-07

What’s covered in this presentation:

  • What is Linear Regression?
  • How is Linear Regression Used?
  • Examples

What is Linear Regression?

According to IBM, Linear regression analysis is used to predict the value of a variable based on the value of another variable.

For the purpose of this assignment, we will be using simple Linear Functions.

An Example of this, I make $20 an hour at work. The more time I spend working the more money I will make.

The money that I make will be dependent on how many hours I work at $20 hourly rate.

How is Linear Regression Used?

Linear Regression can be used to calculate many things in life.

Linear Regression is used to calculate predicted gross income of an hourly employee or distance traveled in miles dependent on how fast the car is moving.

Example 1

hourly rate= $20

money made= 20 x hours work

        Hours worked               Money Made
             1            20X1          20
             2            20X2          40
             3            20X3          60
             10          20X10          200
             30          20X30          600
             40          20X40          800

Example 1 in R

  hourly_rate <- 20
  hours_worked <- 1:40
  gross <- (hourly_rate*hours_worked)
  gross_pay <- data.frame(hours_worked, gross)

Another way to view this function is as: \[ f(x)=x*a \] Where as:
x= hours worked
a= hourly rate

Example of Simple Linear Regression

Why Not? Quadratic Regression

Quadratic Regression is a statistical method used to model a relationship between variable with a parabolic best-fit curve, rather than a straight line.

The data relationship is curvilinear.

Best Described as: \[ y= ax^2 + bx+ c \]

Example of Quadratic Regression

The Quadratic Formula can be used to calculate profit in business settings.

Example:

Dog Walking Business Where:
Cost of the leashes can be defined as:
\[ C(x)=7x+10 \] Revenue can be defined as:
\[ R(x)= -2x^2+59x \]

Let’s find the Profit of our Business

The simple formula to find profit is Revenue - Cost:
\[ R(x)-C(x) \]

Profit in this example:

\[ P(x)= -2x^2+52x-10 \]

Let’s See how it looks in R

  dog_leashes <- 0:20
  profit <- -2*(dog_leashes^2)+(52*dog_leashes)-10
  gross_profit <- data.frame(dog_leashes, profit)

Dog Walking Business Profit Graph