Siti Salwani Yaacob
3/10/2020
The height prediction plotter ia a plotting tool for an exploratory data analysis of the galton dataset. It allows you to predict the height of their children based on galton’s dimensions of the dataset.
This data set lists the individual observations for 934 children in 205 families on which Galton (1886) based his cross-tabulation. In the dataset, the following dimensions/variables are provided;
library(shiny)
shinyUI(fluidPage(
titlePanel("Galton's Dataset : Prediction of Height"),
sidebarLayout(
sidebarPanel(
helpText("Prediction of The Child's Height Considering Gender and Parent's Height"),
helpText("Parameters:"),
sliderInput(inputId = "inFh",
label = "Father's Height (cm):",
value = 150,
min = 150,
max = 220,
step = 1),
sliderInput(inputId = "inMh",
label = "Mother's Height (cm):",
value = 140,
min = 140,
max = 200,
step = 1),
radioButtons(inputId = "inGen",
label = "Child's Gender: ",
choices = c("Female"="female", "Male"="male"),
inline = TRUE)
),
mainPanel(
htmlOutput("pText"),
htmlOutput("pred"),
plotOutput("Plot", width = "50%")
)
)
))library(shiny)
library(HistData)
library(dplyr)
library(ggplot2)
data(GaltonFamilies)
# Step 1 : Passes Inch to CM
galton_families <- GaltonFamilies
galton_families <- galton_families %>% mutate(father=father*2.54,
mother=mother*2.54,
childHeight=childHeight*2.54)
# Liner Model
linear_model <- lm(childHeight ~ father + mother + gender, data=galton_families)
shinyServer(function(input, output) {
output$pText <- renderText({
paste("Father's height is",
strong(round(input$inFh, 1)),
"cm, and mother's height is",
strong(round(input$inMh, 1)),
"cm, then:")
})
output$pred <- renderText({
df <- data.frame(father=input$inFh,
mother=input$inMh,
gender=factor(input$inGen, levels=levels(galton_families$gender)))
ch <- predict(linear_model, newdata=df)
kid <- ifelse(
input$inGen=="female",
"Daugther",
"Son"
)
paste0(em(strong(kid)),
"'s predicted height is going to be around ",
em(strong(round(ch))),
" cm"
)
})
output$Plot <- renderPlot({
kid <- ifelse(
input$inGen=="female",
"Daugther",
"Son"
)
df <- data.frame(father=input$inFh,
mother=input$inMh,
gender=factor(input$inGen, levels=levels(galton_families$gender)))
ch <- predict(linear_model, newdata=df)
yvals <- c("Father", kid, "Mother")
df <- data.frame(
x = factor(yvals, levels = yvals, ordered = TRUE),
y = c(input$inFh, ch, input$inMh))
ggplot(df, aes(x=x, y=y, color=c("green", "blue", "red"), fill=c("green", "blue", "red"))) +
geom_bar(stat="identity", width=0.5) +
xlab("") +
ylab("Height (cm)") +
theme_minimal() +
theme(legend.position="none")
})
})Caption