Principal Component Analysis (PCA) is a dimensionality reduction method that transforms data from a high-dimensional space into a low-dimensional space while retaining the original data's essential properties. This function calculates PCA using the classical prcomp function and visualizes the results.

dr_pca(
  processed_se,
  scaling = TRUE,
  centering = TRUE,
  clustering = c("kmeans", "kmedoids", "hclustering", "dbscan", "group_info"),
  cluster_num = 2,
  kmedoids_metric = NULL,
  distfun = NULL,
  hclustfun = NULL,
  eps = NULL,
  minPts = NULL,
  feature_contrib_pc = c(1, 2),
  plot_topN = 10
)

Arguments

processed_se

A SummarizedExperiment object constructed by as_summarized_experiment and processed by data_process.

scaling

Logical. If scaling=TRUE, each block is standardized to zero means and unit variances. Default is TRUE.

centering

Logical. If centering=TRUE, the variables should be shifted to be zero centered. Alternately, a vector of length equal the number of columns of x can be supplied. The value is passed to scale. Default is TRUE.

clustering

Character. The method to be used for clustering. Allowed method include "kmeans", "kmedoids", "hclustering", "dbscan", "group_info". Default is "kmeans".

cluster_num

Numeric. A positive integer specifying the number of clusters. The number must be between 1 and 10. Default is 2.

kmedoids_metric

Character. The metric to be used for calculating dissimilarities between observations when choosing "kmedoids" as clustering method. Must be one of "euclidean" and "manhattan". If "kmedoids" is not selected as the clustering method, set the value to NULL.

distfun

Character. The distance measure to be used when choosing "hclustering" as clustering method. Allow method include "pearson", "kendall", "spearman", "euclidean", "manhattan", "maximum", "canberra", "binary", and "minkowski". If "hclustering" is not selected as the clustering method, set the value to NULL.

hclustfun

Character. The agglomeration method to be used when choosing "hclustering" as clustering method. This should be (an unambiguous abbreviation of) one of "ward.D", "ward.D2", "single", "complete", "average" (=UPGMA), "mcquitty" (= WPGMA), "median" (= WPGMC), or "centroid" (= UPGMC). If "hclustering" is not selected as the clustering method, set the value to NULL.

eps

Numeric. The size of the epsilon neighborhood when choosing "dbscan" as clustering method. If "dbscan" is not selected as the clustering method, set the value to NULL.

minPts

Numeric. The number of minimum points in the eps region (for core points) when choosing "dbscan" as clustering method. If "dbscan" is not selected as the clustering method, set the value to NULL.

feature_contrib_pc

Numeric. The dimension(s) of interest.

plot_topN

Numeric. The number of top elements to be shown.

Value

Return a list with 2 tables, 4 interactive plots, and 4 static plots.

  1. pca_rotated_data: a data frame of PCA rotated data

  2. table_pca_contribution: a data frame, PCA contribution table

  3. interactive_pca & static_pca: PCA plot

  4. interactive_screePlot & static_screePlot: Scree plot of top n principle components

  5. interactive_feature_contribution & static_feature_contribution: plot, the contribution of top N features of the user-defined principal components.

  6. interactive_variablePlot & static_variablePlot: correlation circle plot(factor map) of PCA variables.

Examples

data("profiling_data")
processed_se <- data_process(profiling_data, exclude_missing=TRUE, exclude_missing_pct=70,
    replace_na_method='min', replace_na_method_ref=0.5, normalization='Percentage')
result_pca <- dr_pca(processed_se, scaling=TRUE, centering=TRUE,
    clustering='kmeans', cluster_num=2, kmedoids_metric=NULL, distfun=NULL,
    hclustfun=NULL, eps=NULL, minPts=NULL, feature_contrib_pc=c(1,2), plot_topN=10)
#> Warning: 'bar' objects don't have these attributes: 'mode'
#> Valid attributes include:
#> '_deprecated', 'alignmentgroup', 'base', 'basesrc', 'cliponaxis', 'constraintext', 'customdata', 'customdatasrc', 'dx', 'dy', 'error_x', 'error_y', 'hoverinfo', 'hoverinfosrc', 'hoverlabel', 'hovertemplate', 'hovertemplatesrc', 'hovertext', 'hovertextsrc', 'ids', 'idssrc', 'insidetextanchor', 'insidetextfont', 'legendgroup', 'legendgrouptitle', 'legendrank', 'marker', 'meta', 'metasrc', 'name', 'offset', 'offsetgroup', 'offsetsrc', 'opacity', 'orientation', 'outsidetextfont', 'selected', 'selectedpoints', 'showlegend', 'stream', 'text', 'textangle', 'textfont', 'textposition', 'textpositionsrc', 'textsrc', 'texttemplate', 'texttemplatesrc', 'transforms', 'type', 'uid', 'uirevision', 'unselected', 'visible', 'width', 'widthsrc', 'x', 'x0', 'xaxis', 'xcalendar', 'xhoverformat', 'xperiod', 'xperiod0', 'xperiodalignment', 'xsrc', 'y', 'y0', 'yaxis', 'ycalendar', 'yhoverformat', 'yperiod', 'yperiod0', 'yperiodalignment', 'ysrc', 'key', 'set', 'frame', 'transforms', '_isNestedKey', '_isSimpleKey', '_isGraticule', '_bbox'
#> Warning: geom_GeomTextRepel() has yet to be implemented in plotly.
#>   If you'd like to see this geom implemented,
#>   Please open an issue with your example code at
#>   https://github.com/ropensci/plotly/issues