LibreOffice Module sc (master) 1
TTestDialog.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 <TTestDialog.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/ttestdialog.ui", "TTestDialog")
25{
26 m_xDialog->set_title(ScResId(STR_TTEST));
27}
28
30{}
31
33{
35}
36
38{
39 return STR_TTEST_UNDO_NAME;
40}
41
43{
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_TTEST_UNDO_NAME));
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 aOutput.nextColumn();
81 aOutput.writeBoldString(ScResId(STR_VARIABLE_1_LABEL));
82 aOutput.nextColumn();
83 aOutput.writeBoldString(ScResId(STR_VARIABLE_2_LABEL));
84 aOutput.newLine();
85
86 aOutput.writeString(ScResId(STRID_CALC_MEAN));
87 aOutput.nextColumn();
88 aTemplate.setTemplate("=AVERAGE(%VARIABLE1_RANGE%)");
89 aOutput.writeFormula(aTemplate.getTemplate());
90 aOutput.nextColumn();
91 aTemplate.setTemplate("=AVERAGE(%VARIABLE2_RANGE%)");
92 aOutput.writeFormula(aTemplate.getTemplate());
93 aOutput.newLine();
94
95 aOutput.writeString(ScResId(STRID_CALC_VARIANCE));
96 aOutput.nextColumn();
97 aTemplate.setTemplate("=VAR(%VARIABLE1_RANGE%)");
98 aOutput.writeFormula(aTemplate.getTemplate());
99 aOutput.nextColumn();
100 aTemplate.setTemplate("=VAR(%VARIABLE2_RANGE%)");
101 aOutput.writeFormula(aTemplate.getTemplate());
102 aOutput.newLine();
103
104 // Observations
105 aOutput.writeString(ScResId(STR_OBSERVATIONS_LABEL));
106 aOutput.nextColumn();
107 aTemplate.setTemplate("=COUNT(%VARIABLE1_RANGE%)");
108 aOutput.writeFormula(aTemplate.getTemplate());
109 aOutput.nextColumn();
110 aTemplate.setTemplate("=COUNT(%VARIABLE2_RANGE%)");
111 aOutput.writeFormula(aTemplate.getTemplate());
112 aOutput.newLine();
113
114 // Pearson Correlation
115 aOutput.writeString(ScResId(STR_TTEST_PEARSON_CORRELATION));
116 aOutput.nextColumn();
117 aTemplate.setTemplate("=CORREL(%VARIABLE1_RANGE%;%VARIABLE2_RANGE%)");
118 aOutput.writeFormula(aTemplate.getTemplate());
119 aOutput.newLine();
120
121 // Observed mean difference
122 aOutput.writeString(ScResId(STR_OBSERVED_MEAN_DIFFERENCE_LABEL));
123 aOutput.nextColumn();
124 aTemplate.setTemplate("=AVERAGE(IF(ISODD(IF(ISNUMBER(%VARIABLE1_RANGE%); 1; 0) * IF(ISNUMBER(%VARIABLE2_RANGE%); 1; 0)); %VARIABLE1_RANGE% - %VARIABLE2_RANGE%; \"NA\"))");
125 aOutput.writeMatrixFormula(aTemplate.getTemplate());
126 aTemplate.autoReplaceAddress("%OBSERVED_MEAN_DIFFERENCE%", aOutput.current());
127 aOutput.newLine();
128
129 // Variance of the Differences
130 aOutput.writeString(ScResId(STR_TTEST_VARIANCE_OF_THE_DIFFERENCES));
131 aOutput.nextColumn();
132 aTemplate.setTemplate("=VAR(IF(ISODD(IF(ISNUMBER(%VARIABLE1_RANGE%); 1; 0) * IF(ISNUMBER(%VARIABLE2_RANGE%); 1; 0)); %VARIABLE1_RANGE% - %VARIABLE2_RANGE%; \"NA\"))");
133 aOutput.writeMatrixFormula(aTemplate.getTemplate());
134 aTemplate.autoReplaceAddress("%VARIANCE_OF_DIFFERENCES%", aOutput.current());
135 aOutput.newLine();
136
137 // df
138 aOutput.writeString(ScResId(STR_ANOVA_LABEL_DF));
139 aOutput.nextColumn();
140 aTemplate.setTemplate("=SUM(IF(ISNUMBER(%VARIABLE1_RANGE%); 1; 0) * IF(ISNUMBER(%VARIABLE2_RANGE%); 1; 0)) - 1");
141 aOutput.writeMatrixFormula(aTemplate.getTemplate());
142 aTemplate.autoReplaceAddress("%DEGREE_OF_FREEDOM%", aOutput.current());
143 aOutput.newLine();
144
145 // t stat
146 aOutput.writeString(ScResId(STR_TTEST_T_STAT));
147 aOutput.nextColumn();
148 aTemplate.setTemplate("=(%OBSERVED_MEAN_DIFFERENCE% - %HYPOTHESIZED_MEAN_DIFFERENCE%) / (%VARIANCE_OF_DIFFERENCES% / ( %DEGREE_OF_FREEDOM% + 1)) ^ 0.5");
149 aOutput.writeFormula(aTemplate.getTemplate());
150 aTemplate.autoReplaceAddress("%T_STAT%", aOutput.current());
151 aOutput.newLine();
152
153 // P one-tail
154 aOutput.writeString(ScResId(STR_TTEST_P_ONE_TAIL));
155 aOutput.nextColumn();
156 aTemplate.setTemplate("=TDIST(ABS(%T_STAT%); %DEGREE_OF_FREEDOM%; 1)");
157 aOutput.writeFormula(aTemplate.getTemplate());
158 aOutput.newLine();
159
160 // T critical one-tail
161 aOutput.writeString(ScResId(STR_TTEST_T_CRITICAL_ONE_TAIL));
162 aOutput.nextColumn();
163 aTemplate.setTemplate("=TINV(2*%ALPHA%; %DEGREE_OF_FREEDOM%)");
164 aOutput.writeFormula(aTemplate.getTemplate());
165 aOutput.newLine();
166
167 // P two-tail
168 aOutput.writeString(ScResId(STR_TTEST_P_TWO_TAIL));
169 aOutput.nextColumn();
170 aTemplate.setTemplate("=TDIST(ABS(%T_STAT%); %DEGREE_OF_FREEDOM%; 2)");
171 aOutput.writeFormula(aTemplate.getTemplate());
172 aOutput.newLine();
173
174 // T critical two-tail
175 aOutput.writeString(ScResId(STR_TTEST_T_CRITICAL_TWO_TAIL));
176 aOutput.nextColumn();
177 aTemplate.setTemplate("=TINV(%ALPHA%; %DEGREE_OF_FREEDOM%)");
178 aOutput.writeFormula(aTemplate.getTemplate());
179
180 return ScRange(aOutput.mMinimumAddress, aOutput.mMaximumAddress);
181}
182
183/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Reference< XExecutableDialog > m_xDialog
void writeMatrixFormula(const OUString &aFormula, SCCOL nCols=1, SCROW nRows=1)
void writeFormula(const OUString &aFormula)
void writeBoldString(const OUString &aString)
void writeString(const OUString &aString)
ScAddress current(SCCOL aRelativeCol=0, SCROW aRelativeRow=0, SCTAB aRelativeTab=0)
void setTemplate(const OUString &aTemplate)
void autoReplaceAddress(const OUString &aVariable, ScAddress const &aAddress)
void autoReplaceRange(const OUString &aVariable, const ScRange &rRange)
bool DoClose(sal_uInt16 nId)
Definition: anyrefdg.cxx:714
virtual ScRange ApplyOutput(ScDocShell *pDocShell) override
Definition: TTestDialog.cxx:42
ScTTestDialog(SfxBindings *pB, SfxChildWindow *pCW, weld::Window *pParent, ScViewData &rViewData)
Definition: TTestDialog.cxx:19
virtual ~ScTTestDialog() override
Definition: TTestDialog.cxx:29
virtual TranslateId GetUndoNameId() override
Definition: TTestDialog.cxx:37
virtual void Close() override
Definition: TTestDialog.cxx:32
static Grammar mergeToGrammar(const Grammar eGrammar, const AddressConvention eConv)
OUString ScResId(TranslateId aId)
Definition: scdll.cxx:90
formula::FormulaGrammar::AddressConvention eConv
Definition: address.hxx:225