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/.
13 #include <reffact.hxx>
14 #include <TableFillingAndNavigationTools.hxx>
15 #include <ZTestDialog.hxx>
16 #include <scresid.hxx>
17 #include <strings.hrc>
19 ScZTestDialog::ScZTestDialog(
20 SfxBindings
* pSfxBindings
, SfxChildWindow
* pChildWindow
,
21 weld::Window
* pParent
, ScViewData
& rViewData
) :
22 ScStatisticsTwoVariableDialog(
23 pSfxBindings
, pChildWindow
, pParent
, rViewData
,
24 u
"modules/scalc/ui/ztestdialog.ui"_ustr
, u
"ZTestDialog"_ustr
)
26 m_xDialog
->set_title(ScResId(STR_ZTEST
));
29 ScZTestDialog::~ScZTestDialog()
32 void ScZTestDialog::Close()
34 DoClose( ScZTestDialogWrapper::GetChildWindowId() );
37 TranslateId
ScZTestDialog::GetUndoNameId()
39 return STR_ZTEST_UNDO_NAME
;
42 ScRange
ScZTestDialog::ApplyOutput(ScDocShell
* pDocShell
)
44 AddressWalkerWriter
aOutput(mOutputAddress
, pDocShell
, mDocument
,
45 formula::FormulaGrammar::mergeToGrammar( formula::FormulaGrammar::GRAM_ENGLISH
, mAddressDetails
.eConv
));
46 FormulaTemplate
aTemplate(&mDocument
);
48 std::unique_ptr
<DataRangeIterator
> pVariable1Iterator
;
49 if (mGroupedBy
== BY_COLUMN
)
50 pVariable1Iterator
.reset(new DataRangeByColumnIterator(mVariable1Range
));
52 pVariable1Iterator
.reset(new DataRangeByRowIterator(mVariable1Range
));
54 std::unique_ptr
<DataRangeIterator
> pVariable2Iterator
;
55 if (mGroupedBy
== BY_COLUMN
)
56 pVariable2Iterator
.reset(new DataRangeByColumnIterator(mVariable2Range
));
58 pVariable2Iterator
.reset(new DataRangeByRowIterator(mVariable2Range
));
60 aTemplate
.autoReplaceRange(u
"%VARIABLE1_RANGE%"_ustr
, pVariable1Iterator
->get());
61 aTemplate
.autoReplaceRange(u
"%VARIABLE2_RANGE%"_ustr
, pVariable2Iterator
->get());
63 aOutput
.writeBoldString(ScResId(STR_ZTEST
));
67 aOutput
.writeString(ScResId(STR_LABEL_ALPHA
));
69 aOutput
.writeValue(0.05);
70 aTemplate
.autoReplaceAddress(u
"%ALPHA%"_ustr
, aOutput
.current());
73 // Hypothesized mean difference
74 aOutput
.writeString(ScResId(STR_HYPOTHESIZED_MEAN_DIFFERENCE_LABEL
));
76 aOutput
.writeValue(0);
77 aTemplate
.autoReplaceAddress(u
"%HYPOTHESIZED_MEAN_DIFFERENCE%"_ustr
, aOutput
.current());
82 aOutput
.writeBoldString(ScResId(STR_VARIABLE_1_LABEL
));
84 aOutput
.writeBoldString(ScResId(STR_VARIABLE_2_LABEL
));
88 aOutput
.writeString(ScResId(STR_ZTEST_KNOWN_VARIANCE
));
90 aOutput
.writeValue(0);
91 aTemplate
.autoReplaceAddress(u
"%KNOWN_VARIANCE_VARIABLE1%"_ustr
, aOutput
.current());
93 aOutput
.writeValue(0);
94 aTemplate
.autoReplaceAddress(u
"%KNOWN_VARIANCE_VARIABLE2%"_ustr
, aOutput
.current());
98 aOutput
.writeString(ScResId(STRID_CALC_MEAN
));
100 aTemplate
.setTemplate("=AVERAGE(%VARIABLE1_RANGE%)");
101 aTemplate
.autoReplaceAddress(u
"%MEAN_VARIABLE1%"_ustr
, aOutput
.current());
102 aOutput
.writeFormula(aTemplate
.getTemplate());
103 aOutput
.nextColumn();
104 aTemplate
.setTemplate("=AVERAGE(%VARIABLE2_RANGE%)");
105 aTemplate
.autoReplaceAddress(u
"%MEAN_VARIABLE2%"_ustr
, aOutput
.current());
106 aOutput
.writeFormula(aTemplate
.getTemplate());
110 aOutput
.writeString(ScResId(STR_OBSERVATIONS_LABEL
));
111 aOutput
.nextColumn();
112 aTemplate
.setTemplate("=COUNT(%VARIABLE1_RANGE%)");
113 aOutput
.writeFormula(aTemplate
.getTemplate());
114 aTemplate
.autoReplaceAddress(u
"%OBSERVATION_VARIABLE1%"_ustr
, aOutput
.current());
115 aOutput
.nextColumn();
116 aTemplate
.setTemplate("=COUNT(%VARIABLE2_RANGE%)");
117 aOutput
.writeFormula(aTemplate
.getTemplate());
118 aTemplate
.autoReplaceAddress(u
"%OBSERVATION_VARIABLE2%"_ustr
, aOutput
.current());
121 // Observed mean difference
122 aOutput
.writeString(ScResId(STR_OBSERVED_MEAN_DIFFERENCE_LABEL
));
123 aOutput
.nextColumn();
124 aTemplate
.setTemplate("=%MEAN_VARIABLE1% - %MEAN_VARIABLE2%");
125 aOutput
.writeMatrixFormula(aTemplate
.getTemplate());
126 aTemplate
.autoReplaceAddress(u
"%OBSERVED_MEAN_DIFFERENCE%"_ustr
, aOutput
.current());
130 aOutput
.writeString(ScResId(STR_ZTEST_Z_VALUE
));
131 aOutput
.nextColumn();
132 aTemplate
.setTemplate("=(%OBSERVED_MEAN_DIFFERENCE% - %HYPOTHESIZED_MEAN_DIFFERENCE%) / SQRT( %KNOWN_VARIANCE_VARIABLE1% / %OBSERVATION_VARIABLE1% + %KNOWN_VARIANCE_VARIABLE2% / %OBSERVATION_VARIABLE2% )");
133 aOutput
.writeFormula(aTemplate
.getTemplate());
134 aTemplate
.autoReplaceAddress(u
"%Z_STAT%"_ustr
, aOutput
.current());
138 aOutput
.writeString(ScResId(STR_ZTEST_P_ONE_TAIL
));
139 aOutput
.nextColumn();
140 aTemplate
.setTemplate("=1 - NORMSDIST(ABS(%Z_STAT%))");
141 aOutput
.writeFormula(aTemplate
.getTemplate());
144 // z critical one-tail
145 aOutput
.writeString(ScResId(STR_ZTEST_Z_CRITICAL_ONE_TAIL
));
146 aOutput
.nextColumn();
147 aTemplate
.setTemplate("=-NORMSINV(%ALPHA%)");
148 aOutput
.writeFormula(aTemplate
.getTemplate());
152 aOutput
.writeString(ScResId(STR_ZTEST_P_TWO_TAIL
));
153 aOutput
.nextColumn();
154 aTemplate
.setTemplate("=2 * NORMSDIST(-ABS(%Z_STAT%))");
155 aOutput
.writeFormula(aTemplate
.getTemplate());
158 // z critical two-tail
159 aOutput
.writeString(ScResId(STR_ZTEST_Z_CRITICAL_TWO_TAIL
));
160 aOutput
.nextColumn();
161 aTemplate
.setTemplate("=-NORMSINV(%ALPHA%/2)");
162 aOutput
.writeFormula(aTemplate
.getTemplate());
164 return ScRange(aOutput
.mMinimumAddress
, aOutput
.mMaximumAddress
);
167 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */