LibreOffice Module sc (master)  1
ChiSquareTestDialog.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 <reffact.hxx>
13 #include <ChiSquareTestDialog.hxx>
14 #include <scresid.hxx>
15 #include <strings.hrc>
16 
18  SfxBindings* pSfxBindings, SfxChildWindow* pChildWindow,
19  weld::Window* pParent, ScViewData* pViewData ) :
21  pSfxBindings, pChildWindow, pParent, pViewData,
22  "modules/scalc/ui/chisquaretestdialog.ui", "ChiSquareTestDialog")
23 {
24  m_xDialog->set_title(ScResId(STR_CHI_SQUARE_TEST));
25 }
26 
28 {}
29 
31 {
33 }
34 
36 {
37  return STR_CHI_SQUARE_TEST;
38 }
39 
41 {
42  AddressWalkerWriter aOutput(mOutputAddress, pDocShell, &mDocument,
44  FormulaTemplate aTemplate(&mDocument);
45 
46  aTemplate.autoReplaceRange("%RANGE%", mInputRange);
47 
48  aOutput.writeBoldString(ScResId(STR_CHI_SQUARE_TEST));
49  aOutput.newLine();
50 
51  // Alpha
52  aOutput.writeString(ScResId(STR_LABEL_ALPHA));
53  aOutput.nextColumn();
54  aOutput.writeValue(0.05);
55  aTemplate.autoReplaceAddress("%ALPHA%", aOutput.current());
56  aOutput.newLine();
57 
58  // DF
59  aOutput.writeString(ScResId(STR_DEGREES_OF_FREEDOM_LABEL));
60  aOutput.nextColumn();
61  aTemplate.setTemplate("=(COLUMNS(%RANGE%) - 1) * (ROWS(%RANGE%) - 1)");
62  aTemplate.autoReplaceAddress("%DEGREES_OF_FREEDOM%", aOutput.current());
63  aOutput.writeFormula(aTemplate.getTemplate());
64  aOutput.newLine();
65 
66  // p Value
67  aOutput.writeString(ScResId(STR_P_VALUE_LABEL));
68  aOutput.nextColumn();
69  aTemplate.setTemplate("=CHITEST(%RANGE%; MMULT(MMULT(%RANGE%;TRANSPOSE(IF(COLUMN(%RANGE%))));MMULT(TRANSPOSE(IF(ROW(%RANGE%)));%RANGE%)) / SUM(%RANGE%))");
70  aTemplate.autoReplaceAddress("%P_VALUE%", aOutput.current());
71  aOutput.writeFormula(aTemplate.getTemplate());
72  aOutput.newLine();
73 
74  // Test Statistic
75  aOutput.writeString(ScResId(STR_TEST_STATISTIC_LABEL));
76  aOutput.nextColumn();
77  aTemplate.setTemplate("=CHIINV(%P_VALUE%; %DEGREES_OF_FREEDOM%)");
78  aOutput.writeFormula(aTemplate.getTemplate());
79  aOutput.newLine();
80 
81  // Critical value
82  aOutput.writeString(ScResId(STR_CRITICAL_VALUE_LABEL));
83  aOutput.nextColumn();
84  aTemplate.setTemplate("=CHIINV(%ALPHA%; %DEGREES_OF_FREEDOM%)");
85  aOutput.writeFormula(aTemplate.getTemplate());
86  aOutput.newLine();
87 
88  return ScRange(aOutput.mMinimumAddress, aOutput.mMaximumAddress);
89 }
90 
91 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ScChiSquareTestDialog(SfxBindings *pB, SfxChildWindow *pCW, weld::Window *pParent, ScViewData *pViewData)
void writeFormula(const OUString &aFormula)
virtual ScRange ApplyOutput(ScDocShell *pDocShell) override
void writeString(const OUString &aString)
virtual ~ScChiSquareTestDialog() override
virtual const char * GetUndoNameId() override
formula::FormulaGrammar::AddressConvention eConv
Definition: address.hxx:213
void writeBoldString(const OUString &aString)
static Grammar mergeToGrammar(const Grammar eGrammar, const AddressConvention eConv)
ScAddress current(SCCOL aRelativeCol=0, SCROW aRelativeRow=0, SCTAB aRelativeTab=0)
virtual void Close() override
OUString ScResId(const char *pId)
Definition: scdll.cxx:95
void autoReplaceRange(const OUString &aVariable, const ScRange &rRange)
void autoReplaceAddress(const OUString &aVariable, ScAddress const &aAddress)
Reference< XExecutableDialog > m_xDialog
void setTemplate(const OUString &aTemplate)
bool DoClose(sal_uInt16 nId)
Definition: anyrefdg.cxx:694