Prediction Accuracy linear vs lin_log_log

Guennie59
January 28th, 2018

Idea behind the app

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.

  1. to the data themselves

  2. 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.

Source of data

Weisberg, S. (1985) Applied Linear Regression. 2nd edition. Wiley, pp. 144

Data exploration

plot of chunk unnamed-chunk-1

  1. data are amassed at the origin and a linear relationship is indicated (left plot)

  2. 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)

Shiny App

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)) })

Predictions in enlarged plot of linear data

predictions in enlarged plot of linear data Snapshot from app with single value for lin-log-log prediction

  1. For data near the origin the pure linear model (red) gives a poor prediction.
  2. A prediction in the lin-log-og model follows the data much closer

Predictions in plot of logarithmic data

predictions in plot of logarithmic data 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!!