This STATISTICA macro doesn't work. Help!

#1
Hi


Help me please with this. My STATISTICA macro doesn't work. Here is its code. The problem is that STATISTICA gives an error when setting newanalysis.Dialog options. It outputs "no such property" error for ".NumberofClusters". What's wrong with that ? I suspect that the property is on additional options page for analysis dialog. But why is this
a problem ?

Option Base 1
Sub Main

Dim S0 As Spreadsheet, S1 As Spreadsheet

Set S0=Spreadsheets.Open("C:\Users\Kostya\Desktop\centers.sta")
Set S1 = New Spreadsheet


With S1

.AddCases(10,990)
Dim delta As Integer
delta=3*S0.NumberOfCases-10

If delta>0 Then
.AddVariables("Var",10,delta)
End If

.Activate

End With

Dim index As Integer
Const sigma="1,5"

For index=1 To S0.NumberOfCases



Dim Xstr As String, Ystr As String, Zstr As String


With S0

Xstr=Str(.Cells(index,1))
Ystr=Str(.Cells(index,2))
Zstr=Str(.Cells(index,3))

End With



With S1

.VariableLongName(3*index-2)="=VNormal(rnd(1);"+Xstr+";"+sigma+")"
.VariableLongName(3*index-1)="=VNormal(rnd(1);"+Ystr+";"+sigma+")"
.VariableLongName(3*index)="="+Zstr

.Recalculate(3*index-2)
.Recalculate(3*index-1)
.Recalculate(3*index)

End With



Next index


With S1


For index=2 To S0.NumberOfCases


.AddCases(1000*(index-1),1000)

Dim jndex As Integer

For jndex=1 To 1000

.Value(1000*(index-1)+jndex,1)=.Value(jndex,3*index-2)
.Value(1000*(index-1)+jndex,2)=.Value(jndex,3*index-1)
.Value(1000*(index-1)+jndex,3)=.Value(jndex,3*index)

Next jndex


Next index


.DeleteVariables(4,Max(3*S0.NumberOfCases,10))
.VariableName(1)="X"
.VariableName(2)="Y"
.VariableName(3)="Class"


End With

Dim res As Object
Dim newanalysis As Analysis
Set newanalysis=Analysis(scClusterAnalysis,S1)

With newanalysis.Dialog
.ClusterMethod = scCluKMeanAnalysis
End With

newanalysis.Run

With newanalysis.Dialog

.CasesOrVariables = scCluCases
.Variables = "1-2"
.NumberOfClusters = 2
.NumberOfIterations = 10
.CasewiseDeletionOfMD = True
.ConstantIntervals = True
.BatchProcessingAndPrinting = False

End With

Set res=newanalysis.Dialog.Summary






End Sub
 

JenB

New Member
#2
In terms of your STATISTICA VB code, I'd recommend declaring and using variables (e.g., oAD1, oAD2, oAD3) for your analysis dialog objects.

Between lines "Set newanalysis=Analysis(scClusterAnalysis,S1)" and "End Sub", replace existing code with the following:

'Clustering Method dialog
Dim oAD1 As STACluster.CluStartup
Set oAD1 = newanalysis.Dialog
oAD1.ClusterMethod = scCluKMeans

newanalysis.Run

'Cluster Analysis: K-Means Clustering dialog
Dim oAD2 As STACluster.CluKMeansSpecifications
Set oAD2 = newanalysis.Dialog
With oAD2
.CasesOrVariables = scCluCases
.Variables = "1-2"
.NumberOfClusters = 2
.NumberOfIterations = 10
.CasewiseDeletionOfMD = True
.ConstantIntervals = True
.BatchProcessingAndPrinting = False​
End With

newanalysis.Run

'kMeans Clustering Results dialog
Dim oAD3 As STACluster.CluKMeansResults
Set oAD3 = newanalysis.Dialog
Set AO = newanalysis.RouteOutput(oAD3.ClusterMeansEuclideanDistances)
AO.Visible = True
If AO.HasWorkbook Then
Set AWB = AO.Workbook​
Else
Set AWB = Nothing​
End If


I'm assuming that with "Set res=newanalysis.Dialog.Summary" you are trying to display the results summary.

Hope this helps.
 
Last edited:
#3
Answer

I've got useful (and simple) answer from StatSoft that finally has hepled.
To fix the problem one should include the "Cluster Analysis" library
declaration in "Function libraries" page. When starting recording macro STATISTICA does it automatically but for general purpose macro it should be done manually.