Post Reply 
FACTOR ANALYSIS
11-17-2019, 08:59 AM (This post was last modified: 11-21-2019 09:39 PM by rawi.)
Post: #1
FACTOR ANALYSIS
Factor analysis is a multivariate statistical method to find hidden variables behind a set of variables.
The following program performs a factor analysis including estimation of communalities according to the iterative principal factor analysis and a varimax factor rotation.
Literature: Tabachnick, Fidell: Using Multivariate Statistics, Boston 2001

Preparation:
- Input of correlation matrix in matrix M5.
- Make sure that the angle mode is set on "Rad"

Application:
- Start program
- The list of eigenvalues of matrix R is shown. This gives you information to
set the number of factors right in the following step. Press "OK" on the
bottom line of the screen
- You are asked for the number of factors you want to extract. Normally the
number is the number of eigenvalues of R > 1. Put in number and press "OK"

During computation you get some interim results:
- Changes of the communalities in the iterative principal factor analysis
- Otimization criterion of factor rotation
- Some hints where to find results
- Mean and minimum communality. Mean should be above .7, minimum above .5
- Finally the word "Ready" shows that the computation was completed.

After that you will find the following results:
- Matrix of unrotated factor loadings A: Matrix M6
- Matrix of rotated factor loadings Ar: Matrix M7
- Eigenvalues of correlation matrix R: List L4
- Eigenvalues of reduced correlation matrix Rh: List L5
- Communalities: List L6
- Reproduced correlation matrix AA': Matrix M8
- Rotation matrix: Matrix M9

Some hints how to get the data in the HP prime:
I did not find a possibility to copy and paste data (like the correlation matrix in the appendix) directly in a matrix. Instead of typing it you can copy and paste it in the spreadsheet app and from there copy and paste it in a matrix.

Enjoy!

Raimund Wildner


