/src/libreoffice/sc/source/ui/StatisticsDialogs/ChiSquareTestDialog.cxx
Line | Count | Source |
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> |
12 | | #include <TableFillingAndNavigationTools.hxx> |
13 | | #include <ChiSquareTestDialog.hxx> |
14 | | #include <scresid.hxx> |
15 | | #include <strings.hrc> |
16 | | |
17 | | ScChiSquareTestDialog::ScChiSquareTestDialog( |
18 | | SfxBindings* pSfxBindings, SfxChildWindow* pChildWindow, |
19 | | weld::Window* pParent, ScViewData& rViewData ) : |
20 | 0 | ScStatisticsInputOutputDialog( |
21 | 0 | pSfxBindings, pChildWindow, pParent, rViewData, |
22 | 0 | u"modules/scalc/ui/chisquaretestdialog.ui"_ustr, u"ChiSquareTestDialog"_ustr) |
23 | 0 | { |
24 | 0 | m_xDialog->set_title(ScResId(STR_CHI_SQUARE_TEST)); |
25 | 0 | } |
26 | | |
27 | | ScChiSquareTestDialog::~ScChiSquareTestDialog() |
28 | 0 | {} |
29 | | |
30 | | void ScChiSquareTestDialog::Close() |
31 | 0 | { |
32 | 0 | DoClose(ScChiSquareTestDialogWrapper::GetChildWindowId()); |
33 | 0 | } |
34 | | |
35 | | TranslateId ScChiSquareTestDialog::GetUndoNameId() |
36 | 0 | { |
37 | 0 | return STR_CHI_SQUARE_TEST; |
38 | 0 | } |
39 | | |
40 | | ScRange ScChiSquareTestDialog::ApplyOutput(ScDocShell* pDocShell) |
41 | 0 | { |
42 | 0 | AddressWalkerWriter aOutput(mOutputAddress, pDocShell, mDocument, |
43 | 0 | formula::FormulaGrammar::mergeToGrammar( formula::FormulaGrammar::GRAM_ENGLISH, mAddressDetails.eConv)); |
44 | 0 | FormulaTemplate aTemplate(&mDocument); |
45 | |
|
46 | 0 | aTemplate.autoReplaceRange(u"%RANGE%"_ustr, mInputRange); |
47 | |
|
48 | 0 | aOutput.writeBoldString(ScResId(STR_CHI_SQUARE_TEST)); |
49 | 0 | aOutput.newLine(); |
50 | | |
51 | | // Alpha |
52 | 0 | aOutput.writeString(ScResId(STR_LABEL_ALPHA)); |
53 | 0 | aOutput.nextColumn(); |
54 | 0 | aOutput.writeValue(0.05); |
55 | 0 | aTemplate.autoReplaceAddress(u"%ALPHA%"_ustr, aOutput.current()); |
56 | 0 | aOutput.newLine(); |
57 | | |
58 | | // DF |
59 | 0 | aOutput.writeString(ScResId(STR_DEGREES_OF_FREEDOM_LABEL)); |
60 | 0 | aOutput.nextColumn(); |
61 | 0 | aTemplate.setTemplate("=(COLUMNS(%RANGE%) - 1) * (ROWS(%RANGE%) - 1)"); |
62 | 0 | aTemplate.autoReplaceAddress(u"%DEGREES_OF_FREEDOM%"_ustr, aOutput.current()); |
63 | 0 | aOutput.writeFormula(aTemplate.getTemplate()); |
64 | 0 | aOutput.newLine(); |
65 | | |
66 | | // p Value |
67 | 0 | aOutput.writeString(ScResId(STR_P_VALUE_LABEL)); |
68 | 0 | aOutput.nextColumn(); |
69 | 0 | aTemplate.setTemplate("=CHITEST(%RANGE%; MMULT(MMULT(%RANGE%;TRANSPOSE(IF(COLUMN(%RANGE%))));MMULT(TRANSPOSE(IF(ROW(%RANGE%)));%RANGE%)) / SUM(%RANGE%))"); |
70 | 0 | aTemplate.autoReplaceAddress(u"%P_VALUE%"_ustr, aOutput.current()); |
71 | 0 | aOutput.writeFormula(aTemplate.getTemplate()); |
72 | 0 | aOutput.newLine(); |
73 | | |
74 | | // Test Statistic |
75 | 0 | aOutput.writeString(ScResId(STR_TEST_STATISTIC_LABEL)); |
76 | 0 | aOutput.nextColumn(); |
77 | 0 | aTemplate.setTemplate("=CHIINV(%P_VALUE%; %DEGREES_OF_FREEDOM%)"); |
78 | 0 | aOutput.writeFormula(aTemplate.getTemplate()); |
79 | 0 | aOutput.newLine(); |
80 | | |
81 | | // Critical value |
82 | 0 | aOutput.writeString(ScResId(STR_CRITICAL_VALUE_LABEL)); |
83 | 0 | aOutput.nextColumn(); |
84 | 0 | aTemplate.setTemplate("=CHIINV(%ALPHA%; %DEGREES_OF_FREEDOM%)"); |
85 | 0 | aOutput.writeFormula(aTemplate.getTemplate()); |
86 | 0 | aOutput.newLine(); |
87 | |
|
88 | 0 | return ScRange(aOutput.mMinimumAddress, aOutput.mMaximumAddress); |
89 | 0 | } |
90 | | |
91 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |