library(ajive)

# for visualization
library(dplyr)

# install.packages(c('cowplot', 'GGally'))
library(ggplot2)
library(GGally)

Sample toy data

blocks <- sample_toy_data(n=200, dx=100, dy=500)

data_blocks_heatmap(blocks)

First decide on the initial signal ranks.

scree_plot_blocks(blocks)

Using the above scree plots we set the initial signal rank equal to 2 for both blocks.

initial_signal_ranks <- c(2, 2)

Now we are ready to compute the JIVE decomposition

jive_results <- ajive(blocks, initial_signal_ranks,
                      n_wedin_samples = 100, n_rand_dir_samples = 100)

Visualizing the results

joint_scores <- jive_results[['joint_scores']]

as_tibble(joint_scores) %>% 
    rename(joint_scores = V1) %>% 
    ggplot() + 
    geom_histogram(aes(x=joint_scores))
scores_block1 <- as_tibble(x=cbind(jive_results$block_decomps[[1]][['joint']][['u']],
                                   jive_results$block_decomps[[1]][['individual']][['u']])) %>% 
                    rename(joint=V1, indiv=V2)


ggplot(scores_block1) + 
    geom_point(aes(x=indiv, y=joint))
ggplot(scores_block1)+
    geom_histogram(aes(x=indiv))

ggplot(scores_block1)+
    geom_histogram(aes(x=joint))
pca <- lapply(blocks, function(x) svd(x))
pca_scores_block1 <- as_tibble(pca[[1]][['u']])[ , 1:2] %>% 
    rename(PC1=V1, PC2=V2)

GGally::ggpairs(pca_scores_block1)
GGally::ggpairs(scores_block1,
                upper='blank',
                 diag=list(continuous='barDiag'))


idc9/r_jive documentation built on Oct. 20, 2020, 4:23 p.m.