A Shiny app for simple linear regression by hand and in R

Antoine Soetewey 2020-01-15 2 minute read

A Shiny app to perform simple linear regression (by hand and in R)

Simple linear regression is a statistical method to summarize and study relationships between two variables. When more than two variables are of interest, it is referred as multiple linear regression. See this article on linear regression for more details.

In this article, we focus only on a Shiny app which allows to perform simple linear regression by hand and in R:

How to use this app?

Follow these steps:

  1. Open the app via this link
  2. Enter your data in the x and y fields. The x field corresponds to the independent variable, while the y field corresponds to the dependent variable
  3. If you do not want to display the confidence interval around the regression line, uncheck the checkbox under Plot
  4. Change the x and y-axis labels for the regression plot if needed

In the results panel (on the right side or below depending on the size of your screen), you will see:

  • a recap of your dataset together with some appropriate descriptive statistics
  • the estimates \(\beta_0\), \(\beta_1\) and the regression model computed by hand
  • the results of the model computed in R
  • the regression plot with some key measures
  • the interpretations
  • and the assumptions to check the validity of the model

All formulas, steps and computations to arrive at the final results are also provided.

Note that although the assumptions are displayed, it is your responsibility to check them to assess the validity of the linear model.

Last but not least, you can download a report of the results (in HTML) by clicking on the Download button, and you can choose whether you want to include the R code or not.

Code

Here is the entire code (or see the last version on GitHub) in case you would like to enhance it.

Note that the link may not work if the app has hit the monthly usage limit. Try again later if that is the case.

Conclusion

For further details about what is linear regression and when it is used, please see:

  • this post, and
  • the numerous resources on the topic available in textbooks and online.

Thanks for reading.

I hope you will find this app useful to do simple linear regression by hand and in R.

As always, if you have a question or a suggestion related to the topic covered in this article, please add it as a comment so other readers can benefit from the discussion.



Liked this post?

  • Get updates every time a new article is published (no spam and unsubscribe anytime):

  • Support the blog
  • Share on: