Monday, November 11, 2013

A Shiny App for Playing with OLS least squares continues to be the staple estimator for causal inference for good reason.  In order to help new and veteran OLS users get a better sense of how it is working I have created a shiny app that allows for instant interactivity returning coefficient estimates and prediction graphs through Shiny's easy to use user interface controls.

The app only has a single x variable which is randomly drawn from a normal distribution with mean 2 and standard deviation specified by the user.  There is also an error term u which has mean 0 and standard deviation specified by the user.

The user also has control of how many observations to generate and how to generate the dependent variable y.

To play around with the app go to:

Source can be found on GitHub:


  1. Thanks for this app. Very nice. Any chance I can get take a look at the source code?

    1. Hi Francis,

      Really good the app. I'm trying to do something similar with ordinary kriging, so if you decide to share the code please make a new post!



  2. This will make a great teaching tool. I can already think of neat ways to expand on it by adding a heteroskedastic and/or autocorrelated error term, lagged regressors, et cetera. You could build a lot of labs out this. Great work!

  3. Francis,
    My name is Andy from RStudio. I noticed you had a note on your application about server performance. I am wondering if you would be interested in participating in the alpha of our new hosted Shiny service. You should be able expect better performance, and the traffic generated from your application should be an excellent test for our systems. Let me know if you're interested!

    1. Hi Andy,
      That would be really great! Thanks for the offer. Is there anything you need me to do?
      - Francis

  4. Really nice app,

    and will be very useful for demonstrating model fit. I teach a number of applied statistics courses to graduate students, and this will be very helpful. Thank you so much.

    Would love to see this same sort of thing extended to other basic stats taught in applied coursework. For example, how about an ANOVA model, where you could modify variances and distribution shape to demonstrate how an ANOVA model works? Even a simply 1-way ANOVA with the three levels would be fantastic. You could include a typical summary table, with values that change as the user sets different parameters.

    Outstanding tool. Keep up the good work!

  5. Francis,

    Great! All you need to do is signup with this form, and we'll get you setup.

    Thanks for your help!