fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / ui / StatisticsDialogs / ZTestDialog.cxx
blob4ab24c4ffbf7a74f9a3b8b8960e19ed78b7bda53
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
9 */
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"
20 #include "docsh.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));
63 else
64 pVariable1Iterator.reset(new DataRangeByRowIterator(mVariable1Range));
66 boost::scoped_ptr<DataRangeIterator> pVariable2Iterator;
67 if (mGroupedBy == BY_COLUMN)
68 pVariable2Iterator.reset(new DataRangeByColumnIterator(mVariable2Range));
69 else
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));
76 aOutput.newLine();
78 // Alpha
79 aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_LABEL_ALPHA));
80 aOutput.nextColumn();
81 aOutput.writeValue(0.05);
82 aTemplate.autoReplaceAddress("%ALPHA%", aOutput.current());
83 aOutput.newLine();
85 // Hypothesized mean difference
86 aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_HYPOTHESIZED_MEAN_DIFFERENCE_LABEL));
87 aOutput.nextColumn();
88 aOutput.writeValue(0);
89 aTemplate.autoReplaceAddress("%HYPOTHESIZED_MEAN_DIFFERENCE%", aOutput.current());
90 aOutput.newLine();
92 // Variable Label
93 aOutput.nextColumn();
94 aOutput.writeBoldString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_VARIABLE_1_LABEL));
95 aOutput.nextColumn();
96 aOutput.writeBoldString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_VARIABLE_2_LABEL));
97 aOutput.newLine();
99 // Known Variance
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());
107 aOutput.newLine();
109 // Mean
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());
119 aOutput.newLine();
121 // Observations
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());
131 aOutput.newLine();
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());
139 aOutput.newLine();
141 // z
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());
147 aOutput.newLine();
149 // P one-tail
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());
154 aOutput.newLine();
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());
161 aOutput.newLine();
163 // P two-tail
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());
168 aOutput.newLine();
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: */