2024-02-17
This is the linear regression equation:
\[ Y = \beta_0 + \beta_1 X + \varepsilon \]
Consider data of hours of physical activity a week (\(X\)) and general happiness from 1-100 (\(Y\)).
# R code for creating a scatter plot library(ggplot2) Physical_Activity <- c(1, 2, 3, 4, 5) Happiness <- c(60, 70, 80, 90, 100) your_data <- data.frame(Physical_Activity, Happiness) scatter_plot <- ggplot(your_data, aes(x = Physical_Activity, y = Happiness)) + geom_point() + labs(title = "Scatter Plot of Physical Activity vs Happiness Level") print(scatter_plot)
## `geom_smooth()` using formula = 'y ~ x'
## ## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2': ## ## last_plot
## The following object is masked from 'package:stats': ## ## filter
## The following object is masked from 'package:graphics': ## ## layout
## Warning: Specifying width/height in layout() is now deprecated. ## Please specify in ggplotly() or plot_ly()
## No scatter3d mode specifed: ## Setting the mode to markers ## Read more about this attribute -> https://plotly.com/r/reference/#scatter-mode
## Warning: `includeHTML()` was provided a `path` that appears to be a complete HTML document. ## ✖ Path: C:\Users\rocco\AppData\Local\Temp\Rtmpm6utMT\file3e10440625c0.html ## ℹ Use `tags$iframe()` to include an HTML document. You can either ensure `path` is accessible in your app or document (see e.g. `shiny::addResourcePath()`) and pass the relative path to the `src` argument. Or you can read the contents of `path` and pass the contents to `srcdoc`.
In conclusion, simple linear regression is a way of showing correlation between two variables. By using a regression line, we can make assumptions about whether or not the variables are dependent on one another.