Skip to content

gratia version 0.7.2 is released and on CRAN

Compare
Choose a tag to compare
@gavinsimpson gavinsimpson released this 18 Mar 08:27

gratia 0.7.2 is available and on CRAN

Following the release of version 0.7.0, a couple of annoying bugs were identified which necessitated a patch release. I had implemented methods to plot partial effects for 3d and 4d smooths so decided to include these early enhancements in the patch release to try to shake out any bugs or problems with the implementation prior to a more substantial point (0.8.0) release later in the year (planned for September 2022 at the latest as gratia is needed for a GAM course). Similarly, the problem that delayed 0.7.1 (below) meant that a new plotting method to handle splines on the sphere snuck in to the release, for the same reasons as handling >2d smooths.

Due to an issue with the size of the package source tarball, which wasn't discovered until after submission to CRAN, 0.7.1 was never released.

While binaries for Windows and MacOS X systems are being built, you can install version 0.7.2 from R Universe: https://gavinsimpson.r-universe.dev/ui#builds

New features

  • draw.gam() and draw.smooth_estimates() can now handle splines on the sphere (s(lat, long, bs = "sos")) with special plotting methods using ggplot2::coord_map() to handle the projection to spherical coordinates. An orthographic projection is used by default, with an essentially arbitrary (and northern hemisphere-centric) default for the orientation of the view.

    plot (1)

  • draw.gam() and draw.smooth_estimates(): {gratia} can now handle smooths of 3 or 4 covariates when plotting. As an example of what is possible, the figure below shows the estimated smooths from y ~ s(x,z) + s(year, bs = "cr") + ti(x,z, year, d = c(2,1), bs = c("tp", "cr")) for a space-time GAM modelling shrimp abundance. The layout has been tweaked a little (via the design argument to patchwork::plot_layout()) from the default you get with draw.gam() but otherwise it is unchanged.

    space-time-tensor-product-ti-smoother

    For smooths of 3 covariates, the third covariate is handled with ggplot2::facet_wrap() and a set (default n = 16) of small multiples is drawn, each a 2d surface evaluated at the specified value of the third covariate. For smooths of 4 covariates, ggplot2::facet_grid() is used to draw the small multiples, with the default producing 4 rows by 4 columns of plots at the specific values of the third and fourth covariates. The number of small multiples produced is controlled by new arguments n_3d (default = n_3d = 16) and n_4d (default n_4d = 4, yielding n_4d * n_4d = 16 facets) respectively.

    This only affects plotting; smooth_estimates() has been able to handle smooths of any number of covariates for a while.

    When handling higher-dimensional smooths, actually drawing the plots on the default device can be slow, especially with the default value of n = 100 (which for 3D or 4D smooths would result in 160,000 data points being plotted). As such it is recommended that you reduce n to a smaller value:

    n = 50 is a reasonable compromise of resolution and speed.

  • model_concurvity() returns concurvity measures from mgcv::concurvity() for estimated GAMs in a tidy format. The synonym concrvity() [sic] is also provided. A draw() method is provided which produces a bar plot or a heatmap of the concurvity values depending on whether the overall concurvity of each smooth or the pairwise concurvity of each smooth in the model is requested.

  • fitted_values() insures that data (and hence the returned object) is a tibble rather than a common or garden data frame.

  • draw.gam() gains argument resid_col = "steelblue3" that allows the colour of the partial residuals (if plotted) to be changed.

Bug fixes

  • draw.posterior_smooths() was redundantly plotting duplicate data in the rug plot. Now only the unique set of covariate values are used for drawing the rug.

  • data_sim() was not passing the scale argument in the bivariate example setting ("eg2").

  • draw() methods for gamm() and gamm4::gamm4() fits were not passing arguments on to draw.gam().

  • draw.smooth_estimates() would produce a subtitle with data for a continuous by smooth as if it were a factor by smooth. Now the subtitle only contains the name of the continuous by variable.

  • model_edf() was not using the type argument. As a result it only ever returned the default EDF type.

  • add_constant() methods weren't applying the constant to all the required variables.

  • draw.gam(), draw.parametric_effects() now actually work for a model with only parametric effects. #142 Reported by @Nelson-Gon

  • parametric_effects() would fail for a model with only parametric terms because predict.gam() returns empty arrays when passed
    exclude = character(0).