LibreOffice Module sc (master)  1
ZTestDialog.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  */
10 
11 #include <memory>
12 
13 #include <reffact.hxx>
15 #include <ZTestDialog.hxx>
16 #include <scresid.hxx>
17 #include <strings.hrc>
18 
20  SfxBindings* pSfxBindings, SfxChildWindow* pChildWindow,
21  weld::Window* pParent, ScViewData& rViewData ) :
23  pSfxBindings, pChildWindow, pParent, rViewData,
24  "modules/scalc/ui/ztestdialog.ui", "ZTestDialog")
25 {
26  m_xDialog->set_title(ScResId(STR_ZTEST));
27 }
28 
30 {}
31 
33 {
35 }
36 
38 {
39  return STR_ZTEST_UNDO_NAME;
40 }
41 
43 {
44  AddressWalkerWriter aOutput(mOutputAddress, pDocShell, mDocument,
46  FormulaTemplate aTemplate(&mDocument);
47 
48  std::unique_ptr<DataRangeIterator> pVariable1Iterator;
49  if (mGroupedBy == BY_COLUMN)
50  pVariable1Iterator.reset(new DataRangeByColumnIterator(mVariable1Range));
51  else
52  pVariable1Iterator.reset(new DataRangeByRowIterator(mVariable1Range));
53 
54  std::unique_ptr<DataRangeIterator> pVariable2Iterator;
55  if (mGroupedBy == BY_COLUMN)
56  pVariable2Iterator.reset(new DataRangeByColumnIterator(mVariable2Range));
57  else
58  pVariable2Iterator.reset(new DataRangeByRowIterator(mVariable2Range));
59 
60  aTemplate.autoReplaceRange("%VARIABLE1_RANGE%", pVariable1Iterator->get());
61  aTemplate.autoReplaceRange("%VARIABLE2_RANGE%", pVariable2Iterator->get());
62 
63  aOutput.writeBoldString(ScResId(STR_ZTEST));
64  aOutput.newLine();
65 
66  // Alpha
67  aOutput.writeString(ScResId(STR_LABEL_ALPHA));
68  aOutput.nextColumn();
69  aOutput.writeValue(0.05);
70  aTemplate.autoReplaceAddress("%ALPHA%", aOutput.current());
71  aOutput.newLine();
72 
73  // Hypothesized mean difference
74  aOutput.writeString(ScResId(STR_HYPOTHESIZED_MEAN_DIFFERENCE_LABEL));
75  aOutput.nextColumn();
76  aOutput.writeValue(0);
77  aTemplate.autoReplaceAddress("%HYPOTHESIZED_MEAN_DIFFERENCE%", aOutput.current());
78  aOutput.newLine();
79 
80  // Variable Label
81  aOutput.nextColumn();
82  aOutput.writeBoldString(ScResId(STR_VARIABLE_1_LABEL));
83  aOutput.nextColumn();
84  aOutput.writeBoldString(ScResId(STR_VARIABLE_2_LABEL));
85  aOutput.newLine();
86 
87  // Known Variance
88  aOutput.writeString(ScResId(STR_ZTEST_KNOWN_VARIANCE));
89  aOutput.nextColumn();
90  aOutput.writeValue(0);
91  aTemplate.autoReplaceAddress("%KNOWN_VARIANCE_VARIABLE1%", aOutput.current());
92  aOutput.nextColumn();
93  aOutput.writeValue(0);
94  aTemplate.autoReplaceAddress("%KNOWN_VARIANCE_VARIABLE2%", aOutput.current());
95  aOutput.newLine();
96 
97  // Mean
98  aOutput.writeString(ScResId(STRID_CALC_MEAN));
99  aOutput.nextColumn();
100  aTemplate.setTemplate("=AVERAGE(%VARIABLE1_RANGE%)");
101  aTemplate.autoReplaceAddress("%MEAN_VARIABLE1%", aOutput.current());
102  aOutput.writeFormula(aTemplate.getTemplate());
103  aOutput.nextColumn();
104  aTemplate.setTemplate("=AVERAGE(%VARIABLE2_RANGE%)");
105  aTemplate.autoReplaceAddress("%MEAN_VARIABLE2%", aOutput.current());
106  aOutput.writeFormula(aTemplate.getTemplate());
107  aOutput.newLine();
108 
109  // Observations
110  aOutput.writeString(ScResId(STR_OBSERVATIONS_LABEL));
111  aOutput.nextColumn();
112  aTemplate.setTemplate("=COUNT(%VARIABLE1_RANGE%)");
113  aOutput.writeFormula(aTemplate.getTemplate());
114  aTemplate.autoReplaceAddress("%OBSERVATION_VARIABLE1%", aOutput.current());
115  aOutput.nextColumn();
116  aTemplate.setTemplate("=COUNT(%VARIABLE2_RANGE%)");
117  aOutput.writeFormula(aTemplate.getTemplate());
118  aTemplate.autoReplaceAddress("%OBSERVATION_VARIABLE2%", aOutput.current());
119  aOutput.newLine();
120 
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("%OBSERVED_MEAN_DIFFERENCE%", aOutput.current());
127  aOutput.newLine();
128 
129  // z
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("%Z_STAT%", aOutput.current());
135  aOutput.newLine();
136 
137  // P one-tail
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());
142  aOutput.newLine();
143 
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());
149  aOutput.newLine();
150 
151  // P two-tail
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());
156  aOutput.newLine();
157 
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());
163 
164  return ScRange(aOutput.mMinimumAddress, aOutput.mMaximumAddress);
165 }
166 
167 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void writeFormula(const OUString &aFormula)
OUString ScResId(TranslateId aId)
Definition: scdll.cxx:89
void writeString(const OUString &aString)
virtual TranslateId GetUndoNameId() override
Definition: ZTestDialog.cxx:37
formula::FormulaGrammar::AddressConvention eConv
Definition: address.hxx:212
void writeBoldString(const OUString &aString)
void writeMatrixFormula(const OUString &aFormula, SCCOL nCols=1, SCROW nRows=1)
static Grammar mergeToGrammar(const Grammar eGrammar, const AddressConvention eConv)
ScZTestDialog(SfxBindings *pB, SfxChildWindow *pCW, weld::Window *pParent, ScViewData &rViewData)
Definition: ZTestDialog.cxx:19
ScAddress current(SCCOL aRelativeCol=0, SCROW aRelativeRow=0, SCTAB aRelativeTab=0)
virtual ScRange ApplyOutput(ScDocShell *pDocShell) override
Definition: ZTestDialog.cxx:42
void autoReplaceRange(const OUString &aVariable, const ScRange &rRange)
virtual void Close() override
Definition: ZTestDialog.cxx:32
void autoReplaceAddress(const OUString &aVariable, ScAddress const &aAddress)
Reference< XExecutableDialog > m_xDialog
virtual ~ScZTestDialog() override
Definition: ZTestDialog.cxx:29
void setTemplate(const OUString &aTemplate)
bool DoClose(sal_uInt16 nId)
Definition: anyrefdg.cxx:695