Análisis de componentes principales "hacia atrás": ¿cuánta varianza de los datos se explica por una combinación lineal dada de las variables?


17

He realizado un análisis de componentes principales de seis variables AA , BB , CC , DD , EE y FF . Si entiendo correctamente, PC1 sin rotar me dice qué combinación lineal de estas variables describe / explica la mayor variación en los datos y PC2 me dice qué combinación lineal de estas variables describe la siguiente mayor variación en los datos y así sucesivamente.

Solo tengo curiosidad: ¿hay alguna forma de hacer esto "al revés"? Digamos que elijo alguna combinación lineal de estas variables, por ejemplo, A + 2 B + 5 CA+2B+5C , ¿podría calcular cuánta varianza en los datos describe?


77
Estrictamente, PC2 es la combinación lineal ortogonal a PC1 que describe la siguiente mayor variación en los datos.
Henry

1
¿Estás tratando de estimar V a r ( A + 2 B + 5 C )Var(A+2B+5C) ?
vqv

Todas buenas respuestas (tres + 1s). Tengo curiosidad acerca de la opinión de las personas sobre si el problema formulado se puede resolver mediante enfoques de variables latentes (SEM / LVM), si consideramos que una o más variables latentes son "una combinación lineal de las variables".
Aleksandr Blekh

1
@ Aleksandr, mi respuesta está en realidad directamente en desacuerdo con los otros dos. Edité mi respuesta para aclarar el desacuerdo (y planeo editarlo más para deletrear las matemáticas). Imagine un conjunto de datos con dos variables idénticas estandarizados X = YX=Y . ¿Cuánta varianza describe XX ? Otras dos soluciones dan el 50 %50% . Sostengo que la respuesta correcta es 100 %100% .
ameba dice Reinstate Monica

1
@amoeba: A pesar de que todavía me cuesta entender el material por completo, entiendo que tu respuesta es diferente. Cuando dije "todas las respuestas agradables", implicaba que me gustaba el nivel de las respuestas per se, no su exactitud . Me parece que tiene un valor educativo para las personas como yo, que están en su búsqueda de autoeducación en un país accidentado, llamado Estadísticas :-). Espero que tenga sentido.
Aleksandr Blekh

Respuestas:


11

Si comenzamos con la premisa de que todas las variables se han centrado (práctica estándar en PCA), entonces la varianza total en los datos es solo la suma de cuadrados:

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)

Esto es igual a la traza de la matriz de covarianza de las variables, que es igual a la suma de los valores propios de la matriz de covarianza. Esta es la misma cantidad de la que habla PCA en términos de "explicar los datos", es decir, desea que sus PC expliquen la mayor proporción de los elementos diagonales de la matriz de covarianza. Ahora, si hacemos de esto una función objetivo para un conjunto de valores pronosticados como este:

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

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

Entonces el primer principal minimiza componentes SS entre los 1 valores ajustados de rango ( A i , ... , F i )(A^i,,F^i) . Entonces parece que la cantidad apropiada que busca es P = 1 - ST Para usar su ejemploA+2B+5C, necesitamos convertir esta ecuación en predicciones de rango 1. Primero necesita normalizar los pesos para tener una suma de cuadrados 1. Entonces reemplazamos(1,2,5,0,0,0)(suma de cuadrados30) con(1

P=1ST
A+2B+5C(1,2,5,0,0,0)3030 ,230 ,530 ,0,0,0). Luego "puntuamos" cada observación de acuerdo con los pesos normalizados:(130,230,530,0,0,0)

Z i = 130 Ai+230 Bi+530 Ci

Zi=130Ai+230Bi+530Ci

Luego multiplicamos los puntajes por el vector de peso para obtener nuestra predicción de rango 1.

( A i la 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

Then we plug these estimates into SS calculate PP. You can also put this into matrix norm notation, which may suggest a different generalisation. If we set OO as the N×qN×q matrix of observed values of the variables (q=6q=6 in your case), and EE as a corresponding matrix of predictions. We can define the proportion of variance explained as:

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

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

Where ||.||2||.||2 is the Frobenius matrix norm. So you could "generalise" this to be some other kind of matrix norm, and you will get a difference measure of "variation explained", although it won't be "variance" per se unless it is sum of squares.


This is a reasonable approach, but your expression can be greatly simplified and shown to be equal to the sum of squares of ZiZi divided by the total sum of squares TT. Also, 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=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 ˉxx¯ is the mean vector of the data set, xixi 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 xixi and its predicted value, f(xi)f(xi), when we set f(xi)=ˉxf(xi)=x¯.

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

fc(xi)=(cxi)c

fc(xi)=(cxi)c

Then the SSESSE for a given cc is SSEc=i(xifc(xi))(xifc(xi))

SSEc=i(xifc(xi))(xifc(xi))

I think that if you choose cc 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
Al usar nuestro sitio, usted reconoce que ha leído y comprende nuestra Política de Cookies y Política de Privacidad.
Licensed under cc by-sa 3.0 with attribution required.