2023-11-19

Introduction

Linear regression is a statistical method used to model the relationship between a dependent variable and one or more independent variables. It assumes a linear relationship between the variables. That can be explained by the change in the dependent variable is directly proportionnal to the change in the indepedent variable.

Example

Here is an example to illustrate simple linear regression

set.seed(12345)

x <- 1:200
y <- 2* x + rnorm(200, mean = 0, sd = 10)

Linear regression model

model <- lm(y~x)

Plot the data and the regression line

library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.3.2
ggplot(data.frame(x,y), aes(x,y)) + geom_point() + geom_smooth(method = "lm", se = FALSE)
## `geom_smooth()` using formula = 'y ~ x'

##Plot the data and regression line in a bar plot

ggplot(data.frame(x,y), aes(x = 1:200, y = 2* x + rnorm(200, mean = 0, sd = 10))) +
 geom_bar(stat = "identity") +
 xlab("x") +
 ylab("y") +
 ggtitle("Bar Graph")

Equation model

This is a simple linear regression model represented by the equation:

[y = _0 + _1x + ]

 ( y ) is the response variable  ( x ) is the predictor variable  ( beta_0 ) is the intercept  ( beta_1 ) is the slope  ( epsilon ) is the error term

install.packages(ggplot2)

Definition of variables

  • (y ) is the response variable
  • (x ) is the predictor variable
  • (beta_0 ) is the intercept
  • (beta_1 ) is the slope
  • (epsilon ) is the error term

Explanation of different terms related

Model Evaluation

To evaluate the fit of the model, we can look at:

  1. R-squared: The proportion of variance in the response variable explained by the predictor variable.
  2. Residuals: The differences between the observed and predicted values of the response variable.

Conclusion

In this concept, I introduced the concept of a simple linear regression and provide an example using simulated data. A linear regression model and plot the data along the regression line.Additionally I mentioned the model equation and evaluation.Linear regression assumes a linear relationship between the variables and that other factors not included in the model may influence the result of a study.