Ashley Thompson
25/11/2021
The application, created with Shiny, can be used to predict a value for fertility in Switzerland 1888 (‘common standardized fertility measure’), using a slider that represents the percentage of males involved in agriculture as occupation
Application link
Source code link
The data is from the swiss dataset. For this application we are only using the Fertility and Agriculture variables.
library(datasets)
library(dplyr)
sws <- select(swiss, 1:2)
head(sws)
Fertility Agriculture
Courtelary 80.2 17.0
Delemont 83.1 45.1
Franches-Mnt 92.5 39.7
Moutier 85.8 36.5
Neuveville 76.9 43.5
Porrentruy 76.1 35.3
A prediction model is made from the swiss data, and then the user selects an Agricultural percentage with a slider, and the resulting predicted Fertility is displayed.
##example using 85 as the input
AgInput <- 85
modelAg <- lm(Fertility ~ Agriculture, data = sws)
modelAgPred <- predict(modelAg, newdata = data.frame(Agriculture = AgInput))
modelAgPred
1
76.81152
A plot is created showing: