draw_spline_basis: Draw spline basis vector values evaluated at abcissa values...

Description Usage Arguments Value Author(s) See Also Examples

View source: R/draw_spline_basis.R

Description

This function uses the extract_spline_basis() output to sketch the thin plate regression spline basis vectors that are being fit in a GAMM. 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
draw_spline_basis(
  spline_basis_data_frame,
  sort_rows = TRUE,
  tolerance = 10^(-12),
  number_facet_rows = nlevels(spline_basis_data_frame$group),
  x_text = "day of study",
  y_text = "spline function value",
  title_text = "spline basis functions",
  legend_position = c("bottom", "none", "left", "top", "right"),
  strip.text.size = 7,
  include_coefs = TRUE,
  x_loc_frac = 0.2,
  y_loc_frac = 0.1
)

Arguments

spline_basis_data_frame

data frame with spline basis information, usually obtained from maeve::extract_spline_basis().

sort_rows

logical whether to apply sorting criteria to spline basis values.

tolerance

numeric spline coefficients below this in absolute value will be removed (set, e.g., to "-1" to avoid filtering entirely).

number_facet_rows

numeric number of rows in ggplot figure (passed to "facet_wrap( ..., nrow = number_facet_rows, ... )").

x_text

character string with x-axis label for figure

y_text

character string with y-axis label for figure

title_text

character string with title label for figure

legend_position

character string with "theme( legend.position = legend_position )" value.

strip.text.size

numeric controls size of facet_wrap() strip labels: "theme( strip.text.x = element_text( size = strip.text.size ) )".

include_coefs

logical whether to include estimated spline coefficients in panels of faceted plot.

x_loc_frac

numeric horizontal fraction for placing geom_text() of coefficient value.

y_loc_frac

numeric vertical fraction for placing geom_text() of coefficient value.

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
31
32
33
34
35
 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
                      )
 ##
 main <- 'thin plate regression spline basis for three groups from vismodegib over 21 days'
 basis_spline_DF_3groups <-
     dplyr::filter( basis_spline_DF, group %in% c('dose_1.0', 'dose_6.0', 'dose_100') )
 ##
 ind_1.0 <- grepl( 'groupdose_1.0', basis_spline_DF_3groups$coef_name_pretty, fixed = TRUE )
 ind_6.0 <- grepl( 'groupdose_6.0', basis_spline_DF_3groups$coef_name_pretty, fixed = TRUE )
 ind_100 <- grepl( 'groupdose_100', basis_spline_DF_3groups$coef_name_pretty, fixed = TRUE )
 ##
 basis_spline_DF_3groups <-
     droplevels( subset( basis_spline_DF_3groups, ( ind_1.0 | ind_6.0 | ind_100 ) ) )
 basis_spline_DF_3groups <- droplevels( subset( basis_spline_DF_3groups, !is.na( group ) ) )
 basis_spline_DF_3groups <- subset( basis_spline_DF_3groups, abs( Ey ) > 1e-12 )
 basis_spline_DF_3groups %<>%
     dplyr::mutate( group = factor( group, levels = c('dose_1.0', 'dose_6.0', 'dose_100') ) )
 basis_spline_DF_3groups <-
     dplyr::mutate( basis_spline_DF_3groups, coef_name_pretty = factor( coef_name_pretty ) )
 basis_spline_DF_3groups %<>% dplyr::arrange( group, coef_name_pretty ) %>% freeze_factor_levels()
 ##
 figure_vismo_basis <- draw_spline_basis( basis_spline_DF_3groups, title_text = main )
 
## End(Not run)

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