Analisi dei componenti principali "all'indietro": quanta varianza dei dati è spiegata da una data combinazione lineare delle variabili?


17

Ho effettuato un'analisi delle componenti principali delle sei variabili , , , , e . Se ho capito bene, PC1 non ruotato mi dice quale combinazione lineare di queste variabili descrive / spiega la maggiore varianza nei dati e PC2 mi dice quale combinazione lineare di queste variabili descrive la successiva più varianza nei dati e così via.A AB BC CD DE EFF

Sono solo curioso - c'è un modo di fare questo "all'indietro"? Diciamo che scelgo una combinazione lineare di queste variabili - ad esempio , potrei capire quanta varianza nei dati che descrive?A + 2 B + 5 CA+2B+5C


7
In senso stretto, PC2 è la combinazione lineare ortogonale a PC1 che descrive la varianza più prossima nei dati.
Henry,

1
Stai cercando di stimare il ? V a r ( A + 2 B + 5 C )Var(A+2B+5C)
vqv,

Tutte belle risposte (tre + 1). Sono curioso dell'opinione della gente sul fatto che il problema formulato sia risolvibile tramite approcci a variabili latenti (SEM / LVM), se consideriamo una o più variabili latenti "una combinazione lineare delle variabili".
Aleksandr Blekh,

1
@Aleksandr, la mia risposta è in realtà direttamente in contrasto con le altre due. Ho modificato la mia risposta per chiarire il disaccordo (e ho intenzione di modificarlo ulteriormente per precisare la matematica). Immaginare un set di dati con due variabili identici standardizzati X = YX=Y . Quanta varianza è descritta da XX ? Altre due soluzioni danno il 50 %50% . Sostengo che la risposta corretta è al 100 %100% .
ameba dice di reintegrare Monica il

1
@amoeba: nonostante stia ancora lottando per comprendere completamente il materiale, capisco che la tua risposta è diversa. Quando ho detto "tutte belle risposte", ho insinuato che mi piace il livello delle risposte in sé, non la loro correttezza . Trovo che abbia un valore educativo per le persone come me, che sono nella loro ricerca di auto-educazione in un paese accidentato, chiamato Statistiche :-). Spero abbia senso.
Aleksandr Blekh,

Risposte:


11

Se iniziamo con la premessa che tutte le variabili sono state centrate (pratica standard in PCA), la varianza totale nei dati è solo la somma dei quadrati:

T = i ( A 2 i + B 2 i + C 2 i + D 2 i + E 2 i + F 2 i )

T=i(A2i+B2i+C2i+D2i+E2i+F2i)

Questo è uguale alla traccia della matrice di covarianza delle variabili, che equivale alla somma degli autovalori della matrice di covarianza. Questa è la stessa quantità di cui parla PCA in termini di "spiegazione dei dati" - vale a dire che vuoi che i tuoi PC spieghino la maggior parte degli elementi diagonali della matrice di covarianza. Ora, se rendiamo questa una funzione oggettiva per un insieme di valori previsti in questo modo:

S = Σ i ( [ A i - A i ] 2 + + [ F i - F i ] 2 )

S=i([AiA^i]2++[FiF^i]2)

Poi le prime principali minimizza elementi SS tra tutti rango 1 valori stimati ( A i , ... , F i )(A^i,,F^i) . Quindi sembrerebbe che la quantità appropriata che stai cercando sia P = 1 - ST

P=1ST
Per usare il tuo esempioA+2B+5CA+2B+5C, dobbiamo trasformare questa equazione in previsioni di rango 1. Per prima cosa devi normalizzare i pesi per avere la somma dei quadrati 1. Quindi sostituiamo(1,2,5,0,0,0)(1,2,5,0,0,0)(somma dei quadrati3030) con(130 ,230 ,530 ,0,0,0)(130,230,530,0,0,0). Successivamente "segniamo" ogni osservazione secondo i pesi normalizzati:

Z i = 130 Ai+230 Bi+530 Ci

Zi=130Ai+230Bi+530Ci

Quindi moltiplichiamo i punteggi per il vettore del peso per ottenere la nostra previsione di grado 1.

( A i B i C i D i E i F i ) = Z i × ( 130 230 530 000)

A^iB^iC^iD^iE^iF^i=Zi×130230530000

Poi inseriamo queste stime in S calcolare P . Puoi anche metterlo nella notazione a matrice, che può suggerire una generalizzazione diversa. Se impostiamo O come matrice N × q dei valori osservati delle variabili ( q = 6 nel tuo caso), ed E come matrice corrispondente di previsioni. Possiamo definire la percentuale di varianza spiegata come:SPON×qq=6E

