Last updated: 2022-10-27
Checks: 7 0
Knit directory: bioinformatics_tips/ 
This reproducible R Markdown analysis was created with workflowr (version 1.7.0). The Checks tab describes the reproducibility checks that were applied when the results were created. The Past versions tab lists the development history.
Great! Since the R Markdown file has been committed to the Git repository, you know the exact version of the code that produced these results.
Great job! The global environment was empty. Objects defined in the global environment can affect the analysis in your R Markdown file in unknown ways. For reproduciblity it’s best to always run the code in an empty environment.
The command set.seed(20200503) was run prior to running
the code in the R Markdown file. Setting a seed ensures that any results
that rely on randomness, e.g. subsampling or permutations, are
reproducible.
Great job! Recording the operating system, R version, and package versions is critical for reproducibility.
Nice! There were no cached chunks for this analysis, so you can be confident that you successfully produced the results during this run.
Great job! Using relative paths to the files within your workflowr project makes it easier to run your code on other machines.
Great! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility.
The results in this page were generated with repository version cfb532a. See the Past versions tab to see a history of the changes made to the R Markdown and HTML files.
Note that you need to be careful to ensure that all relevant files for
the analysis have been committed to Git prior to generating the results
(you can use wflow_publish or
wflow_git_commit). workflowr only checks the R Markdown
file, but you know if there are other scripts or data files that it
depends on. Below is the status of the Git repository when the results
were generated:
Ignored files:
    Ignored:    .Rhistory
    Ignored:    .Rproj.user/
Unstaged changes:
    Modified:   .Rprofile
    Modified:   analysis/scripting.Rmd
