diff --git a/instat/dlgDescribeTwoVariable.Designer.vb b/instat/dlgDescribeTwoVariable.Designer.vb index 6f4ad6015c..5eb45c48ae 100644 --- a/instat/dlgDescribeTwoVariable.Designer.vb +++ b/instat/dlgDescribeTwoVariable.Designer.vb @@ -80,13 +80,13 @@ Partial Class dlgDescribeTwoVariable Me.ucrPnlDescribe = New instat.UcrPanel() Me.ucrReceiverSkimrGroupByFactor = New instat.ucrReceiverSingle() Me.ucrChkDisplayMargins = New instat.ucrCheck() - Me.ucrChkSummariesRowCol = New instat.ucrCheck() Me.ucrChkLevSig = New instat.ucrCheck() Me.ucrChkTotal = New instat.ucrCheck() Me.ucrChkMeans = New instat.ucrCheck() Me.ucrChkCorrelations = New instat.ucrCheck() Me.ucrChkSwapXYVar = New instat.ucrCheck() Me.ucrChkOmitMissing = New instat.ucrCheck() + Me.ucrChkInteraction = New instat.ucrCheck() Me.grpSummaries.SuspendLayout() Me.grpDisplay.SuspendLayout() Me.SuspendLayout() @@ -350,11 +350,11 @@ Partial Class dlgDescribeTwoVariable ' Me.grpDisplay.Controls.Add(Me.ucrReceiverColumns) Me.grpDisplay.Controls.Add(Me.ucrChkDisplayAsPercentage) - Me.grpDisplay.Location = New System.Drawing.Point(414, 278) + Me.grpDisplay.Location = New System.Drawing.Point(414, 286) Me.grpDisplay.Margin = New System.Windows.Forms.Padding(4) Me.grpDisplay.Name = "grpDisplay" Me.grpDisplay.Padding = New System.Windows.Forms.Padding(4) - Me.grpDisplay.Size = New System.Drawing.Size(291, 219) + Me.grpDisplay.Size = New System.Drawing.Size(291, 265) Me.grpDisplay.TabIndex = 15 Me.grpDisplay.TabStop = False Me.grpDisplay.Text = "Percentages" @@ -363,29 +363,29 @@ Partial Class dlgDescribeTwoVariable ' Me.ucrReceiverColumns.AutoSize = True Me.ucrReceiverColumns.frmParent = Me - Me.ucrReceiverColumns.Location = New System.Drawing.Point(20, 92) + Me.ucrReceiverColumns.Location = New System.Drawing.Point(40, 138) Me.ucrReceiverColumns.Margin = New System.Windows.Forms.Padding(0) Me.ucrReceiverColumns.Name = "ucrReceiverColumns" Me.ucrReceiverColumns.Selector = Nothing - Me.ucrReceiverColumns.Size = New System.Drawing.Size(180, 122) + Me.ucrReceiverColumns.Size = New System.Drawing.Size(180, 123) Me.ucrReceiverColumns.strNcFilePath = "" - Me.ucrReceiverColumns.TabIndex = 55 + Me.ucrReceiverColumns.TabIndex = 46 Me.ucrReceiverColumns.ucrSelector = Nothing ' 'ucrChkDisplayAsPercentage ' Me.ucrChkDisplayAsPercentage.AutoSize = True Me.ucrChkDisplayAsPercentage.Checked = False - Me.ucrChkDisplayAsPercentage.Location = New System.Drawing.Point(14, 22) - Me.ucrChkDisplayAsPercentage.Margin = New System.Windows.Forms.Padding(6, 6, 6, 6) + Me.ucrChkDisplayAsPercentage.Location = New System.Drawing.Point(21, 32) + Me.ucrChkDisplayAsPercentage.Margin = New System.Windows.Forms.Padding(9) Me.ucrChkDisplayAsPercentage.Name = "ucrChkDisplayAsPercentage" - Me.ucrChkDisplayAsPercentage.Size = New System.Drawing.Size(171, 51) + Me.ucrChkDisplayAsPercentage.Size = New System.Drawing.Size(256, 36) Me.ucrChkDisplayAsPercentage.TabIndex = 54 ' 'rdoOCol ' Me.rdoOCol.AutoSize = True - Me.rdoOCol.Location = New System.Drawing.Point(432, 336) + Me.rdoOCol.Location = New System.Drawing.Point(432, 357) Me.rdoOCol.Name = "rdoOCol" Me.rdoOCol.Size = New System.Drawing.Size(81, 24) Me.rdoOCol.TabIndex = 40 @@ -396,7 +396,7 @@ Partial Class dlgDescribeTwoVariable 'rdoOCell ' Me.rdoOCell.AutoSize = True - Me.rdoOCell.Location = New System.Drawing.Point(612, 334) + Me.rdoOCell.Location = New System.Drawing.Point(612, 355) Me.rdoOCell.Name = "rdoOCell" Me.rdoOCell.Size = New System.Drawing.Size(84, 24) Me.rdoOCell.TabIndex = 41 @@ -407,7 +407,7 @@ Partial Class dlgDescribeTwoVariable 'rdoORow ' Me.rdoORow.AutoSize = True - Me.rdoORow.Location = New System.Drawing.Point(518, 336) + Me.rdoORow.Location = New System.Drawing.Point(518, 357) Me.rdoORow.Name = "rdoORow" Me.rdoORow.Size = New System.Drawing.Size(90, 24) Me.rdoORow.TabIndex = 42 @@ -432,7 +432,7 @@ Partial Class dlgDescribeTwoVariable ' Me.ucrReceiverPercentages.AutoSize = True Me.ucrReceiverPercentages.frmParent = Me - Me.ucrReceiverPercentages.Location = New System.Drawing.Point(430, 369) + Me.ucrReceiverPercentages.Location = New System.Drawing.Point(430, 390) Me.ucrReceiverPercentages.Margin = New System.Windows.Forms.Padding(0) Me.ucrReceiverPercentages.Name = "ucrReceiverPercentages" Me.ucrReceiverPercentages.Selector = Nothing @@ -444,7 +444,7 @@ Partial Class dlgDescribeTwoVariable 'ucrpnlPercent ' Me.ucrpnlPercent.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink - Me.ucrpnlPercent.Location = New System.Drawing.Point(424, 332) + Me.ucrpnlPercent.Location = New System.Drawing.Point(424, 353) Me.ucrpnlPercent.Margin = New System.Windows.Forms.Padding(6, 6, 6, 6) Me.ucrpnlPercent.Name = "ucrpnlPercent" Me.ucrpnlPercent.Size = New System.Drawing.Size(270, 38) @@ -512,7 +512,7 @@ Partial Class dlgDescribeTwoVariable ' 'ucrReorderSummary ' - Me.ucrReorderSummary.Location = New System.Drawing.Point(412, 409) + Me.ucrReorderSummary.Location = New System.Drawing.Point(412, 410) Me.ucrReorderSummary.Margin = New System.Windows.Forms.Padding(9) Me.ucrReorderSummary.Name = "ucrReorderSummary" Me.ucrReorderSummary.Size = New System.Drawing.Size(291, 234) @@ -587,16 +587,6 @@ Partial Class dlgDescribeTwoVariable Me.ucrChkDisplayMargins.Size = New System.Drawing.Size(214, 34) Me.ucrChkDisplayMargins.TabIndex = 18 ' - 'ucrChkSummariesRowCol - ' - Me.ucrChkSummariesRowCol.AutoSize = True - Me.ucrChkSummariesRowCol.Checked = False - Me.ucrChkSummariesRowCol.Location = New System.Drawing.Point(22, 507) - Me.ucrChkSummariesRowCol.Margin = New System.Windows.Forms.Padding(9) - Me.ucrChkSummariesRowCol.Name = "ucrChkSummariesRowCol" - Me.ucrChkSummariesRowCol.Size = New System.Drawing.Size(270, 34) - Me.ucrChkSummariesRowCol.TabIndex = 20 - ' 'ucrChkLevSig ' Me.ucrChkLevSig.AutoSize = True @@ -641,7 +631,7 @@ Partial Class dlgDescribeTwoVariable ' Me.ucrChkSwapXYVar.AutoSize = True Me.ucrChkSwapXYVar.Checked = False - Me.ucrChkSwapXYVar.Location = New System.Drawing.Point(465, 347) + Me.ucrChkSwapXYVar.Location = New System.Drawing.Point(465, 346) Me.ucrChkSwapXYVar.Margin = New System.Windows.Forms.Padding(9) Me.ucrChkSwapXYVar.Name = "ucrChkSwapXYVar" Me.ucrChkSwapXYVar.Size = New System.Drawing.Size(236, 34) @@ -657,6 +647,16 @@ Partial Class dlgDescribeTwoVariable Me.ucrChkOmitMissing.Size = New System.Drawing.Size(214, 34) Me.ucrChkOmitMissing.TabIndex = 0 ' + 'ucrChkInteraction + ' + Me.ucrChkInteraction.AutoSize = True + Me.ucrChkInteraction.Checked = False + Me.ucrChkInteraction.Location = New System.Drawing.Point(465, 380) + Me.ucrChkInteraction.Margin = New System.Windows.Forms.Padding(9) + Me.ucrChkInteraction.Name = "ucrChkInteraction" + Me.ucrChkInteraction.Size = New System.Drawing.Size(214, 34) + Me.ucrChkInteraction.TabIndex = 45 + ' 'dlgDescribeTwoVariable ' Me.AutoScaleDimensions = New System.Drawing.SizeF(144.0!, 144.0!) @@ -664,8 +664,10 @@ Partial Class dlgDescribeTwoVariable Me.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink Me.ClientSize = New System.Drawing.Size(723, 700) Me.Controls.Add(Me.cmdSummaries) - Me.Controls.Add(Me.ucrReceiverThreeVariableThirdVariable) Me.Controls.Add(Me.ucrReceiverPercentages) + Me.Controls.Add(Me.ucrReorderSummary) + Me.Controls.Add(Me.ucrChkInteraction) + Me.Controls.Add(Me.ucrReceiverThreeVariableThirdVariable) Me.Controls.Add(Me.rdoORow) Me.Controls.Add(Me.rdoOCell) Me.Controls.Add(Me.rdoOCol) @@ -676,7 +678,6 @@ Partial Class dlgDescribeTwoVariable Me.Controls.Add(Me.ucrSaveTable) Me.Controls.Add(Me.grpDisplay) Me.Controls.Add(Me.ucrInputMarginName) - Me.Controls.Add(Me.ucrReorderSummary) Me.Controls.Add(Me.lblMarginName) Me.Controls.Add(Me.cmdFormatTable) Me.Controls.Add(Me.ucrBase) @@ -695,7 +696,6 @@ Partial Class dlgDescribeTwoVariable Me.Controls.Add(Me.lblThreeVariableSecondFactor) Me.Controls.Add(Me.ucrChkDisplayMargins) Me.Controls.Add(Me.cmdMissingOptions) - Me.Controls.Add(Me.ucrChkSummariesRowCol) Me.Controls.Add(Me.lblThirdVariable) Me.Controls.Add(Me.ucrChkLevSig) Me.Controls.Add(Me.ucrChkTotal) @@ -756,7 +756,6 @@ Partial Class dlgDescribeTwoVariable Friend WithEvents ucrChkDisplayAsPercentage As ucrCheck Friend WithEvents ucrSaveTable As ucrSave Friend WithEvents ucrReceiverFirstVars As ucrReceiverMultiple - Friend WithEvents ucrChkSummariesRowCol As ucrCheck Friend WithEvents ucrChkCorrelations As ucrCheck Friend WithEvents ucrChkSwapXYVar As ucrCheck Friend WithEvents ucrChkMeans As ucrCheck @@ -766,6 +765,7 @@ Partial Class dlgDescribeTwoVariable Friend WithEvents rdoOCell As RadioButton Friend WithEvents rdoOCol As RadioButton Friend WithEvents ucrpnlPercent As UcrPanel - Friend WithEvents ucrReceiverColumns As ucrReceiverMultiple Friend WithEvents ucrChkTotal As ucrCheck + Friend WithEvents ucrChkInteraction As ucrCheck + Friend WithEvents ucrReceiverColumns As ucrReceiverMultiple End Class diff --git a/instat/dlgDescribeTwoVariable.vb b/instat/dlgDescribeTwoVariable.vb index 7c0bf0f82d..0da50e2892 100644 --- a/instat/dlgDescribeTwoVariable.vb +++ b/instat/dlgDescribeTwoVariable.vb @@ -42,7 +42,7 @@ Public Class dlgDescribeTwoVariable clsTabFootnoteSubtitleFunction, clsTabFootnoteTitleFunction, clsTableSourcenoteFunction, clsTableTitleFunction, clsThemesTabOptionFunction, clsTabStyleCellTextFunction, clsTabStyleCellTitleFunction, clsTabStyleFunction, - clsTabStylePxFunction, clsgtExtrasThemesFuction As New RFunction + clsTabStylePxFunction, clsgtExtrasThemesFuction, clsCrossDfFunction, clsListFunction As New RFunction Private clsGroupByPipeOperator, clsSummaryOperator, clsGroupByPipeOperator2, clsGroupByPipeOperator3, clsGroupByPipeOperator4, clsGroupByPipeOperatorData As New ROperator @@ -50,14 +50,14 @@ Public Class dlgDescribeTwoVariable Private clsTildOperator, clsMapOperator, clsPivotOperator As New ROperator - Private clsgtFunction, clsMapSummaryFunction, clsMapGtFunction As New RFunction + Private clsgtFunction, clsMapSummaryFunction, clsMap2SummaryFunction, clsMapGtFunction As New RFunction 'Frequency Parameters Private lstFrequencyParameters As New List(Of String)({"percentage_type", "margin_name", "perc_total_factors", "perc_decimal", "signif_fig", "include_margins"}) 'Format Operators - Private clsPipeOperator, clsTabFootnoteOperator, + Private clsPipeOperator, clsFactorOperator, clsSummariesOperator, clsTabFootnoteOperator, clsJoiningPipeOperator, clsMutableOperator, clsAnovaSwapTable2Opeator, clsAnovaTable2Operator, clsYlist2Operator, clsYlistOperator As New ROperator Private iUcrBaseXLocation, iDialogueXsize As Integer @@ -73,6 +73,7 @@ Public Class dlgDescribeTwoVariable SetHelpOptions() bReset = False TestOKEnabled() + ManageControlsVisibility() autoTranslate(Me) End Sub @@ -145,10 +146,6 @@ Public Class dlgDescribeTwoVariable ucrChkDisplayAsPercentage.AddToLinkedControls(ucrReceiverPercentages, {True}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True, bNewLinkedUpdateFunction:=True) ucrChkDisplayAsPercentage.AddToLinkedControls(ucrpnlPercent, {True}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True) - ucrChkSummariesRowCol.SetText("Summaries in Rows") - ucrChkSummariesRowCol.AddParameterValuesCondition(True, "row_sum", "True") - ucrChkSummariesRowCol.AddParameterValuesCondition(False, "row_sum", "False") - ucrChkCorrelations.SetText("Correlations") ucrChkCorrelations.AddParameterValuesCondition(True, "corr", "True") ucrChkCorrelations.AddParameterValuesCondition(False, "corr", "False") @@ -164,10 +161,15 @@ Public Class dlgDescribeTwoVariable ucrChkLevSig.SetRDefault("FALSE") ucrChkTotal.SetText("Total") - ucrChkTotal.SetParameter(New RParameter("total", 5)) + ucrChkTotal.SetParameter(New RParameter("total", 6)) ucrChkTotal.SetValuesCheckedAndUnchecked("TRUE", "FALSE") ucrChkTotal.SetRDefault("FALSE") + ucrChkInteraction.SetText("Interaction") + ucrChkInteraction.SetParameter(New RParameter("interaction", 5)) + ucrChkInteraction.SetValuesCheckedAndUnchecked("TRUE", "FALSE") + ucrChkInteraction.SetRDefault("FALSE") + ucrChkSwapXYVar.SetText("Swap First/Second Variables") ucrChkSwapXYVar.AddParameterValuesCondition(True, "var", "True") ucrChkSwapXYVar.AddParameterValuesCondition(False, "var", "False") @@ -187,7 +189,7 @@ Public Class dlgDescribeTwoVariable ucrpnlPercent.AddParameterValuesCondition(rdoOCell, "percent", "cell") ucrPnlDescribe.AddToLinkedControls({ucrReceiverSkimrGroupByFactor, ucrReceiverSecondSkimrGroupByFactor}, {rdoSkim}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True) - ucrPnlDescribe.AddToLinkedControls({ucrReceiverThreeVariableThirdVariable}, {rdoThreeVariable}, bNewLinkedHideIfParameterMissing:=True) + ucrPnlDescribe.AddToLinkedControls({ucrReceiverThreeVariableThirdVariable}, {rdoThreeVariable}, bNewLinkedHideIfParameterMissing:=True, bNewLinkedAddRemoveParameter:=True) ucrPnlDescribe.AddToLinkedControls({ucrReceiverSecondTwoVariableFactor}, {rdoTwoVariable}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True) ucrPnlDescribe.AddToLinkedControls({ucrReceiverThreeVariableSecondFactor}, {rdoThreeVariable}, bNewLinkedAddRemoveParameter:=True, bNewLinkedHideIfParameterMissing:=True) @@ -201,9 +203,10 @@ Public Class dlgDescribeTwoVariable ucrSaveTable.SetDataFrameSelector(ucrSelectorDescribeTwoVar.ucrAvailableDataFrames) ucrSaveTable.SetIsTextBox() - rdoThreeVariable.Enabled = False ucrReorderSummary.bDataIsSummaries = True AddRemoveTotalParm() + AddInteraction() + ManageControlsVisibility() End Sub Private Sub SetDefaults() @@ -264,11 +267,16 @@ Public Class dlgDescribeTwoVariable clsYlist2Operator = New ROperator clsRAnovaTable2Function = New RFunction clsRAnovaSwapTable2Funtion = New RFunction + clsCrossDfFunction = New RFunction + clsListFunction = New RFunction + clsMap2SummaryFunction = New RFunction clsTildOperator = New ROperator clsMapSummaryFunction = New RFunction clsMapGtFunction = New RFunction clsPivotOperator = New ROperator + clsFactorOperator = New ROperator + clsSummariesOperator = New ROperator ucrSelectorDescribeTwoVar.Reset() ucrReceiverFirstVars.SetMeAsReceiver() @@ -281,6 +289,25 @@ Public Class dlgDescribeTwoVariable clsCombineFunction.SetRCommand("c") + clsSummariesOperator.SetOperation("", bBracketsTemp:=False) + clsSummariesOperator.SetAssignTo("summaries") + + clsFactorOperator.SetOperation("", bBracketsTemp:=False) + clsFactorOperator.SetAssignTo("factors") + + clsListFunction.SetRCommand("list") + clsListFunction.AddParameter("factor", "factors", iPosition:=0) + clsListFunction.AddParameter("summary", "summaries", iPosition:=1) + + clsCrossDfFunction.SetRCommand("cross_df") + clsCrossDfFunction.AddParameter("list", clsRFunctionParameter:=clsListFunction, iPosition:=0, bIncludeArgumentName:=False) + clsCrossDfFunction.SetAssignTo("combinations") + + clsMap2SummaryFunction.SetPackageName("purrr") + clsMap2SummaryFunction.SetRCommand("map2") + clsMap2SummaryFunction.AddParameter(".x", "combinations$factor", iPosition:=0) + clsMap2SummaryFunction.AddParameter(".y", "combinations$summary", iPosition:=1) + clsDummyFunction.AddParameter("checked", "skim", iPosition:=0) clsDummyFunction.AddParameter("factor_cols", "Sum", iPosition:=1) clsDummyFunction.AddParameter("theme", "select", iPosition:=2) @@ -426,7 +453,6 @@ Public Class dlgDescribeTwoVariable clsMapSummaryFunction.SetPackageName("purrr") clsMapSummaryFunction.SetRCommand("map") - clsMapSummaryFunction.AddParameter(".f", clsROperatorParameter:=clsMapOperator, iPosition:=1) clsMapGtFunction.SetPackageName("purrr") clsMapGtFunction.SetRCommand("map") @@ -437,7 +463,6 @@ Public Class dlgDescribeTwoVariable clsSummaryOperator.SetOperation("%>%") clsSummaryOperator.AddParameter("data", clsRFunctionParameter:=ucrSelectorDescribeTwoVar.ucrAvailableDataFrames.clsCurrDataFrame, iPosition:=0) - clsSummaryOperator.AddParameter("tableFun", clsRFunctionParameter:=clsMapSummaryFunction, iPosition:=1) clsPivotOperator.SetOperation("%>%") clsPivotOperator.AddParameter("left", clsRFunctionParameter:=clsPivotWiderFunction) @@ -492,6 +517,7 @@ Public Class dlgDescribeTwoVariable ucrBase.clsRsyntax.ClearCodes() ucrBase.clsRsyntax.SetBaseROperator(clsGroupByPipeOperator) + ThreeVarSummariesVar() bResetSubdialog = True End Sub @@ -505,6 +531,8 @@ Public Class dlgDescribeTwoVariable ucrChkLevSig.AddAdditionalCodeParameterPair(clsRAnovaSwapTable2Funtion, New RParameter("sign_level", iNewPosition:=4), iAdditionalPairNo:=1) ucrChkDisplayMargins.AddAdditionalCodeParameterPair(clsCombineFrequencyColParametersFunction, New RParameter("include_margins", iNewPosition:=5), iAdditionalPairNo:=1) ucrChkDisplayAsPercentage.AddAdditionalCodeParameterPair(clsCombineFrequencyColParametersFunction, New RParameter("percentage_type", iNewPosition:=1), iAdditionalPairNo:=1) + ucrChkDisplayMargins.AddAdditionalCodeParameterPair(clsThreeVariableCombineFrequencyParametersFunction, New RParameter("include_margins", iNewPosition:=5), iAdditionalPairNo:=2) + ucrChkInteraction.AddAdditionalCodeParameterPair(clsRAnovaSwapTable2Funtion, New RParameter("interaction", iNewPosition:=7), iAdditionalPairNo:=1) ucrSelectorDescribeTwoVar.AddAdditionalCodeParameterPair(clsSummaryTableFunction, ucrSelectorDescribeTwoVar.GetParameter(), iAdditionalPairNo:=1) ucrSaveTable.AddAdditionalRCode(clsJoiningPipeOperator, iAdditionalPairNo:=1) @@ -521,11 +549,11 @@ Public Class dlgDescribeTwoVariable ucrReceiverColumns.SetRCode(clsCombineFrequencyColParametersFunction, bReset) ucrPnlDescribe.SetRCode(clsDummyFunction, bReset) ucrpnlPercent.SetRCode(clsDummyFunction, bReset) - ucrChkSummariesRowCol.SetRCode(clsDummyFunction, bReset) ucrChkCorrelations.SetRCode(clsDummyFunction, bReset) ucrChkSwapXYVar.SetRCode(clsDummyFunction, bReset) ucrChkMeans.SetRCode(clsRAnovaTable2Function, bReset) ucrChkLevSig.SetRCode(clsRAnovaTable2Function, bReset) + ucrChkInteraction.SetRCode(clsRAnovaTable2Function, bReset) ucrReceiverThreeVariableSecondFactor.SetRCode(clsSummaryTableCombineFactorsFunction, bReset) ucrReceiverThreeVariableThirdVariable.SetRCode(clsSummaryTableCombineFactorsFunction, bReset) ucrChkDisplayMargins.SetRCode(clsCombineFrequencyParametersFunction, bReset) @@ -534,6 +562,9 @@ Public Class dlgDescribeTwoVariable FillListView() AddRemoveTotalParm() + AddInteraction() + ChangeBaseRCode() + ThreeVarSummariesVar() End Sub Public Sub TestOKEnabled() @@ -628,10 +659,12 @@ Public Class dlgDescribeTwoVariable Private Sub ManageControlsVisibility() grpSummaries.Visible = rdoThreeVariable.Checked OrElse rdoTwoVariable.Checked ucrChkDisplayMargins.Visible = rdoTwoVariable.Checked AndAlso IsFactorByFactor() - ucrInputMarginName.Visible = ucrChkDisplayMargins.Checked AndAlso IsFactorByFactor() + ucrChkDisplayMargins.Visible = rdoThreeVariable.Checked AndAlso IsFactorByFactorByNumeric() OrElse IsFactorByNumericByFactor() OrElse IsFactorByFactorByFactor() + ucrInputMarginName.Visible = ucrChkDisplayMargins.Checked AndAlso (IsFactorByFactor() OrElse IsFactorByFactorByNumeric() OrElse IsFactorByNumericByFactor()) + ucrInputMarginName.Visible = ucrChkDisplayMargins.Checked AndAlso IsFactorByFactorByNumeric() OrElse IsFactorByNumericByFactor() OrElse IsFactorByFactorByFactor() grpDisplay.Visible = rdoTwoVariable.Checked AndAlso IsFactorByFactor() ucrReceiverPercentages.Visible = ucrChkDisplayAsPercentage.Checked AndAlso rdoORow.Checked AndAlso IsFactorByFactor() - ucrpnlPercent.Visible = IsFactorByFactor() AndAlso ucrChkDisplayAsPercentage.Checked + ucrpnlPercent.Visible = rdoTwoVariable.Checked AndAlso IsFactorByFactor() AndAlso ucrChkDisplayAsPercentage.Checked ucrReceiverColumns.Visible = ucrChkDisplayAsPercentage.Checked AndAlso IsFactorByFactor() AndAlso rdoOCol.Checked ucrChkCorrelations.Visible = False ucrChkSwapXYVar.Visible = False @@ -639,10 +672,11 @@ Public Class dlgDescribeTwoVariable cmdMissingOptions.Visible = False If rdoTwoVariable.Checked Then - ucrChkOmitMissing.Visible = IsNumericByNumeric() OrElse IsNumericByFactor() + ucrChkOmitMissing.Visible = False + ucrChkOmitMissing.Visible = Not ucrChkSwapXYVar.Checked AndAlso IsFactorByNumeric() ucrChkSwapXYVar.Visible = IsNumericByNumeric() OrElse IsFactorByNumeric() ucrChkCorrelations.Visible = IsNumericByNumeric() - cmdMissingOptions.Visible = ucrChkOmitMissing.Checked + cmdMissingOptions.Visible = ucrChkOmitMissing.Checked AndAlso ucrChkOmitMissing.Visible End If If rdoThreeVariable.Checked Then If IsFactorByFactorByNumeric() OrElse IsFactorByNumericByFactor() Then @@ -652,9 +686,8 @@ Public Class dlgDescribeTwoVariable ucrReorderSummary.Visible = False cmdSummaries.Visible = False End If - ucrChkSwapXYVar.Visible = IsNumericByNumericByNumeric() OrElse IsNumericByNumericByFactor() - ucrChkSummariesRowCol.Visible = IsFactorByFactorByNumeric() OrElse IsFactorByNumericByFactor() - ucrChkOmitMissing.Visible = IsFactorByNumericByNumeric() OrElse IsNumericByNumericByFactor() + ucrChkOmitMissing.Visible = IsFactorByNumericByFactor() OrElse IsFactorByFactorByNumeric() + cmdMissingOptions.Visible = ucrChkOmitMissing.Checked End If End Sub @@ -662,12 +695,13 @@ Public Class dlgDescribeTwoVariable ucrSaveTable.Visible = False ucrReorderSummary.Visible = False cmdSummaries.Visible = False - ucrChkSummariesRowCol.Visible = False cmdFormatTable.Visible = False ucrChkMeans.Visible = False ucrChkLevSig.Visible = False ucrChkTotal.Visible = False + ucrChkInteraction.Visible = False cmdMissingOptions.Visible = False + ucrChkOmitMissing.Visible = False If rdoSkim.Checked Then clsDummyFunction.AddParameter("checked", "skim", iPosition:=0) cmdFormatTable.Visible = False @@ -685,12 +719,12 @@ Public Class dlgDescribeTwoVariable strObjectName:="last_summary") ElseIf rdoTwoVariable.Checked Then + ucrChkOmitMissing.Visible = False clsDummyFunction.AddParameter("checked", "customize", iPosition:=0) If IsNumericByNumeric() Then If ucrChkSwapXYVar.Checked Then ucrBase.clsRsyntax.SetBaseRFunction(clsMapping2Function) clsDummyFunction.AddParameter("var", "True", iPosition:=5) - Else ucrBase.clsRsyntax.SetBaseRFunction(clsMappingFunction) clsDummyFunction.AddParameter("var", "False", iPosition:=5) @@ -705,16 +739,25 @@ Public Class dlgDescribeTwoVariable End If ucrSaveTable.Visible = False cmdFormatTable.Visible = False + ucrChkInteraction.Visible = False ucrChkMeans.Visible = True ucrChkLevSig.Visible = True ucrChkTotal.Visible = True + ucrChkTotal.Location = New Point(310, 189) + ucrChkLevSig.Location = New Point(397, 186) + ucrChkMeans.Location = New Point(310, 210) + ElseIf IsNumericByFactor() Then ucrBase.clsRsyntax.SetBaseRFunction(clsMappingFunction) + ucrChkInteraction.Visible = False ucrChkMeans.Visible = True ucrChkLevSig.Visible = True ucrChkTotal.Visible = True ucrSaveTable.Visible = True ucrSaveTable.Location = New Point(23, 450) + ucrChkTotal.Location = New Point(310, 189) + ucrChkMeans.Location = New Point(310, 210) + ucrChkLevSig.Location = New Point(397, 186) clsDummyFunction.AddParameter("factor_cols", "Sum", iPosition:=1) ucrSaveTable.SetPrefix("summary_table") ucrSaveTable.SetSaveType(RObjectTypeLabel.Table, strRObjectFormat:=RObjectFormat.Html) @@ -727,7 +770,8 @@ Public Class dlgDescribeTwoVariable ucrChkMeans.Visible = False ucrChkLevSig.Visible = False ucrChkTotal.Visible = False - ucrSaveTable.Location = New Point(23, 351) + ucrChkInteraction.Visible = False + ucrSaveTable.Location = New Point(23, 370) clsDummyFunction.AddParameter("factor_cols", "FactorVar", iPosition:=1) ucrBase.clsRsyntax.SetBaseROperator(clsJoiningPipeOperator) ucrSaveTable.SetPrefix("frequency_table") @@ -747,22 +791,30 @@ Public Class dlgDescribeTwoVariable clsDummyFunction.AddParameter("var", "True", iPosition:=5) ucrReorderSummary.Visible = False cmdSummaries.Visible = False - ucrChkSummariesRowCol.Visible = False cmdFormatTable.Visible = False + ucrChkInteraction.Visible = False + ucrChkOmitMissing.Visible = False + cmdMissingOptions.Visible = False ucrChkMeans.Visible = True ucrChkLevSig.Visible = True ucrChkTotal.Visible = True + ucrChkTotal.Location = New Point(310, 189) + ucrChkLevSig.Location = New Point(397, 186) + ucrChkMeans.Location = New Point(310, 210) Else clsDummyFunction.AddParameter("var", "False", iPosition:=5) ucrSaveTable.Visible = True ucrReorderSummary.Visible = True cmdSummaries.Visible = True - ucrChkSummariesRowCol.Visible = True cmdFormatTable.Visible = True + ucrChkOmitMissing.Visible = True ucrChkMeans.Visible = False ucrChkLevSig.Visible = False ucrChkTotal.Visible = False + ucrChkInteraction.Visible = False ucrSaveTable.Location = New Point(23, 450) + ucrChkOmitMissing.Location = New Point(15, 365) + cmdMissingOptions.Location = New Point(17, 385) clsDummyFunction.AddParameter("factor_cols", "Sum", iPosition:=1) ucrBase.clsRsyntax.SetBaseROperator(clsJoiningPipeOperator) ucrSaveTable.SetPrefix("summary_table") @@ -779,7 +831,9 @@ Public Class dlgDescribeTwoVariable End If ElseIf rdoThreeVariable.Checked Then clsDummyFunction.AddParameter("checked", "three_variable", iPosition:=0) - + ucrBase.clsRsyntax.RemoveFromBeforeCodes(clsSummariesOperator) + ucrBase.clsRsyntax.RemoveFromBeforeCodes(clsFactorOperator) + ucrBase.clsRsyntax.RemoveFromBeforeCodes(clsCrossDfFunction) If IsFactorByFactorByFactor() Then cmdFormatTable.Visible = True ucrSaveTable.Location = New Point(23, 341) @@ -802,18 +856,24 @@ Public Class dlgDescribeTwoVariable ucrSaveTable.SetSaveType(RObjectTypeLabel.Table, strRObjectFormat:=RObjectFormat.Html) ucrSaveTable.SetAssignToIfUncheckedValue("last_table") ucrSaveTable.SetCheckBoxText("Store Cor") - ucrBase.clsRsyntax.SetBaseROperator(clsGroupByPipeOperator4) - clsGroupByPipeOperator4.SetAssignToOutputObject(strRObjectToAssignTo:="last_table", + ucrBase.clsRsyntax.SetBaseROperator(clsJoiningPipeOperator) + clsJoiningPipeOperator.SetAssignToOutputObject(strRObjectToAssignTo:="last_table", strRObjectTypeLabelToAssignTo:=RObjectTypeLabel.Table, strRObjectFormatToAssignTo:=RObjectFormat.Html, strRDataFrameNameToAddObjectTo:=ucrSelectorDescribeTwoVar.strCurrentDataFrame, strObjectName:="last_table") + ElseIf IsNumericByNumericByFactor() Then cmdFormatTable.Visible = False ucrSaveTable.Visible = False ucrChkMeans.Visible = True ucrChkLevSig.Visible = True ucrChkTotal.Visible = True + ucrChkInteraction.Visible = True + ucrChkTotal.Location = New Point(310, 250) + ucrChkLevSig.Location = New Point(397, 250) + ucrChkInteraction.Location = New Point(310, 275) + ucrChkMeans.Location = New Point(310, 300) If ucrChkSwapXYVar.Checked Then ucrBase.clsRsyntax.SetBaseRFunction(clsMapping2Function) clsDummyFunction.AddParameter("var", "True", iPosition:=5) @@ -824,20 +884,47 @@ Public Class dlgDescribeTwoVariable ElseIf IsNumericByNumericByNumeric() Then cmdFormatTable.Visible = False ucrSaveTable.Visible = False + ucrChkMeans.Visible = True + ucrChkLevSig.Visible = True + ucrChkTotal.Visible = True + ucrChkInteraction.Visible = True + ucrChkTotal.Location = New Point(310, 250) + ucrChkLevSig.Location = New Point(397, 250) + ucrChkInteraction.Location = New Point(310, 275) + ucrChkMeans.Location = New Point(310, 300) ucrBase.clsRsyntax.SetBaseRFunction(clsMappingFunction) ElseIf IsNumericByFactorByFactor() Then cmdFormatTable.Visible = False ucrSaveTable.Visible = False + ucrChkMeans.Visible = True + ucrChkLevSig.Visible = True + ucrChkTotal.Visible = True + ucrChkInteraction.Visible = True + ucrChkTotal.Location = New Point(310, 250) + ucrChkLevSig.Location = New Point(397, 250) + ucrChkInteraction.Location = New Point(310, 275) + ucrChkMeans.Location = New Point(310, 300) ucrBase.clsRsyntax.SetBaseRFunction(clsMappingFunction) ElseIf IsNumericByFactorByNumeric() Then cmdFormatTable.Visible = False ucrSaveTable.Visible = False + ucrChkMeans.Visible = True + ucrChkLevSig.Visible = True + ucrChkTotal.Visible = True + ucrChkInteraction.Visible = True + ucrChkTotal.Location = New Point(310, 250) + ucrChkLevSig.Location = New Point(397, 250) + ucrChkInteraction.Location = New Point(310, 275) + ucrChkMeans.Location = New Point(310, 300) ucrBase.clsRsyntax.SetBaseRFunction(clsMappingFunction) ElseIf IsFactorByNumericByFactor() OrElse IsFactorByFactorByNumeric() Then ucrSaveTable.SetPrefix("summary_table") ucrSaveTable.SetSaveType(RObjectTypeLabel.Table, strRObjectFormat:=RObjectFormat.Html) ucrSaveTable.SetAssignToIfUncheckedValue("last_table") ucrSaveTable.SetCheckBoxText("Save Table") + ucrBase.clsRsyntax.AddToBeforeCodes(clsSummariesOperator, 0) + ucrBase.clsRsyntax.AddToBeforeCodes(clsFactorOperator, 1) + ucrBase.clsRsyntax.AddToBeforeCodes(clsCrossDfFunction, 2) ucrBase.clsRsyntax.SetBaseROperator(clsJoiningPipeOperator) clsJoiningPipeOperator.SetAssignToOutputObject(strRObjectToAssignTo:="last_table", strRObjectTypeLabelToAssignTo:=RObjectTypeLabel.Table, @@ -847,11 +934,17 @@ Public Class dlgDescribeTwoVariable ucrReorderSummary.Visible = True cmdSummaries.Visible = True ucrSaveTable.Visible = True - ucrChkSummariesRowCol.Visible = True + ucrChkOmitMissing.Visible = True ucrSaveTable.Location = New Point(23, 440) + ucrChkOmitMissing.Location = New Point(15, 360) + cmdMissingOptions.Location = New Point(17, 380) End If End If FactorColumns() + AddInteraction() + AddRemoveSecondAnovaParam() + AddRemoveThirdCorrParam() + ThreeVarSummariesVar() End Sub Private Sub UpdateCombineFactorParameterFunction() @@ -864,11 +957,11 @@ Public Class dlgDescribeTwoVariable clsSummaryTableFunction.RemoveParameterByName("na.rm") If ucrChkOmitMissing.Checked Then If rdoTwoVariable.Checked Then - If IsNumericByFactor() Then + If Not ucrChkSwapXYVar.Checked AndAlso IsFactorByNumeric() Then clsSummaryTableFunction.AddParameter("na.rm", "TRUE", iPosition:=5) End If ElseIf rdoThreeVariable.Checked Then - If IsNumericByFactor() OrElse IsFactorByNumeric() Then + If IsFactorByFactorByNumeric() OrElse IsFactorByNumericByFactor() Then clsSummaryTableFunction.AddParameter("na.rm", "TRUE", iPosition:=5) End If End If @@ -894,11 +987,15 @@ Public Class dlgDescribeTwoVariable clsSummaryTableFunction.AddParameter("na_type", clsRFunctionParameter:=clsCombineFunction, iPosition:=9) End If cmdMissingOptions.Visible = ucrChkOmitMissing.Checked - + ManageControlsVisibility() + ChangeBaseRCode() End Sub Private Sub ucrPnlDescribe_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrPnlDescribe.ControlValueChanged ucrReceiverFirstVars.Clear() + ucrReceiverThreeVariableSecondFactor.Clear() + ucrReceiverThreeVariableThirdVariable.Clear() + ucrReceiverSecondTwoVariableFactor.Clear() ucrReceiverFirstVars.SetMeAsReceiver() If rdoSkim.Checked Then @@ -933,6 +1030,7 @@ Public Class dlgDescribeTwoVariable AddRemoveSecondAnovaParam() AddRemoveThirdAnovaParam() AddRemoveFirstAnova2Param() + ThreeVarSummariesVar() End Sub Private Sub ChangeLocations() @@ -951,8 +1049,8 @@ Public Class dlgDescribeTwoVariable ucrBase.Location = New Point(iUcrBaseXLocation, 319) Me.Size = New Point(iDialogueXsize, 415) ElseIf IsFactorByFactor() Then - ucrBase.Location = New Point(iUcrBaseXLocation, 372) - Me.Size = New Point(iDialogueXsize, 465) + ucrBase.Location = New Point(iUcrBaseXLocation, 392) + Me.Size = New Point(iDialogueXsize, 485) cmdFormatTable.Location = New Point(326, 330) Else ucrBase.Location = New Point(iUcrBaseXLocation, 328) @@ -962,7 +1060,6 @@ Public Class dlgDescribeTwoVariable If IsNumericByNumericByFactor() OrElse IsNumericByNumericByNumeric() OrElse IsNumericByFactorByFactor() OrElse IsNumericByFactorByNumeric() Then ucrBase.Location = New Point(iUcrBaseXLocation, 353) - ucrChkSwapXYVar.Location = New Point(300, 320) Me.Size = New Point(iDialogueXsize, 450) ElseIf IsFactorByFactorByFactor() Then ucrBase.Location = New Point(iUcrBaseXLocation, 370) @@ -978,8 +1075,8 @@ Public Class dlgDescribeTwoVariable End If Else - ucrBase.Location = New Point(iUcrBaseXLocation, 328) - Me.Size = New Point(iDialogueXsize, 425) + ucrBase.Location = New Point(iUcrBaseXLocation, 333) + Me.Size = New Point(iDialogueXsize, 430) End If End Sub @@ -1023,10 +1120,12 @@ Public Class dlgDescribeTwoVariable If rdoThreeVariable.Checked Then If IsFactorByNumericByNumeric() Then If ucrReceiverThreeVariableThirdVariable.IsEmpty Then - clsCorrFunction.RemoveParameterByName("y") + clsSummaryTableFunction.RemoveParameterByName("y") Else - clsCorrFunction.AddParameter("y", ucrReceiverThreeVariableThirdVariable.GetVariableNames(False), iPosition:=2, bIncludeArgumentName:=False) + clsSummaryTableFunction.AddParameter("y", ucrReceiverThreeVariableThirdVariable.GetVariableNames) End If + Else + clsSummaryTableFunction.RemoveParameterByName("y") End If End If End Sub @@ -1042,36 +1141,75 @@ Public Class dlgDescribeTwoVariable clsPivotWiderFunction.AddParameter("names_from", "{{ .x }}", iPosition:=1) clsSummaryTableFunction.AddParameter("columns_to_summarise", ucrReceiverSecondTwoVariableFactor.GetVariableNames) clsMapSummaryFunction.AddParameter(".x", ucrReceiverFirstVars.GetVariableNames, iPosition:=3) - SummariesInRowsOrCols() Else clsSummaryTableFunction.AddParameter("factors", ucrReceiverSecondTwoVariableFactor.GetVariableNames) clsPivotWiderFunction.AddParameter("names_from", Chr(39) & "summary-variable" & Chr(39), iPosition:=1) clsSummaryTableFunction.AddParameter("columns_to_summarise", ucrReceiverFirstVars.GetVariableNames) - SummariesInRowsOrCols() End If End If If rdoThreeVariable.Checked Then - clsSummaryOperator.AddParameter("col_factor", clsRFunctionParameter:=clsPivotWiderFunction, iPosition:=1) If IsFactorByFactorByFactor() Then clsSummaryTableFunction.AddParameter("factors", "c(" & ucrReceiverThreeVariableSecondFactor.GetVariableNames & "," & ucrReceiverThreeVariableThirdVariable.GetVariableNames & "," & ".x" & ")") clsSummaryTableFunction.AddParameter("columns_to_summarise", ".x") - clsPivotWiderFunction.AddParameter("names_from", "{{ .x }}", iPosition:=1) + clsPivotWiderFunction.AddParameter("names_from", ucrReceiverThreeVariableThirdVariable.GetVariableNames(False), iPosition:=0) + clsSummaryOperator.AddParameter("col_factor", clsRFunctionParameter:=clsPivotWiderFunction, iPosition:=1) ElseIf IsFactorByFactorByNumeric() Then - clsMapSummaryFunction.AddParameter(".x", "c(" & ucrReceiverFirstVars.GetVariableNames.Replace("c(", "").Replace(")", "") & "," & ucrReceiverThreeVariableSecondFactor.GetVariableNames.Replace("c(", "").Replace(")", "") & ")") - clsSummaryTableFunction.AddParameter("factors", ".x") + clsSummaryTableFunction.AddParameter("factors", "c(" & ".x" & "," & ucrReceiverThreeVariableSecondFactor.GetVariableNames & ")") clsSummaryTableFunction.AddParameter("columns_to_summarise", ucrReceiverThreeVariableThirdVariable.GetVariableNames) - SummariesInRowsOrCols() + clsSummaryTableFunction.AddParameter("summaries", ".y", iPosition:=0) + clsPivotWiderFunction.AddParameter("names_from", ucrReceiverThreeVariableSecondFactor.GetVariableNames(False), iPosition:=0) + clsSummaryOperator.RemoveParameterByName("col_factor") ElseIf IsFactorByNumericByFactor() Then - clsMapSummaryFunction.AddParameter(".x", "c(" & ucrReceiverFirstVars.GetVariableNames.Replace("c(", "").Replace(")", "") & "," & ucrReceiverThreeVariableThirdVariable.GetVariableNames.Replace("c(", "").Replace(")", "") & ")") - clsSummaryTableFunction.AddParameter("factors", ".x") + clsSummaryTableFunction.AddParameter("factors", "c(" & ".x" & "," & ucrReceiverThreeVariableThirdVariable.GetVariableNames & ")") clsSummaryTableFunction.AddParameter("columns_to_summarise", ucrReceiverThreeVariableSecondFactor.GetVariableNames) - SummariesInRowsOrCols() + clsSummaryTableFunction.AddParameter("summaries", ".y", iPosition:=0) + clsSummaryOperator.RemoveParameterByName("col_factor") + clsPivotWiderFunction.AddParameter("names_from", ucrReceiverThreeVariableThirdVariable.GetVariableNames(False), iPosition:=0) + + ElseIf IsFactorByNumericByNumeric() Then + clsMapSummaryFunction.AddParameter(".x", ucrReceiverFirstVars.GetVariableNames) + clsPivotWiderFunction.AddParameter("names_from", Chr(39) & "summary-variable" & Chr(39), iPosition:=0) + clsSummaryTableFunction.AddParameter("columns_to_summarise", ucrReceiverThreeVariableSecondFactor.GetVariableNames) + clsSummaryTableFunction.AddParameter("summaries", Chr(34) & "summary_cor" & Chr(34), iPosition:=0) + clsSummaryTableFunction.AddParameter("factors", ".x") + clsSummaryOperator.AddParameter("col_factor", clsRFunctionParameter:=clsPivotWiderFunction, iPosition:=1) Else clsPivotWiderFunction.AddParameter("names_from", Chr(39) & "summary-variable" & Chr(39), iPosition:=0) clsSummaryTableFunction.AddParameter("columns_to_summarise", ucrReceiverFirstVars.GetVariableNames) - SummariesInRowsOrCols() + clsSummaryOperator.AddParameter("col_factor", clsRFunctionParameter:=clsPivotWiderFunction, iPosition:=1) End If End If + ThreeVarSummariesVar() + End Sub + + Private Sub ThreeVarSummariesVar() + clsMap2SummaryFunction.RemoveParameterByName(".f") + clsMapSummaryFunction.RemoveParameterByName(".f") + clsSummaryOperator.RemoveParameterByName("right") + clsSummaryOperator.RemoveParameterByName("tableFun") + If rdoThreeVariable.Checked Then + If IsFactorByNumericByFactor() OrElse IsFactorByFactorByNumeric() Then + clsFactorOperator.AddParameter("factors", ucrReceiverFirstVars.GetVariableNames, iPosition:=0, bIncludeArgumentName:=False) + clsSummariesOperator.AddParameter("summary", clsRFunctionParameter:=clsSummariesListFunction, iPosition:=0, bIncludeArgumentName:=False) + clsMap2SummaryFunction.AddParameter(".f", clsROperatorParameter:=clsMapOperator, iPosition:=2) + clsSummaryOperator.AddParameter("right", clsRFunctionParameter:=clsMap2SummaryFunction, iPosition:=2) + + ElseIf IsFactorByNumericByNumeric() Then + clsMapSummaryFunction.AddParameter(".f", clsROperatorParameter:=clsMapOperator, iPosition:=1) + clsSummaryOperator.AddParameter("tableFun", clsRFunctionParameter:=clsMapSummaryFunction, iPosition:=2) + + ElseIf IsFactorByNumericByNumeric() Then + clsMapSummaryFunction.AddParameter(".f", clsROperatorParameter:=clsMapOperator, iPosition:=1) + clsSummaryOperator.AddParameter("tableFun", clsRFunctionParameter:=clsMapSummaryFunction, iPosition:=2) + + ElseIf IsFactorByFactorByFactor() Then + clsMapSummaryFunction.AddParameter(".f", clsROperatorParameter:=clsMapOperator, iPosition:=1) + clsSummaryOperator.AddParameter("tableFun", clsRFunctionParameter:=clsMapSummaryFunction, iPosition:=2) + End If + ElseIf rdoTwoVariable.Checked Then + clsMapSummaryFunction.AddParameter(".f", clsROperatorParameter:=clsMapOperator, iPosition:=1) + clsSummaryOperator.AddParameter("tableFun", clsRFunctionParameter:=clsMapSummaryFunction, iPosition:=2) + End If End Sub Private Sub AddRemoveFirstAnova2Param() @@ -1135,6 +1273,8 @@ Public Class dlgDescribeTwoVariable End Sub Private Sub AddRemoveSecondAnovaParam() + clsCombineSwapAnova2Table.RemoveParameterByName("x") + clsCombineAnova2Function.RemoveParameterByName("x") If rdoThreeVariable.Checked Then If Not ucrReceiverThreeVariableSecondFactor.IsEmpty Then If IsNumericByNumericByFactor() Then @@ -1216,6 +1356,8 @@ Public Class dlgDescribeTwoVariable Else clsCombineAnova2Function.RemoveParameterByName("y") End If + Else + clsCombineAnova2Function.RemoveParameterByName("y") End If End Sub @@ -1262,10 +1404,25 @@ Public Class dlgDescribeTwoVariable End If Next End If + ElseIf rdoThreeVariable.Checked Then + + For Each clsParameter In clsTempFrequency.clsParameters + If IsFactorByFactorByFactor() Then + clsSummaryTableFunction.AddParameter(clsParameter) + Else + If IsFactorByFactorByNumeric() OrElse IsFactorByNumericByFactor() Then + Select Case clsParameter.strArgumentName + Case "signif_fig", "include_margins", "margin_name" + clsSummaryTableFunction.AddParameter(clsParameter) + End Select + End If + End If + Next + End If End Sub - Private Sub Frequencies_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrReceiverPercentages.ControlValueChanged, ucrReceiverColumns.ControlValueChanged, + Private Sub Frequencies_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrReceiverPercentages.ControlValueChanged, ucrChkDisplayAsPercentage.ControlValueChanged, ucrChkDisplayMargins.ControlValueChanged, ucrInputMarginName.ControlValueChanged, ucrpnlPercent.ControlValueChanged If rdoTwoVariable.Checked Then If ucrChkDisplayAsPercentage.Checked Then @@ -1303,7 +1460,16 @@ Public Class dlgDescribeTwoVariable clsCombineFrequencyColParametersFunction.RemoveParameterByName("margin_name") clsCombineFrequencyParametersFunction.RemoveParameterByName("margin_name") End If + If rdoThreeVariable.Checked AndAlso IsFactorByFactorByFactor() OrElse IsFactorByFactorByNumeric() OrElse IsFactorByNumericByFactor() Then + If ucrChkDisplayMargins.Checked Then + ucrInputMarginName.Visible = True + clsThreeVariableCombineFrequencyParametersFunction.AddParameter("margin_name", Chr(34) & ucrInputMarginName.GetText & Chr(34), iPosition:=6) + Else + ucrInputMarginName.Visible = False + clsThreeVariableCombineFrequencyParametersFunction.RemoveParameterByName("margin_name") + End If + End If FactorColumns() AddRemoveFrequencyParameters() AddingColumnFactor() @@ -1426,17 +1592,6 @@ Public Class dlgDescribeTwoVariable ManageControlsVisibility() End Sub - Private Sub SummariesInRowsOrCols() - If ucrChkSummariesRowCol.Checked Then - clsPivotWiderFunction.AddParameter("names_from", "{{ .x }}", iPosition:=1) - clsDummyFunction.AddParameter("row_sum", "True", iPosition:=3) - Else - clsPivotWiderFunction.AddParameter("names_from", Chr(39) & "summary-variable" & Chr(39), iPosition:=1) - clsDummyFunction.AddParameter("row_sum", "False", iPosition:=3) - End If - ManageControlsVisibility() - End Sub - Private Sub ucrReceiverSecondTwoVariableFactor_ValueAndContentChanged(ucrChangedControl As ucrCore) Handles ucrReceiverSecondTwoVariableFactor.ControlValueChanged, ucrReceiverSecondTwoVariableFactor.ControlContentsChanged AssignSecondVariableType() @@ -1449,6 +1604,7 @@ Public Class dlgDescribeTwoVariable AddRemoveFirstAnova2Param() AddRemoveSecondAnovaParam() AddingColumnFactor() + AddRemoveThirdAnovaParam() End Sub Private Sub ChangeFirstTypeLabel() @@ -1524,6 +1680,7 @@ Public Class dlgDescribeTwoVariable AddRemoveThirdAnovaParam() AddRemoveFirstAnova2Param() AddingColumnFactor() + ThreeVarSummariesVar() End Sub Private Sub ucrReceiverThreeVariableSecondFactor_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrReceiverThreeVariableSecondFactor.ControlValueChanged @@ -1533,6 +1690,7 @@ Public Class dlgDescribeTwoVariable AddRemoveSecondCorrParam() AddRemoveSecondAnovaParam() AddRemoveFirstAnova2Param() + UpdateSummaryTableFunction() FactorColumns() ChangeLocations() ChangeSumaryLabelText() @@ -1659,14 +1817,13 @@ Public Class dlgDescribeTwoVariable Next End Sub - Private Sub ucrChkSummariesRowCol_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrChkSummariesRowCol.ControlValueChanged - ManageControlsVisibility() - SummariesInRowsOrCols() - ChangeBaseRCode() - End Sub - Private Sub ucrChkCorrelations_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrChkCorrelations.ControlValueChanged ChangeBaseRCode() + If ucrChkCorrelations.Checked AndAlso Not ucrReceiverFirstVars.IsEmpty Then + clsRCorrelationFunction.AddParameter("x_col_names", ucrReceiverFirstVars.GetVariableNames) + Else + clsRCorrelationFunction.RemoveParameterByName("x_col_names") + End If End Sub Private Sub ucrChkSwapXYVar_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrChkSwapXYVar.ControlValueChanged @@ -1734,6 +1891,19 @@ Public Class dlgDescribeTwoVariable Private Sub AddRemoveTotalParm() clsRAnovaTable2Function.AddParameter("total", If(ucrChkTotal.Checked, "TRUE", "FALSE"), iPosition:=6) clsRAnovaSwapTable2Funtion.AddParameter("total", If(ucrChkTotal.Checked AndAlso ucrChkSwapXYVar.Checked, "TRUE", "FALSE"), iPosition:=6) + End Sub + + Private Sub ucrChkInteraction_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrChkInteraction.ControlValueChanged + AddInteraction() + End Sub + Private Sub AddInteraction() + If rdoThreeVariable.Checked AndAlso ucrChkInteraction.Checked Then + clsRAnovaTable2Function.AddParameter("interaction", "TRUE", iPosition:=7) + clsRAnovaSwapTable2Funtion.AddParameter("interaction", "TRUE", iPosition:=7) + Else + clsRAnovaTable2Function.RemoveParameterByName("interaction") + clsRAnovaSwapTable2Funtion.RemoveParameterByName("interaction") + End If End Sub End Class diff --git a/instat/static/InstatObject/R/Backend_Components/summary_functions.R b/instat/static/InstatObject/R/Backend_Components/summary_functions.R index 06fcf50953..44779cf8d5 100644 --- a/instat/static/InstatObject/R/Backend_Components/summary_functions.R +++ b/instat/static/InstatObject/R/Backend_Components/summary_functions.R @@ -192,7 +192,10 @@ DataBook$set("public", "calculate_summary", function(data_name, columns_to_summa # function_exp <- paste0(function_exp, ", na.rm =", na.rm, ")") if(is.null(result_names)) { result_name = summaries_display[j] - if(include_columns_to_summarise) result_name = paste0(result_name, sep, column_names) + if(include_columns_to_summarise){ + if (!is.null(extra_args$y)) result_name <- paste0(result_name, sep, extra_args$y, sep, column_names) + else result_name <- paste0(result_name, sep, column_names) + } } #TODO result_names could be horizontal/vertical vector, matrix or single value else result_name <- result_names[i,j] diff --git a/instat/static/InstatObject/R/data_object_R6.R b/instat/static/InstatObject/R/data_object_R6.R index 394c50eff4..2bea3ede08 100644 --- a/instat/static/InstatObject/R/data_object_R6.R +++ b/instat/static/InstatObject/R/data_object_R6.R @@ -4645,39 +4645,79 @@ DataSheet$set("public", "has_labels", function(col_names) { } ) -DataSheet$set("public", "anova_tables2", function(x_col_names, y_col_name, total = FALSE, signif.stars = FALSE, sign_level = FALSE, means = FALSE) { - if (missing(x_col_names) || missing(y_col_name)) stop("Both x_col_names and y_col_names are required") +DataSheet$set("public", "anova_tables2", function(x_col_names, y_col_name, total = FALSE, signif.stars = FALSE, sign_level = FALSE, means = FALSE, interaction = FALSE) { + if (missing(x_col_names) || missing(y_col_name)) stop("Both x_col_names and y_col_name are required") if (sign_level || signif.stars) message("This is no longer descriptive") - if (sign_level) end_col = 5 else end_col = 4 + end_col <- if (sign_level) 5 else 4 + # Construct the formula if (length(x_col_names) == 1) { - formula_str <- paste0(as.name(y_col_name), "~ ", as.name(x_col_names)) - } else if (length(x_col_names) > 1) { - formula_str <- paste0(as.name(y_col_name), "~ ", as.name(paste(x_col_names, collapse = " + "))) + formula_str <- paste0(as.name(y_col_name), " ~ ", as.name(x_col_names)) + } else if (interaction && length(x_col_names) > 1) { + formula_str <- paste0(as.name(y_col_name), " ~ ", as.name(paste(x_col_names, collapse = " * "))) + } else { + formula_str <- paste0(as.name(y_col_name), " ~ ", as.name(paste(x_col_names, collapse = " + "))) } - - # Fit the model + mod <- lm(formula = as.formula(formula_str), data = self$get_data_frame()) - anova_mod <- anova(mod)[1:end_col] %>% tibble::as_tibble(rownames = " ") + anova_mod <- anova(mod)[1:end_col] + + # Process ANOVA table + anova_mod <- anova_mod %>% + dplyr::mutate( + `Sum Sq` = signif(`Sum Sq`, 3), + `Mean Sq` = signif(`Mean Sq`, 3), + `F value` = ifelse(`F value` < 100, round(`F value`, 1), round(`F value`)) + ) %>% + dplyr::mutate(`F value` = as.character(`F value`)) %>% + dplyr::mutate(across(`F value`, ~ tidyr::replace_na(., "--"))) %>% + tibble::as_tibble(rownames = " ") # Add the total row if requested - if (total) anova_mod <- anova_mod %>% tibble::add_row(` ` = "Total", dplyr::summarise(., across(where(is.numeric), sum))) - anova_mod$`F value` <- round(anova_mod$`F value`, 4) - if (sign_level) anova_mod$`Pr(>F)` <- format.pval(anova_mod$`Pr(>F)`, digits = 4, eps = 0.001) - cat(paste0("ANOVA of ", formula_str, ":\n")) - print(anova_mod) + if (total) { + anova_mod <- anova_mod %>% + tibble::add_row(` ` = "Total", dplyr::summarise(., across(where(is.numeric), sum))) %>% + dplyr::mutate(`F value` = ifelse(` ` == "Total", "--", `F value`)) # Replace NA with "--" for Total row + } + + # Handle significance levels + if (sign_level) { + anova_mod <- anova_mod %>% + dplyr::mutate( + `Pr(>F)` = ifelse( + is.na(`Pr(>F)`) | !is.numeric(`Pr(>F)`), "--", + ifelse(`Pr(>F)` < 0.001, "<0.001", formatC(`Pr(>F)`, format = "f", digits = 3)) + ) + ) + } + + # Generate the table with a title + title <- paste0("ANOVA of ", formula_str) + formatted_table <- anova_mod %>% + knitr::kable(format = "simple", caption = title) + + print(formatted_table) + + # Add line break before means section cat("\n") - # Optionally print means + + # Optionally print means or model coefficients if (means) { - if (class(mod$model[[x_col_names]]) %in% c("numeric", "integer")){ - cat("Model coefficients:\n") - print(mod$coefficients) - cat("\n") + has_numeric <- any(sapply(x_col_names, function(x) class(mod$model[[x]]) %in% c("numeric", "integer"))) + has_factor <- any(sapply(x_col_names, function(x) class(mod$model[[x]]) == "factor")) + + if (has_numeric && has_factor) { + cat("Model coefficients:\n") + print(mod$coefficients) + } else if (class(mod$model[[x_col_names[[1]]]]) %in% c("numeric", "integer")) { + cat("Model coefficients:\n") + print(mod$coefficients) } else { - cat(paste0("Means table of ", y_col_name, ":\n")) - print(model.tables(aov(mod), type = "means")) - cat("\n") + cat(paste0("Means tables of ", y_col_name, ":\n")) + means_table <- capture.output(model.tables(aov(mod), type = "means")) + means_table <- means_table[-1] + cat(paste(means_table, collapse = "\n")) } } } diff --git a/instat/static/InstatObject/R/instat_object_R6.R b/instat/static/InstatObject/R/instat_object_R6.R index 5270526bc5..b8ccb4a5c6 100644 --- a/instat/static/InstatObject/R/instat_object_R6.R +++ b/instat/static/InstatObject/R/instat_object_R6.R @@ -3043,7 +3043,7 @@ DataBook$set("public","wrap_or_unwrap_data", function(data_name, col_name, colum } ) -DataBook$set("public", "anova_tables2", function(data_name, x_col_names, y_col_name, total = TRUE, signif.stars = FALSE, sign_level = FALSE, means = FALSE) { - self$get_data_objects(data_name)$anova_tables2(x_col_names = x_col_names, y_col_name = y_col_name, total = total, signif.stars = signif.stars, sign_level = sign_level, means = means) +DataBook$set("public", "anova_tables2", function(data_name, x_col_names, y_col_name, total = TRUE, signif.stars = FALSE, sign_level = FALSE, means = FALSE, interaction=FALSE) { + self$get_data_objects(data_name)$anova_tables2(x_col_names = x_col_names, y_col_name = y_col_name, total = total, signif.stars = signif.stars, sign_level = sign_level, means = means, interaction=interaction) } )