make_ref: Create a reference object

View source: R/make_ref.R

make_refR Documentation

Create a reference object

Description

Make a reference object from a geim model

Usage

make_ref(
  m,
  from = NULL,
  to = NULL,
  cov.levels = NULL,
  n.inter = 500,
  by.inter = NULL,
  t.unit = "no unit specified",
  metadata = list()
)

Arguments

m

a geim model object (as returned by ge_im).

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 seq(start, end, length.out = n.inter). One of n.inter or by.inter must be specified.

by.inter

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

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).

Value

a 'ref' object to use with ae for age estimation.

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.