Sufua Khatun
August 23, 2016
'data.frame': 1078 obs. of 2 variables:
$ fheight: num 65 63.3 65 65.8 61.1 ...
$ sheight: num 59.8 63.2 63.3 62.8 64.3 ...
Since, there are only two variables in this dataset, linear regression model was used to fit the dataset and predict the son's height. For an example, let's assume to predict son's height for father's height of 65 inches.
1
67.3
function(input, output){
fit1 <- lm(sheight~fheight, data = father.son)
output$pred <- renderPrint({
paste(round(as.numeric(predict(fit1, newdata=data.frame(fheight=input$height))),2))
}) # Predicted value
output$gplot <- renderPlot({
g <- ggplot(data = father.son, aes(x=fheight, y=sheight))
g + geom_point(col="light green") + geom_smooth(method = "lm")+
geom_hline(yintercept = predict(fit1, newdata=data.frame(fheight=input$height)))
}) # Plot with Predicted value
}