EXPORT FACANE()
BEGIN
// CORR.MAT: M5
LOCAL FZ0,VZ0,AK0,I1,I2,HIMEAN,HIMIN;
LOCAL LHI,MEV,LE,LIX,F0,B0,C0,D0;
LOCAL LDIM,I3,UI0,VI0;
LOCAL ZZ0,ZN0,AL4,T4A,AD0,ZW0,AL0,AK1;
LOCAL SJ1,SJ2,SI1,SI2;
DIM(M5)▶LDIM;
LDIM(1)▶VZ0;//VZ0: Number of variables
MAKELIST(I1,I1,1,VZ0,1)▶LHI;
MAKELIST(I1,I1,1,VZ0,1)▶LE;
MAKEMAT(0,VZ0,VZ0)▶MEV;
EIGENVAL(M5)▶LE;
FOR I1 FROM 1 TO VZ0 DO
RE(LE(I1))▶LE(I1);
END;
LE▶L5;
SORT(L5)▶L5;
REVERSE(L5)▶L5;
L5▶L4; //L4: Eigenvalues of R
EDITLIST(L4);
INPUT(FZ0,"NUMBER OF FACTORS","FZ0=",2);
MAKELIST(I1,I1,1,FZ0,1)▶LIX;
REDIM(M6,{VZ0,FZ0}); //M6: MATRIX FAKTORL.
REDIM(M7,{VZ0,FZ0}); //M7: MATRIX ROT FAKTORL.
REDIM(M8,{VZ0,VZ0}); //M8: F. BER UND AA'
REDIM(M9,{FZ0,FZ0}); //M9: ROTATIONMATRIX
M5▶M8;
// Start iterative estimation of communalities.
REPEAT
diag(M8)▶LHI;
EIGENVAL(M8)▶LE;
FOR I1 FROM 1 TO VZ0 DO
RE(LE(I1))▶LE(I1);
END;
LE▶L5;
SORT(L5)▶L5;
REVERSE(L5)▶L5;
eigVc(M8)▶MEV;
//LIX: List of eigenvalues ordered to size
FOR I1 FROM 1 TO FZ0 DO
FOR I2 FROM 1 TO VZ0 DO
IF L5(I1)=LE(I2) THEN I2▶LIX(I1);
END;
END;
END;
FOR I1 FROM 1 TO FZ0 DO //BER. MATR. A
FOR I2 FROM 1 TO VZ0 DO
MEV(I2,LIX(I1))*√(L5(I1))▶M6(I2,I1);
END;
END;
//Norming of factor loadings
FOR I1 FROM 1 TO FZ0 DO
0▶ZW0;
FOR I2 FROM 1 TO VZ0 DO
ZW0+M6(I2,I1)▶ZW0;
END;
IF ZW0<0 THEN
FOR I2 FROM 1 TO VZ0 DO
M6(I2,I1)*(−1)▶M6(I2,I1);
END;
END;
END;
0▶AK0; // Comp. of termination croterion.
FOR I1 FROM 1 TO VZ0 DO
0▶M8(I1,I1);
FOR I2 FROM 1 TO FZ0 DO
M8(I1,I1)+(M6(I1,I2))^2▶M8(I1,I1);
END;
IF M8(I1,I1)>1 THEN
FOR I2 FROM 1 TO FZ0 DO
M6(I1,I2)/√M8(I1,I1)▶M6(I1,I2);
END;
1▶M8(I1,I1);
END;
AK0+ABS(LHI(I1)-M8(I1,I1))▶AK0;
END;
AK0/VZ0▶AK0;
PRINT(AK0);
UNTIL AK0<.0005;
diag(M8)▶L6;
//END of iterative est. of communalities
//BEGIN of factor rotation -------------
REDIM(MEV,{VZ0,FZ0});
IF FZ0>1 THEN
PRINT("Factor Rotation");
M6▶M7;
FOR I1 FROM 1 TO VZ0 DO
FOR I2 FROM 1 TO FZ0 DO
M6(I1,I2)^2/L6(I1)▶MEV(I1,I2);
END;
END;
ΣLIST(variance(MEV))/FZ0▶AK0;
PRINT(AK0);
REPEAT
FOR I1 FROM 1 TO FZ0-1 DO
FOR I2 FROM I1+1 TO FZ0 DO
0▶F0;
0▶B0;
0▶C0;
0▶D0;
FOR I3 FROM 1 TO VZ0 DO
(M7(I3,I1)^2-M7(I3,I2)^2)/L6(I3)▶UI0;
2.*M7(I3,I1)*M7(I3,I2)/L6(I3)▶VI0;
F0+UI0▶F0;
B0+VI0▶B0;
C0+UI0^2-VI0^2▶C0;
D0+2.*UI0*VI0▶D0;
END;
D0-2.*F0*B0/VZ0▶ZZ0;
C0-(F0^2-B0^2)/VZ0▶ZN0;
IF ZN0=0 THEN 100▶T4A;
ELSE ZZ0/ZN0▶T4A;
END;
ATAN(T4A)▶AL4;
0▶AD0;
IF ZZ0<0 THEN AD0+π▶AD0;
END;
IF T4A<0 THEN AD0+π▶AD0;
END;
(AL4+AD0)/4▶AL0;
FOR I3 FROM 1 TO VZ0 DO
M7(I3,I1)*COS(AL0)+M7(I3,I2)*SIN(AL0)▶ZW0;
−M7(I3,I1)*SIN(AL0)+M7(I3,I2)*COS(AL0)▶M7(I3,I2);
ZW0▶M7(I3,I1);
END;
END;
END;
FOR I1 FROM 1 TO VZ0 DO
FOR I2 FROM 1 TO FZ0 DO
M7(I1,I2)^2/L6(I1)▶MEV(I1,I2);
END;
END;
ΣLIST(variance(MEV))/FZ0▶AK1;
AK1-AK0▶ZW0;
PRINT(AK1);
AK1▶AK0;
UNTIL ZW0<0.00001;
(TRN(M6)*M6)^(−1)*TRN(M6)*M7▶M9;
END;
// Start fianl procedures
// Ordering of factors to size
IF FZ0 > 1 THEN
FOR I1 FROM 1 TO FZ0 DO
LHI(I1)=0;
FOR I2 FROM 1 TO VZ0 DO
LHI(I1)+M7(I2,I1)^2▶LHI(I1);
END;
END;
REPEAT
0▶AK0;
FOR I1 FROM 1 TO FZ0-1 DO
FOR I2 FROM I1+1 TO FZ0 DO
IF LHI(I1)<LHI(I2) THEN
AK0+1▶AK0;
FOR I3 FROM 1TO VZ0 DO
M7(I3,I1)▶ZW0;
M7(I3,I2)▶M7(I3,I1);
ZW0▶M7(I3,I2);
END;
LHI(I1)▶ZW0;
LHI(I2)▶LHI(I1);
ZW0▶LHI(I2);
END;
END;
END;
UNTIL AK0=0;
END;
// Normation that sum of loadings >0
FOR I1 FROM 1 TO FZ0 DO
0▶SJ1;
FOR I2 FROM 1 TO VZ0 DO
SJ1+M7(I2,I1)▶SJ1;
END;
IF SJ1<0 THEN
FOR I2 FROM 1 TO VZ0 DO
M7(I2,I1)*(−1)▶M7(I2,I1);
END;
END;
END;
PRINT(" ");
PRINT("Result: A unrot: M6, A rot: M7,");
PRINT(" AA':M8, Rotation matrix.: M9");
PRINT(" Eigenvalues R: L4, Ev Rh: L5, hi2: L6");
0▶HIMEAN;
1▶HIMIN;
FOR I1 FROM 1 TO VZ0 DO
HIMEAN+L6(I1)▶HIMEAN;
IF L6(I1)<HIMIN THEN L6(I1)▶HIMIN;
END;
END;
M6*TRN(M6)▶M8;
(TRN(M6)*M6)^(−1)*(TRN(M6)*M7)▶M9;
HIMEAN/VZ0▶HIMEAN;
PRINT("Mean(hi2)=" +HIMEAN);
PRINT("Minimum(hi2)=" +HIMIN);
PRINT("Ready");
END;


Attached File(s)
.docx  Example_factor-analysis.docx (Size: 13.18 KB / Downloads: 0)
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)