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 "TTestDialog.hxx"
30 :
31 : namespace
32 : {
33 :
34 76 : static const OUString strWildcardVariable1Range("%VAR1_RANGE%");
35 76 : static const OUString strWildcardVariable2Range("%VAR2_RANGE%");
36 :
37 : }
38 :
39 0 : ScTTestDialog::ScTTestDialog(
40 : SfxBindings* pSfxBindings, SfxChildWindow* pChildWindow,
41 : vcl::Window* pParent, ScViewData* pViewData ) :
42 : ScStatisticsTwoVariableDialog(
43 : pSfxBindings, pChildWindow, pParent, pViewData,
44 0 : "TTestDialog", "modules/scalc/ui/ttestdialog.ui" )
45 : {
46 0 : SetText(SC_STRLOAD(RID_STATISTICS_DLGS, STR_TTEST));
47 0 : }
48 :
49 0 : ScTTestDialog::~ScTTestDialog()
50 0 : {}
51 :
52 0 : bool ScTTestDialog::Close()
53 : {
54 0 : return DoClose( ScTTestDialogWrapper::GetChildWindowId() );
55 : }
56 :
57 0 : sal_Int16 ScTTestDialog::GetUndoNameId()
58 : {
59 0 : return STR_TTEST_UNDO_NAME;
60 : }
61 :
62 0 : ScRange ScTTestDialog::ApplyOutput(ScDocShell* pDocShell)
63 : {
64 : AddressWalkerWriter aOutput(mOutputAddress, pDocShell, mDocument,
65 0 : formula::FormulaGrammar::mergeToGrammar( formula::FormulaGrammar::GRAM_ENGLISH, mAddressDetails.eConv));
66 0 : FormulaTemplate aTemplate(mDocument);
67 :
68 0 : boost::scoped_ptr<DataRangeIterator> pVariable1Iterator;
69 0 : if (mGroupedBy == BY_COLUMN)
70 0 : pVariable1Iterator.reset(new DataRangeByColumnIterator(mVariable1Range));
71 : else
72 0 : pVariable1Iterator.reset(new DataRangeByRowIterator(mVariable1Range));
73 :
74 0 : boost::scoped_ptr<DataRangeIterator> pVariable2Iterator;
75 0 : if (mGroupedBy == BY_COLUMN)
76 0 : pVariable2Iterator.reset(new DataRangeByColumnIterator(mVariable2Range));
77 : else
78 0 : pVariable2Iterator.reset(new DataRangeByRowIterator(mVariable2Range));
79 :
80 0 : aTemplate.autoReplaceRange(strWildcardVariable1Range, pVariable1Iterator->get());
81 0 : aTemplate.autoReplaceRange(strWildcardVariable2Range, pVariable2Iterator->get());
82 :
83 0 : aOutput.writeBoldString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_TTEST_UNDO_NAME));
84 0 : aOutput.newLine();
85 :
86 0 : aOutput.writeString("Alpha");
87 0 : aOutput.nextColumn();
88 0 : aOutput.writeValue(0.05);
89 0 : aTemplate.autoReplaceAddress("%ALPHA%", aOutput.current());
90 0 : aOutput.newLine();
91 :
92 0 : aOutput.nextColumn();
93 0 : aOutput.writeBoldString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_VARIABLE_1_LABEL));
94 0 : aOutput.nextColumn();
95 0 : aOutput.writeBoldString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_VARIABLE_2_LABEL));
96 0 : aOutput.newLine();
97 :
98 0 : aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STRID_CALC_MEAN));
99 0 : aOutput.nextColumn();
100 0 : aTemplate.setTemplate("=AVERAGE(%VAR1_RANGE%)");
101 0 : aOutput.writeFormula(aTemplate.getTemplate());
102 0 : aOutput.nextColumn();
103 0 : aTemplate.setTemplate("=AVERAGE(%VAR2_RANGE%)");
104 0 : aOutput.writeFormula(aTemplate.getTemplate());
105 0 : aOutput.newLine();
106 :
107 0 : aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STRID_CALC_VARIANCE));
108 0 : aOutput.nextColumn();
109 0 : aTemplate.setTemplate("=VAR(%VAR1_RANGE%)");
110 0 : aOutput.writeFormula(aTemplate.getTemplate());
111 0 : aOutput.nextColumn();
112 0 : aTemplate.setTemplate("=VAR(%VAR2_RANGE%)");
113 0 : aOutput.writeFormula(aTemplate.getTemplate());
114 0 : aOutput.newLine();
115 :
116 : // Observations
117 0 : aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_FTEST_OBSERVATIONS_LABEL));
118 0 : aOutput.nextColumn();
119 0 : aTemplate.setTemplate("=COUNT(%VAR1_RANGE%)");
120 0 : aOutput.writeFormula(aTemplate.getTemplate());
121 0 : aOutput.nextColumn();
122 0 : aTemplate.setTemplate("=COUNT(%VAR2_RANGE%)");
123 0 : aOutput.writeFormula(aTemplate.getTemplate());
124 0 : aOutput.newLine();
125 :
126 : // Pearson Correlation
127 0 : aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_TTEST_PEARSON_CORRELATION));
128 0 : aOutput.nextColumn();
129 0 : aTemplate.setTemplate("=CORREL(%VAR1_RANGE%;%VAR2_RANGE%)");
130 0 : aOutput.writeFormula(aTemplate.getTemplate());
131 0 : aOutput.newLine();
132 :
133 : // Hypothesized mean difference
134 0 : aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_TTEST_HYPOTHESIZED_MEAN_DIFFERENCE));
135 0 : aOutput.nextColumn();
136 0 : aOutput.writeValue(2);
137 0 : aTemplate.autoReplaceAddress("%HYPOTHESIZED_MEAN_DIFFERENCE%", aOutput.current());
138 0 : aOutput.newLine();
139 :
140 : // Observed mean difference
141 0 : aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_TTEST_OBSERVED_MEAN_DIFFERENCE));
142 0 : aOutput.nextColumn();
143 0 : aTemplate.setTemplate("=AVERAGE(IF(ISODD(IF(ISNUMBER(%VAR1_RANGE%); 1; 0) * IF(ISNUMBER(%VAR2_RANGE%); 1; 0)); %VAR1_RANGE% - %VAR2_RANGE%; \"NA\"))");
144 0 : aOutput.writeMatrixFormula(aTemplate.getTemplate());
145 0 : aTemplate.autoReplaceAddress("%OBSERVED_MEAN_DIFFERENCE%", aOutput.current());
146 0 : aOutput.newLine();
147 :
148 : // Variance of the Differences
149 0 : aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_TTEST_VARIANCE_OF_THE_DIFFERENCES));
150 0 : aOutput.nextColumn();
151 0 : aTemplate.setTemplate("=VAR(IF(ISODD(IF(ISNUMBER(%VAR1_RANGE%); 1; 0) * IF(ISNUMBER(%VAR2_RANGE%); 1; 0)); %VAR1_RANGE% - %VAR2_RANGE%; \"NA\"))");
152 0 : aOutput.writeMatrixFormula(aTemplate.getTemplate());
153 0 : aTemplate.autoReplaceAddress("%VARIANCE_OF_DIFFERENCES%", aOutput.current());
154 0 : aOutput.newLine();
155 :
156 : // df
157 0 : aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_ANOVA_LABEL_DF));
158 0 : aOutput.nextColumn();
159 0 : aTemplate.setTemplate("=SUM(IF(ISNUMBER(%VAR1_RANGE%); 1; 0) * IF(ISNUMBER(%VAR2_RANGE%); 1; 0)) - 1");
160 0 : aOutput.writeMatrixFormula(aTemplate.getTemplate());
161 0 : aTemplate.autoReplaceAddress("%DEGREE_OF_FREEDOM%", aOutput.current());
162 0 : aOutput.newLine();
163 :
164 : // t stat
165 0 : aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_TTEST_T_STAT));
166 0 : aOutput.nextColumn();
167 0 : aTemplate.setTemplate("=(%OBSERVED_MEAN_DIFFERENCE% - %HYPOTHESIZED_MEAN_DIFFERENCE%) / (%VARIANCE_OF_DIFFERENCES% / ( %DEGREE_OF_FREEDOM% + 1)) ^ 0.5");
168 0 : aOutput.writeFormula(aTemplate.getTemplate());
169 0 : aTemplate.autoReplaceAddress("%T_STAT%", aOutput.current());
170 0 : aOutput.newLine();
171 :
172 : // P one-tail
173 0 : aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_TTEST_P_ONE_TAIL));
174 0 : aOutput.nextColumn();
175 0 : aTemplate.setTemplate("=TDIST(ABS(%T_STAT%); %DEGREE_OF_FREEDOM%; 1)");
176 0 : aOutput.writeFormula(aTemplate.getTemplate());
177 0 : aOutput.newLine();
178 :
179 : // T critical one-tail
180 0 : aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_TTEST_T_CRITICAL_ONE_TAIL));
181 0 : aOutput.nextColumn();
182 0 : aTemplate.setTemplate("=TINV(2*%ALPHA%; %DEGREE_OF_FREEDOM%)");
183 0 : aOutput.writeFormula(aTemplate.getTemplate());
184 0 : aOutput.newLine();
185 :
186 : // P two-tail
187 0 : aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_TTEST_P_TWO_TAIL));
188 0 : aOutput.nextColumn();
189 0 : aTemplate.setTemplate("=TDIST(ABS(%T_STAT%); %DEGREE_OF_FREEDOM%; 2)");
190 0 : aOutput.writeFormula(aTemplate.getTemplate());
191 0 : aOutput.newLine();
192 :
193 : // T critical two-tail
194 0 : aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_TTEST_T_CRITICAL_TWO_TAIL));
195 0 : aOutput.nextColumn();
196 0 : aTemplate.setTemplate("=TINV(%ALPHA%; %DEGREE_OF_FREEDOM%)");
197 0 : aOutput.writeFormula(aTemplate.getTemplate());
198 :
199 0 : return ScRange(aOutput.mMinimumAddress, aOutput.mMaximumAddress);
200 228 : }
201 :
202 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|