gam_growthrate_plot: plot gam factor with deriv

View source: R/growthrate_gam.R

gam_growthrate_plotR Documentation

plot gam factor with deriv

Description

plot output of growthrate_gam and list for gam_growthrate_plot_combine

Usage

gam_growthrate_plot(
  d,
  model,
  ci,
  agevar,
  idvar = NULL,
  yvar = as.character(model$formula[2]),
  plotsavename = NA,
  xplotname = "Age",
  yplotname = yvar,
  draw_maturation = T,
  draw_points = T,
  show_all_fill = F,
  ci_plot = T
)

Arguments

d

dataframe model was built on (for actual points)

model

gam model (for predicted line)

ci

growthrate_gam output (confidence interval and derivitive)

agevar

column name of age var e.g. 'Ageatvisit'

idvar

line grouping var e.g., 'lunaid', set to NULL if no random effect in model

yvar

model yvar e.g. 'f1score', default pulled from model formula

plotsavename

PDF output name e.g. 'growth.pdf', not saved when NA, not ploted when NULL

xplotname

'Age'

yplotname

'f1score', default is yvar (model yvar)

draw_maturation

T|F, show dotted line on first maturation point

draw_points

T|F, show individual points as scatter plot over gam fit line

show_all_fill

T|F, should we clip the raster fill to only significant ages?

ci_plot

T|F, plot 95 percent confidence interval with geom_ribbon?

Examples

 # no random effects
 m <- mgcv::gam(f1score ~ s(Ageatvisit), data=d)
 ci <- gam_growthrate(m, 'Ageatvisit')
 gam_growthrate_plot(d, m, ci, 'Ageatvisit')

 # w/random effects 'id'
 m <- mgcv::gam(f1score ~ s(Ageatvisit) + s(visit) + s(id, bs="re"), data=d)
 ci <- gam_growthrate(m, 'Ageatvisit')
 gam_growthrate_plot(d, m, ci, 'Ageatvisit', 'id')

 # replot example, see gam_growthrate_plot_combine
 mod <- mgcv::gam(conc~s(uptake), data=CO2)
 ci <- LNCDR::gam_growthrate(mod, 'uptake', n = 10000, qnt = c(0.025, 0.975))
 plist <- gam_growthrate_plot(cars, mod, ci, 'uptake', xplotname='uptake')
 plist$ageplot <- plist$ageplot + xlab('foobar')
 gam_growthrate_plot_combine(plist$ageplot, plist$tile)

LabNeuroCogDevel/LNCDR documentation built on Oct. 13, 2023, 4:31 a.m.