Macro (SVB) Programs Example - Accessing Multiple Modules in a Single Program

Statistica Visual Basic, and the Statistica Visual Basic libraries provide comprehensive access to all Statistical and graphics analysis function in the program. The Visual Basic language allows you to build completely customized programs (which may include user interfaces; however, see also Custom Dialog Boxes; Custom User Interfaces, for some limitations and other considerations), that may combine results from multiple analyses, or perform analyses sequentially, where the results from one analysis are used as the input to another. Shown below is an example program, which combines multiple analyses.

' This program will compute tests comparing the 
' central tendency measures in multiple groups. 
' The Basic Statistics Breakdowns options will 
' be used to compute the ANOVA; the Nonparametric 
' Statistics Kruskal-Wallis and Median tests will 
' be computed as nonparametrics alternatives to 
' ANOVA. 
' The following variables are declared as public 
' symbols, i.e., they will be "visible" to 
' all routines throughout this program. 

Public GroupingVariable As Integer 
Public DependentVariableList() As Integer 
Public ndep As Integer 
Public NVars As Long 
Public ResultsWorkbook As Workbook 
Public Folder As WorkbookItem 
Public InputSpreadsheet As Spreadsheet 

' The main program will ask for variable selections 
' and then perform the necessary computations by calling 
' two subroutines. Sub MainSet InputSpreadsheet = ActiveDataSet
' Determine the number of variables in the input data fileNVars = InputSpreadsheet.NumberOfVariables
' Set up an array to hold the dependent variable listReDim DependentVariableList(1 To NVars) 
Dim i As Integer, ret As Integer, nindep As Integer

' Bring up the Statistica variable selection dialogret = SelectVariables2 (InputSpreadsheet, _ "
Select dependent variables, 
and grouping variable", _ 1, NVars, DependentVariableList, ndep, _ "Dependent variables:", _ 1, 1, 
GroupingVariable, nindep, _ "Independent (grouping) variable: ")

If ret=0 Then GoTo Finish
' Make new workbookSet ResultsWorkbook = Workbooks.New ResultsWorkbook.Visible = True
' Call the subroutine to compute the ANOVA tablesANOVATable
' Call the subroutine to compute the Kruskal-Wallis 
' and Median testsKruskalWallisAndMedianTestsFinish: End Sub 
' This subroutine uses the Basic Statistics modules, option 
' Breakdowns to compute the ANOVA tables; the results will 
' be moved into the Workbook set up in the Main program. 
Sub ANOVATableSet newanalysis = Analysis (scBasicStatistics, InputSpreadsheet) 
newanalysis.Dialog.Statistics = scBasBreakdowns newanalysis.Run

' NOTE: The Array function is a standard Visual Basic 
' function that combines the (two in this case) arrays of integers into 
' a Variant that is an array of those arrays.newanalysis.Dialog.Variables = _ Array(DependentVariableList,GroupingVariable)
newanalysis.Dialog.Codes = ""newanalysis.Run
' Compute the ANOVA results SpreadsheetSet ResultsSpreadsheet _ =newanalysis.Dialog.AnalysisOfVariance
' Set up a folder in the Workbook, and call it "ANOVA Results"
Set Folder=ResultsWorkbook.InsertFolder( _ ResultsWorkbook.Root, scWorkbookLastChild)
Folder.Name="ANOVA Results"' Move the results Spreadsheet into the Workbook; remember 
' that all results Spreadsheets returned from analysis objects 
' in Statistica are collections of objects (Spreadsheets); 
' thus we need to explicitly reference Item(1) 
in the collection.ResultsWorkbook.InsertObject( _ ResultsSpreadsheet.Item(1), Folder, scWorkbookLastChild)
End Sub 
' This subroutine uses the Nonparametric Statistics module 
' to compute the Kruskal-Wallis and Median tests; the results 
' will be moved into the Workbook set up in the Main program. 
Sub KruskalWallisAndMedianTestsDim i As Integer 
Set newanalysis = Analysis (scNonparametrics, InputSpreadsheet) 
newanalysis.Dialog.NonparametricStatistics = _ scNonComparingMultipleIndependentSamplesnewanalysis.Run
' NOTE: The Array function is a standard Visual Basic 
' function that turns the two arrays of integers into 
' arrays of type Variantnewanalysis.Dialog.Variables = _ Array(DependentVariableList,GroupingVariable)
newanalysis.Dialog.Codes = ""Set 
ResultsSpreadsheet=newanalysis.Dialog.Summary 
Set Folder=ResultsWorkbook.InsertFolder( _ ResultsWorkbook.Root, scWorkbookLastChild)
' Set up a folder in the Workbook, and call it 
' "Nonparametric tests"Folder.Name="Nonparametric tests"
' Move the results Spreadsheet into the Workbook; remember 
' that all results Spreadsheets returned from analysis objects 
' in Statistica are collections of objects (Spreadsheets); 
' the .Count property will retrieve the number of objects 
' (Spreadsheets) in the collection.
For i =1 To ResultsSpreadsheet.CountResultsWorkbook.InsertObject( _ ResultsSpreadsheet.Item(i), Folder, scWorkbookLastChild)
Next i
End Sub

As you can see, the SVB environment not only allows you to automate routine analyses, but also in a sense to "program your own Statistical package," with various nonstandard options tailored to your specific needs. For more details on how to set up complete user-interfaces (dialogs); for more information on how to edit and manipulate results spreadsheets and graphs (objects), see Basic Functions for Editing Objects (Spreadsheets, Graphs, etc.).