PCA - retrieving the original data

For econometric discussions not necessarily related to EViews.

Moderators: EViews Gareth, EViews Moderator

cc100
Posts: 62
Joined: Wed Jul 22, 2015 1:58 pm

PCA - retrieving the original data

Postby cc100 » Wed Jul 22, 2015 2:07 pm

hi, I have performed a PCA on 4 time series. The time series are interest rates denominated in the same currency. The output gives me the weighting of each PC on the rate and time series of the principal components. I know that rate1 = PC1 weight *PC1 + PC2 weight*PC2 +PC3 weight *PC3 + PC4 weight * PC4, but when I do this I do not get the original rate. I have performed the PCA on the covariance matrix - I understand that there is some scaling issue, but I am not clear on how to recalculate the original data (ie what rescaling factor to use).

cc100
Posts: 62
Joined: Wed Jul 22, 2015 1:58 pm

Re: PCA - retrieving the original data

Postby cc100 » Wed Jul 22, 2015 2:33 pm

do i just multiply by the standard deviation of the original data set for the rate in question?

EViews Glenn
EViews Developer
Posts: 2682
Joined: Wed Oct 15, 2008 9:17 am

Re: PCA - retrieving the original data

Postby EViews Glenn » Wed Jul 22, 2015 4:33 pm

Mean and standard deviation (non-d.f. adjusted).

Code: Select all

rndseed 1 wfcreate u 1 100 series oil=nrnd series loan=oil*2+nrnd*5 series orders=loan*-.1+nrnd*7 group group01 loan oil orders group01.makepcomp(eigvec=evec) a1 a2 a3 group group02 a1 a2 a3 stom(group02, scores) matrix data = scores*@transpose(evec) vector loan1 = data.@col(1)*@stdevp(loan)+@mean(loan) vector oil1 = data.@col(2)*@stdevp(oil)+@mean(oil) vector orders1 = data.@col(3)*@stdevp(orders)+@mean(orders)
Last edited by EViews Glenn on Thu Jul 23, 2015 8:11 am, edited 1 time in total.

cc100
Posts: 62
Joined: Wed Jul 22, 2015 1:58 pm

Re: PCA - retrieving the original data

Postby cc100 » Thu Jul 23, 2015 12:55 am

Thanks really helpful. But could you give an example of where you have 4 or more time series and you use only 3 principal components to recreate them.

stom(group03, ff)

the above line in your code only works because you have three series and three components

thanks again - really helpful.

cc100
Posts: 62
Joined: Wed Jul 22, 2015 1:58 pm

Re: PCA - retrieving the original data

Postby cc100 » Thu Jul 23, 2015 1:28 am

also what line in your code tells eviews to do the pca on the covariance matrix (and not the correlation matrix)?

EViews Glenn
EViews Developer
Posts: 2682
Joined: Wed Oct 15, 2008 9:17 am

Re: PCA - retrieving the original data

Postby EViews Glenn » Thu Jul 23, 2015 7:45 am

Response to first post:

You can't recreate the 4 original series from only 3 orthogonal components.


Response to second post:

The example uses the covariance. I don't remember the option off of the top of my head, but it's in the documentation for makepcomp.

cc100
Posts: 62
Joined: Wed Jul 22, 2015 1:58 pm

Re: PCA - retrieving the original data

Postby cc100 » Thu Jul 23, 2015 8:02 am

Thanks Glenn. Sorry I probably didn't explain myself properly. What i mean't was I have 4 interest rate series, i perform a PCA on them. Using the PC weights and the PC values I can recreate each rate. But I only want to approximate each rate. So i will write rate1 = (PC1 weight for rate 1 *PC1)+(PC2 weight for rate 1 *PC2)+(PC3 weight for rate 1 *PC3) as 3 PCs explain the majority of the covariance. The difference between rate1 and my original data point will be the missing PC4 weight*PC4.

EViews Glenn
EViews Developer
Posts: 2682
Joined: Wed Oct 15, 2008 9:17 am

Re: PCA - retrieving the original data

Postby EViews Glenn » Thu Jul 23, 2015 8:15 am

Just output the subset of scores in the original score saving, and use the corresponding subset of the eigenvectors in the multiply step. In your example, just drop the higher order PC4 and weight, then reweight as I did.

cc100
Posts: 62
Joined: Wed Jul 22, 2015 1:58 pm

Re: PCA - retrieving the original data

Postby cc100 » Thu Jul 23, 2015 11:25 am

yep thanks Glenn - I'm new to programming in eviews so I was more asking how to take a subset of elements from a vector. I figured it out - thanks again for you help - I appreciate it.

cc100
Posts: 62
Joined: Wed Jul 22, 2015 1:58 pm

Re: PCA - retrieving the original data

Postby cc100 » Tue Jul 28, 2015 2:20 am

Hi Glenn, in the above posts you said to multiply by the std dev and add back the mean to recalculate the original dataset. If i choose the argument 'ucov' then am I right in thinking that I only need to multiply by the std dev? (Just making sure I understand the different arg choices). thanks

cc100
Posts: 62
Joined: Wed Jul 22, 2015 1:58 pm

Re: PCA - retrieving the original data

Postby cc100 » Tue Jul 28, 2015 6:27 am

Actually ignore previous post...keeping the argument as 'cov' - I think you only need to add back the mean. In your example I don't understand why you multiply by the std dev of the original time series if you have used the cov matrix?

EViews Glenn
EViews Developer
Posts: 2682
Joined: Wed Oct 15, 2008 9:17 am

Re: PCA - retrieving the original data

Postby EViews Glenn » Tue Jul 28, 2015 7:50 am

You don't. I misspoke in the earlier post, I meant to say that "The example uses the correlation. I don't remember the option..." Apologies.

cc100
Posts: 62
Joined: Wed Jul 22, 2015 1:58 pm

Re: PCA - retrieving the original data

Postby cc100 » Tue Jul 28, 2015 8:09 am

Great thanks for clarifying - thanks Glenn


Return to “Econometric Discussions”

Who is online

Users browsing this forum: No registered users and 2 guests