Skip to contents

Methods for gam_influence objects

Usage

# S3 method for class 'gam_influence'
print(x, n = 5, ...)

# S3 method for class 'gam_influence'
summary(object, ...)

# S3 method for class 'summary.gam_influence'
print(x, ...)

# S3 method for class 'gam_influence'
as.data.frame(x, row.names = NULL, optional = FALSE, ...)

top_units(x, by = "total", n = 10)

Arguments

x, object

A gam_influence object.

n

Number of sites to show or return.

...

Unused.

row.names, optional

Accepted for compatibility; ignored.

by

Column of the site table to rank by (largest first): "total", "fixed" or "added".

Value

  • print(): the gam_influence object x, unchanged and invisibly. It is called for its side effect of printing the sites with the largest changes and the largest hyperparameter changes.

  • summary(): an object of class summary.gam_influence, a list with quantiles (a matrix: minimum, median, 90th percentile and maximum of fixed, added and total, and the number of missing values), hyper (a data frame: for each hyperparameter, its full-data value and the range of its ratios when a site is removed; NULL if the model has no estimated hyperparameters), n_sites (the number of sites), status (a table of site statuses) and info (as in gam_influence()).

  • print() for a summary.gam_influence object: x, unchanged and invisibly. It is called for its side effect of printing the summary.

  • as.data.frame(): the site table x$sites, a data frame with one row per site and columns id, n_obs, fixed, added, total, status and note (see gam_influence()).

  • top_units(): a data frame with the same columns as x$sites, holding the n sites with the largest by, largest first.

Examples

library(mgcv)
#> Loading required package: nlme
#> This is mgcv 1.9-4. For overview type '?mgcv'.
set.seed(1)
d <- data.frame(site = factor(rep(1:12, each = 6)), x = runif(72))
d$y <- sin(2 * pi * d$x) + rnorm(12, 0, 0.4)[d$site] + rnorm(72, 0, 0.5)
m <- gam(y ~ s(x) + s(site, bs = "re"), data = d, method = "REML")
infl <- gam_influence(m, cluster = "site", progress = FALSE)
print(infl, n = 3)
#> gamfluence: fixed vs re-estimated deletion, 12 sites
#>   model: gaussian (identity), 72 rows
#> 
#> Largest total change in the other sites' fitted values (RMS, link scale):
#>  id n_obs  fixed  added  total
#>   8     6 0.0576 0.0109 0.0635
#>   9     6 0.0274 0.0467 0.0579
#>   2     6 0.0413 0.0116 0.0442
#> 
#> Largest hyperparameter changes when a site is removed:
#>  id parameter  full deleted ratio
#>   9   s(site) 0.351  0.2500 0.710
#>   8      s(x) 0.021  0.0161 0.767
#>   5      s(x) 0.021  0.0264 1.260
#> 
#> fixed = hyperparameters held; added = what re-estimating them adds.
#> No null reference: compare sites with each other.
summary(infl)
#> gamfluence summary: 12 sites
#> 
#>           min  median    90%    max NA
#> fixed 0.01510 0.03340 0.0409 0.0576  0
#> added 0.00307 0.00867 0.0116 0.0467  0
#> total 0.01510 0.03830 0.0565 0.0635  0
#> 
#> Hyperparameters: full-data value and range of ratios when a site is removed
#>  parameter   type  full min_ratio max_ratio
#>    s(site)     sd 0.351     0.710      1.07
#>       s(x) lambda 0.021     0.767      1.26
#> 
#> Status:
#> 
#> ok 
#> 12 
top_units(infl, by = "added", n = 3)
#>   id n_obs      fixed      added      total status note
#> 1  9     6 0.02743580 0.04668035 0.05787634     ok <NA>
#> 2  4     6 0.03659087 0.01157631 0.03866023     ok <NA>
#> 3  2     6 0.04125977 0.01155479 0.04416793     ok <NA>
head(as.data.frame(infl))
#>   id n_obs      fixed       added      total status note
#> 1  1     6 0.03816118 0.003070984 0.03879776     ok <NA>
#> 2  2     6 0.04125977 0.011554789 0.04416793     ok <NA>
#> 3  3     6 0.01768985 0.003806297 0.01815013     ok <NA>
#> 4  4     6 0.03659087 0.011576310 0.03866023     ok <NA>
#> 5  5     6 0.03147895 0.009073134 0.03789261     ok <NA>
#> 6  6     6 0.03802231 0.008275617 0.04041229     ok <NA>