| | O | | 2 2 - | | O - E | | 2 2| | O | | 2 2

||O||22||OE||22||O||22

Dove | | . | | 2 è la norma della matrice di Frobenius . Quindi potresti "generalizzare" questo come un altro tipo di norma matriciale e otterrai una misura della differenza di "variazione spiegata", sebbene non sia "varianza" di per sé a meno che non sia una somma di quadrati.||.||2


Questo è un approccio ragionevole, ma l'espressione può essere notevolmente semplificata e mostrato essere uguale alla somma dei quadrati di Z i diviso per la somma dei quadrati totale T . Inoltre, penso che questo non sia il modo migliore per interpretare la domanda; vedi la mia risposta per un approccio alternativo che sostengo abbia più senso (in particolare, vedi la mia figura di esempio lì). ZiT
ameba dice di reintegrare Monica il

Think about it like that. Imagine a dataset with two standardized identical variables X=YX=Y. How much variance is described by XX? Your calculation gives 50%50%. I argue that the correct answer is 100%100%.
amoeba says Reinstate Monica

@amoeba - if X=YX=Y then the first PC is (12,12)(12,12) - this makes rank 11 scores of zi=xi+yi2=xi2zi=xi+yi2=xi2 (assuming xi=yixi=yi). This gives rank 11 predictions of ˆxi=xix^i=xi, and similarly ˆyi=yiy^i=yi. Hence you get OE=0OE=0 and S=0S=0. Hence you get 100% as your intuition suggests.
probabilityislogic

Hey, yes, sure, the 1st PC explains 100% variance, but that's not what I meant. What I meant is that X=YX=Y, but the question is how much variance is described by XX, i.e. by (1,0)(1,0) vector? What does your formula say then?
amoeba says Reinstate Monica

@amoeba - this says 50%, but note that the (1,0)(1,0) vector says that the best rank 11 predictor for (xi,yi)(xi,yi) is given as ˆxi=xix^i=xi and ˆyi=0y^i=0 (noting that zi=xizi=xi under your choice of vector). This is not an optimal prediction, which is why you don't get 100%. You need to predict both XX and YY in this set-up.
probabilityislogic

8

Let's say I choose some linear combination of these variables -- e.g. A+2B+5CA+2B+5C, could I work out how much variance in the data this describes?

This question can be understood in two different ways, leading to two different answers.

A linear combination corresponds to a vector, which in your example is [1,2,5,0,0,0][1,2,5,0,0,0]. This vector, in turn, defines an axis in the 6D space of the original variables. What you are asking is, how much variance does projection on this axis "describe"? The answer is given via the notion of "reconstruction" of original data from this projection, and measuring the reconstruction error (see Wikipedia on Fraction of variance unexplained). Turns out, this reconstruction can be reasonably done in two different ways, yielding two different answers.


Approach #1

Let XX be the centered dataset (nn rows correspond to samples, dd columns correspond to variables), let ΣΣ be its covariance matrix, and let ww be a unit vector from RdRd. The total variance of the dataset is the sum of all dd variances, i.e. the trace of the covariance matrix: T=tr(Σ)T=tr(Σ). The question is: what proportion of TT does ww describe? The two answers given by @todddeluca and @probabilityislogic are both equivalent to the following: compute projection XwXw, compute its variance and divide by TT: R2first=Var(Xw)T=wΣwtr(Σ).

R2first=Var(Xw)T=wΣwtr(Σ).

This might not be immediately obvious, because e.g. @probabilityislogic suggests to consider the reconstruction XwwXww and then to compute X2XXww2X2,

X2XXww2X2,
but with a little algebra this can be shown to be an equivalent expression.

Approach #2

Okay. Now consider a following example: XX is a d=2d=2 dataset with covariance matrix Σ=(10.990.991)

Σ=(10.990.991)
and w=(10)w=(10) is simply an xx vector:

variance explained

The total variance is T=2T=2. The variance of the projection onto ww (shown in red dots) is equal to 11. So according to the above logic, the explained variance is equal to 1/21/2. And in some sense it is: red dots ("reconstruction") are far away from the corresponding blue dots, so a lot of the variance is "lost".

On the other hand, the two variables have 0.990.99 correlation and so are almost identical; saying that one of them describes only 50%50% of the total variance is weird, because each of them contains "almost all the information" about the second one. We can formalize it as follows: given projection XwXw, find a best possible reconstruction XwvXwv with vv not necessarily the same as ww, and then compute the reconstruction error and plug it into the expression for the proportion of explained variance: R2second=X2XXwv2X2,

