STATISTICA







STATISTICA BASIC Program HgwBreak.stb

Graph { This program is useful in creating a histogram of data which has several "bins" with high frequencies as well as some "bins" with low frequencies. In a default histogram the display of the low frequencies will be difficult to differentiate. The graph is drawn using the results from a Frequency Table produced either in the Basic Statistics and Tables module or by requesting frequencies from the Quick Basic Statistics option which is available when the right mouse button is used on a data file. Since the histograms produced by this program have the y-axis displayed in two sections with separate scaling more detail can be shown, although direct comparison becomes more difficult. If a Frequency Table is to be created in Basic Statistics for a Variable with some text values, but not all, then deselect the "With Text Values" option, since a mixture of numbers and text will disrupt the x-axis.

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


RandomAccess;
NoDataFileVariableNames;

freqs := GetScrollsheet (0);

cats := ScrollsheetGetNbRows (freqs);

ReDim xaxis (cats);
ReDim oldxaxis (cats);
ReDim yaxis (cats);

miss := 0;
trip := 0;
groupcode := 0;

{loop to obtain data}

for i := 1 to cats do begin
	ScrollsheetGetRowName (freqs, i, TempName$);
	if Mid(TempName$, 1, 4) = 'Miss' then miss := 1 else xaxis(i) := Val (TempName$);
	if Mid(TempName$, 1, 7) = 'Not Sel' then miss := 2;
	ScrollsheetGetValue (freqs, i, 1, yaxis(i));
end;

cats := cats - miss;

ReDim xdiff (cats - 1);
ReDim ycopy (cats);
ReDim propydiff (cats - 1);
ReDim ydiffcount (cats - 1);
ReDim yaxis1 (cats);
ReDim yaxis2 (cats);

{look for the biggest difference in relative frequencies}

MatrixCopy (yaxis, 1, 1, 0, 1, ycopy, 1, 1);

VectorSort (ycopy, SORT_ASCENDING);

for i := 1 to (cats - 1) do begin
	propydiff (i) := (ycopy (i + 1) - ycopy (i)) / ycopy(i);
	ydiffcount (i) := i;
end;

VectorDualSort (propydiff, ydiffcount, SORT_DESCENDING);

{define the break point as the biggest of the small frequencies plus 25%}

break := ycopy(ydiffcount(1))*1.25;

if break < 5 then break := 5;

{create data for the two graphs}

for i := 1 to cats do
	if yaxis (i) < break then yaxis1 (i) := 1/0 else yaxis1 (i) := yaxis (i);

for i := 1 to cats do
	if yaxis (i) >= break then yaxis2 (i) := break else yaxis2 (i) := yaxis (i);

{obtain the variable name from the Scrollsheet}

ScrollsheetGetTitle (freqs, 1, String$);

if Mid (String$, 1, 13) = 'Distribution:' then String$ := SDelete (String$, 1, 13);

for i := 2 to 9 do
	if ((Mid (String$, i, 1) = ' ') or (Mid (String$, i, 1) = ':')) and (trip = 0)
		then begin
			graphtitle$ := Mid (String$, 1, (i-1));
				trip := 1;
			end;

{make a blank graph}

graph := NewGraph (IGNOREDPLOT, graphtitle$, ?Title$, ?Title$, 0, x, y);

{change the x-axis values and bar size if necessary to properly display groups}

for i := 1 to (cats - 1) do
	xdiff (i) := xaxis (i + 1) - xaxis (i);

ValMin (xdiff, 1, 0, BarWidth);

if BarWidth = 0 then
	for i := 1 to cats do begin
		ScrollsheetGetRowName (freqs, i, TempName$);
		xaxislabels$ := xaxislabels$ + TempName$ + '|';
end else
	for i := 1 to cats do xaxislabels$ := xaxislabels$ + Str (xaxis(i), 6, 1) + '|';

if BarWidth = 0 then begin
	for i := 1 to cats do xaxis(i) := i;
	BarWidth := 1;
end;

MatrixDuplicate (xaxis, oldxaxis);

ScrollsheetGetRowName (freqs, 2, TempName$);

if Mid (TempName$, 8, 1) = '<' then begin
	MatrixElemAdd (xaxis, (BarWidth/2), xaxis);
	ReDim oldxaxis (cats + 1);
	groupcode := 1;
	oldxaxis (cats + 1) := oldxaxis (cats) + BarWidth;
	xaxislabels$ := xaxislabels$ + Str (oldxaxis (cats + 1), 6, 1);
end;

{make graph of large values}

graph1 := NewGraph (BARPLOT, graphtitle$, ?Title$, ?Title$, cats, xaxis, yaxis1);

{standardize its features for display}

ValMin (yaxis1, 1, 0, lowbig);
ValMax (yaxis1, 1, 0, highbig);

lowbig := trunc (lowbig * 0.75);
highbig := trunc (highbig * 1.25);
ticks := trunc ((highbig - lowbig) / 5);

GraphSetPlot2DLayout (graph1, 1, barplot, DATALABELS_Y, ?BarStyle, BarWidth, ?DevLevel,
?IsRightAxis);
GraphSetGridlines (graph1, GRIDLINES_Y);
GraphSetDefaultFont (graph1, 'Courier New', 12, BLACK);
GraphSetScaleValuesStyle (graph1, AX_Y, ?Style, 6, 0, ?DateType, ?Skipped);
GraphSetScaleValuesStyle (graph1, AX_X, SCALEVALUES_OFF, ?Num, ?Num, ?Date, ?Skipped);
GraphSetScaling (graph1, AX_Y, SCALING_MANUAL, lowbig, highbig, ticks);
GraphSetScaling (graph1, AX_RY, SCALING_MANUAL, lowbig, highbig, ticks);
GraphSetScaleTickmarks (graph1, AX_X, TICKMARKS_OFF, ?Size, TICKMARKS_OFF, ?Size,
?Count);

{make graph of small values}

graph2 := NewGraph (BARPLOT, ?Title$, ?Title$, ?Title$, cats, xaxis, yaxis2);

{standardize its features}

GraphSetPlot2DLayout (graph2, 1, barplot, DATALABELS_Y, ?BarStyle, BarWidth, ?DevLevel,
?IsRightAxis);
GraphSetGridlines (graph2, GRIDLINES_Y);
GraphSetDefaultFont (graph2, 'Courier New', 12, BLACK);
GraphSetScaleValuesStyle (graph2, AX_Y, ?Style, 6, 0, ?DateType, ?Skipped);
GraphSetScaleParam (graph2, AX_X, ?Type, SCALING_LAYOUT_NORMAL, 0, ?Break, ?Reversed);
GraphSetScaleTextLabels (graph2, AX_X, cats + groupcode, oldxaxis, xaxislabels$);
GraphSetScaling (graph2, AX_Y, SCALING_MANUAL, 0, break, trunc (break / 5));
GraphSetScaling (graph2, AX_RY, SCALING_MANUAL, 0, break, trunc (break / 5));
GraphSetScaleTickmarks (graph2, AX_TOP, TICKMARKS_OFF, ?Size, TICKMARKS_OFF, ?Size,
?Count);


{embed the two new graphs in the blank graph}

GraphEmbedGraph (graph, graph1, FALSE, FALSE,
	?MappingMode, 0, 100, 100, 50, ?Dynamic);

GraphEmbedGraph (graph, graph2, FALSE, FALSE,
	?MappingMode, 0, 50, 100, 0, ?Dynamic);
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.