# gratia 0.4.1 released

**From the Bottom of the Heap - R**, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

After a slight snafu related to the 1.0.0 release of **dplyr**, a new version of **gratia** is out and available on CRAN. This release brings a number of new features, including differences of smooths, partial residuals on partial plots of univariate smooths, and a number of utility functions, while under the hood **gratia** works for a wider range of models that can be fitted by **mgcv**.

###
Partial residuals

The `draw()`

method for `gam()`

and related models produces partial effects plots. `plot.gam()`

has long had the ability to add partial residuals to partial plots of univariate smooths, and with the latest release `draw()`

can now do so too.

If the estimated functions have the correct degree of wiggliness, the partial residuals should be approximately uniformly distributed about the estimated smooth.

###
Simulating data

The previous example demonstrated another new feature of the latest release; `data_sim()`

. This is a reimplementation of `mgcv::gamSim()`

, which is used to simulate data for testing GAMs. Data can be simulated from several widely-used functions that illustrate the power an capabilities of estimating smooth functions using penalised splines.

`data_sim()`

returns simulated data in a tidy fashion and all the various example test data sets return consistently. Also, data from the example functions can be simulated from a number of probability distributions — currently the Gaussian, Poisson, and Bernoulli distributions are supported, but future versions will offer a wider range to simulate from.

For example, the response data modelled above came from the following four functions used by Gu and Wahba

###
Difference smooths

When GAMs contain smooth-factor interactions, we often want to compare smooths between levels of the factor to determine how the smooth effects vary between groups. The new release contains a function `difference_smooths()`

that implements this idea.

The **mgcv** example for factor-smooth interactions using the `by`

mechanism can be simulated from using `data_sim()`

. The model fitted to the data contains a smooth of covariate `x1`

and a smooth of `x2`

for each level of the factor `fac`

. Note that we need the parametric effect for `fac`

as the `by`

smooths are all centred about 0; the parametric term models the different group means.

`difference_smooths()`

returns differences between the smooth functions for all pairs of the levels of `fac`

, plus a credible interval for the difference.

There is a `draw()`

method for objects returned by `difference_smooths()`

, which will plot the pairwise differences

Note that these differences exclude differences in the group means and the differences between smooths are computed on the scale of the link function. A future version will allow for differences that include the group means.

###
Fitted values and residuals utility functions

Two new utility functions are in the current release, `add_fitted()`

and `add_residuals()`

add fitted values and residuals to a data frame of observations used to fit a model.

###
Other changes

This release contains a number of other less-visible changes. **gratia** now handles models fitted by `gamm4::gamm4()`

in more functions than before, while the utility functions `link()`

and `inv_link()`

now work for all families in **mgcv**, including the general family functions and those used for fitting location scale models.

**leave a comment**for the author, please follow the link and comment on their blog:

**From the Bottom of the Heap - R**.

R-bloggers.com offers

**daily e-mail updates**about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.