make_ref | R Documentation |
Make a reference object from a geim model
make_ref(
m,
from = NULL,
to = NULL,
cov.levels = NULL,
n.inter = 500,
by.inter = NULL,
t.unit = "no unit specified",
metadata = list()
)
m |
a geim model object (as returned by |
from, to |
start/end of the interpolation (defaults to first and last time points) |
cov.levels |
a named list with potential model covariate levels (e.g batch, strain) to predict as (defaults to first level). |
n.inter |
interpolation resolution, as in |
by.inter |
interpolation resolution, as in |
t.unit |
an optional string specifying the time unit and t-zero, e.g "h past egg-laying". |
metadata |
an optional named list with reference metadata (e.g. organism, tissue). |
a 'ref
' object to use with ae
for age estimation.
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.