reconstruct {tempted}R Documentation

Reconstruct tensor from low dimensional components

Description

This function reconstructs the temporal tensor from the low dimensional components extracted by tempted and svd_centralize.

Usage

reconstruct(res_tempted, res_svd = NULL, datlist = NULL, r_reconstruct = NULL)

Arguments

res_tempted

Output of function tempted.

res_svd

Output of function svd_centralize if mean subtraction svd_centralize was performed before tempted. If mean subtraction was not performed, specify res_svd=NULL and provide datlist.

datlist

Output of function format_tempted if mean subtraction was not performed and res_svd=NULL, or left as NULL if mean subtraction was performed and res_svd is provided.

r_reconstruct

The number of components from TEMPTED to be used for the tensor reconstruction.

Value

datlist_est The reconstructed tensor stored in a datlist format same as the output of format_tempted.

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,]
# reconstruct with mean subtraction
datlist <- format_tempted(processed_table_sub,
                          meta_table_sub$day_of_life,
                          meta_table_sub$studyid,
                          pseudo=NULL,
                          transform="none")

mean_svd <- svd_centralize(datlist, r=1)

res_tempted <- tempted(mean_svd$datlist, r=2, smooth=1e-5)

datlist_est <- reconstruct(res_tempted, mean_svd, datlist=NULL, r_reconstruct=2)
vec_est <- unlist(sapply(datlist_est, function(x){x[-1,]}))
vec_obs <- unlist(sapply(datlist, function(x){x[-1,]}))
R2 <- 1-sum((vec_est-vec_obs)^2)/sum(vec_obs^2)
R2

# reconstruct without mean subtraction
datlist <- format_tempted(processed_table_sub,
                          meta_table_sub$day_of_life,
                          meta_table_sub$studyid,
                          pseudo=NULL,
                          transform="none")

res_tempted <- tempted(datlist, r=2, smooth=1e-5)

datlist_est <- reconstruct(res_tempted, res_svd=NULL, datlist=datlist, r_reconstruct=2)
vec_est <- unlist(sapply(datlist_est, function(x){x[-1,]}))
vec_obs <- unlist(sapply(datlist, function(x){x[-1,]}))
R2 <- 1-sum((vec_est-vec_obs)^2)/sum(vec_obs^2)
R2


[Package tempted version 0.1.1 Index]