2023-05-23

Course Project: Shiny Application and Reproducible Pitch

Details of the data

library(dplyr)
library(HistData)
data(GaltonFamilies)
head(GaltonFamilies)
  family father mother midparentHeight children childNum gender childHeight
1    001   78.5   67.0           75.43        4        1   male        73.2
2    001   78.5   67.0           75.43        4        2 female        69.2
3    001   78.5   67.0           75.43        4        3 female        69.0
4    001   78.5   67.0           75.43        4        4 female        69.0
5    002   75.5   66.5           73.66        4        1   male        73.5
6    002   75.5   66.5           73.66        4        2   male        72.5

Data manipulation

At first, the heights were converted to meter.

newGalton <- GaltonFamilies %>% 
        mutate(father = 2.54 * father / 100,
               mother = 2.54 * mother / 100,
               midparent = 2.54 * midparentHeight / 100,
               child = 2.54 * childHeight / 100)

summary(newGalton[c("father", "mother", "midparent", "child")])
     father          mother        midparent         child      
 Min.   :1.575   Min.   :1.473   Min.   :1.636   Min.   :1.422  
 1st Qu.:1.727   1st Qu.:1.600   1st Qu.:1.731   1st Qu.:1.626  
 Median :1.753   Median :1.626   Median :1.759   Median :1.689  
 Mean   :1.758   Mean   :1.628   Mean   :1.758   Mean   :1.695  
 3rd Qu.:1.803   3rd Qu.:1.673   3rd Qu.:1.782   3rd Qu.:1.770  
 Max.   :1.994   Max.   :1.791   Max.   :1.916   Max.   :2.007  

Fitting a model

Then, father & mother height, gender of children, and midparent were fitted to a linear model to predict children height.

LM <- lm(child ~ father + mother + gender + midparent, newGalton)

Then, gender of children and father & mother height were taken input via radioGroupButtons, and sliderInput; midparent was calculated from the father & mother height. After that, children height is predicted and shown in the ggplot.