R2second=X2XXwv2X2,
where vv is chosen such that XXwv2XXwv2 is minimal (i.e. R2R2 is maximal). This is exactly equivalent to computing R2R2 of multivariate regression predicting original dataset XX from the 11-dimensional projection XwXw.

It is a matter of straightforward algebra to use regression solution for vv to find that the whole expression simplifies to R2second=Σw2wΣwtr(Σ).

R2second=Σw2wΣwtr(Σ).
In the example above this is equal to 0.99010.9901, which seems reasonable.

Note that if (and only if) ww is one of the eigenvectors of ΣΣ, i.e. one of the principal axes, with eigenvalue λλ (so that Σw=λwΣw=λw), then both approaches to compute R2R2 coincide and reduce to the familiar PCA expression R2PCA=R2first=R2second=λ/tr(Σ)=λ/λi.

R2PCA=R2first=R2second=λ/tr(Σ)=λ/λi.

PS. See my answer here for an application of the derived formula to the special case of ww being one of the basis vectors: Variance of the data explained by a single variable.


Appendix. Derivation of the formula for R2secondR2second

Finding vv minimizing the reconstruction XXwv2XXwv2 is a regression problem (with XwXw as univariate predictor and XX as multivariate response). Its solution is given by v=((Xw)(Xw))1(Xw)X=(wΣw)1wΣ.

v=((Xw)(Xw))1(Xw)X=(wΣw)1wΣ.

Next, the R2R2 formula can be simplified as R2=X2XXwv2X2=Xwv2X2

R2=X2XXwv2X2=Xwv2X2
due to the Pythagoras theorem, because the hat matrix in regression is an orthogonal projection (but it is also easy to show directly).

Plugging now the equation for vv, we obtain for the numerator: Xwv2=tr(Xwv(Xwv))=tr(XwwΣΣwwX)/(wΣw)2=tr(wΣΣw)/(wΣw)=Σw2/(wΣw).

Xwv2=tr(Xwv(Xwv))=tr(XwwΣΣwwX)/(wΣw)2=tr(wΣΣw)/(wΣw)=Σw2/(wΣw).

The denominator is equal to X2=tr(Σ)X2=tr(Σ) resulting in the formula given above.


I think this is an answer to a different question. For example, it not the case that that optimising your R2R2 wrt ww will give the first PC as the unique answer (in those cases where it is unique). The fact that (1,0)(1,0) and 12(1,1)12(1,1) both give 100% when X=YX=Y is evidence enough. Your proposed method seems to assume that the "normalised" objective function for PCA will always understate the variance explained (yours isn't a normalised PCA objective function as it normalises by the quantity being optimised in PCA).
probabilityislogic

I agree that our answers are to different questions, but it's not clear to me which one OP had in mind. Also, note that my interpretation is not something very weird: it's a standard regression approach: when we say that xx explains so and so much variance in yy, we compute reconstruction error of yxbyxb with an optimal bb, not just yxyx. Here is another argument: if all nn variables are standardized, then in your approach each one explains 1/n1/n amount of variance. This is not very informative: some variables can be much more predictive than others! My approach reflects that.
amoeba says Reinstate Monica

@amoeba (+1) Great answer, it's really helpful! Would you know any reference that tackles this issue? Thanks!
PierreE

@PierreE Thanks. No, I don't think I have any reference for that.
amoeba says Reinstate Monica

4

Let the total variance, TT, in a data set of vectors be the sum of squared errors (SSE) between the vectors in the data set and the mean vector of the data set, T=i(xiˉx)(xiˉx)

T=i(xix¯)(xix¯)
where ˉx is the mean vector of the data set, xi is the ith vector in the data set, and is the dot product of two vectors. Said another way, the total variance is the SSE between each xi and its predicted value, f(xi), when we set f(xi)=ˉx.

Now let the predictor of xi, f(xi), be the projection of vector xi onto a unit vector c.

fc(xi)=(cxi)c

Then the SSE for a given c is SSEc=i(xifc(xi))(xifc(xi))

I think that if you choose c to minimize SSEc, then c is the first principal component.

If instead you choose c to be the normalized version of the vector (1,2,5,...), then TSSEc is the variance in the data described by using c as a predictor.


This is a reasonable approach, but I think this is not the best way to interpret the question; see my answer for an alternative approach that I argue makes more sense (in particular, see my example figure there).
amoeba says Reinstate Monica

Think about it like that. Imagine a dataset with two standardized identical variables X=Y. How much variance is described by X? Your calculation gives 50%. I argue that the correct answer is 100%.
amoeba says Reinstate Monica
Utilizzando il nostro sito, riconosci di aver letto e compreso le nostre Informativa sui cookie e Informativa sulla privacy.
Licensed under cc by-sa 3.0 with attribution required.