plot.geim | R Documentation |
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.
## 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,
...
)
x |
a |
ref |
a |
ncs |
which components to plot, defaults to all. |
n.inter |
interpolation resolution, as in |
by.inter |
interpolation resolution, as in |
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 |
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 |
Invisibly returns a table with component variance explained and model fit on component indices (R2, deviance explained, relative error).
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.