Kaydet (Commit) be8a5d44 authored tarafından Tomaž Vajngerl's avatar Tomaž Vajngerl

tdf#74667 Regression dialog: linear, logarithmic, power

Add a new statistics dialog for calculating regression. First
supported regression models are linear, logarithmic and power.

Change-Id: I6fa18136455d4bc4d69edbaa7d19ee6b5b6e5703
üst 1e81e82a
......@@ -744,6 +744,14 @@
<value>1</value>
</prop>
</node>
<node oor:name=".uno:RegressionDialog" oor:op="replace">
<prop oor:name="Label" oor:type="xs:string">
<value xml:lang="en-US">~Regression...</value>
</prop>
<prop oor:name="Properties" oor:type="xs:int">
<value>1</value>
</prop>
</node>
<node oor:name=".uno:TTestDialog" oor:op="replace">
<prop oor:name="Label" oor:type="xs:string">
<value xml:lang="en-US">~t-test...</value>
......
......@@ -508,6 +508,7 @@ $(eval $(call gb_Library_add_exception_objects,sc,\
sc/source/ui/StatisticsDialogs/MatrixComparisonGenerator \
sc/source/ui/StatisticsDialogs/MovingAverageDialog \
sc/source/ui/StatisticsDialogs/RandomNumberGeneratorDialog \
sc/source/ui/StatisticsDialogs/RegressionDialog \
sc/source/ui/StatisticsDialogs/SamplingDialog \
sc/source/ui/StatisticsDialogs/StatisticsInputOutputDialog \
sc/source/ui/StatisticsDialogs/StatisticsTwoVariableDialog \
......
......@@ -138,6 +138,7 @@ $(eval $(call gb_UIConfig_add_uifiles,modules/scalc,\
sc/uiconfig/scalc/ui/protectsheetdlg \
sc/uiconfig/scalc/ui/queryrunstreamscriptdialog \
sc/uiconfig/scalc/ui/randomnumbergenerator \
sc/uiconfig/scalc/ui/regressiondialog \
sc/uiconfig/scalc/ui/retypepassdialog \
sc/uiconfig/scalc/ui/retypepassworddialog \
sc/uiconfig/scalc/ui/rightfooterdialog \
......
......@@ -269,11 +269,12 @@
#define SID_COVARIANCE_DIALOG (SC_MESSAGE_START + 75)
#define SID_EXPONENTIAL_SMOOTHING_DIALOG (SC_MESSAGE_START + 76)
#define SID_MOVING_AVERAGE_DIALOG (SC_MESSAGE_START + 77)
#define SID_TTEST_DIALOG (SC_MESSAGE_START + 78)
#define SID_FTEST_DIALOG (SC_MESSAGE_START + 79)
#define SID_ZTEST_DIALOG (SC_MESSAGE_START + 80)
#define SID_CHI_SQUARE_TEST_DIALOG (SC_MESSAGE_START + 81)
#define SID_SEARCH_RESULTS_DIALOG (SC_MESSAGE_START + 82)
#define SID_REGRESSION_DIALOG (SC_MESSAGE_START + 78)
#define SID_TTEST_DIALOG (SC_MESSAGE_START + 79)
#define SID_FTEST_DIALOG (SC_MESSAGE_START + 80)
#define SID_ZTEST_DIALOG (SC_MESSAGE_START + 81)
#define SID_CHI_SQUARE_TEST_DIALOG (SC_MESSAGE_START + 82)
#define SID_SEARCH_RESULTS_DIALOG (SC_MESSAGE_START + 83)
// functions
......
......@@ -162,6 +162,7 @@ interface CellSelection
SID_CORRELATION_DIALOG [ ExecMethod = ExecuteEdit; StateMethod = GetBlockState; ]
SID_COVARIANCE_DIALOG [ ExecMethod = ExecuteEdit; StateMethod = GetBlockState; ]
SID_EXPONENTIAL_SMOOTHING_DIALOG [ ExecMethod = ExecuteEdit; StateMethod = GetBlockState; ]
SID_REGRESSION_DIALOG [ ExecMethod = ExecuteEdit; StateMethod = GetBlockState; ]
SID_MOVING_AVERAGE_DIALOG [ ExecMethod = ExecuteEdit; StateMethod = GetBlockState; ]
SID_TTEST_DIALOG [ ExecMethod = ExecuteEdit; StateMethod = GetBlockState; ]
SID_FTEST_DIALOG [ ExecMethod = ExecuteEdit; StateMethod = GetBlockState; ]
......
......@@ -3159,6 +3159,30 @@ SfxVoidItem MovingAverageDialog SID_MOVING_AVERAGE_DIALOG
GroupId = GID_OPTIONS;
]
SfxVoidItem RegressionDialog SID_REGRESSION_DIALOG
()
[
/* flags: */
AutoUpdate = FALSE,
Cachable = Cachable,
FastCall = FALSE,
HasCoreId = FALSE,
HasDialog = TRUE,
ReadOnlyDoc = TRUE,
Toggle = FALSE,
Container = FALSE,
RecordAbsolute = FALSE,
RecordPerSet;
Synchron;
/* config: */
AccelConfig = TRUE,
MenuConfig = TRUE,
StatusBarConfig = FALSE,
ToolBoxConfig = TRUE,
GroupId = GID_OPTIONS;
]
SfxVoidItem TTestDialog SID_TTEST_DIALOG
()
[
......
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
*/
#include <sfx2/dispatch.hxx>
#include <svl/zforlist.hxx>
#include <svl/undo.hxx>
#include "formulacell.hxx"
#include "rangelst.hxx"
#include "scitems.hxx"
#include "docsh.hxx"
#include "document.hxx"
#include "uiitems.hxx"
#include "reffact.hxx"
#include "strload.hxx"
#include "docfunc.hxx"
#include "StatisticsDialogs.hrc"
#include "TableFillingAndNavigationTools.hxx"
#include "RegressionDialog.hxx"
namespace
{
sal_Int16 constRegressionModel[] =
{
STR_LABEL_LINEAR,
STR_LABEL_LOGARITHMIC,
STR_LABEL_POWER
};
OUString constTemplateRSQUARED[] =
{
"=RSQ(%VARIABLE2_RANGE% ; %VARIABLE1_RANGE%)",
"=RSQ(%VARIABLE2_RANGE% ; LN(%VARIABLE1_RANGE%))",
"=RSQ(LN(%VARIABLE2_RANGE%) ; LN(%VARIABLE1_RANGE%))"
};
OUString constTemplatesSTDERR[] =
{
"=STEYX(%VARIABLE2_RANGE% ; %VARIABLE1_RANGE%)",
"=STEYX(%VARIABLE2_RANGE% ; LN(%VARIABLE1_RANGE%))",
"=STEYX(LN(%VARIABLE2_RANGE%) ; LN(%VARIABLE1_RANGE%))"
};
OUString constTemplatesSLOPE[] =
{
"=SLOPE(%VARIABLE2_RANGE% ; %VARIABLE1_RANGE%)",
"=SLOPE(%VARIABLE2_RANGE% ; LN(%VARIABLE1_RANGE%))",
"=EXP(INTERCEPT(LN(%VARIABLE2_RANGE%) ; LN(%VARIABLE1_RANGE%)))"
};
OUString constTemplatesINTERCEPT[] =
{
"=INTERCEPT(%VARIABLE2_RANGE% ; %VARIABLE1_RANGE%)",
"=INTERCEPT(%VARIABLE2_RANGE% ; LN(%VARIABLE1_RANGE%))",
"=SLOPE(LN(%VARIABLE2_RANGE%) ; LN(%VARIABLE1_RANGE%))"
};
OUString constRegressionFormula[] =
{
"=%A% * %ADDRESS% + %B%",
"=%A% * LN(%ADDRESS%) + %B%",
"=%A% * %ADDRESS% ^ %B%"
};
} // end anonymous namespace
ScRegressionDialog::ScRegressionDialog(
SfxBindings* pSfxBindings, SfxChildWindow* pChildWindow,
vcl::Window* pParent, ScViewData* pViewData ) :
ScStatisticsTwoVariableDialog(
pSfxBindings, pChildWindow, pParent, pViewData,
"RegressionDialog", "modules/scalc/ui/regressiondialog.ui" )
{
get(mpLinearCheckBox, "linear-check");
get(mpLogarithmicCheckBox, "logarithmic-check");
get(mpPowerCheckBox, "power-check");
}
ScRegressionDialog::~ScRegressionDialog()
{}
bool ScRegressionDialog::Close()
{
return DoClose(ScRegressionDialogWrapper::GetChildWindowId());
}
sal_Int16 ScRegressionDialog::GetUndoNameId()
{
return STR_REGRESSION_UNDO_NAME;
}
ScRange ScRegressionDialog::ApplyOutput(ScDocShell* pDocShell)
{
AddressWalkerWriter aOutput(mOutputAddress, pDocShell, mDocument,
formula::FormulaGrammar::mergeToGrammar( formula::FormulaGrammar::GRAM_ENGLISH, mAddressDetails.eConv));
FormulaTemplate aTemplate(mDocument);
aTemplate.autoReplaceUses3D(false);
std::unique_ptr<DataRangeIterator> pVariable1Iterator;
if (mGroupedBy == BY_COLUMN)
pVariable1Iterator.reset(new DataRangeByColumnIterator(mVariable1Range));
else
pVariable1Iterator.reset(new DataRangeByRowIterator(mVariable1Range));
std::unique_ptr<DataRangeIterator> pVariable2Iterator;
if (mGroupedBy == BY_COLUMN)
pVariable2Iterator.reset(new DataRangeByColumnIterator(mVariable2Range));
else
pVariable2Iterator.reset(new DataRangeByRowIterator(mVariable2Range));
aTemplate.autoReplaceRange("%VARIABLE1_RANGE%", pVariable1Iterator->get());
aTemplate.autoReplaceRange("%VARIABLE2_RANGE%", pVariable2Iterator->get());
aOutput.writeBoldString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_REGRESSION));
aOutput.newLine();
aOutput.newLine();
aOutput.push();
// REGRESSION MODEL
aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_LABEL_REGRESSION_MODEL));
aOutput.nextRow();
// RSQUARED
aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_LABEL_RSQUARED));
aOutput.nextRow();
// Standard Error
aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STRID_CALC_STD_ERROR));
aOutput.nextRow();
aOutput.nextRow();
// Slope
aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_LABEL_SLOPE));
aOutput.nextRow();
// Intercept
aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_LABEL_INTERCEPT));
aOutput.nextRow();
aOutput.nextRow();
size_t nVariable1Size = pVariable1Iterator->size();
OUString sFormula;
if (mGroupedBy == BY_COLUMN)
sFormula = "=INDEX(%VARIABLE1_RANGE%; %VAR1_CELL_INDEX%; 1)";
else
sFormula = "=INDEX(%VARIABLE1_RANGE%; 1; %VAR1_CELL_INDEX%)";
for (size_t i = 0; i < nVariable1Size; i++)
{
aTemplate.setTemplate(sFormula);
aTemplate.applyNumber("%VAR1_CELL_INDEX%", i + 1);
aOutput.writeFormula(aTemplate.getTemplate());
aOutput.nextRow();
}
aOutput.reset();
bool aEnabledRegressionTypes[3];
aEnabledRegressionTypes[0] = mpLinearCheckBox->IsChecked();
aEnabledRegressionTypes[1] = mpLogarithmicCheckBox->IsChecked();
aEnabledRegressionTypes[2] = mpPowerCheckBox->IsChecked();
sal_Int16 nColumn = 0;
for (size_t nRegressionIndex = 0; nRegressionIndex < SAL_N_ELEMENTS(aEnabledRegressionTypes); ++nRegressionIndex)
{
if (!aEnabledRegressionTypes[nRegressionIndex])
continue;
aOutput.nextColumn();
nColumn += 1;
// REGRESSION MODEL
aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, constRegressionModel[nRegressionIndex]));
aOutput.nextRow();
// RSQUARED
aTemplate.setTemplate(constTemplateRSQUARED[nRegressionIndex]);
aOutput.writeMatrixFormula(aTemplate.getTemplate());
aTemplate.autoReplaceAddress("%RSQUARED%", aOutput.current());
aOutput.nextRow();
// Standard Error
aTemplate.setTemplate(constTemplatesSTDERR[nRegressionIndex]);
aOutput.writeMatrixFormula(aTemplate.getTemplate());
aTemplate.autoReplaceAddress("%STD_ERROR%", aOutput.current());
aOutput.nextRow();
aOutput.nextRow();
// Slope
aTemplate.setTemplate(constTemplatesSLOPE[nRegressionIndex]);
aOutput.writeMatrixFormula(aTemplate.getTemplate());
aTemplate.autoReplaceAddress("%A%", aOutput.current());
aOutput.nextRow();
// Intercept
aTemplate.setTemplate(constTemplatesINTERCEPT[nRegressionIndex]);
aOutput.writeMatrixFormula(aTemplate.getTemplate());
aTemplate.autoReplaceAddress("%B%", aOutput.current());
aOutput.nextRow();
aOutput.nextRow();
for (size_t i = 0; i < nVariable1Size; i++)
{
aTemplate.setTemplate(constRegressionFormula[nRegressionIndex]);
aTemplate.applyAddress("%ADDRESS%", aOutput.current(-nColumn), false);
aOutput.writeFormula(aTemplate.getTemplate());
aOutput.nextRow();
}
aOutput.resetRow();
}
return ScRange(aOutput.mMinimumAddress, aOutput.mMaximumAddress);
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -55,13 +55,15 @@
#define STR_COVARIANCE_UNDO_NAME 63
#define STR_EXPONENTIAL_SMOOTHING_UNDO_NAME 64
#define STR_MOVING_AVERAGE_UNDO_NAME 65
#define STR_TTEST 66
#define STR_TTEST_UNDO_NAME 67
#define STR_FTEST 68
#define STR_FTEST_UNDO_NAME 69
#define STR_ZTEST 70
#define STR_ZTEST_UNDO_NAME 71
#define STR_CHI_SQUARE_TEST 72
#define STR_REGRESSION 66
#define STR_REGRESSION_UNDO_NAME 67
#define STR_TTEST 68
#define STR_TTEST_UNDO_NAME 69
#define STR_FTEST 70
#define STR_FTEST_UNDO_NAME 71
#define STR_ZTEST 72
#define STR_ZTEST_UNDO_NAME 73
#define STR_CHI_SQUARE_TEST 74
#define STR_COLUMN_LABEL_TEMPLATE 100
#define STR_ROW_LABEL_TEMPLATE 101
......@@ -93,6 +95,15 @@
#define STR_CRITICAL_VALUE_LABEL 150
#define STR_TEST_STATISTIC_LABEL 151
#define STR_LABEL_LINEAR 160
#define STR_LABEL_LOGARITHMIC 161
#define STR_LABEL_POWER 162
#define STR_LABEL_REGRESSION_MODEL 170
#define STR_LABEL_RSQUARED 171
#define STR_LABEL_SLOPE 172
#define STR_LABEL_INTERCEPT 173
#define STR_FTEST_P_RIGHT_TAIL 200
#define STR_FTEST_F_CRITICAL_RIGHT_TAIL 201
#define STR_FTEST_P_LEFT_TAIL 202
......
......@@ -305,6 +305,14 @@ Resource RID_STATISTICS_DLGS
{
Text [ en-US ] = "Test of Independence (Chi-Square)";
};
String STR_REGRESSION_UNDO_NAME
{
Text [ en-US ] = "Regression";
};
String STR_REGRESSION
{
Text [ en-US ] = "Regression";
};
/* Common */
String STR_COLUMN_LABEL_TEMPLATE
......@@ -356,6 +364,38 @@ Resource RID_STATISTICS_DLGS
Text [ en-US ] = "Test Statistic";
};
/* RegressionDialog */
String STR_LABEL_LINEAR
{
Text [ en-US ] = "Linear";
};
String STR_LABEL_LOGARITHMIC
{
Text [ en-US ] = "Logarithmic";
};
String STR_LABEL_POWER
{
Text [ en-US ] = "Power";
};
String STR_LABEL_REGRESSION_MODEL
{
Text [ en-US ] = "Regression Model";
};
String STR_LABEL_RSQUARED
{
Text [ en-US ] = "R^2";
};
String STR_LABEL_SLOPE
{
Text [ en-US ] = "Slope";
};
String STR_LABEL_INTERCEPT
{
Text [ en-US ] = "Intercept";
};
/*F Test */
String STR_FTEST_P_RIGHT_TAIL
{
......
......@@ -243,6 +243,7 @@ void ScDLL::Init()
ScCovarianceDialogWrapper ::RegisterChildWindow(false, pMod);
ScExponentialSmoothingDialogWrapper ::RegisterChildWindow(false, pMod);
ScMovingAverageDialogWrapper ::RegisterChildWindow(false, pMod);
ScRegressionDialogWrapper ::RegisterChildWindow(false, pMod);
ScTTestDialogWrapper ::RegisterChildWindow(false, pMod);
ScFTestDialogWrapper ::RegisterChildWindow(false, pMod);
ScZTestDialogWrapper ::RegisterChildWindow(false, pMod);
......
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
*/
#ifndef INCLUDED_SC_SOURCE_UI_INC_REGRESSIONDIALOG_HXX
#define INCLUDED_SC_SOURCE_UI_INC_REGRESSIONDIALOG_HXX
#include "StatisticsTwoVariableDialog.hxx"
class ScRegressionDialog : public ScStatisticsTwoVariableDialog
{
VclPtr<CheckBox> mpLinearCheckBox;
VclPtr<CheckBox> mpLogarithmicCheckBox;
VclPtr<CheckBox> mpPowerCheckBox;
public:
ScRegressionDialog(
SfxBindings* pB, SfxChildWindow* pCW,
vcl::Window* pParent, ScViewData* pViewData );
virtual ~ScRegressionDialog();
virtual bool Close() override;
protected:
virtual sal_Int16 GetUndoNameId() override;
virtual ScRange ApplyOutput(ScDocShell* pDocShell) override;
};
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -108,6 +108,13 @@ private:
ScMovingAverageDialogWrapper() = delete;
};
class ScRegressionDialogWrapper :
public ChildWindowWrapper<SID_REGRESSION_DIALOG>
{
private:
ScRegressionDialogWrapper() = delete;
};
class ScTTestDialogWrapper :
public ChildWindowWrapper<SID_TTEST_DIALOG>
{
......
......@@ -985,6 +985,15 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq )
pScMod->SetRefDialog( nId, pWnd == nullptr );
}
break;
case SID_REGRESSION_DIALOG:
{
sal_uInt16 nId = ScRegressionDialogWrapper::GetChildWindowId();
SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
pScMod->SetRefDialog( nId, pWnd == nullptr );
}
break;
case SID_TTEST_DIALOG:
{
sal_uInt16 nId = ScTTestDialogWrapper::GetChildWindowId();
......
......@@ -96,6 +96,7 @@ void ScTabViewShell::InitInterface_Impl()
GetStaticInterface()->RegisterChildWindow(ScCovarianceDialogWrapper::GetChildWindowId());
GetStaticInterface()->RegisterChildWindow(ScExponentialSmoothingDialogWrapper::GetChildWindowId());
GetStaticInterface()->RegisterChildWindow(ScMovingAverageDialogWrapper::GetChildWindowId());
GetStaticInterface()->RegisterChildWindow(ScRegressionDialogWrapper::GetChildWindowId());
GetStaticInterface()->RegisterChildWindow(ScTTestDialogWrapper::GetChildWindowId());
GetStaticInterface()->RegisterChildWindow(ScFTestDialogWrapper::GetChildWindowId());
GetStaticInterface()->RegisterChildWindow(ScZTestDialogWrapper::GetChildWindowId());
......
......@@ -66,6 +66,7 @@
#include "CovarianceDialog.hxx"
#include "ExponentialSmoothingDialog.hxx"
#include "MovingAverageDialog.hxx"
#include "RegressionDialog.hxx"
#include "TTestDialog.hxx"
#include "FTestDialog.hxx"
#include "ZTestDialog.hxx"
......@@ -371,6 +372,12 @@ VclPtr<SfxModelessDialog> ScTabViewShell::CreateRefDialog(
}
break;
case SID_REGRESSION_DIALOG:
{
pResult = VclPtr<ScRegressionDialog>::Create( pB, pCW, pParent, &GetViewData() );
}
break;
case SID_TTEST_DIALOG:
{
pResult = VclPtr<ScTTestDialog>::Create( pB, pCW, pParent, &GetViewData() );
......
......@@ -545,6 +545,7 @@
<menu:menuitem menu:id=".uno:CovarianceDialog"/>
<menu:menuitem menu:id=".uno:ExponentialSmoothingDialog"/>
<menu:menuitem menu:id=".uno:MovingAverageDialog"/>
<menu:menuitem menu:id=".uno:RegressionDialog"/>
<menu:menuitem menu:id=".uno:TTestDialog"/>
<menu:menuitem menu:id=".uno:FTestDialog"/>
<menu:menuitem menu:id=".uno:ZTestDialog"/>
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment