Evaluates the relative influence of each smooth term in a GAM model by computing its contribution to the fitted values using the linear predictor matrix (type = "lpmatrix"). Three summary methods are available: sum of squares, variance, and mean absolute value across all observations. #'

sterm_imp(gam_model, method = c("ssq", "var", "meanabs"))

Arguments

gam_model

A GAM model object.

method

A character string specifying the method to compute importance. One of "ssq", "var", or "meanabs".

Value

A data.table with columns:

var

Name of the smooth term.

importance_pct

Relative importance as a percentage.

method

The method used for calculating the importance.

Examples

# loading processed data
dt.samples_trt <- readRDS(system.file("extdata", "dt.samples_trt.rds", package = "growthTrendR"))
# climate
dt.clim <- data.table::fread(system.file("extdata", "dt.clim.csv", package = "growthTrendR"))
# pre-data for model
dt.samples_clim <- prepare_samples_clim(dt.samples_trt, dt.clim)
dt.m <- dt.samples_clim[ageC >1]
# using gamm_spatial model as an example
m.sp <-gamm_spatial(data = dt.m, resp_scale = "resp_log",
       m.candidates = "bai_cm2 ~ log(ba_cm2_t_1) + s(ageC) + s(FFD)")

dt.m[, uid_site.fac:= as.factor(as.character(uid_site))]
#>      site_id  year uid_radius uid_site species uid_tree uid_sample    sample_id
#>       <char> <int>      <int>    <int>  <char>    <int>      <int>       <char>
#>   1:   X003b  1992          1        1 PSEUMEN        1          1 X003_101_008
#>   2:   X003b  1993          1        1 PSEUMEN        1          1 X003_101_008
#>   3:   X003b  1994          1        1 PSEUMEN        1          1 X003_101_008
#>   4:   X003b  1995          1        1 PSEUMEN        1          1 X003_101_008
#>   5:   X003b  1996          1        1 PSEUMEN        1          1 X003_101_008
#>  ---                                                                           
#> 239:   X011c  2014          9        3 PSEUMEN        9          9 X011_101_005
#> 240:   X011c  2015          9        3 PSEUMEN        9          9 X011_101_005
#> 241:   X011c  2016          9        3 PSEUMEN        9          9 X011_101_005
#> 242:   X011c  2017          9        3 PSEUMEN        9          9 X011_101_005
#> 243:   X011c  2018          9        3 PSEUMEN        9          9 X011_101_005
#>         radius_id rw_mm  ageC ba_cm2_t_1   bai_cm2      FFD uid_site.fac
#>            <char> <num> <int>      <num>     <num>    <num>       <fctr>
#>   1: X003_101_008  2.32     2  0.1618831 0.4999908 24.72527            1
#>   2: X003_101_008  2.21     3  0.6618739 0.7907986 53.59116            1
#>   3: X003_101_008  2.79     4  1.4526724 1.4365906 33.70166            1
#>   4: X003_101_008  1.97     5  2.8892631 1.3089603 41.43646            1
#>   5: X003_101_008  2.07     6  4.1982234 1.6381301 41.75824            1
#>  ---                                                                    
#> 239: X011_101_005  1.66    24 65.4683562 4.8479047 20.99448            3
#> 240: X011_101_005  1.04    25 70.3162609 3.1254574 13.81215            3
#> 241: X011_101_005  1.18    26 73.4417183 3.6284892 16.48352            3
#> 242: X011_101_005  1.08    27 77.0702076 3.3976702 35.35912            3
#> 243: X011_101_005  1.21    28 80.4678777 3.8936994 27.07182            3
dt.imp <- sterm_imp(m.sp$model$gam)