extract_spline_basis: Extract spline basis vector values evaluated at abcissa...

Description Usage Arguments Value Author(s) See Also Examples

View source: R/extract_spline_basis.R

Description

This function uses extracts the plate regression spline basis vectors that are being fit in a GAMM. They can be visualized with draw_spline_basis(). Both extract_spline_basis() and draw_spline_basis() are experimental and still require some work to extract & order the spline bases you want, so use with care.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
extract_spline_basis(
  gam_model,
  current_DF,
  spacing = 0.25,
  tag_sort_vector = c("X.Intercept.", "group_01", "group_02", "group_03", "group_04"),
  sort_by_tag = FALSE,
  include_spline_coefficients = FALSE,
  restrict_to_x_by_group = FALSE,
  group_name_char = maeve_options("group_name"),
  x_name_char = "x",
  restrict_global_intercept = FALSE,
  global_intercept_char = "X.Intercept.",
  return_list = FALSE
)

Arguments

gam_model

object of class "gam" returned from a maeve:: call to mgcv::gam()

current_DF

data.frame with group and x-value information for the fitted object.

spacing

numeric how finely spaced should points be for grid evaluation?

tag_sort_vector

character vector with distinct character string "tags" by which to partially sort model basis vector names

sort_by_tag

logical whether to partially sort basis vector names by components of tag_sort_vector.

include_spline_coefficients

logical whether to merge in the actual numeric coefficient of each spline basis in each group.

restrict_to_x_by_group

logical whether to exclude from a group x-values beyond the range of those observed in that group.

group_name_char

character name of the group-level identifier in the current_DF data.frame.

x_name_char

character name of the x-value (usually, e.g., time or concentration) identifier in the current_DF data.frame.

restrict_global_intercept

logical whether to restrict global intercept values to only the reference group (i.e., the only group to get its intercept solely from the global intercept).

global_intercept_char

character name of global intercept column.

return_list

logical whether to return additional information, with also the design matrix included.

Value

a data.frame with values of basis vectors at different x-values across different groups.

Author(s)

Bill Forrest forrest@gene.com

See Also

data.frame

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
 cat('Example in dontrun block.')
 ## Not run: 
 data( vismodegib )
 vismo21 <- dplyr::filter( vismodegib, DAY_OF_STUDY <= 21 )
 model_list = model_study( vismo21, metric = 'AUC' )
 basis_spline_DF <-
 extract_spline_basis( gam_model = model_list$md4_gamm4[['gam']],
                       current_DF = vismo21,
                       sort_by_tag = TRUE,
                       include_spline_coefficients = TRUE,
                       x_name_char = 'DAY_OF_STUDY', # x-variable name in vismodegib
                       spacing = .50
                      )
 ##
 ## Need to extract features of interest.
 ## Example:
 ##
 basis_spline_DF_2groups <- dplyr::filter( basis_spline_DF, group %in% c('dose_1.0', 'dose_100') )
 ##
 ind_1.0 <- grepl( 'groupdose_1.0', basis_spline_DF_2groups$coef_name_pretty, fixed = TRUE )
 ind_100 <- grepl( 'groupdose_100', basis_spline_DF_2groups$coef_name_pretty, fixed = TRUE )
 ##
 basis_spline_DF_2groups <-
     droplevels( subset( basis_spline_DF_2groups, (ind_1.0 | ind_100 ) & !is.na( group ) ) )
 basis_spline_DF_2groups <- subset( basis_spline_DF_2groups, abs( Ey ) > 1e-12 )
 basis_spline_DF_2groups <-
     dplyr::mutate( basis_spline_DF_2groups, coef_name_pretty = factor( coef_name_pretty ) )
 basis_spline_DF_2groups %<>% dplyr::arrange( group, coef_name_pretty ) %>% freeze_factor_levels()
 
## End(Not run)

wfforrest/maeve documentation built on Jan. 1, 2021, 12:47 p.m.