Marcello Del Bono
12/10/2018
This peer assessed assignment has two parts.
Links:
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:
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)
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)