Note that any generated files, e.g. HTML, png, CSS, etc., are not included in this status report because it is ok for generated content to have uncommitted changes.
These are the previous versions of the repository in which changes were
made to the R Markdown (analysis/dim_reduct.Rmd) and HTML
(docs/dim_reduct.html) files. If you’ve configured a remote
Git repository (see ?wflow_git_remote), click on the
hyperlinks in the table below to view the files as they were in that
past version.
| File | Version | Author | Date | Message | 
|---|---|---|---|---|
| Rmd | cfb532a | Dave Tang | 2022-10-27 | Dimension reduction | 
Dimension reduction is useful for identifying correlated features and reducing the data size, which is very useful for visualising large datasets.
PCA.
pca <- prcomp(iris[, 1:4])
my_col <- as.integer(iris$Species)
plot(pca$x, col = my_col, pch = 16)
t-SNE default perplexity of 30.
if(!require(tsne)){
  install.packages("tsne")
}Loading required package: tsnelibrary(tsne)
tsne_ <- tsne(iris[, 1:4])sigma summary: Min. : 0.486505661043274 |1st Qu. : 0.587913800179832 |Median : 0.614872437640536 |Mean : 0.623051089344394 |3rd Qu. : 0.654914112723525 |Max. : 0.796707932771489 |Epoch: Iteration #100 error is: 13.1171061837296Epoch: Iteration #200 error is: 0.238938736285296Epoch: Iteration #300 error is: 0.237580495588205Epoch: Iteration #400 error is: 0.2374547569615Epoch: Iteration #500 error is: 0.237448878840098Epoch: Iteration #600 error is: 0.237448500418977Epoch: Iteration #700 error is: 0.237448477241058Epoch: Iteration #800 error is: 0.237448475805662Epoch: Iteration #900 error is: 0.23744847571858Epoch: Iteration #1000 error is: 0.237448475713213plot(tsne_, col = my_col, pch = 16)
Perplexity of 20.
tsne_p20 <- tsne(iris[, 1:4], perplexity = 20)sigma summary: Min. : 0.42864778740551 |1st Qu. : 0.523593962475894 |Median : 0.553545139847788 |Mean : 0.563823813379956 |3rd Qu. : 0.596877396756174 |Max. : 0.752227354673175 |Epoch: Iteration #100 error is: 13.5073150056192Epoch: Iteration #200 error is: 0.268228858442339Epoch: Iteration #300 error is: 0.262336620485244Epoch: Iteration #400 error is: 0.261018858034014Epoch: Iteration #500 error is: 0.260588711691426Epoch: Iteration #600 error is: 0.260399044375287Epoch: Iteration #700 error is: 0.260293870035397Epoch: Iteration #800 error is: 0.260228227596464Epoch: Iteration #900 error is: 0.260186737975538Epoch: Iteration #1000 error is: 0.260157652086673plot(tsne_p20, col = my_col, pch = 16)
Perplexity of 40.
tsne_p40 <- tsne(iris[, 1:4], perplexity = 40)sigma summary: Min. : 0.527309628938834 |1st Qu. : 0.636786401601399 |Median : 0.667089986073136 |Mean : 0.671796474888864 |3rd Qu. : 0.70053875222358 |Max. : 0.836996944234283 |Epoch: Iteration #100 error is: 12.620846895381Epoch: Iteration #200 error is: 0.258452741303131Epoch: Iteration #300 error is: 0.257015837325158Epoch: Iteration #400 error is: 0.256962711285107Epoch: Iteration #500 error is: 0.256962707558697Epoch: Iteration #600 error is: 0.256962707553156Epoch: Iteration #700 error is: 0.256962707553153Epoch: Iteration #800 error is: 0.256962707553153Epoch: Iteration #900 error is: 0.256962707553153Epoch: Iteration #1000 error is: 0.256962707553153plot(tsne_p40, col = my_col, pch = 16)
Perplexity of 50.
tsne_p50 <- tsne(iris[, 1:4], perplexity = 50)sigma summary: Min. : 0.565012665854053 |1st Qu. : 0.681985646004023 |Median : 0.713004330336136 |Mean : 0.716213420895748 |3rd Qu. : 0.74581655363904 |Max. : 0.874979764925049 |Epoch: Iteration #100 error is: 12.0664597536258Epoch: Iteration #200 error is: 0.20135560570987Epoch: Iteration #300 error is: 0.199907660516558Epoch: Iteration #400 error is: 0.199720346311414Epoch: Iteration #500 error is: 0.199720055735862Epoch: Iteration #600 error is: 0.199720055732102Epoch: Iteration #700 error is: 0.199720055732101Epoch: Iteration #800 error is: 0.199720055732101Epoch: Iteration #900 error is: 0.199720055732101Epoch: Iteration #1000 error is: 0.199720055732101plot(tsne_p50, col = my_col, pch = 16)
UMAP default settings.
if(!require(umap)){
  install.packages("umap")
}Loading required package: umaplibrary(umap)
umap.defaultsumap configuration parameters           n_neighbors: 15          n_components: 2                metric: euclidean              n_epochs: 200                 input: data                  init: spectral              min_dist: 0.1      set_op_mix_ratio: 1    local_connectivity: 1             bandwidth: 1                 alpha: 1                 gamma: 1  negative_sample_rate: 5                     a: NA                     b: NA                spread: 1          random_state: NA       transform_state: NA                   knn: NA           knn_repeats: 1               verbose: FALSE       umap_learn_args: NAUMAP with default settings.
umap_ <- umap(iris[, 1:4])
plot(umap_$layout, col = my_col, pch = 16)
Adjust number of neighbours.
umap_conf <- umap.defaults
umap_conf$n_neighbors <- 20
umap_n20 <- umap(iris[, 1:4], config = umap_conf)
plot(umap_n20$layout, col = my_col, pch = 16)
sessionInfo()R version 4.2.0 (2022-04-22)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.04.4 LTS
Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3
LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/liblapack.so.3
locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       
attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     
other attached packages:
[1] umap_0.2.9.0    tsne_0.1-3.1    workflowr_1.7.0
loaded via a namespace (and not attached):
 [1] Rcpp_1.0.8.3     RSpectra_0.16-1  highr_0.9        bslib_0.3.1     
 [5] compiler_4.2.0   pillar_1.7.0     later_1.3.0      git2r_0.30.1    
 [9] jquerylib_0.1.4  tools_4.2.0      getPass_0.2-2    digest_0.6.29   
[13] lattice_0.20-45  jsonlite_1.8.0   evaluate_0.15    tibble_3.1.7    
[17] lifecycle_1.0.1  png_0.1-7        pkgconfig_2.0.3  rlang_1.0.2     
[21] Matrix_1.4-1     cli_3.3.0        rstudioapi_0.13  yaml_2.3.5      
[25] xfun_0.31        fastmap_1.1.0    httr_1.4.3       stringr_1.4.0   
[29] knitr_1.39       askpass_1.1      sass_0.4.1       fs_1.5.2        
[33] vctrs_0.4.1      grid_4.2.0       rprojroot_2.0.3  reticulate_1.25 
[37] glue_1.6.2       R6_2.5.1         processx_3.5.3   fansi_1.0.3     
[41] rmarkdown_2.14   callr_3.7.0      magrittr_2.0.3   whisker_0.4     
[45] ps_1.7.0         promises_1.2.0.1 htmltools_0.5.2  ellipsis_0.3.2  
[49] httpuv_1.6.5     utf8_1.2.2       stringi_1.7.6    openssl_2.0.1   
[53] crayon_1.5.1