Line data Source code
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 <sfx2/dispatch.hxx>
12 : #include <svl/zforlist.hxx>
13 : #include <svl/undo.hxx>
14 : #include <boost/random.hpp>
15 : #include <boost/scoped_ptr.hpp>
16 :
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"
28 :
29 : #include "ZTestDialog.hxx"
30 :
31 0 : ScZTestDialog::ScZTestDialog(
32 : SfxBindings* pSfxBindings, SfxChildWindow* pChildWindow,
33 : vcl::Window* pParent, ScViewData* pViewData ) :
34 : ScStatisticsTwoVariableDialog(
35 : pSfxBindings, pChildWindow, pParent, pViewData,
36 0 : "ZTestDialog", "modules/scalc/ui/ztestdialog.ui" )
37 : {
38 0 : SetText(SC_STRLOAD(RID_STATISTICS_DLGS, STR_ZTEST));
39 0 : }
40 :
41 0 : ScZTestDialog::~ScZTestDialog()
42 0 : {}
43 :
44 0 : bool ScZTestDialog::Close()
45 : {
46 0 : return DoClose( ScZTestDialogWrapper::GetChildWindowId() );
47 : }
48 :
49 0 : sal_Int16 ScZTestDialog::GetUndoNameId()
50 : {
51 0 : return STR_ZTEST_UNDO_NAME;
52 : }
53 :
54 0 : ScRange ScZTestDialog::ApplyOutput(ScDocShell* pDocShell)
55 : {
56 : AddressWalkerWriter aOutput(mOutputAddress, pDocShell, mDocument,
57 0 : formula::FormulaGrammar::mergeToGrammar( formula::FormulaGrammar::GRAM_ENGLISH, mAddressDetails.eConv));
58 0 : FormulaTemplate aTemplate(mDocument);
59 :
60 0 : boost::scoped_ptr<DataRangeIterator> pVariable1Iterator;
61 0 : if (mGroupedBy == BY_COLUMN)
62 0 : pVariable1Iterator.reset(new DataRangeByColumnIterator(mVariable1Range));
63 : else
64 0 : pVariable1Iterator.reset(new DataRangeByRowIterator(mVariable1Range));
65 :
66 0 : boost::scoped_ptr<DataRangeIterator> pVariable2Iterator;
67 0 : if (mGroupedBy == BY_COLUMN)
68 0 : pVariable2Iterator.reset(new DataRangeByColumnIterator(mVariable2Range));
69 : else
70 0 : pVariable2Iterator.reset(new DataRangeByRowIterator(mVariable2Range));
71 :
72 0 : aTemplate.autoReplaceRange("%VARIABLE1_RANGE%", pVariable1Iterator->get());
73 0 : aTemplate.autoReplaceRange("%VARIABLE2_RANGE%", pVariable2Iterator->get());
74 :
75 0 : aOutput.writeBoldString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_ZTEST));
76 0 : aOutput.newLine();
77 :
78 : // Alpha
79 0 : aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_LABEL_ALPHA));
80 0 : aOutput.nextColumn();
81 0 : aOutput.writeValue(0.05);
82 0 : aTemplate.autoReplaceAddress("%ALPHA%", aOutput.current());
83 0 : aOutput.newLine();
84 :
85 : // Hypothesized mean difference
86 0 : aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_HYPOTHESIZED_MEAN_DIFFERENCE_LABEL));
87 0 : aOutput.nextColumn();
88 0 : aOutput.writeValue(0);
89 0 : aTemplate.autoReplaceAddress("%HYPOTHESIZED_MEAN_DIFFERENCE%", aOutput.current());
90 0 : aOutput.newLine();
91 :
92 : // Variable Label
93 0 : aOutput.nextColumn();
94 0 : aOutput.writeBoldString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_VARIABLE_1_LABEL));
95 0 : aOutput.nextColumn();
96 0 : aOutput.writeBoldString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_VARIABLE_2_LABEL));
97 0 : aOutput.newLine();
98 :
99 : // Known Variance
100 0 : aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_ZTEST_KNOWN_VARIANCE));
101 0 : aOutput.nextColumn();
102 0 : aOutput.writeValue(0);
103 0 : aTemplate.autoReplaceAddress("%KNOWN_VARIANCE_VARIABLE1%", aOutput.current());
104 0 : aOutput.nextColumn();
105 0 : aOutput.writeValue(0);
106 0 : aTemplate.autoReplaceAddress("%KNOWN_VARIANCE_VARIABLE2%", aOutput.current());
107 0 : aOutput.newLine();
108 :
109 : // Mean
110 0 : aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STRID_CALC_MEAN));
111 0 : aOutput.nextColumn();
112 0 : aTemplate.setTemplate("=AVERAGE(%VARIABLE1_RANGE%)");
113 0 : aTemplate.autoReplaceAddress("%MEAN_VARIABLE1%", aOutput.current());
114 0 : aOutput.writeFormula(aTemplate.getTemplate());
115 0 : aOutput.nextColumn();
116 0 : aTemplate.setTemplate("=AVERAGE(%VARIABLE2_RANGE%)");
117 0 : aTemplate.autoReplaceAddress("%MEAN_VARIABLE2%", aOutput.current());
118 0 : aOutput.writeFormula(aTemplate.getTemplate());
119 0 : aOutput.newLine();
120 :
121 : // Observations
122 0 : aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_OBSERVATIONS_LABEL));
123 0 : aOutput.nextColumn();
124 0 : aTemplate.setTemplate("=COUNT(%VARIABLE1_RANGE%)");
125 0 : aOutput.writeFormula(aTemplate.getTemplate());
126 0 : aTemplate.autoReplaceAddress("%OBSERVATION_VARIABLE1%", aOutput.current());
127 0 : aOutput.nextColumn();
128 0 : aTemplate.setTemplate("=COUNT(%VARIABLE2_RANGE%)");
129 0 : aOutput.writeFormula(aTemplate.getTemplate());
130 0 : aTemplate.autoReplaceAddress("%OBSERVATION_VARIABLE2%", aOutput.current());
131 0 : aOutput.newLine();
132 :
133 : // Observed mean difference
134 0 : aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_OBSERVED_MEAN_DIFFERENCE_LABEL));
135 0 : aOutput.nextColumn();
136 0 : aTemplate.setTemplate("=%MEAN_VARIABLE1% - %MEAN_VARIABLE2%");
137 0 : aOutput.writeMatrixFormula(aTemplate.getTemplate());
138 0 : aTemplate.autoReplaceAddress("%OBSERVED_MEAN_DIFFERENCE%", aOutput.current());
139 0 : aOutput.newLine();
140 :
141 : // z
142 0 : aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_ZTEST_Z_VALUE));
143 0 : aOutput.nextColumn();
144 0 : aTemplate.setTemplate("=(%OBSERVED_MEAN_DIFFERENCE% - %HYPOTHESIZED_MEAN_DIFFERENCE%) / SQRT( %KNOWN_VARIANCE_VARIABLE1% / %OBSERVATION_VARIABLE1% + %KNOWN_VARIANCE_VARIABLE2% / %OBSERVATION_VARIABLE2% )");
145 0 : aOutput.writeFormula(aTemplate.getTemplate());
146 0 : aTemplate.autoReplaceAddress("%Z_STAT%", aOutput.current());
147 0 : aOutput.newLine();
148 :
149 : // P one-tail
150 0 : aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_ZTEST_P_ONE_TAIL));
151 0 : aOutput.nextColumn();
152 0 : aTemplate.setTemplate("=1 - NORMSDIST(ABS(%Z_STAT%))");
153 0 : aOutput.writeFormula(aTemplate.getTemplate());
154 0 : aOutput.newLine();
155 :
156 : // z critical one-tail
157 0 : aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_ZTEST_Z_CRITICAL_ONE_TAIL));
158 0 : aOutput.nextColumn();
159 0 : aTemplate.setTemplate("=-NORMSINV(%ALPHA%)");
160 0 : aOutput.writeFormula(aTemplate.getTemplate());
161 0 : aOutput.newLine();
162 :
163 : // P two-tail
164 0 : aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_ZTEST_P_TWO_TAIL));
165 0 : aOutput.nextColumn();
166 0 : aTemplate.setTemplate("=2 * NORMSDIST(-ABS(%Z_STAT%))");
167 0 : aOutput.writeFormula(aTemplate.getTemplate());
168 0 : aOutput.newLine();
169 :
170 : // z critical two-tail
171 0 : aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_ZTEST_Z_CRITICAL_TWO_TAIL));
172 0 : aOutput.nextColumn();
173 0 : aTemplate.setTemplate("=-NORMSINV(%ALPHA%/2)");
174 0 : aOutput.writeFormula(aTemplate.getTemplate());
175 :
176 0 : return ScRange(aOutput.mMinimumAddress, aOutput.mMaximumAddress);
177 156 : }
178 :
179 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|