Смекни!
smekni.com

Создание макроса на языке Statistica Visual Basic для проверки гипотезы о нормальности остатков регрессии (стр. 7 из 7)

"Multiple Regression. Residual Analysis", .UI ' %GRID:10,7,1,1

PushButton 20,14,120,21,"Variables",.VariableSelection

Text 40,42,70,14,"Grouping:",.Text1

Text 110,42,180,14,"none",.Text2

Text 30,56,80,14,"Dependent:",.Text3

Text 110,56,180,14,"none",.Text4

Text 30,84,200,14,"Alpha:",.Text5

TextBox 220,77,90,21,.AlphaValue

Text 30,104,200,14,"Alpha for highlighting effects:",.Text6

TextBox 220,100,90,21,.Alpha

OKButton 310,14,70,21,.OkButton

CancelButton 310,42,70,21,.CancelButton

End Dialog

Dim dlg As UserDialog

dlg.AlphaValue=",05"

dlg.Alpha=",05"

TryAgain:

On Error GoTo Finish

Dialog dlg

On Error GoTo BadAlphaValue

AlphaValue = CDbl(dlg.AlphaValue)

Alpha = CDbl(dlg.Alpha)

InputDialog=True

Finish:

Exit Function

BadAlphaValue:

MsgBox "Bad alpha value; please specify a valid alpha value."

GoTo TryAgain

End Function

Private Function UI(DlgItem$, Action%, SuppValue&) As Boolean

Dim ok As Boolean

Select Case Action%

Case 1 ' Dialog box initialization

Case 2 ' Value changing or button pressed

UI = True

Select Case DlgItem

Case "CancelButton"

UI=False

Case "OkButton"

ok=False

If InList1<1 Or InList2<1 Then

ok=True

GoTo DoVariables

End If

UI=False

Case "VariableSelection"

ok=False

DoVariables:

ret = SelectVariables2 (ActiveDataSet, _

"Select dependent and independent variable lists:", _

1, Nvars, VarList1, InList1, "Dependent var. (or list for batch):", _

1, Nvars, VarList2, InList2, "Independent variable list:")

If ret=0 Then GoTo Finish

If InList1>0 Then


DlgText "Text4", "Selected"

Else

DlgText "Text4", "none"

End If

If InList2>0 Then

DlgText "Text2", "Selected"

Else

DlgText "Text2", "none"

End If

End Select

End Select

Finish:

End Function

Sub MultipleRegression

Set S1 = ActiveSpreadsheet

Dim newanalysis2 As Analysis

Set newanalysis2 = Analysis (scMultipleRegression,S1)


With newanalysis2.Dialog

Variables = Array(VarList1,VarList2)

InputFile = scRegRawData

CasewiseDeletionOfMD = True

PerformDefaultNonStepwiseAnalysis = False

ReviewDescriptiveStatistics = False

ExtendedPrecisionComputations = False

BatchProcessingAndPrinting = False

End With

newanalysis2.Run

With newanalysis2.Dialog

.ComputeConfidenceLimits = True

.AlphaForLimits = AlphaValue

.PLevelForHighlighting = Alpha

End With

newanalysis2.RouteOutput(newanalysis2.Dialog.Summary).Visible = True

newanalysis2.Run

With newanalysis2.Dialog

RawResiduals = True

StandardResidualPlusMinusSigmaOutliers = True

RawPredictedValues = True

MaxNumberOfCasesInSpreadsheetsAndGraphs = 100000

End With

newanalysis2.RouteOutput(newanalysis2.Dialog.Summary).Visible = True

newanalysis2.RouteOutput(newanalysis2.Dialog.HistogramOfResiduals).Visible = True

newanalysis2.RouteOutput(newanalysis2.Dialog.DurbinWatsonStatistics).Visible = True

newanalysis2.RouteOutput(newanalysis2.Dialog.ScatterplotOfPredictedVsResiduals).Visible = True

newanalysis2.RouteOutput(newanalysis2.Dialog.NormalPlotOfResiduals).Visible = True

Set ResSpreadsheetCollection=newanalysis2.Dialog.Summary

Set ResSpreadsheet=ResSpreadsheetCollection.Item(1)

Dim n As Long

n=ResSpreadsheet.NumberOfCases-4

Set Cells=ResSpreadsheet.CellsRange( _

1, 3,n, 3)

Cells.Select

ResSpreadsheet.CopyWithHeaders

NewSpreadsheet.SetSize n, 1

NewSpreadsheet.Visible=True

Set Cells=NewSpreadsheet.CellsRange(1,1,1,1)

Cells.Select

NewSpreadsheet.Paste

End Sub

Sub NormalDistribution

Dim newanalysis3 As Analysis

Set newanalysis3 = Analysis (scDistributions, NewSpreadsheet)

With newanalysis3.Dialog

.FitContinuousDistributions = True

.ContinuousDistribution = scNonNormal

End With

newanalysis3.Run

With newanalysis3.Dialog

Variable = "1"

Distribution = scNonNormal

KolmogorvNo = True

CombineBinsForChiSquare = True

FrequencyDistribution = True

RawFrequencies = True

End With

newanalysis3.RouteOutput(newanalysis3.Dialog.Summary).Visible = True

newanalysis3.RouteOutput(newanalysis3.Dialog.PlotOfDistribution).Visible = True

End Sub


ПРИЛОЖЕНИЕ Б

Листинг программы

Sub Main

Dim bars As CommandBars

Set bars = CommandBarOptions.CommandBars(scBarTypeToolBar)

Dim newBar As CommandBar

Set newBar = bars.Add("CUSTOM")

newBar.InsertMacroButton 1, "d:&bsol;work&bsol;Macros&bsol;_1_&bsol;regres-normal.svb" , "Нормальностьостатков"

newBar.InsertSeparator 2

newBar.Item(1).DisplayMode = scCommandDisplayTextAndImage

End Sub


ПРИЛОЖЕНИЕ В

Таблица 1

Глобальные переменные

Переменные Описание переменных Значение переменных
Dim S1 As Spreadsheet Объект таблица Текущая таблица
Dim NewSpreadsheet As New Spreadsheet Объект таблица Таблица для остатков
Public AlphaValue As Double Переменная типа Double
Public Alpha As Double Переменная типа Double
Dim VarList1() As Long Динамический массив типа Long Список зависимых переменных
Dim VarList2() As Long Динамический массив типа Long Список независимых переменных
Dim Nvars As Long Переменная типа Long Количество переменных в текущей таблице
Dim InList1 As Long Переменная типа Long Номера зависимых переменных
Dim InList2 As Long Переменная типа Long Номера независимых переменных
Dim ret As Integer Переменная типа Integer