Adding Data to a Model: A Shiny App

Paul Clark
06-04-2017

See app at https://clarpaul.shinyapps.io/add_point/

For all code, see repo https://github.com/clarpaul/DevDataProducts_Project/
App code in subfolder “Add_Point

The app is a learning tool for linear regression

Primary Goals

  • Understand how adding more data increases/decreases p-values
  • Visualize scatterplots for different regression statistics
    • Correlation coefficients
    • P-values
  • See how differently positioned points impact the regression
    • Which points most affect the best-fit line
    • I.e., which points are high vs. low leverage/influence
  • Have fun!

Operation of the app

  1. The app displays a 2D scatterplot and regression line
  2. The user clicks plot locations to add observations in red
  3. With each added observation, the app updates and displays…
    • the observation's coordinates
    • the regression line for the scatterplot
    • the equation for the line
    • the correlation coef and p-value of the slope/regression
  4. Input widgets include…
    • check-box to show or hide the original trend line
    • button to clear added points and start over

Regression plot before adding data

plot(mtcars$mpg, mtcars$hp, 
   main = paste0("Horsepower",
     " vs. Miles-per-gallon"), 
   xlab = "MPG", ylab = "HP", 
   bty = "n", pch = 16,
   xlim = c(10, 35), 
   ylim = c(50, 350))
mtext("R `mtcars` dataset")
model1 <- lm(hp ~ mpg,
   data = mtcars)
abline(model1, col = "red",
   lwd = 2)

plot of chunk initialplot_revealed

Application *after* adding data