MENU

Fun & Interesting

Visualizing generalized additive models in R using gratia and conditional_values()

Bottom of the Heap 555 3 months ago
Video Not Working? Fix It Now

In this first video in a new series, I take a look at the conditional_values() function in my R package gratia. One of the first things you'll probably want to do with after fitting a GAM is to visualize it in some way. With complex models containing several smooths or other terms it is not always immediately clear what the model has captured about the data when we just look at the component smooths or parametric effects. To view features of the model on the response scale, we need to predict from the model and then plot the fitted values given a set of data points we predict at. gratia makes doing this relatively easy with its `data_slice()` and `fitted_values()` functions, but you still need to write the data viz code using ggplot. This is where the new `conditional_values()` function comes in; you tell it which variables to condition on and it produces all the data required to produce a plot showing the conditional effects you chose, and its `draw()` method plots those conditional effects for you using ggplot2. #Rstats #mgcv #GAMs #GeneralizedAdditiveModels #statistics #datavisualization

Comment