Welcome, Register  | Login
Search Options
Electronic Statistics Textbook
StatSoft Blog
 Video TutorialsWebcasts
BrochuresWhite Papers
Example ApplicationsHelpInstallation InstructionsSTATISTICA Software UpdatesVersion Manager..\Visual Basic Examples
 Free STATISTICA 9 Trial
Chat Live with StatSoft
Featuring
  • Credit Scoring
  • Upgrade to 64-bit
  • STATISTICA User Forum
  • Free Electronic Statistics Textbook
Product Information
  • STATISTICA Product Catalog
  • Predictive Analytics Solutions
  • Statistical Consulting, Training
  • Enterprise Solutions
  • Web-based Analytics
  • Energy & Utilities
What's New

Odds Ratios in Generalized Linear/Nonlinear (GLZ) Models

Mon, 30 Aug 2010 22:29:00 -0500

SPOTLIGHT ON: John Elder, Ph.D.

Mon, 30 Aug 2010 20:33:00 -0500

Monte Carlo and Sample Size

Mon, 30 Aug 2010 17:48:00 -0500

Skip Navigation Links.
Collapse SubscriptionsSubscriptions
STATISTICA Newsletter
STATISTICA Webcasts
AnalyticBridge
YouTube
Twitter
Facebook
LinkedIn

STATISTICA Visual Basic Example Programs

Have questions about SVB? You can email DeveloperDocumentation@statsoft.com with your questions.

The industry standard STATISTICA Visual Basic language (integrated into STATISTICA) offers incomparably more than just a supplementary application programming language that can be used to write custom extensions. STATISTICA Visual Basic adds an arsenal of more than 13,000 new functions to the standard comprehensive syntax of Microsoft Visual Basic, thus comprising one of the largest and richest development environments available.

DownloadDownload free library of STATISTICA Visual Basic programs
(written by StatSoft employees and by STATISTICA users). Read the macro descriptions below.

We invite you to contribute and would appreciate your input. To submit your own programs for inclusion here, e-mail: info@statsoft.com. We ask that you please follow the guidelines below to ensure that other users will best take advantage of your efforts:

  • Provide a description of the task the program will perform.
  • Provide a list of requirements for running the program (such as the type of output spreadsheet which must be active before running the program or the necessary data file needed to run the program properly).
  • Note any adjustments that must be made to the code before running the program (such as data file path or variable names).
  • Include comments throughout the code that will assist others in understanding each section's purpose. The better the documentation, the easier it will be for someone to use your program. Also, please include the description in (1) at the beginning of your program.

Disclaimer: StatSoft offers the Forum in order to promote the sharing of STATISTICA Visual Basic programs between STATISTICA users. We will attempt to post accurate and functional programs, no guarantee regarding these programs is provided by StatSoft, Inc.

The free library of STATISTICA Visual Basic programs contains:

  • Analysis Examples
  • Custom Dialog Examples
  • Document Event Examples
  • General Purpose Examples
  • Graph Examples
  • Spreadsheet Examples
  • STATISTICA Interface Examples
  • Workbook Examples

Analysis Examples

Bias.svb

This program will report the following statistics:

  1. Bias
  2. %Bias relative to process variation
  3. %Bias relative to tolerance width

The data are assumed to be in one variable which the user will be prompted to select. The user will also be prompted for the master value, method to estimate process variation, and tolerance width.

Reference: Measurement Systems Analysis Reference Manual, Chrysler Corporation, Ford Motor Company, General Motors Company, 1995.

Confidence Intervals.svb

This program will compute confidence intervals for the differences of group means on one or more dependent variables from two independent samples (Milliken & Johnson, 1984). This program uses the data from the Grouping output spreadsheet in the Basic Statistics and Tables module.

To use this program, create the Grouping output spreadsheet for a specific between-group factor with two levels and a set of dependent variables in t-test for independent samples, by groups of the Basic Statistics and Tables module. Click on T-tests to obtain the Grouping output spreadsheet so that it is the active output spreadsheet. The program will perform the computations and add three additional columns to the output spreadsheet. The columns contain the differences of the group means, the upper confidence limits and the lower confidence limits of the differences of the means. Users will be prompted to specify the alpha value for the desired confidence intervals.

Eta-Tran.svb

