 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, that will combine 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

' The main program will ask for variable selections

' and then perform the necessary computations by calling

' two subroutines.

Sub
Main

' Determine the number of variables in the input data file

' Set up an array to hold the dependent variable list

ReDim DependentVariableList(1 To NVars)
Dim i As Integer, ret As Integer, nindep As Integer

' Bring up the STATISTICA variable selection dialog

"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 workbook

Set ResultsWorkbook = Workbooks.New
ResultsWorkbook.Visible = True

' Call the subroutine to compute the ANOVA tables

ANOVATable

' Call the subroutine to compute the Kruskal-Wallis
' and Median tests

KruskalWallisAndMedianTests

Finish:
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
ANOVATable

Set 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 Spreadsheet

=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( _
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
KruskalWallisAndMedianTests

Dim i As Integer
Set
newanalysis.
Dialog.NonparametricStatistics = _
scNonComparingMultipleIndependentSamples

newanalysis.Run

' NOTE: The Array function is a standard Visual Basic
' function that turns the two arrays of integers into

' arrays of type Variant

newanalysis.Dialog.Variables = _
Array
(DependentVariableList,GroupingVariable)

newanalysis.Dialog.Codes = ""

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