Hi,
I am looking for a way to save the scores from Principal Component analysis using makepcomp. The added "difficulty" is that I would like to retain all scores -- i.e. if the sample comprises 10 series, 10 scores would be retained -- yet the number of indicators is not known in advance.
So, for instance I would have something like this:
group indicators
for !i=1 to end_value
indicators.add s{!i}
next
indicators.pcomp(cor, eigvale=v1, eigvec=m1)
indicators.makepcomp p1 p2 p3 p4 ...p(end_value)
.... but end_value depends, say, on a specific criterion which series may or may not fulfill (I'll test for it in the program).
Is there an easy way to retain all scores, regardless of how many indicators I have in my group? Would I have to build a strong containing so many p's as I have indicators?
Thanks, Philipp
makepcomp
Moderators: EViews Gareth, EViews Moderator, EViews Jason, EViews Matt
-
EViews Gareth
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13603
- Joined: Tue Sep 16, 2008 5:38 pm
Re: makepcomp
I think you're going to have to build up the string.
Re: makepcomp
Thanks for the quick reply.
Somewhat related to this: if I extract, say, 20 principal components from 20 series, and multiply them with their factor loadings - shouldn't I be able to obtain the exact same values of the original series? So far they don't seem to match...
Somewhat related to this: if I extract, say, 20 principal components from 20 series, and multiply them with their factor loadings - shouldn't I be able to obtain the exact same values of the original series? So far they don't seem to match...
-
EViews Glenn
- EViews Developer
- Posts: 2682
- Joined: Wed Oct 15, 2008 9:17 am
Re: makepcomp
Have you added the means back in?
Principal components
Hi,
I have a question about Principal Components. I am probably missing something very obvious here, but I’m a bit puzzled that factors, multiplied by their loadings, do not give me back the original series.
Consider, for instance, the following example. Let's take 4 series, labelled ser01-ser04:
This code will first normalize them and group them into a group called EM, then estimate principal components and scores, and lastly, multiply the factors and the scores.(*)
Shouldn’t the matrix M contain the same values as the group EM?
Any insights/help would be appreciated,
Philipp
(*) Probably not the most elegant way to program this, but alas...
I have a question about Principal Components. I am probably missing something very obvious here, but I’m a bit puzzled that factors, multiplied by their loadings, do not give me back the original series.
Consider, for instance, the following example. Let's take 4 series, labelled ser01-ser04:
Code: Select all
7 26 6 60
1 29 15 52
11 56 8 20
11 31 8 47
7 52 6 33
11 55 9 22
3 71 17 6
1 31 22 44
2 54 18 22
21 47 4 26
1 40 23 34
11 66 9 12
10 68 8 12
Code: Select all
' Normalize the series
for !i=1 to 4
series n{!i}=(ser0{!i}-@mean(ser0{!i}))/@stdev(ser0{!i})
next
group em n1 n2 n3 n4
em.pcomp(cor, eigval=eigv, eigvec=L)
em.makepcomp f1 f2 f3 f4
group g_temp f1 f2 f3 f4
stom(g_temp, F)
matrix M = F*L
Shouldn’t the matrix M contain the same values as the group EM?
Any insights/help would be appreciated,
Philipp
(*) Probably not the most elegant way to program this, but alas...
-
EViews Glenn
- EViews Developer
- Posts: 2682
- Joined: Wed Oct 15, 2008 9:17 am
Re: makepcomp
[Note: Gareth merged your separate posting on this issue with a request not to double post on the same topic.]
There are two things wrong with your computation. First, your standardization isn't quite right since it uses the df corrected variance instead of the non-df corrected version. It doesn't matter for computation of correlations, but since you are computing the PC on the correlation matrix and then trying to recover the original standardized data, it will ...(you could always scale the product of the eigenvector and the scores, but changing the original scaling is easier).
Secondly, you've got a transpose wrong. Here is a corrected version of the program.
There are two things wrong with your computation. First, your standardization isn't quite right since it uses the df corrected variance instead of the non-df corrected version. It doesn't matter for computation of correlations, but since you are computing the PC on the correlation matrix and then trying to recover the original standardized data, it will ...(you could always scale the product of the eigenvector and the scores, but changing the original scaling is easier).
Secondly, you've got a transpose wrong. Here is a corrected version of the program.
Code: Select all
' Normalize the series
for !i=1 to 4
series n{!i}=(series0{!i}-@mean(series0{!i}))/@stdevp(series0{!i})
next
group em n1 n2 n3 n4
em.pcomp(cor, eigval=eigv, eigvec=L)
em.makepcomp f1 f2 f3 f4
group g_temp f1 f2 f3 f4
stom(g_temp, F)
matrix M = F*@transpose(L)
-
EViews Glenn
- EViews Developer
- Posts: 2682
- Joined: Wed Oct 15, 2008 9:17 am
Re: makepcomp
One more thing. I actually hadn't read the original post since Gareth had answered it. But I will note that if you want to get the scores using all of the components, you may just want to work with the original data and loadings matrix. In your example
Note that all that's happened here in the computation of M is that is that we've multiplied the original data by L*@transpose(L) which is the identity matrix (so not surprisingly you get the original data back).
Code: Select all
em.pcomp(cor, eigval=eigv, eigvec=L)
stom(em, ydat)
matrix g_temp = ydat*L
matrix M = g_temp*@transpose(L)
Who is online
Users browsing this forum: No registered users and 2 guests
