R/AllGenerics.R, R/getRankShift.R
getRankShift.RdCalculates how much the abundance ranks of features change between each sample and the previous sample of the same subject.
getRankShift(x, ...)
addRankShift(x, ...)
# S4 method for class 'SummarizedExperiment'
getRankShift(
x,
time.col,
assay.type = "counts",
time.interval = 1L,
time.lag = NULL,
group = NULL,
...
)
# S4 method for class 'SummarizedExperiment'
addRankShift(x, name = c("rank_shift", "time_diff", "ref_samples"), ...)A
SummarizedExperiment
object.
additional arguments.
Character scalar. Specifies a name of the column from
colData that identifies the sampling time points for the samples.
Character scalar. Specifies which assay values are
used in the dissimilarity estimation. (Default: "counts")
Integer scalar. Indicates the increment between
time steps. By default, the function compares each sample to the
previous one. If you need to take every second, every third, or so, time
step, then increase this accordingly. (Default: 1L)
NULL or Numeric scalar. If specified, each
sample is compared to the earlier sample whose time is closest to
time.lag time units before it, instead of counting time steps with
time.interval. Useful when samples are not evenly spaced in time.
The first sample of each group gets NA. (Default: NULL)
Character scalar. Specifies a name of the column from
colData that identifies the grouping of the samples.
(Default: NULL)
Character vector. Specifies the names of the three
columns of results. (Default: c("rank_shift", "time_diff",
"ref_samples"))
getRankShift returns a DataFrame with one row per sample and
the rank shift, the time from the previous sample and the previous
sample. addRankShift adds these to colData(x). The first
sample of each subject gets NA.
The mean rank shift (Collins et al. 2008) compares two samples through the
features present (above zero) in both. The features are ranked by
abundance in each sample, with tied values getting their average rank, and
the rank shift is the mean absolute change in rank. It is 0 when the order
of the features does not change. The previous sample is chosen as in
getStepwiseDivergence().
Collins SL, et al. (2008) Rank clocks and plant community dynamics. Ecology 89(12), 3534-3541. doi: 10.1890/07-1646.1
library(miaTime)
# A defined community of 16 species in three replicate bioreactors
data(minimalgut)
tse <- addRankShift(minimalgut, time.col = "Time_hr_num",
group = "StudyIdentifier")
# Rank shift over time in each bioreactor; the first samples have no
# previous sample
library(ggplot2)
df <- as.data.frame(colData(tse))
df <- df[!is.na(df[["rank_shift"]]), ]
ggplot(df, aes(x = Time_hr_num, y = rank_shift, colour = StudyIdentifier)) +
geom_line()