Skip to content

Commit

Permalink
Merge pull request #974 from nyagishira/dlgCorrelation
Browse files Browse the repository at this point in the history
Dlg correlation
  • Loading branch information
dannyparsons committed Mar 1, 2016
2 parents 94705d9 + cf7149e commit d135723
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 21 deletions.
25 changes: 14 additions & 11 deletions instat/dlgCorrelation.designer.vb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

88 changes: 78 additions & 10 deletions instat/dlgCorrelation.vb
Original file line number Diff line number Diff line change
Expand Up @@ -14,46 +14,82 @@
' You should have received a copy of the GNU General Public License k
' along with this program. If not, see <http://www.gnu.org/licenses/>.
Imports instat.Translations

Public Class dlgCorrelation
Public bFirstLoad As Boolean = True
Public bIsTwoColumnFunction As Boolean

Private Sub dlgCorrelation_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'Set properties needed on load
ucrBase.clsRsyntax.iCallType = 2
ucrReceiverFirstColumn.Selector = ucrSelectorDataFrameVarAddRemove
ucrReceiverSecondColumn.Selector = ucrSelectorDataFrameVarAddRemove
ucrReceiverMultipleColumns.Selector = ucrSelectorDataFrameVarAddRemove
ucrReceiverFirstColumn.SetDataType("numeric")
ucrReceiverSecondColumn.SetDataType("numeric")
ucrReceiverMultipleColumns.SetDataType("numeric")

autoTranslate(Me)

'this default is independent of TwoColumn/MultipleColumn option so can be set here
rdoPearson.Checked = True
ucrBase.clsRsyntax.AddParameter("method", Chr(34) & "pearson" & Chr(34))
ucrBase.iHelpTopicID = 316

If bFirstLoad Then
SetDefaults()
bFirstLoad = False
End If

If bIsTwoColumnFunction Then
TestOKEnabledForTwoColumns()
Else
TestOKEnabledForMultipleColumns()
End If

'default is the TwoColumn option
End Sub

Private Sub SetDefaults()
ucrSelectorDataFrameVarAddRemove.Reset()
ucrSelectorDataFrameVarAddRemove.Focus()
rdoPearson.Checked = True
rdoTwoColumns.Checked = True
SetTwoColumnAsFunction()
TestOKEnabledForTwoColumns()
End Sub

Private Sub ucrReceiverFirstColumn_Leave(sender As Object, e As EventArgs) Handles ucrReceiverFirstColumn.Leave


Private Sub ucrReceiverFirstColumn_SelectionChanged(sender As Object, e As EventArgs) Handles ucrReceiverFirstColumn.SelectionChanged
ucrBase.clsRsyntax.AddParameter("x", clsRFunctionParameter:=ucrReceiverFirstColumn.GetVariables())
TestOKEnabledForTwoColumns()
End Sub

Private Sub ucrReceiverSecondColumn_Leave(sender As Object, e As EventArgs) Handles ucrReceiverSecondColumn.Leave
Private Sub ucrReceiverSecondColumn_SelectionChanged(sender As Object, e As EventArgs) Handles ucrReceiverSecondColumn.SelectionChanged
ucrBase.clsRsyntax.AddParameter("y", clsRFunctionParameter:=ucrReceiverSecondColumn.GetVariables())
TestOKEnabledforTwoColumns()

End Sub

Private Sub ucrReceiverMultipleColumns_Leave(sender As Object, e As EventArgs) Handles ucrReceiverMultipleColumns.Leave
Private Sub ucrReceiverMultipleColumns_SelectionChanged() Handles ucrReceiverMultipleColumns.SelectionChanged
ucrBase.clsRsyntax.AddParameter("x", clsRFunctionParameter:=ucrReceiverMultipleColumns.GetVariables())
TestOKEnabledForMultipleColumns()
End Sub

'put all rdo button checked changed in one sub to make it shorter
Private Sub rdoForMethodsCheckedChanged(sender As Object, e As EventArgs) Handles rdoPearson.CheckedChanged, rdoKendall.CheckedChanged, rdoSpearman.CheckedChanged
If rdoPearson.Checked Then
ucrBase.clsRsyntax.AddParameter("method", Chr(34) & "pearson" & Chr(34))
If frmMain.clsInstatOptions.bIncludeRDefaultParameters Then
ucrBase.clsRsyntax.AddParameter("method", Chr(34) & "pearson" & Chr(34))
Else
ucrBase.clsRsyntax.RemoveParameter("method")
End If
ElseIf rdoKendall.Checked Then
ucrBase.clsRsyntax.AddParameter("method", Chr(34) & "kendall" & Chr(34))