This program will compute the standard (Taguchi) Signal-To-Noise ratios for a user-specified list of Variables. The resulting index can be used as the dependent or Y-Variable together with all types of designs available In the Experimental Design Module of STATISTICA. The number of dependent variables selected must be greater than 1.

Read more information about Taguchi methods for robust Experimental Design.

Grubbs Test.svb

This program will perform Grubbs test for outlying observations. The procedure for this test is taken from Quality Assurance of Chemical Measurements. It outputs a calculated t and Grubbs t. If the calculated t is greater than Grubbs t then you can reject the null hypothesis and conclude that the data point being tested is an outlier. If this is the case then the calculated t will show up in red.

Please note that the program uses an alpha level of .05 meaning that 5% of the time this test will conclude that an observation is an outlier when in fact it is not. Also, the user must select the number of data points from a list since the C8 table does not give Grubbs t for every possible sample size.

ICC.svb

This program will calculate intraclass correlation coefficients for estimating interrater reliability, following methods outlined in the following article:

Shrout, P.E. & Fleiss, J.L. (1979). Intraclass correlations: Uses in assessing rater reliability. Psychological Bulletin, 86,420-428.

On execution, a variable selection dialog will appear. Two or more variables (i.e., two or more raters' ratings) from the currently active STATISTICA data file must be selected or an error message is displayed and the program terminates. If case selection conditions are currently in effect, they will be recognized by this program and reported along with the other results. After variables are selected and the user clicks on OK, the program builds a data matrix using only cases with no missing data on the selected variables, and calculates some intermediate variables. If there are many cases or many variables selected this phase can take some time (the STATISTICA status bar in the lower left will show "processing"). Then another dialog appears asking the user to specify which of three models (described in the article) to use. Models can be selected individually, or all three can be selected for the report.

Output from the program is a simple text report, which will be directed to the currently selected output device. If output is turned off, a new text window will open to receive the results. The first part of the report will include the status of case selection conditions, the number of cases used in the analysis, and a list of the selected variables. Following that will be values for the intermediate terms that are common to all three ICC models. Finally, the selected intraclass correlations are shown, along with the F statistic and significance level for the ANOVA model on which the ICC is based.

This program was written by Richard A. McLellan, Personnel Decisions International Modified by Statsoft Inc.

Intervals.svb

This macro allows you to select from several intervals to calculate given a few statistics from the dataset. The macro only uses the information provided at run-time and does not interact with the datasets directly.

Levene.svb

This program performs the Brown-Forsythe & Levene Tests for homogeneity of variances for the two group case.

An important assumption in the t-test for mean differences is that the variances in the two groups are equal (homogeneous). Two powerful and commonly used tests of this assumption are the Levene test and the Brown-Forsythe modification of this test. However, it is important to realize that (1) the homogeneity of variances assumption is usually not as crucial as other assumptions for the t-test for mean differences, particularly in the case of equal n, and (2) that the tests described below are not necessarily very robust themselves (e.g., Glass and Hopkins, 1996, p. 436, call these tests "fatally flawed;" see also the description of these tests below). If you are concerned about a violation of the HOV assumption, it is always advisable to repeat the key analyses using nonparametric methods.

Levene's test (homogeneity of variances): For each dependent variable, a t-test for mean differences is performed on the absolute deviations of values from the respective group means. If the Levene test is statistically significant, then the hypothesis of homogeneous variances should be rejected.

Brown & Forsythe's test (homogeneity of variances): Some authors (e.g., Glass and Hopkins, 1996) have called into question the power of the Levene test for unequal variances. Specifically, the absolute deviation (from the group means) scores can be expected to be highly skewed; thus, the normality assumption for t-test for mean differences of those absolute deviation scores is usually violated. This poses a particular problem when there is unequal n in the two groups that are to be compared. A more robust test that is very similar to the Levene test has been proposed by Brown and Forsythe (1974). Instead of performing the t-test for mean differences on the deviations from the mean, one can perform the analysis on the deviations from the group medians. Olejnik and Algina (1987) have shown that this test will give quite accurate error rates even when the underlying distributions for the raw scores deviate significantly from the normal distribution. However, as Glass and Hopkins (1996, p. 436) have pointed out, both the Levene test as well as the Brown-Forsythe modification suffer from what those authors call a "fatal flaw," namely, that both tests themselves rely on the homogeneity of variances assumption (of the absolute deviations from the means or medians); and hence, it is not clear how robust these tests are themselves in the presence of significant variance heterogeneity and unequal n.

Mantel-Haenscel.svb

This program will compute the Mantel-Haenszel statistics (relative risk) for a set of 2x2 frequency tables, specified by the user. The program will compute the Mantel-Haenszel statistic:

RMH = Sum(a11i*a22i/Ni)/Sum(12i*a21i/Ni) where a11i is the frequency in cell a11 In the i'th 2x2 table, and Ni is the total frequency in the i'th table.

The program will also compute a Chi-square test for the hypothesis that RMH=1.

For details, see Mantel, N., And Haenszel, W. (1959). Statistical aspects of the Analysis of data from retrospective studies of disease. Journal of the National Cancer Institute, 22, 719-748; see also Bishop, Fienberg, And Holland (1975).

Multiple Regression By-Group.svb

This program will perform a multiple regression analysis by groups. The user will be prompted to specify the variables for the multiple regression, and one or more categorical variables for by-group analysis. The program will then perform the requested regression analysis for each combination of the values of the categorical (grouping) variables (e.g., Male-Experimental, Male-Control, Female-Experimental...). The by-group analysis is performed by assembling case selection conditions that will select for each analysis only those cases that belong to the respective combination of values in the selected categorical variables. If the input datafile has any active pre-set case selection conditions "connected" already with the analysis, then these will be merged with the ones assembled in this program.

Numeric Series Extrapolation.svb

The purpose of this program is to fill a variable in a datafile with a series such as 1,2,3,4,1,2,3,4,1,2,3,4... Or 1,1,1,1,1,1,2,2,2,2,2,2,3,3,3,3,3,3...

This procedure might often be useful when filling in codes for an analysis of variance.

The program accepts three parameters from the user: a start value, an end value and the number of repetitions for each value. The variable selected by the user is then filled with a series consisting of each integer from the start value to the end value, with each integer repeated as many times as specified by the user.

Post Hoc For Friedman.svb

This program performs nonparametric multiple comparisons. It uses the output from Friedman ANOVA by Ranks, either testing the Average Rank (in Column 1) or the Sum of Ranks (in Column 2). The test compares the absolute value of the differences for all pairs with a critical value which is determined using a normal approximation with suitable adjustment of alpha to take the multiple comparisons into account.

Post Hoc For Kruskal.svb

This program performs nonparametric multiple comparisons. It uses the output from a Kruskal-Wallis ANOVA and Median Test analysis. The test compares the absolute value of the differences in mean ranks for all pairs with a critical value which is determined using a normal approximation with suitable adjustment of alpha to take the multiple comparisons into account.

Review Outliers.svb

This macro will select a spreadsheet and either mark or remove the outliers for the variables specified. You will be able to select which method to calculate the outliers. Methods include quartile ranges, standard error/means, and user-defined boundaries.

Please note that case selection conditions are taken into effect and that missing data is ignored.

Ridge Regression.svb

This program will compute the Ridge Regression estimates with Trace Statistics. For Computation details, see Classical And Modern Regression With Applications (Chapter 8) 2nd. Edition (Myers, 1990).

Note: program assumes that All Cases are complete (no missing data!)

Program author: Wong Chun Kit E-mail: chunkit@hkstar.com URL: http://www.hkstar.com/~chunkit/

Modified by Statsoft

Scaled Partial Pivot.svb

This macro solves a system of equations using the scaled partial pivoting method. The input spreadsheet should have the coefficients for the unknowns in the first N X N entries. The N+1th variable should hold the constants for the system.

For example, if you have the system:

X + Y - Z = 2

X + 2Y + Z = 6

2X - Y + Z = 1

Your input spreadsheet should be entered as follows:

1 1 -1 2

1 2 1 6

2 -1 1 1

The results for this system are X = 1, Y = 2 and Z = 1

Scaled partial pivoting is an enhancement to the Gaussian elimination method for solving systems of equations and produces more accurate results in ill-conditioned systems.

Shaich-Hamerle.svb

This program performs Schaich's and Hamerle's multiple comparison of rank sums.

Author: Dr. Stefan Funke, Braunschweig, Germany

Modified by Statsoft.

Literature: Bortz, Lienert, and Boehnke: Verteilungsfreie Methoden in der Biostatistik, Springer 1990 p. 230

Generate the output spreadsheet from Nonparametrics: Comparing multiple independent samples(groups) (Kruskal-Wallis Anova by Ranks).

Its structure is:

  code valid n sum of ranks
group1 c1 n1 sum1
....      
groupn cn nn sumn

 

Significant DV's.svb

This program will use the Basic Statistics Breakdown options to find the dependent variables in a list of dependent variables that are significantly related to a set of categorical predictors; the program also computes the overall R-Square values for those variables. The following statement makes all arrays by default 1-referenced; thus, the declaration "Dim x( 10) as Double" is the same by default as "Dim x(10) as Double".

Weighted Least-Squares.svb

This program will perform a weighted least-squares analysis for the current data file. For computational details, see Neter, Wasserman, & Kutner (1985), page 168; see also the Examples section in the Nonlinear Estimation chapter of the manual.

NOTE: program assumes that all cases are complete (no missing data!); The program will also compute various alternative R-square statistics; see Kvålseth, 1985, JAS, 39, p. 279-285.

Custom Dialog Examples

Dialog Controls.svb

This program demonstrates how one can service various controls in a complex dialog. The following arrays will be used to handle the text in the list box and combo box.

Document Event Examples

Cell Function Demo.sta

This example demonstrates using variable functions and the spreadsheet-level event "DataChanged()" to update both a variable and a single cell. Note that the "Final Item Cost" (defined with a spreadsheet formula) and the "Total Cost of All Items" (defined by a STATISTICA Visual Basic macro) columns are protected using the custom event handling (and cannot be changed); both columns will recalculate automatically as you change the "Item Cost" and/or the "Coupon" values. To review or modify the code of the program attached to this spreadsheet use the menu View / Events / View Code.

Statistics Updating Demo.sta

This example demonstrates how the DataChanged() event can be used to recalculate this spreadsheet's statistics whenever its data is altered. After the statistics are calculated, they are passed to an associated results spreadsheet.

User Defined Data Type Demo.sta

This example illustrates implementing a boolean (true or false) data type to a variable through the document-level event DataChanged(). The variable "Passed/Failed" will only accept the values "1" or "0"; if any other value is entered then the user will be prompted to properly enter a "1" or "0" and then the variable will be updated.

Back to Top

General Purpose Examples

SendMail.svb

The following macro demonstrates how to send a simple email message from an SVB program using standard Microsoft objects. Please note that this example requires Microsoft CDO For Exchange 2000 Library and Microsoft ActiveX Data Objects 2.5 Library.

Back to Top

Graph Examples

BoxCoxp.svb

This program will produce (1) a plot of the means versus standard deviations, and (2) the Log(means) versus Log(standard deviations) from the spreadsheet generated by clicking the "Display" button on the quick tab under the section "Observed Marginal Means" within the analyze design option in Experimental Design (if all means and standard deviations are greater than zero). The program will look for "Means" and "Std.Dev." in the column headers.

For additional information, see: Box, G. E. P. & Cox, D. R. (1964). An analysis of transformations. Journal of the Royal Statistical Society, B, 26, 211-234.

Case Plots.svb

This program will make a line graph of the values in selected cases for the specified variables of the data file. A maximum of 100 cases can be plotted in a single plot (adjust "maxcase" if necessary).

Customized Box Plot.svb

This program creates box plots it allows user to select variables box plot can be based on mean or median additionally we allow user to scale it to arbitrary scale.

Dot Plot.svb

This program will produce a "dot-plot" of values for a list of variables.

Graph Analysis Output to Graph Template.svb

The following example generates regular histograms for each variable in the active dataset and routes the output to a single graph template, rather than the conventional output settings. This can be applied to any analysis or master macro by copying & pasting the"GraphWizardOutput()" function listed below into the analysis macro and making a single call to it (passing the current Analysis object into it as an argument).

GraphLib.svx

This library of graph functions can be included into an SVB application by either copy and pasting it into the new SVB program or by including a "#Uses" statement. Refer to the online documentation to see how to use the "#Uses" directive in a new macro.

Henon Strange Attractor.svb

Creates a Henon Strange Attractor as a 2D scatterplot. See Welstead, 1994, Neural Networks.

Histogram with break.svb

This program creates a histogram containing 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. Since the histograms have the y-axis displayed in two sections with separate scaling, more detail can be shown.

Because the resulting graph is a combination of two graphs, any graph customization after creation will need to be applied to both graphs independently.

Image Histogram.svb

This macro will create a Histogram of a particular variable, where each bar of the histogram is replaced with a user-selected image. The variable ImageEqualProportion may be changed to produce more pleasing results when datasets with large numbers of observations are graphed.

Interest.svb

This macro will allow you to calculate simple or compounded interest on a given principal. You will be required to provide principal amount, interest rate, number of rollovers per year, and the number of rollovers to be calculated. All of the calculations will be sent to a spreadsheet, report, and graph and will be optimally formatted.

It demonstrates creating and customizing multiple document formats, including graphs, spreadsheets, reports, and workbooks.

Log Probability Plot.svb

This program functions by finding the Log of a variable and then computes its mean and stdev (of logged variable). It then converts this into a Normal dsn where the probability scales are calculated from this. The fitted line is the equation y=exp(mean+stdev*inverse Normal Dsn).

Stacked Bar Graph.svb

This example takes the data from two user-specific variables in a STATISTICA spreadsheet and produces a bar graph with one variable stacked on the other. A typical dataset may contain two variables to compare and a categorical variable.

Back to Top

Spreadsheet Examples

Auto Format Spreadsheet Variables.svb

This macro will auto fit the variable column of every open, individual spreadsheet.

Import Multiple Text Files.svb

This example imports multiple text files into a single spreadsheet.

Merge Variables into Grouping Variable.svb

This program will restructure a data file, so that the values for selected variables become consecutive "groups" in a new spreadsheet; that data file will also include a grouping variable with text values that are identical to the original variable names.

For example, suppose your data in the current file are arranged like this:

  Males      Females
1 4.5 5.6
2 3.9 6.7
3 2.3 3.3
3 --- 3.5

 

After running this program, the new file will look like this:

  Var_1 Var_2
1 Males     4.5
2 Males     3.9
3 Males     2.3
4 Females     5.6
5 Females     6.7
6 Females     3.3
7 Females     3.5

 

Multiple Variable Recode.svb

This example provides the ability to build a spreadsheet recoding expression and then apply the same recoding to multiple variables simultaneously.

Print Selected Variables and Cases.svb

This macro allows you to print a set of selected cases and variables. While this can be done in the program for a contiguous block of cells, this macro allows the user to select discontiguous groups of variables and cases.

QuickVariableSummary.svb

This program will generate a spreadsheet with a quick summary of user-selected variables:

  • Number of Valid Cases
  • Number of Missing Cases
  • Number of Unique Cases
  • Top 1 Frequent Value
  • Top 2 Frequent Value
  • Top 3 Frequent Value
  • Top 4 Frequent Value
  • Top 5 Frequent Value
  • Minimum Value
  • Maximum Value
  • Mean Value
  • Standard Deviation

Spreadsheet Data Type Convert.svb

This example provides the ability to alter the data type of multiple variables of a given spreadsheet.

Sort by Range.svb

This example demonstrates sorting one or more variables by a specified case range. Rather than sorting the entire variable, only a block of cells can be sorted.

Unique Values.svb

This program will generate a spreadsheet which provides the unique values in a variable, and any associated text labels for those values.

See also QuickVariableSummary.svb

Back to Top

STATISTICA Interface Examples

Add Spreadsheet Menu.svb

The following example demonstrates dynamically adding a new menu to the spreadsheet menu bar, along with adding and customizing menu options. After running this macro, bring a spreadsheet to the top of STATISTICA and you will see that a menu named "Favorite Spreadsheet Commands" has been added before the "File" menu.

STATISTICA Query Toolbar.svb

This example will add a STATISTICA Query toolbar to your application if one does not already exist. This is a good demonstration of how you can add and edit toolbars within your STATISTICA environment.

Back to Top

Workbook Examples

Print Workbook Items by Document Type.svb

This example contains functions for printing a workbook's documents by document type. For example, the function PrintWorkbookGraphs() will print only the graphs inside of the specified workbook.

Search for Workbook Item by Name.svb

This example will prompt you for the name of a document or folder to search for in the active workbook by name, find it, and then highlight it for you. If it is unable to find the document, then it will display an error message informing you of this.

Home   |   Products   |   Services   |   Solutions   |   Support   |   Customers   |   Academic   |   Company   |   Contact Us
Copyright (c) 2010 www.statsoft.com Privacy Statement   |  Terms Of Use