16 September 2017

Instruction

This peer assessed assignment has two parts. First, you will create a Shiny application and deploy it on Rstudio's servers. Second, you will use Slidify or Rstudio Presenter to prepare a reproducible pitch presentation about your application.

Plot a best fit line on 3 polynomial model

Description
This application allows you to generate a 3 polynomial model with a customizable sample size You can then plot a simple regression line or a more complex line going up to 10 degrees The aim of this app is to show the effect of complex polynomial and data size on overfitting

Example of a 3 degree poly line

n <- 20
x <- sort(runif(n, -2, 2))
y <- 3*x^3 + 5*x^2 + 0.5*x + 20 # a 3 polynomial model
err <- rnorm(n, sd=3)
ye <- y + err
df <- data.frame(x, ye)
 p<-ggplot(df, aes(x, ye)) + 
        geom_point(alpha=2/10, shape=21, fill="blue", 
            colour="black", size=5)+
        stat_smooth(method="lm", se=TRUE, fill=NA,
            formula=y ~ poly(x, 3, raw=TRUE),colour="red")

3 degree fit line

Example of a 10 degree poly line

How to use

  • Select the sample size
  • Then select the polynomial degree you want to plot
  • the drop-down box is a reactive object henc ethe plot will always get updated while you're changing the polydegre vlaue
  • The slide bar is a reactive and isolate object hence if you the plot will only change after selecting a polydegree value from the dropdown App link