ElseIf rdoSpearman.Checked Then
ucrBase.clsRsyntax.AddParameter("method", Chr(34) & "spearman" & Chr(34))

Else
ucrBase.clsRsyntax.RemoveParameter("method")

'the else case should never happen but is there just in case
End If
End Sub
Expand All @@ -65,10 +101,15 @@ Public Class dlgCorrelation
Private Sub SetUseParameter()
If rdoCompleteRowsOnly.Checked Then
ucrBase.clsRsyntax.AddParameter("use", Chr(34) & "pairwise.complete.obs" & Chr(34))


ElseIf rdoPairwise.Checked Then
ucrBase.clsRsyntax.AddParameter("use", Chr(34) & "complete.obs" & Chr(34))


Else
ucrBase.clsRsyntax.RemoveParameter("use")

End If
End Sub

Expand All @@ -79,7 +120,7 @@ Public Class dlgCorrelation
ucrBase.clsRsyntax.SetFunction("cor.test")
'Set what should be visible/invisible
grpMissing.Visible = False
cmdPlots.Visible = False
cmdCorrplot.Visible = False
lblConfInterval.Visible = True
txtConfidenceInterval.Visible = True
ucrReceiverFirstColumn.Visible = True
Expand All @@ -96,6 +137,9 @@ Public Class dlgCorrelation
ucrBase.clsRsyntax.AddParameter("y", clsRFunctionParameter:=ucrReceiverSecondColumn.GetVariables())
ucrBase.clsRsyntax.AddParameter("alternative", Chr(34) & "two.sided" & Chr(34))
ucrBase.clsRsyntax.AddParameter("exact", "NULL")
bIsTwoColumnFunction = True


End Sub

Private Sub SetMultipleColumnAsFunction()
Expand All @@ -104,7 +148,7 @@ Public Class dlgCorrelation
ucrBase.clsRsyntax.SetFunction("cor")
'Set what should be visible/invisible
grpMissing.Visible = True
cmdPlots.Visible = True
cmdCorrplot.Visible = True
lblConfInterval.Visible = False
txtConfidenceInterval.Visible = False
ucrReceiverFirstColumn.Visible = False
Expand All @@ -118,6 +162,7 @@ Public Class dlgCorrelation
'Add back in parameters they may have been removed in TwoColumn case
SetUseParameter()
ucrBase.clsRsyntax.AddParameter("x", clsRFunctionParameter:=ucrReceiverMultipleColumns.GetVariables())
bIsTwoColumnFunction = False
End Sub


Expand All @@ -132,4 +177,27 @@ Public Class dlgCorrelation
Private Sub txtConfidenceInterval_Leave(sender As Object, e As EventArgs) Handles txtConfidenceInterval.Leave
ucrBase.clsRsyntax.AddParameter("conf.level", txtConfidenceInterval.Text)
End Sub
Private Sub ucrBase_ClickReset(sender As Object, e As EventArgs) Handles ucrBase.ClickReset
SetDefaults()
End Sub

Private Sub cmdPlots_Click(sender As Object, e As EventArgs) Handles cmdCorrplot.Click
sdgCorrPlot.ShowDialog()
End Sub
Private Sub TestOKEnabledForTwoColumns()
If ucrReceiverFirstColumn.IsEmpty() = False And ucrReceiverSecondColumn.IsEmpty() = False And (rdoPearson.Checked = True Or rdoKendall.Checked = True Or rdoSpearman.Checked = True) Then
ucrBase.OKEnabled(True)
Else
ucrBase.OKEnabled(False)
End If
End Sub
Private Sub TestOKEnabledForMultipleColumns()
If ucrReceiverMultipleColumns.IsEmpty() = False And ucrReceiverMultipleColumns.lstSelectedVariables.Items.Count > 1 And (rdoCompleteRowsOnly.Checked = True Or rdoPairwise.Checked = True) AndAlso (rdoPearson.Checked = True Or rdoKendall.Checked = True Or rdoSpearman.Checked = True) Then
ucrBase.OKEnabled(True)
Else
ucrBase.OKEnabled(False)
End If


End Sub
End Class

0 comments on commit d135723

Please sign in to comment.