Niraj Yadav
04/30/2017
This application predict Weight based on Height. Its based on a model created from data set which contains “Average Heights and Weights for American Women”
Data Set Name: women
This app is trying to build a model to correlate height and weight of subject. It builds that model based on “women” dataset. Let's look at this dataset
data(women)
head(women)
height weight
1 58 115
2 59 117
3 60 120
4 61 123
5 62 126
6 63 129
Let's build this model
model <- lm(weight ~ height,data = women)
Let's take a sample input and predict weight
input <- 67
Predicted Weight
predictedWt <- predict(model, newdata = data.frame(height = input))
predictedWt
1
143.6333
This app takes Height as Input from Sliderbox and tries to predict weight
modelpred <- reactive({
heightInput <- input$height
predict(model, newdata = data.frame(height = heightInput))
})
It renders output as text
output$pred <- renderText({
modelpred()
})
It also Plots the result and model in a chart
plot(women$height, women$weight, xlab = "Height",
ylab = "Weight", bty = "n", pch = 16,
xlim = c(55, 75), ylim = c(100, 180))
if(input$showModel){
abline(model, col = "red", lwd = 2)
}
points(heightInput, modelpred(), col = "blue", pch = 16, cex = 2)
abline(h=modelpred(),col=4,lty=3)
abline(v=heightInput,col=4,lty=3)
})