1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
11 #include <sfx2/dispatch.hxx>
12 #include <svl/zforlist.hxx>
13 #include <svl/undo.hxx>
14 #include <boost/random.hpp>
15 #include <boost/scoped_ptr.hpp>
17 #include "formulacell.hxx"
18 #include "rangelst.hxx"
19 #include "scitems.hxx"
21 #include "document.hxx"
22 #include "uiitems.hxx"
23 #include "reffact.hxx"
24 #include "strload.hxx"
25 #include "docfunc.hxx"
26 #include "StatisticsDialogs.hrc"
27 #include "TableFillingAndNavigationTools.hxx"
29 #include "ZTestDialog.hxx"
31 ScZTestDialog::ScZTestDialog(
32 SfxBindings
* pSfxBindings
, SfxChildWindow
* pChildWindow
,
33 vcl::Window
* pParent
, ScViewData
* pViewData
) :
34 ScStatisticsTwoVariableDialog(
35 pSfxBindings
, pChildWindow
, pParent
, pViewData
,
36 "ZTestDialog", "modules/scalc/ui/ztestdialog.ui" )
38 SetText(SC_STRLOAD(RID_STATISTICS_DLGS
, STR_ZTEST
));
41 ScZTestDialog::~ScZTestDialog()
44 bool ScZTestDialog::Close()
46 return DoClose( ScZTestDialogWrapper::GetChildWindowId() );
49 sal_Int16
ScZTestDialog::GetUndoNameId()
51 return STR_ZTEST_UNDO_NAME
;
54 ScRange
ScZTestDialog::ApplyOutput(ScDocShell
* pDocShell
)
56 AddressWalkerWriter
aOutput(mOutputAddress
, pDocShell
, mDocument
,
57 formula::FormulaGrammar::mergeToGrammar( formula::FormulaGrammar::GRAM_ENGLISH
, mAddressDetails
.eConv
));
58 FormulaTemplate
aTemplate(mDocument
);
60 boost::scoped_ptr
<DataRangeIterator
> pVariable1Iterator
;
61 if (mGroupedBy
== BY_COLUMN
)
62 pVariable1Iterator
.reset(new DataRangeByColumnIterator(mVariable1Range
));
64 pVariable1Iterator
.reset(new DataRangeByRowIterator(mVariable1Range
));
66 boost::scoped_ptr
<DataRangeIterator
> pVariable2Iterator
;
67 if (mGroupedBy
== BY_COLUMN
)
68 pVariable2Iterator
.reset(new DataRangeByColumnIterator(mVariable2Range
));
70 pVariable2Iterator
.reset(new DataRangeByRowIterator(mVariable2Range
));
72 aTemplate
.autoReplaceRange("%VARIABLE1_RANGE%", pVariable1Iterator
->get());
73 aTemplate
.autoReplaceRange("%VARIABLE2_RANGE%", pVariable2Iterator
->get());
75 aOutput
.writeBoldString(SC_STRLOAD(RID_STATISTICS_DLGS
, STR_ZTEST
));
79 aOutput
.writeString(SC_STRLOAD(RID_STATISTICS_DLGS
, STR_LABEL_ALPHA
));
81 aOutput
.writeValue(0.05);
82 aTemplate
.autoReplaceAddress("%ALPHA%", aOutput
.current());
85 // Hypothesized mean difference
86 aOutput
.writeString(SC_STRLOAD(RID_STATISTICS_DLGS
, STR_HYPOTHESIZED_MEAN_DIFFERENCE_LABEL
));
88 aOutput
.writeValue(0);
89 aTemplate
.autoReplaceAddress("%HYPOTHESIZED_MEAN_DIFFERENCE%", aOutput
.current());
94 aOutput
.writeBoldString(SC_STRLOAD(RID_STATISTICS_DLGS
, STR_VARIABLE_1_LABEL
));
96 aOutput
.writeBoldString(SC_STRLOAD(RID_STATISTICS_DLGS
, STR_VARIABLE_2_LABEL
));
100 aOutput
.writeString(SC_STRLOAD(RID_STATISTICS_DLGS
, STR_ZTEST_KNOWN_VARIANCE
));
101 aOutput
.nextColumn();
102 aOutput
.writeValue(0);
103 aTemplate
.autoReplaceAddress("%KNOWN_VARIANCE_VARIABLE1%", aOutput
.current());
104 aOutput
.nextColumn();
105 aOutput
.writeValue(0);
106 aTemplate
.autoReplaceAddress("%KNOWN_VARIANCE_VARIABLE2%", aOutput
.current());
110 aOutput
.writeString(SC_STRLOAD(RID_STATISTICS_DLGS
, STRID_CALC_MEAN
));
111 aOutput
.nextColumn();
112 aTemplate
.setTemplate("=AVERAGE(%VARIABLE1_RANGE%)");
113 aTemplate
.autoReplaceAddress("%MEAN_VARIABLE1%", aOutput
.current());
114 aOutput
.writeFormula(aTemplate
.getTemplate());
115 aOutput
.nextColumn();
116 aTemplate
.setTemplate("=AVERAGE(%VARIABLE2_RANGE%)");
117 aTemplate
.autoReplaceAddress("%MEAN_VARIABLE2%", aOutput
.current());
118 aOutput
.writeFormula(aTemplate
.getTemplate());
122 aOutput
.writeString(SC_STRLOAD(RID_STATISTICS_DLGS
, STR_OBSERVATIONS_LABEL
));
123 aOutput
.nextColumn();
124 aTemplate
.setTemplate("=COUNT(%VARIABLE1_RANGE%)");
125 aOutput
.writeFormula(aTemplate
.getTemplate());
126 aTemplate
.autoReplaceAddress("%OBSERVATION_VARIABLE1%", aOutput
.current());
127 aOutput
.nextColumn();
128 aTemplate
.setTemplate("=COUNT(%VARIABLE2_RANGE%)");
129 aOutput
.writeFormula(aTemplate
.getTemplate());
130 aTemplate
.autoReplaceAddress("%OBSERVATION_VARIABLE2%", aOutput
.current());
133 // Observed mean difference
134 aOutput
.writeString(SC_STRLOAD(RID_STATISTICS_DLGS
, STR_OBSERVED_MEAN_DIFFERENCE_LABEL
));
135 aOutput
.nextColumn();
136 aTemplate
.setTemplate("=%MEAN_VARIABLE1% - %MEAN_VARIABLE2%");
137 aOutput
.writeMatrixFormula(aTemplate
.getTemplate());
138 aTemplate
.autoReplaceAddress("%OBSERVED_MEAN_DIFFERENCE%", aOutput
.current());
142 aOutput
.writeString(SC_STRLOAD(RID_STATISTICS_DLGS
, STR_ZTEST_Z_VALUE
));
143 aOutput
.nextColumn();
144 aTemplate
.setTemplate("=(%OBSERVED_MEAN_DIFFERENCE% - %HYPOTHESIZED_MEAN_DIFFERENCE%) / SQRT( %KNOWN_VARIANCE_VARIABLE1% / %OBSERVATION_VARIABLE1% + %KNOWN_VARIANCE_VARIABLE2% / %OBSERVATION_VARIABLE2% )");
145 aOutput
.writeFormula(aTemplate
.getTemplate());
146 aTemplate
.autoReplaceAddress("%Z_STAT%", aOutput
.current());
150 aOutput
.writeString(SC_STRLOAD(RID_STATISTICS_DLGS
, STR_ZTEST_P_ONE_TAIL
));
151 aOutput
.nextColumn();
152 aTemplate
.setTemplate("=1 - NORMSDIST(ABS(%Z_STAT%))");
153 aOutput
.writeFormula(aTemplate
.getTemplate());
156 // z critical one-tail
157 aOutput
.writeString(SC_STRLOAD(RID_STATISTICS_DLGS
, STR_ZTEST_Z_CRITICAL_ONE_TAIL
));
158 aOutput
.nextColumn();
159 aTemplate
.setTemplate("=-NORMSINV(%ALPHA%)");
160 aOutput
.writeFormula(aTemplate
.getTemplate());
164 aOutput
.writeString(SC_STRLOAD(RID_STATISTICS_DLGS
, STR_ZTEST_P_TWO_TAIL
));
165 aOutput
.nextColumn();
166 aTemplate
.setTemplate("=2 * NORMSDIST(-ABS(%Z_STAT%))");
167 aOutput
.writeFormula(aTemplate
.getTemplate());
170 // z critical two-tail
171 aOutput
.writeString(SC_STRLOAD(RID_STATISTICS_DLGS
, STR_ZTEST_Z_CRITICAL_TWO_TAIL
));
172 aOutput
.nextColumn();
173 aTemplate
.setTemplate("=-NORMSINV(%ALPHA%/2)");
174 aOutput
.writeFormula(aTemplate
.getTemplate());
176 return ScRange(aOutput
.mMinimumAddress
, aOutput
.mMaximumAddress
);
179 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */