STATISTICA







STATISTICA BASIC Program LoadingsCircle.stb

{ This program will generate a 2D-scatterplot of the factor loadings in a Principal Components Analysis or in a Principal Factor Analysis. This graph differs from the regular plot of loadings given by the analysis on 3 points: The active scrollsheet (top) must be the Factor Loadings scrollsheet (rotated or unrotated). When you execute the program, it will first check that the active scrollsheet is the Factor Loadings scrollsheet (if not, an error message will pop up and the program will stop). Then, it will ask you to choose the two factors to plot the graph (x- and y- axes). You will get an error message if the active (top) scrollsheet is not the Factor Loadings scrollsheet, or if you select more than 2 factors from the list to plot the 2D-graph. The obtained graph is square and has pre-scaled axes: this allows you to do straightforward comparisons between plots of loadings (e.g. rotated and unrotated). Because of the way the loadings are calculated, the variables will all be included inside the circle. The closer a variable is from the circle, the better this variable is represented in the 2D-space defined by the 2 factors (i.e. high correlation between the variable and one or two factors). Any variable that is well inside the circle is uncorrelated with the factors and thus, you cannot draw any conclusion on the relationship of this variable with the others based on this plot.

Program written, modified, or edited at StatSoft Ltd.}


RandomAccess ;


{Get the top scrollsheet = Factor Loadings = 'Scroll'}

Scroll := GetScrollsheet(0);


{Checks if current (active) scrollsheet is the Factor Loadings scrollsheet}

if Scroll = 0 then 								{check if there is an open scrollsheet}
	begin
	DisplayMessageBox (MB_OK+MB_ICONEXCLAMATION, 'No valid scrollsheet was found',
   	'No valid scrollsheet was found. To run this program, you need to produce the Factor Loadings scrollsheet first.');
	stop;
	end;

ScrollsheetGetTitle (Scroll, 1, Title$);						{check if title of active scrollsheet}
Valid$:='Factor Loadings';							{contains the string 'Factor Loadings'}
Lenght:=Len (Valid$); {Len(a) = lenght of string a}
Sub$:=Mid(Title$, 1, Lenght);

if Sub$<>Valid$ then
	begin
	DisplayMessageBox (MB_OK+MB_ICONEXCLAMATION, 'Incorrect active scrollsheet',
	'The currently active (on top) scrollsheet is not the Factor Loadings scrollsheet. To run this program, you need to
produce the Factor Loadings scrollsheet first.');
	stop;
	end;


{NbFactors = nb of factors in 'Scroll'}

NbFactors := ScrollsheetGetNbCols(Scroll);


{List of the factors}

List$ := ' Factor 1';
For i:= 2 to NbFactors do
	List$ := List$ + '| Factor ' + Str(i, 1, 0);


{Asks to choose the 2 Factors to be used as x- and y-axes in the list of all factors
and places the numbers of the 2 factors selected in the array Setxy.
Gives an error message if 0 or 1 factor is selected (or more than 2 factors)}

ReDim Setxy(2);
NbSel := DisplaySelectionBox('Select the factors for the plot', List$, Setxy, 2);

If (NbSel = 0) or (nbSel = 1) then
	begin
	DisplayMessageBox (MB_OK+MB_ICONEXCLAMATION, 'Incorrect number of factors selected',
	'You need to select 2 factors to be used as x-and y- axes');
	stop;
	end;



{NbPoints to be plotted = nb of vars in the data set}

NbPoints := ScrollsheetGetNbRows(Scroll) - 2;


{Definition of vectors Factorx (x coordinates of the vars) and Factory (y coordinates of the vars)}

ReDim Factorx (NbPoints);
ReDim Factory (NbPoints);


{Gets the values of Factorx = column Setxy(1) of 'Scroll' and of Factory = column Setxy(2) of 'Scroll'}

ScrollsheetGetMatrix(Scroll, 1, Setxy(1), Factorx);
ScrollsheetGetMatrix(Scroll, 1, Setxy(2), Factory);


{Defines the name of the 2 axes to be display on the graph}

xaxis$ := 'Factor ' + Str(Setxy(1), 1, 0);
yaxis$ := 'Factor ' + Str(Setxy(2), 1, 0);


{Generates the scatterplot 'Loadings' and sets x- and y- axes from -1 to +1 with a step of 0.2}

Loadings := NewGraph (SCATTERPLOT, 'Circle of Loadings', yaxis$, xaxis$, NbPoints, Factorx, Factory);
GraphSetScaling (Loadings, AX_X, SCALING_MANUAL, -1, 1, 0.2);
GraphSetScaling (Loadings, AX_Y, SCALING_MANUAL, -1, 1, 0.2);


{Adds the points labels (i.e. variable names) to the plot 'Loadings'}

For i := 1 to NbPoints do
	Begin
	ScrollsheetGetRowName(Scroll, i, PointName$);
	GraphDrawTextParam(Loadings, PointName$, 'Arial', 8, BLACK, O_HORIZONTAL, AL_CENTER, AL_BOTTOM,
			         OFF, Fill_TRANSPARENT, Factorx (i), Factory (i)+0.025, TRUE);
	End;


{Draws an ellipse (= circle) 'Ellipse' centered on (0,0) and with a unit radius}

Ellipse := GraphDrawShape(Loadings, Shape_ellipse, -1, 1, 1, -1, TRUE);
GraphSetObjectLineStyle(Loadings, Ellipse, ON, L_SOLID, 1, RED);


{Adds the x- and y-axes inside the circle (dotted lines)}

Dim P1(2,2); 								{defines a table of coordinates for the x-axis}
P1(1,1):=1;   P1(1,2):=0;
P1(2,1):=-1;   P1(2,2):=0;

Dim P2(2,2); 								{defines a table of coordinates for the y-axis}
P2(1,1):=0;   P2(1,2):=1;
P2(2,1):=0;   P2(2,2):=-1;

Lines:=GraphDrawPolyline(Loadings, 2, P1, TRUE); 			{draws the x-axis inside the circle}
GraphSetObjectLineStyle(Loadings, Lines, ON, L_DOTTED, 1, BLACK);

Lines:=GraphDrawPolyline(Loadings, 2, P2, TRUE); 			{draws the y-axis inside the circle}
GraphSetObjectLineStyle(Loadings, Lines, ON, L_DOTTED, 1, BLACK);


{Sets the graph proportion to 1 = length/width i.e square}

GraphSetProportion (Loadings, 1); 
Back to List of Programs



[StatSoft]
2300 East 14th Street, Tulsa, OK 74104
Phone: (918) 749-1119; Fax: (918) 749-2217

[StatSoft]e-mail: info@statsoft.com

©Copyright StatSoft, Inc., 1984-2004.
StatSoft, StatSoft logo, STATISTICA, SEWSS, SEDAS, Data Miner, SEPATH and GTrees are trademarks of StatSoft, Inc.