diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.com> | 2014-11-15 18:13:45 +0100 |
---|---|---|
committer | Tomaž Vajngerl <tomaz.vajngerl@collabora.com> | 2014-11-15 18:42:48 +0100 |
commit | 475c2a083965cf358414f9ddb7d8e191f547a9d9 (patch) | |
tree | 174d824b4af236df4f38d43e54734aa1f9bd38df /sc/source/ui/StatisticsDialogs | |
parent | 225af09be9ae7b10aaf5bf0e3714c74c5a2f1391 (diff) |
fdo#74669 Add z-test Statistics Dialog
Change-Id: I8169e9ceefc48c06b358d5a8e1fc08dabf019eb3
Diffstat (limited to 'sc/source/ui/StatisticsDialogs')
-rw-r--r-- | sc/source/ui/StatisticsDialogs/StatisticsDialogs.hrc | 11 | ||||
-rw-r--r-- | sc/source/ui/StatisticsDialogs/StatisticsDialogs.src | 42 | ||||
-rw-r--r-- | sc/source/ui/StatisticsDialogs/ZTestDialog.cxx | 179 |
3 files changed, 227 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: */ |