Developing Data Products, Final Project

Marcello Del Bono
12/10/2018

2. Objectives

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.

Links:

3. Concept, Data & Algorithm

The simulator is a simulation app that we can use for create a distribution of pairs Age/Income, plotting it and calculating the Correlation coefficient.

The age and income distributions are simulated as follows:

  • Age: a random sampled Uniform distribution, range from 16 to 70
  • Income: a linear function as: Age+RN, with RN= random sampled Normal distribution with mean = 30 and Standard Deviation from users' input
  • numerosity of sample: from users' input for both the age and income distribution

4. The App

The URL for the Shiny application is: https://marcellodelbono.shinyapps.io/w4_final_project/

The Application contains, in the Left Panel: A) Slider 1: select the number of observations in the sample and B) Slider 2: select the target Standard Deviation of the normal component of th Y var (income)

Main Panel : A) Title of the chart , B) Plot of the simulated distributions and regression line, C) Caption : chosen n of sample, chosen SD of Y, calculated cor(age, income)

The App

5. The Code

Here's the code for creating the distributions and the plot

# loading packages
library(ggplot2)
library(dplyr)

# set random seed for reproducibility
set.seed(151)

# simulate age and income distributions
N=100 # sample n
SD=20 # standard dev

age <- runif(n = N, 
           min = 16, 
           max = 75)

income <- age + rnorm(n=N, 30, SD)

  # create the dataframe for ggplot
    mydf<- data.frame(age,income)
    mycor<-cor(age,income)
    mycaption<-substitute(paste("Sample n=", N, 
                                 " ; Standard Deviation=", SD, " ; Pearson Correlation coeff.: ", mycor))

  # draw the plot
    mydf %>% ggplot(aes(x=age, y=income))+
    geom_point()+
      geom_smooth()+
      labs(title="Age and Income distributions simulator", 
           caption=mycaption)

plot of chunk unnamed-chunk-1