plot.geim: Plot a GEIM object

View source: R/ge_im.R

plot.geimR Documentation

Plot a GEIM object

Description

Plots geim interpolation on components. Interpolation metadata (such as time units, inteprolation resolution or covariates) can be specified through an existing ref object, or directly to this function.

Usage

## S3 method for class 'geim'
plot(
  x,
  ref = NULL,
  ncs = NULL,
  n.inter = NULL,
  by.inter = NULL,
  cov.levels = NULL,
  t.unit = NULL,
  col = NULL,
  col.i = "red",
  show.legend = T,
  l.pos = "topleft",
  show.stats = T,
  ...
)

Arguments

x

a geim object, as returned by ge_im.

ref

a ref object, as returned by make_ref.

ncs

which components to plot, defaults to all.

n.inter

interpolation resolution, as in seq(start, end, length.out = n.inter). One of ref, n.inter, or by.inter must be specified.

by.inter

interpolation resolution, as in seq(start, end, by = by.inter). One of ref, n.inter, or by.inter must be specified.

cov.levels

a named list with potential model covariate levels (e.g batch, strain) to predict as (defaults to first level).

t.unit

an optional string specifying the time unit and t-zero, e.g "h past egg-laying".

col, col.i

color for data and interpolation line respectively.

show.legend, l.pos

whether to show the legend, and its position passed on to legend

show.stats

whether to print model fit (deviance explained and relative error) and component (variance explained) statistics on the plot.

...

additional arguments passed on to plot.

Value

Invisibly returns a table with component variance explained and model fit on component indices (R2, deviance explained, relative error).

Examples


requireNamespace('wormRef', quietly = TRUE)
requireNamespace('stats', quietly = TRUE)

# gene expression data
X <- wormRef::Cel_larval$g

# pheno data (e.g time, batch)
p <- wormRef::Cel_larval$p

# do a pca & select nb of components to use for interpol
pca <- stats::prcomp(X, rank = 20)
nc <- sum(summary(pca)$importance[3, ] < .999) + 1


# find optimal spline type
# setup formulas
smooths <- c('bs', 'tp', 'cr', 'ds')
flist <- as.list(paste0('X ~ s(age, bs = \'', smooths, '\') + cov'))
# do CV
cvres <- ge_imCV(X = scale(X), p = p, formula_list = flist,
                 cv.n = 20, nc = nc)
# check results
plot(cvres, names.arrange = 4) # lowest pred error with 'ds' spline

# build model & make reference
m <- ge_im(X = X, p = p, formula = 'X ~ s(age, bs = \'ds\') + cov', nc = nc)

ref <- make_ref(m, cov.levels = list('cov'='O.20'), n.inter = 100, 
                t.unit='h past egg-laying (20C)')

# check model interpolation on pca components
par(mfrow = c(2,2))
plot(m, ref, ncs=1:4) # showing first 4 PCs


# test
ae_X <- ae(X, ref)
par(mfrow = c(1,2))
plot(p$age, ae_X$age.estimates[,1])
plot(ae_X, groups = p$cov)




LBMC/wormAge documentation built on April 6, 2023, 3:52 a.m.