diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.com> | 2014-11-18 10:13:50 +0100 |
---|---|---|
committer | Tomaž Vajngerl <tomaz.vajngerl@collabora.com> | 2014-11-18 10:16:46 +0100 |
commit | c080641d2f45c6b455d6a60836f53d054853fc53 (patch) | |
tree | 5c838f7d0041a36d0c5566d5e400894650fd0474 /sc/source/ui/StatisticsDialogs | |
parent | 5c339be474c93c0bf42c593b48fd683ea4614250 (diff) |
fdo#76868 Add chi-square test Statistics Dialog
Change-Id: I35c115a1f1cb733a0d6841596d8baf2e5ade4a1d
Diffstat (limited to 'sc/source/ui/StatisticsDialogs')
-rw-r--r-- | sc/source/ui/StatisticsDialogs/ChiSquareTestDialog.cxx | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/sc/source/ui/StatisticsDialogs/ChiSquareTestDialog.cxx b/sc/source/ui/StatisticsDialogs/ChiSquareTestDialog.cxx new file mode 100644 index 000000000000..f4d092ab7989 --- /dev/null +++ b/sc/source/ui/StatisticsDialogs/ChiSquareTestDialog.cxx @@ -0,0 +1,97 @@ +/* -*- 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 <sfx2/dispatch.hxx> +#include <svl/zforlist.hxx> +#include <svl/undo.hxx> +#include <boost/random.hpp> +#include <boost/scoped_ptr.hpp> + +#include "formulacell.hxx" +#include "rangelst.hxx" +#include "scitems.hxx" +#include "docsh.hxx" +#include "document.hxx" +#include "uiitems.hxx" +#include "reffact.hxx" +#include "strload.hxx" +#include "docfunc.hxx" +#include "StatisticsDialogs.hrc" +#include "TableFillingAndNavigationTools.hxx" + +#include "ChiSquareTestDialog.hxx" + +ScChiSquareTestDialog::ScChiSquareTestDialog( + SfxBindings* pSfxBindings, SfxChildWindow* pChildWindow, + vcl::Window* pParent, ScViewData* pViewData ) : + ScStatisticsInputOutputDialog( + pSfxBindings, pChildWindow, pParent, pViewData, + "ChiSquareTestDialog", "modules/scalc/ui/chisquaretestdialog.ui" ) +{ + SetText(SC_STRLOAD(RID_STATISTICS_DLGS, STR_ZTEST)); +} + +ScChiSquareTestDialog::~ScChiSquareTestDialog() +{} + +bool ScChiSquareTestDialog::Close() +{ + return DoClose(ScChiSquareTestDialogWrapper::GetChildWindowId()); +} + +sal_Int16 ScChiSquareTestDialog::GetUndoNameId() +{ + return STR_ZTEST_UNDO_NAME; +} + +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("Independence Test (Chi-Square)"); + aOutput.newLine(); + + // Alpha + aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_LABEL_ALPHA)); + aOutput.nextColumn(); + aOutput.writeValue(0.05); + aTemplate.autoReplaceAddress("%ALPHA%", aOutput.current()); + aOutput.newLine(); + + // DF + aOutput.writeString("df"); + 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("P-Value"); + aOutput.nextColumn(); + aTemplate.setTemplate("=CHITEST(%RANGE%; MMULT(MMULT(%RANGE%;TRANSPOSE(IF(COLUMN(%RANGE%))));MMULT(TRANSPOSE(IF(ROW(%RANGE%)));%RANGE%)) / SUM(%RANGE%))"); + aOutput.writeFormula(aTemplate.getTemplate()); + aOutput.newLine(); + + // Critical value + aOutput.writeString("Critical Value"); + 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: */ |