summaryrefslogtreecommitdiff
path: root/sc/source/ui
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.com>2014-11-15 18:13:45 +0100
committerTomaž Vajngerl <tomaz.vajngerl@collabora.com>2014-11-15 18:42:48 +0100
commit475c2a083965cf358414f9ddb7d8e191f547a9d9 (patch)
tree174d824b4af236df4f38d43e54734aa1f9bd38df /sc/source/ui
parent225af09be9ae7b10aaf5bf0e3714c74c5a2f1391 (diff)
fdo#74669 Add z-test Statistics Dialog
Change-Id: I8169e9ceefc48c06b358d5a8e1fc08dabf019eb3
Diffstat (limited to 'sc/source/ui')
-rw-r--r--sc/source/ui/StatisticsDialogs/StatisticsDialogs.hrc11
-rw-r--r--sc/source/ui/StatisticsDialogs/StatisticsDialogs.src42
-rw-r--r--sc/source/ui/StatisticsDialogs/ZTestDialog.cxx179
-rw-r--r--sc/source/ui/app/scdll.cxx1
-rw-r--r--sc/source/ui/inc/ZTestDialog.hxx34
-rw-r--r--sc/source/ui/inc/reffact.hxx7
-rw-r--r--sc/source/ui/view/cellsh1.cxx10
-rw-r--r--sc/source/ui/view/tabvwsh.cxx1
-rw-r--r--sc/source/ui/view/tabvwshc.cxx7
9 files changed, 287 insertions, 5 deletions
diff --git a/sc/source/ui/StatisticsDialogs/StatisticsDialogs.hrc b/sc/source/ui/StatisticsDialogs/StatisticsDialogs.hrc
index 2574797c6f5a..c4fdd4c950cb 100644
--- a/sc/source/ui/StatisticsDialogs/StatisticsDialogs.hrc
+++ b/sc/source/ui/StatisticsDialogs/StatisticsDialogs.hrc
@@ -59,6 +59,8 @@
#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_COLUMN_LABEL_TEMPLATE 100
#define STR_ROW_LABEL_TEMPLATE 101
@@ -84,6 +86,7 @@
#define STR_VARIABLE_2_LABEL 134
#define STR_HYPOTHESIZED_MEAN_DIFFERENCE_LABEL 135
#define STR_OBSERVATIONS_LABEL 136
+#define STR_OBSERVED_MEAN_DIFFERENCE_LABEL 137
#define STR_FTEST_P_RIGHT_TAIL 140
#define STR_FTEST_F_CRITICAL_RIGHT_TAIL 141
@@ -93,7 +96,6 @@
#define STR_FTEST_F_CRITICAL_TWO_TAIL 145
#define STR_TTEST_PEARSON_CORRELATION 150
-#define STR_TTEST_OBSERVED_MEAN_DIFFERENCE 151
#define STR_TTEST_VARIANCE_OF_THE_DIFFERENCES 152
#define STR_TTEST_T_STAT 153
#define STR_TTEST_P_ONE_TAIL 154
@@ -101,4 +103,11 @@
#define STR_TTEST_P_TWO_TAIL 156
#define STR_TTEST_T_CRITICAL_TWO_TAIL 157
+#define STR_ZTEST_KNOWN_VARIANCE 160
+#define STR_ZTEST_Z_VALUE 161
+#define STR_ZTEST_P_ONE_TAIL 162
+#define STR_ZTEST_Z_CRITICAL_ONE_TAIL 163
+#define STR_ZTEST_P_TWO_TAIL 164
+#define STR_ZTEST_Z_CRITICAL_TWO_TAIL 165
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/StatisticsDialogs/StatisticsDialogs.src b/sc/source/ui/StatisticsDialogs/StatisticsDialogs.src
index 49c9575b9c37..f6865627d232 100644
--- a/sc/source/ui/StatisticsDialogs/StatisticsDialogs.src
+++ b/sc/source/ui/StatisticsDialogs/StatisticsDialogs.src
@@ -292,6 +292,14 @@ Resource RID_STATISTICS_DLGS
{
Text [ en-US ] = "t-test";
};
+ String STR_ZTEST
+ {
+ Text [ en-US ] = "z-test";
+ };
+ String STR_ZTEST_UNDO_NAME
+ {
+ Text [ en-US ] = "z-test";
+ };
/* Common */
String STR_COLUMN_LABEL_TEMPLATE
@@ -322,6 +330,10 @@ Resource RID_STATISTICS_DLGS
{
Text [ en-US ] = "Observations";
};
+ String STR_OBSERVED_MEAN_DIFFERENCE_LABEL
+ {
+ Text [ en-US ] = "Observed Mean Difference";
+ };
/*F Test */
String STR_FTEST_P_RIGHT_TAIL
@@ -354,10 +366,6 @@ Resource RID_STATISTICS_DLGS
{
Text [ en-US ] = "Pearson Correlation";
};
- String STR_TTEST_OBSERVED_MEAN_DIFFERENCE
- {
- Text [ en-US ] = "Observed Mean Difference";
- };
String STR_TTEST_VARIANCE_OF_THE_DIFFERENCES
{
Text [ en-US ] = "Variance of the Differences";
@@ -382,6 +390,32 @@ Resource RID_STATISTICS_DLGS
{
Text [ en-US ] = "t Critical two-tail";
};
+
+ /*Z Test*/
+ String STR_ZTEST_Z_VALUE
+ {
+ Text [ en-US ] = "z";
+ };
+ String STR_ZTEST_KNOWN_VARIANCE
+ {
+ Text [ en-US ] = "Known Variance";
+ };
+ String STR_ZTEST_P_ONE_TAIL
+ {
+ Text [ en-US ] = "P (Z<=z) one-tail";
+ };
+ String STR_ZTEST_Z_CRITICAL_ONE_TAIL
+ {
+ Text [ en-US ] = "z Critical one-tail";
+ };
+ String STR_ZTEST_P_TWO_TAIL
+ {
+ Text [ en-US ] = "P (Z<=z) two-tail";
+ };
+ String STR_ZTEST_Z_CRITICAL_TWO_TAIL
+ {
+ Text [ en-US ] = "z Critical two-tail";
+ };
};
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/StatisticsDialogs/ZTestDialog.cxx b/sc/source/ui/StatisticsDialogs/ZTestDialog.cxx
new file mode 100644
index 000000000000..4ab24c4ffbf7
--- /dev/null
+++ b/sc/source/ui/StatisticsDialogs/ZTestDialog.cxx
@@ -0,0 +1,179 @@
+/* -*- 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 <boost/random.hpp>
+#include <boost/scoped_ptr.hpp>
+
+#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 "ZTestDialog.hxx"
+
+ScZTestDialog::ScZTestDialog(
+ SfxBindings* pSfxBindings, SfxChildWindow* pChildWindow,
+ vcl::Window* pParent, ScViewData* pViewData ) :
+ ScStatisticsTwoVariableDialog(
+ pSfxBindings, pChildWindow, pParent, pViewData,
+ "ZTestDialog", "modules/scalc/ui/ztestdialog.ui" )
+{
+ SetText(SC_STRLOAD(RID_STATISTICS_DLGS, STR_ZTEST));
+}
+
+ScZTestDialog::~ScZTestDialog()
+{}
+
+bool ScZTestDialog::Close()
+{
+ return DoClose( ScZTestDialogWrapper::GetChildWindowId() );
+}
+
+sal_Int16 ScZTestDialog::GetUndoNameId()
+{
+ return STR_ZTEST_UNDO_NAME;
+}
+
+ScRange ScZTestDialog::ApplyOutput(ScDocShell* pDocShell)
+{
+ AddressWalkerWriter aOutput(mOutputAddress, pDocShell, mDocument,
+ formula::FormulaGrammar::mergeToGrammar( formula::FormulaGrammar::GRAM_ENGLISH, mAddressDetails.eConv));
+ FormulaTemplate aTemplate(mDocument);
+
+ boost::scoped_ptr<DataRangeIterator> pVariable1Iterator;
+ if (mGroupedBy == BY_COLUMN)
+ pVariable1Iterator.reset(new DataRangeByColumnIterator(mVariable1Range));
+ else
+ pVariable1Iterator.reset(new DataRangeByRowIterator(mVariable1Range));
+
+ boost::scoped_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_ZTEST));
+ aOutput.newLine();
+
+ // Alpha
+ aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_LABEL_ALPHA));
+ aOutput.nextColumn();
+ aOutput.writeValue(0.05);
+ aTemplate.autoReplaceAddress("%ALPHA%", aOutput.current());
+ aOutput.newLine();
+
+ // Hypothesized mean difference
+ aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_HYPOTHESIZED_MEAN_DIFFERENCE_LABEL));
+ aOutput.nextColumn();
+ aOutput.writeValue(0);
+ aTemplate.autoReplaceAddress("%HYPOTHESIZED_MEAN_DIFFERENCE%", aOutput.current());
+ aOutput.newLine();
+
+ // Variable Label
+ aOutput.nextColumn();
+ aOutput.writeBoldString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_VARIABLE_1_LABEL));
+ aOutput.nextColumn();
+ aOutput.writeBoldString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_VARIABLE_2_LABEL));
+ aOutput.newLine();
+
+ // Known Variance
+ aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_ZTEST_KNOWN_VARIANCE));
+ aOutput.nextColumn();
+ aOutput.writeValue(0);
+ aTemplate.autoReplaceAddress("%KNOWN_VARIANCE_VARIABLE1%", aOutput.current());
+ aOutput.nextColumn();
+ aOutput.writeValue(0);
+ aTemplate.autoReplaceAddress("%KNOWN_VARIANCE_VARIABLE2%", aOutput.current());
+ aOutput.newLine();
+
+ // Mean
+ aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STRID_CALC_MEAN));
+ aOutput.nextColumn();
+ aTemplate.setTemplate("=AVERAGE(%VARIABLE1_RANGE%)");
+ aTemplate.autoReplaceAddress("%MEAN_VARIABLE1%", aOutput.current());
+ aOutput.writeFormula(aTemplate.getTemplate());
+ aOutput.nextColumn();
+ aTemplate.setTemplate("=AVERAGE(%VARIABLE2_RANGE%)");
+ aTemplate.autoReplaceAddress("%MEAN_VARIABLE2%", aOutput.current());
+ aOutput.writeFormula(aTemplate.getTemplate());
+ aOutput.newLine();
+
+ // Observations
+ aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_OBSERVATIONS_LABEL));
+ aOutput.nextColumn();
+ aTemplate.setTemplate("=COUNT(%VARIABLE1_RANGE%)");
+ aOutput.writeFormula(aTemplate.getTemplate());
+ aTemplate.autoReplaceAddress("%OBSERVATION_VARIABLE1%", aOutput.current());
+ aOutput.nextColumn();
+ aTemplate.setTemplate("=COUNT(%VARIABLE2_RANGE%)");
+ aOutput.writeFormula(aTemplate.getTemplate());
+ aTemplate.autoReplaceAddress("%OBSERVATION_VARIABLE2%", aOutput.current());
+ aOutput.newLine();
+
+ // Observed mean difference
+ aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_OBSERVED_MEAN_DIFFERENCE_LABEL));
+ aOutput.nextColumn();
+ aTemplate.setTemplate("=%MEAN_VARIABLE1% - %MEAN_VARIABLE2%");
+ aOutput.writeMatrixFormula(aTemplate.getTemplate());
+ aTemplate.autoReplaceAddress("%OBSERVED_MEAN_DIFFERENCE%", aOutput.current());
+ aOutput.newLine();
+
+ // z
+ aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_ZTEST_Z_VALUE));
+ aOutput.nextColumn();
+ aTemplate.setTemplate("=(%OBSERVED_MEAN_DIFFERENCE% - %HYPOTHESIZED_MEAN_DIFFERENCE%) / SQRT( %KNOWN_VARIANCE_VARIABLE1% / %OBSERVATION_VARIABLE1% + %KNOWN_VARIANCE_VARIABLE2% / %OBSERVATION_VARIABLE2% )");
+ aOutput.writeFormula(aTemplate.getTemplate());
+ aTemplate.autoReplaceAddress("%Z_STAT%", aOutput.current());
+ aOutput.newLine();
+
+ // P one-tail
+ aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_ZTEST_P_ONE_TAIL));
+ aOutput.nextColumn();
+ aTemplate.setTemplate("=1 - NORMSDIST(ABS(%Z_STAT%))");
+ aOutput.writeFormula(aTemplate.getTemplate());
+ aOutput.newLine();
+
+ // z critical one-tail
+ aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_ZTEST_Z_CRITICAL_ONE_TAIL));
+ aOutput.nextColumn();
+ aTemplate.setTemplate("=-NORMSINV(%ALPHA%)");
+ aOutput.writeFormula(aTemplate.getTemplate());
+ aOutput.newLine();
+
+ // P two-tail
+ aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_ZTEST_P_TWO_TAIL));
+ aOutput.nextColumn();
+ aTemplate.setTemplate("=2 * NORMSDIST(-ABS(%Z_STAT%))");
+ aOutput.writeFormula(aTemplate.getTemplate());
+ aOutput.newLine();
+
+ // z critical two-tail
+ aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_ZTEST_Z_CRITICAL_TWO_TAIL));
+ aOutput.nextColumn();
+ aTemplate.setTemplate("=-NORMSINV(%ALPHA%/2)");
+ aOutput.writeFormula(aTemplate.getTemplate());
+
+ return ScRange(aOutput.mMinimumAddress, aOutput.mMaximumAddress);
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/app/scdll.cxx b/sc/source/ui/app/scdll.cxx
index d94522205a28..d62004964da2 100644
--- a/sc/source/ui/app/scdll.cxx
+++ b/sc/source/ui/app/scdll.cxx
@@ -259,6 +259,7 @@ void ScDLL::Init()
ScMovingAverageDialogWrapper ::RegisterChildWindow(false, pMod);
ScTTestDialogWrapper ::RegisterChildWindow(false, pMod);
ScFTestDialogWrapper ::RegisterChildWindow(false, pMod);
+ ScZTestDialogWrapper ::RegisterChildWindow(false, pMod);
// First docking Window for Calc
ScFunctionChildWindow ::RegisterChildWindow(false, pMod);
diff --git a/sc/source/ui/inc/ZTestDialog.hxx b/sc/source/ui/inc/ZTestDialog.hxx
new file mode 100644
index 000000000000..8af6f14ee65a
--- /dev/null
+++ b/sc/source/ui/inc/ZTestDialog.hxx
@@ -0,0 +1,34 @@
+/* -*- 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_ZTESTDIALOG_HXX
+#define INCLUDED_SC_SOURCE_UI_INC_ZTESTDIALOG_HXX
+
+#include "StatisticsTwoVariableDialog.hxx"
+
+class ScZTestDialog : public ScStatisticsTwoVariableDialog
+{
+public:
+ ScZTestDialog(
+ SfxBindings* pB, SfxChildWindow* pCW,
+ vcl::Window* pParent, ScViewData* pViewData );
+
+ virtual ~ScZTestDialog();
+
+ virtual bool Close() SAL_OVERRIDE;
+
+protected:
+ virtual sal_Int16 GetUndoNameId() SAL_OVERRIDE;
+ virtual ScRange ApplyOutput(ScDocShell* pDocShell) SAL_OVERRIDE;
+};
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/inc/reffact.hxx b/sc/source/ui/inc/reffact.hxx
index 7ae4a9f0a29e..4fd3b270d631 100644
--- a/sc/source/ui/inc/reffact.hxx
+++ b/sc/source/ui/inc/reffact.hxx
@@ -121,6 +121,13 @@ private:
ScFTestDialogWrapper() SAL_DELETED_FUNCTION;
};
+class ScZTestDialogWrapper :
+ public ChildWindowWrapper<SID_ZTEST_DIALOG>
+{
+private:
+ ScZTestDialogWrapper() SAL_DELETED_FUNCTION;
+};
+
class ScAcceptChgDlgWrapper: public SfxChildWindow
{
public:
diff --git a/sc/source/ui/view/cellsh1.cxx b/sc/source/ui/view/cellsh1.cxx
index 32c237daa2ad..624b77dc8e14 100644
--- a/sc/source/ui/view/cellsh1.cxx
+++ b/sc/source/ui/view/cellsh1.cxx
@@ -992,6 +992,16 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq )
}
break;
+ case SID_ZTEST_DIALOG:
+ {
+ sal_uInt16 nId = ScZTestDialogWrapper::GetChildWindowId();
+ SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
+ SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
+
+ pScMod->SetRefDialog( nId, pWnd ? false : sal_True );
+
+ }
+ break;
case SID_SEARCH_RESULTS_DIALOG:
{
diff --git a/sc/source/ui/view/tabvwsh.cxx b/sc/source/ui/view/tabvwsh.cxx
index 51aaae8facef..d07feb7bb453 100644
--- a/sc/source/ui/view/tabvwsh.cxx
+++ b/sc/source/ui/view/tabvwsh.cxx
@@ -95,6 +95,7 @@ void ScTabViewShell::InitInterface_Impl()
GetStaticInterface()->RegisterChildWindow(ScMovingAverageDialogWrapper::GetChildWindowId());
GetStaticInterface()->RegisterChildWindow(ScTTestDialogWrapper::GetChildWindowId());
GetStaticInterface()->RegisterChildWindow(ScFTestDialogWrapper::GetChildWindowId());
+ GetStaticInterface()->RegisterChildWindow(ScZTestDialogWrapper::GetChildWindowId());
}
SFX_IMPL_NAMED_VIEWFACTORY( ScTabViewShell, "Default" )
diff --git a/sc/source/ui/view/tabvwshc.cxx b/sc/source/ui/view/tabvwshc.cxx
index 2285768fca73..6621d55bc3bb 100644
--- a/sc/source/ui/view/tabvwshc.cxx
+++ b/sc/source/ui/view/tabvwshc.cxx
@@ -68,6 +68,7 @@
#include "MovingAverageDialog.hxx"
#include "TTestDialog.hxx"
#include "FTestDialog.hxx"
+#include "ZTestDialog.hxx"
#include "PivotLayoutDialog.hxx"
@@ -381,6 +382,12 @@ SfxModelessDialog* ScTabViewShell::CreateRefDialog(
}
break;
+ case SID_ZTEST_DIALOG:
+ {
+ pResult = new ScZTestDialog( pB, pCW, pParent, &GetViewData() );
+ }
+ break;
+
case SID_OPENDLG_OPTSOLVER:
{
ScViewData& rViewData = GetViewData();