Prediction on The Child´s Height Relative to The Parents’ Height

author: Claudio Sobral date: 12/30/2019 autosize: false

This paper refers to the heredity prediction of children's heights in relation to the height of these parents. Our code used the galton dataset found in UsingR package, before we had to load some libraries and create a new database.

library(UsingR)
library(shiny)
data(galton)
head(galton, 3)
  child parent
1  61.7   70.5
2  61.7   68.5
3  61.7   65.5

The UsingR library was to load our dataset “data(galto)” and library(shiny) was used to create a test app. The database galton has two variables - child and parent, that contain data of their respective heights.

How to use the App

This App has two parts.

1 - UI - “User Interface” where the inputs and outputs of information produced by the database (galton).

2 - This is the Server code, belonging to the second part of the code. All entries are processed here and their results printed. This part of the code functions similarly as where data was stored, so it's called a server.

In the figure1 are detailed these inputs and outputs.

  • 1 - Enter value to calculate mean of child height. You just need to slide the button to select any value within the established range.
  • 2 - Value input to calculate mean of parent heigh. It follows the same operation of item 1.
  • 3 - Here are the values you chose for child and parent heights.
  • 4 - Here is the result of the prediction of the relationship between child height and parent height.
  • 5 - These histograms are relative to the database samples for each of the variables, the lines (red and blue) represent the mean of each of the variables. Also see results MSE (mean squared error)

Figure1

server <- shinyServer(
        function(input, output) {
        fit <- lm(child ~ parent, data = galton)
        output$inputValue <- renderPrint({input$mu})
        output$newHist <- renderPlot({
            hist(galton$child, xlab='child height', col='lightblue',main='Histogram')
            mu <- input$mu
            lines(c(mu, mu), c(0, 200),col="red",lwd=5)
            mse <- mean((galton$child - mu)^2)
            text(63, 150, paste("mu = ", mu))
            text(63, 140, paste("MSE = ", round(mse, 2)))
            output$inputValue1 <- renderPrint({input$mu1})
            output$newHist1 <- renderPlot({
                hist(galton$parent, xlab='parent height', col='green',main='Histogram')
                mu1 <- input$mu1
                lines(c(mu1, mu1), c(0, 200),col="blue",lwd=5)
                mse1 <- mean((galton$parent - mu1)^2)
                text(72, 150, paste("mu1 = ", mu1))
                text(72, 140, paste("MSE1 = ", round(mse1, 2)))
                output$prediction <- renderPrint({predict(fit, newdata = data.frame(parent = mu1))})

            })})})

ACKNOWLEDGMENTS

I want to express my thanks to Professor Brian Caffo where all the code developed in this App was taken from his book - DDP - Developing Data Products In R. All credits are to teacher Brian Caffo.

Thanks God for the gift life.