Guennie59
January 28th, 2018
Comparison of two different approaches to linear regression in an interactive shiny app.
Basis is the mammals dataframe (in MASS). It includes body and brain weight data of 62 species.
There are linear model fits applied to the data, body weight is regressor and brain weight the outcome.
to the data themselves
to the natural log values of both
The linear fit looks acceptable within reason. The linear fit to the log values showes a decent linear relation across the whole range of the data.
Weisberg, S. (1985) Applied Linear Regression. 2nd edition. Wiley, pp. 144
data are amassed at the origin and a linear relationship is indicated (left plot)
there appears to be a quite good linear dependency of brain weight to body weight for the log value across the complete data range (plot at the right side)
There are three sliders in the sidebar-panel example code of first slider
sliderInput("body", slider_text, min = min(mammals$body), max = max(mammals$body),
value = median(mammals$body)),
Similarly sliders are defined for an enalargement factor for the linear plot and the input for a prediction of the lin-log-log fit.
Two plots are shown on the main panel, which are very similar to the plots on the previous slide. Predictions are being calculated via reactive statements (code snippet below) and shown in the plots.
pred_lin <- reactive({predict(bb_lin, newdata = data.frame(body=input$body)) })
Snapshot from app with single value for lin-log-log prediction
Snapshot from app with single value for linear prediction
A prediction in the lin-log-og model (green) follows the data much closer in contrast to the linear model (red).
Go try more predictions as you like in the shiny app by moving the sliders!!