summaryrefslogtreecommitdiffstats
path: root/sc/source/ui/StatisticsDialogs/ChiSquareTestDialog.cxx
blob: cfcf53699df90e3daa5274a105f0a58df72b7646 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 */

#include <reffact.hxx>
#include <TableFillingAndNavigationTools.hxx>
#include <ChiSquareTestDialog.hxx>
#include <scresid.hxx>
#include <strings.hrc>

ScChiSquareTestDialog::ScChiSquareTestDialog(
                    SfxBindings* pSfxBindings, SfxChildWindow* pChildWindow,
                    weld::Window* pParent, ScViewData& rViewData ) :
    ScStatisticsInputOutputDialog(
            pSfxBindings, pChildWindow, pParent, rViewData,
            "modules/scalc/ui/chisquaretestdialog.ui", "ChiSquareTestDialog")
{
    m_xDialog->set_title(ScResId(STR_CHI_SQUARE_TEST));
}

ScChiSquareTestDialog::~ScChiSquareTestDialog()
{}

void ScChiSquareTestDialog::Close()
{
    DoClose(ScChiSquareTestDialogWrapper::GetChildWindowId());
}

TranslateId ScChiSquareTestDialog::GetUndoNameId()
{
    return STR_CHI_SQUARE_TEST;
}

ScRange ScChiSquareTestDialog::ApplyOutput(ScDocShell* pDocShell)
{
    AddressWalkerWriter aOutput(mOutputAddress, pDocShell, mDocument,
            formula::FormulaGrammar::mergeToGrammar( formula::FormulaGrammar::GRAM_ENGLISH, mAddressDetails.eConv));
    FormulaTemplate aTemplate(&mDocument);

    aTemplate.autoReplaceRange("%RANGE%", mInputRange);

    aOutput.writeBoldString(ScResId(STR_CHI_SQUARE_TEST));
    aOutput.newLine();

    // Alpha
    aOutput.writeString(ScResId(STR_LABEL_ALPHA));
    aOutput.nextColumn();
    aOutput.writeValue(0.05);
    aTemplate.autoReplaceAddress("%ALPHA%", aOutput.current());
    aOutput.newLine();

    // DF
    aOutput.writeString(ScResId(STR_DEGREES_OF_FREEDOM_LABEL));
    aOutput.nextColumn();
    aTemplate.setTemplate("=(COLUMNS(%RANGE%) - 1) * (ROWS(%RANGE%) - 1)");
    aTemplate.autoReplaceAddress("%DEGREES_OF_FREEDOM%", aOutput.current());
    aOutput.writeFormula(aTemplate.getTemplate());
    aOutput.newLine();

    // p Value
    aOutput.writeString(ScResId(STR_P_VALUE_LABEL));
    aOutput.nextColumn();
    aTemplate.setTemplate("=CHITEST(%RANGE%; MMULT(MMULT(%RANGE%;TRANSPOSE(IF(COLUMN(%RANGE%))));MMULT(TRANSPOSE(IF(ROW(%RANGE%)));%RANGE%)) / SUM(%RANGE%))");
    aTemplate.autoReplaceAddress("%P_VALUE%", aOutput.current());
    aOutput.writeFormula(aTemplate.getTemplate());
    aOutput.newLine();

    // Test Statistic
    aOutput.writeString(ScResId(STR_TEST_STATISTIC_LABEL));
    aOutput.nextColumn();
    aTemplate.setTemplate("=CHIINV(%P_VALUE%; %DEGREES_OF_FREEDOM%)");
    aOutput.writeFormula(aTemplate.getTemplate());
    aOutput.newLine();

    // Critical value
    aOutput.writeString(ScResId(STR_CRITICAL_VALUE_LABEL));
    aOutput.nextColumn();
    aTemplate.setTemplate("=CHIINV(%ALPHA%; %DEGREES_OF_FREEDOM%)");
    aOutput.writeFormula(aTemplate.getTemplate());
    aOutput.newLine();

    return ScRange(aOutput.mMinimumAddress, aOutput.mMaximumAddress);
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */