主成分分析 ( Principal Component Analysis , PCA )是一種掌握事物主要矛盾的統計分析方法,它可以從多元事物中解析出主要影響因素,揭示事物的本質,簡化複雜的問題。計算主成分的目的是將高維數據投影到較低維空間。給定
n 個變量的 m 個觀察值,形成一個 n ′ m 的數據矩陣,
n 通常比較大。對於一個由多個變量描述的複雜事物,人們難以認識,那麼是否可以抓住事物主要方面進行重點分析呢?如果事物的主要方面剛好體現在幾個主要變量上,我們只需要將這幾個變量分離出來,進行詳細分析。但是,在一般情況下,並不能直接找出這樣的關鍵變量。這時我們可以用原有變量的線性組合來表示事物的主要方面, PCA 就是這樣一種分析方法。
PCA 的目標是尋找 r ( r<n )個新變量,使它們反映事物的主要特徵,壓縮原有數據矩陣的規模。每個新變量是原有變量的線性組合,體現原有變量的綜合效果,具有一定的實際含義。這 r 個新變量稱爲“主成分”,它們可以在很大程度上反映原來 n 個變量的影響,並且這些新變量是互不相關的,也是正交的。通過主成分分析,壓縮數據空間,將多元數據的特徵在低維空間裏直觀地表示出來。例如,將多個時間點、多個實驗條件下的基因表達譜數據(
N 維)表示爲 3 維空間中的一個點,即將數據的維數從 RN 降到 R3 。
在進行基因表達數據分析時,一個重要問題是確定每個實驗數據是否是獨立的,如果每次實驗數據之間不是獨立的,則會影響基因表達數據分析結果的準確性。對於利用基因芯片所檢測到的基因表達數據,如果用 PCA 方法進行分析,可以將各個基因作爲變量,也可以將實驗條件作爲變量。當將基因作爲變量時,通過分析確定一組“主要基因元素”,它們能夠很好地說明基因的特徵,解釋實驗現象;當將實驗條件作爲變量時,通過分析確定一組“主要實驗因素”,它們能夠很好地刻畫實驗條件的特徵,解釋基因的行爲。下面着重考慮以實驗條件作爲變量的
PCA 分析方法。假設將數據的維數從 R N 降到 R 3 ,具體的 PCA 分析步驟如下:
對於 PCA ,確定新變量的個數 r 是一個兩難的問題。我們的目標是減小 r ,如果 r 小,則數據的維數低,便於分析,同時也降低了噪聲,但可能丟失一些有用的信息。究竟如何確定 r 呢?這需要進一步分析每個主元素對信息的貢獻。
貢獻率表示所定義的主成分在整個數據分析中承擔的主要意義佔多大的比重,當取前 r 個主成分來代替原來全部變量時,累計貢獻率的大小反應了這種取代的可靠性,累計貢獻率越大,可靠性越大;反之,則可靠性越小。一般要求累計貢獻率達到 70% 以上。
經過 PCA 分析,一個多變量的複雜問題被簡化爲低維空間的簡單問題。可以利用這種簡化方法進行作圖,形象地表示和分析複雜問題。在分析基因表達數據時,可以針對基因作圖,也可以針對實驗條件作圖。前者稱爲 Q 分析,後者稱爲 R 分析。
PCA在matlab中的實現舉例
以下資料來自matlab的help,翻譯和註解部分由筆者添加:(重點部分添加了翻譯!)
princomp-----函數名稱
Principal component analysis (PCA) on data
Syntax------函數調用語法
[COEFF,SCORE] = princomp(X)
[COEFF,SCORE,latent] = princomp(X)
[COEFF,SCORE,latent,tsquare] = princomp(X)
[...] = princomp(X,'econ')
Description -----函數描述
COEFF = princomp(X) performs
principal components analysis (PCA) on the n-by-p data matrix X, and returns the principal component coefficients, also known as loadings. Rows of X correspond to observations, columns to variables. COEFF is a p-by-p matrix, each column containing coefficients
for one principal component. The columns are in order of decreasing component variance.
princomp centers X by subtracting off column means, but does not rescale the columns of X. To perform principal components analysis with standardized variables, that is, based
on correlations, use princomp(zscore(X)). To perform principal components analysis directly on a covariance or correlation matrix, use pcacov.
[COEFF,SCORE] = princomp(X) returns
SCORE, the principal component scores; that is, the representation of X in the principal component space. Rows of SCORE correspond to observations, columns to components.
[COEFF,SCORE,latent] = princomp(X) returns
latent, a vector containing the eigenvalues of the covariance matrix of X.
返回的latent是一個向量,它是X所對應的協方差矩陣的特徵值向量。
[COEFF,SCORE,latent,tsquare] = princomp(X) returns
tsquare, which contains Hotelling's T2 statistic for each data point.
返回的tsquare,是表示對每個樣本點Hotelling的T方統計量(我也不很清楚是什麼東東)。
The scores are the data formed by transforming the original data into the space of the principal components. The values of the vector latent are the variance of the columns of
SCORE. Hotelling's T2 is a measure of the multivariate distance of each observation from the center of the data set.
When n <= p, SCORE(:,n:p) and latent(n:p) are necessarily zero, and the columns of COEFF(:,n:p) define directions that are orthogonal to X.
[...] = princomp(X,'econ') returns
only the elements of latent that are not necessarily zero, and the corresponding columns of COEFF and SCORE, that is, when n <= p, only the first n-1. This can be significantly faster when p is much larger than n.