mcm45
May 15, 2017
This presentation describes a Shiny App that plots the relationships between life expectancy and three factors measured in the United States around 1970:
Illiteracy rate
Income per capita
Population Density
Data are from the state dataset in the datsets package. Data used include:
Life expectancy, in years, 1969-1971
Illiteracy, as a percent of population in 1970
Income per capita in 1974
Population estimate in 1975
Area (in square miles)
#setting up data
states <- as.data.frame(state.x77)
colnames(states)[4] <- "LifeExpectancy"
#defining Population Density
states$PopulationDensity <- states$Population/states$Area
This Shiny App will allow the user to select which factor they want to relate to life expectancy and show a plot with that factor on the x-axis and life expectancy on the y-axis.
This app will also fit linear models with life expectancy as the dependent variable and each factor as an independent variable. The user can select whether to show this line on the plot.
Finally, the app will display with coefficient demonstrating the direction and magnitude of the relationship and a p-value indicating whether it is significantly different than a null relationship of 0.
summary(lm(LifeExpectancy ~ Illiteracy, data=states))$coefficients
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 72.394947 0.3383361 213.973443 3.474322e-73
## Illiteracy -1.296023 0.2570095 -5.042706 6.969250e-06
summary(lm(LifeExpectancy ~ Income, data=states))$coefficients
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 6.758132e+01 1.3275714260 50.905975 1.979131e-43
## Income 7.433343e-04 0.0002965107 2.506939 1.561728e-02
summary(lm(LifeExpectancy ~ PopulationDensity, data=states))$coefficients
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 70.7960625 0.2312136 306.1933440 1.190757e-80
## PopulationDensity 0.5531096 0.8730646 0.6335265 5.293972e-01