tempted_all {tempted} | R Documentation |
Run all major functions of tempted
Description
This function wraps functions format_tempted
, svd_centralize
, tempted
,
ratio_feature
, \
and aggregate_feature
.
Usage
tempted_all(
featuretable,
timepoint,
subjectID,
threshold = 0.95,
pseudo = NULL,
transform = "clr",
r = 3,
smooth = 1e-06,
interval = NULL,
resolution = 51,
maxiter = 20,
epsilon = 1e-04,
r_svd = 1,
do_ratio = TRUE,
pct_ratio = 0.05,
absolute = FALSE,
pct_aggregate = 1,
contrast = NULL
)
Arguments
featuretable |
A sample by feature matrix. It is an input for |
timepoint |
The time stamp of each sample, matched with the rows of |
subjectID |
The subject ID of each sample, matched with the rows of |
threshold |
A threshold for feature filtering for microbiome data.
Features with zero value percentage >= threshold will be excluded. Default is 0.95.
It is an input for |
pseudo |
A small number to add to all the counts before
normalizing into proportions and log transformation.
Default is 1/2 of the smallest non-zero value that is specific for each sample.
This pseudo count is added for |
transform |
The transformation applied to the data.
|
r |
Number of components to decompose into, i.e. rank of the CP type decomposition.
Default is set to 3.
It is an input for |
smooth |
Smoothing parameter for RKHS norm.
Larger means smoother temporal loading functions. Default is set to be 1e-8.
Value can be adjusted depending on the dataset by checking the smoothness of the estimated temporal loading function in plot.
It is an input for |
interval |
The range of time points to ran the decomposition for.
Default is set to be the range of all observed time points.
User can set it to be a shorter interval than the observed range.
It is an input for |
resolution |
Number of time points to evaluate the value of the temporal loading function.
Default is set to 101. It does not affect the subject or feature loadings. It is an input for |
maxiter |
Maximum number of iteration. Default is 20. It is an input for |
epsilon |
Convergence criteria for difference between iterations. Default is 1e-4. It is an input for |
r_svd |
The number of ranks in the mean structure. Default is 1. It is an input for |
do_ratio |
Whether to calculate the log ratio of features. |
pct_ratio |
The percent of features to sum up. Default is 0.05, i.e. 5%.
It is an input for |
absolute |
|
pct_aggregate |
The percent of features to aggregate,
features ranked by absolute value of the feature loading of each component.
Default is 1, which means 100% of features are aggregated.
Setting |
contrast |
A matrix choosing how components are combined,
each column is a contrast of length r and used to calculate the linear combination of
the feature loadings of r components.
It is an input for |
Value
A list including all the input and output of functions format_tempted
, svd_centralize
, tempted
,
ratio_feature
, and aggregate_feature
.
- input
All the input options of function
tempted_all
.- datalist_raw
Output of
format_tempted
with optiontransform="none"
.- datlist
Output of
format_tempted
.- mean_svd
Output of
svd_centralize
.- A_hat
Subject loading, a subject by r matrix.
- B_hat
Feature loading, a feature by r matrix.
- Phi_hat
Temporal loading function, a resolution by r matrix.
- time_Phi
The time points where the temporal loading function is evaluated.
- Lambda
Eigen value, a length r vector.
- r_square
Variance explained by each component. This is the R-squared of the linear regression of the vectorized temporal tensor against the vectorized low-rank reconstruction using individual components.
- accum_r_square
Variance explained by the first few components accumulated. This is the R-squared of the linear regression of the vectorized temporal tensor against the vectorized low-rank reconstruction using the first few components.
- metafeature_ratio
The log ratio abundance of the top over bottom ranking features. It is a data.frame with five columns: "value" for the log ratio values, "subID" for the subject ID, and "timepoint" for the time points, and "PC" indicating which component was used to construct the meta feature.
- toppct_ratio
A matrix of TRUE/FALSE indicating which features are ranked top in each component (and contrast) and used as the numerator of the log ratio.
- bottompct_ratio
A matrix of TRUE/FALSE indicating which features are ranked bottom in each component (and contrast) and used as the denominator of the log ratio.
- metafeature_aggregate
The meta feature obtained by aggregating the observed temporal tensor. It is a data.frame with four columns: "value" for the meta feature values, "subID" for the subject ID, "timepoint" for the time points, and "PC" indicating which component was used to construct the meta feature.
- toppct_aggregate
A matrix of TRUE/FALSE indicating which features are aggregated in each component and contrast.
- contrast
The contrast used to linearly combine the components from input.
References
Shi P, Martino C, Han R, Janssen S, Buck G, Serrano M, Owzar K, Knight R, Shenhav L, Zhang AR. (2023) Time-Informed Dimensionality Reduction for Longitudinal Microbiome Studies. bioRxiv. doi: 10.1101/550749. https://www.biorxiv.org/content/10.1101/550749.
Examples
# Take a subset of the samples so the example runs faster
# Here we are taking samples from the odd months
sub_sample <- rownames(meta_table)[(meta_table$day_of_life%/%12)%%2==1]
count_table_sub <- count_table[sub_sample,]
processed_table_sub <- processed_table[sub_sample,]
meta_table_sub <- meta_table[sub_sample,]
# for preprocessed data that do not need to be transformed
res.processed <- tempted_all(processed_table_sub,
meta_table_sub$day_of_life,
meta_table_sub$studyid,
threshold=1,
transform="none",
r=2,
smooth=1e-5,
do_ratio=FALSE)
# for count data that will have pseudo added and clr transformed
res.count <- tempted_all(count_table_sub,
meta_table_sub$day_of_life,
meta_table_sub$studyid,
threshold=0.95,
transform="clr",
pseudo=0.5,
r=2,
smooth=1e-5,
pct_ratio=0.1,
pct_aggregate=1)
# for proportional data that will have pseudo added and clr transformed
res.proportion <- tempted_all(count_table_sub/rowSums(count_table_sub),
meta_table_sub$day_of_life,
meta_table_sub$studyid,
threshold=0.95,
transform="clr",
pseudo=NULL,
r=2,
smooth=1e-5,
pct_ratio=0.1,
pct_aggregate=1)
# plot the temporal loading and subject trajectories grouped by delivery mode
plot_time_loading(res.proportion, r=2)
group <- unique(meta_table[,c("studyid", "delivery")])
# plot the aggregated features
plot_metafeature(res.proportion$metafeature_aggregate, group, bws=30)