sc: Add F-Test to Statistics

Change-Id: I31281e863d82a211d7cca897f3e65a0ecfcb5f6b
This commit is contained in:
Tomaž Vajngerl
2014-04-19 20:15:35 +02:00
parent 8b84408ebd
commit 3ce1b10ba7
15 changed files with 360 additions and 18 deletions

View File

@@ -725,6 +725,14 @@
<value>1</value>
</prop>
</node>
<node oor:name=".uno:FTestDialog" oor:op="replace">
<prop oor:name="Label" oor:type="xs:string">
<value xml:lang="en-US">~F-test...</value>
</prop>
<prop oor:name="Properties" oor:type="xs:int">
<value>1</value>
</prop>
</node>
<node oor:name=".uno:EditHeaderAndFooter" oor:op="replace">
<prop oor:name="Label" oor:type="xs:string">
<value xml:lang="en-US">~Headers &amp; Footers...</value>

View File

@@ -496,6 +496,7 @@ $(eval $(call gb_Library_add_exception_objects,sc,\
sc/source/ui/StatisticsDialogs/CovarianceDialog \
sc/source/ui/StatisticsDialogs/DescriptiveStatisticsDialog \
sc/source/ui/StatisticsDialogs/ExponentialSmoothingDialog \
sc/source/ui/StatisticsDialogs/FTestDialog \
sc/source/ui/StatisticsDialogs/MatrixComparisonGenerator \
sc/source/ui/StatisticsDialogs/MovingAverageDialog \
sc/source/ui/StatisticsDialogs/RandomNumberGeneratorDialog \

View File

@@ -269,6 +269,7 @@
#define SID_EXPONENTIAL_SMOOTHING_DIALOG (SC_MESSAGE_START + 76)
#define SID_MOVING_AVERAGE_DIALOG (SC_MESSAGE_START + 77)
#define SID_TTEST_DIALOG (SC_MESSAGE_START + 78)
#define SID_FTEST_DIALOG (SC_MESSAGE_START + 79)
// functions

View File

@@ -159,6 +159,7 @@ interface CellSelection
SID_EXPONENTIAL_SMOOTHING_DIALOG [ ExecMethod = ExecuteEdit; StateMethod = GetBlockState; ]
SID_MOVING_AVERAGE_DIALOG [ ExecMethod = ExecuteEdit; StateMethod = GetBlockState; ]
SID_TTEST_DIALOG [ ExecMethod = ExecuteEdit; StateMethod = GetBlockState; ]
SID_FTEST_DIALOG [ ExecMethod = ExecuteEdit; StateMethod = GetBlockState; ]
SID_MARKDATAAREA [ ExecMethod = ExecuteMove; StateMethod = GetStateCursor; ]
SID_MARKARRAYFORMULA [ ExecMethod = ExecuteMove; StateMethod = GetStateCursor; ]
SID_SETINPUTMODE [ ExecMethod = ExecuteMove; StateMethod = GetStateCursor; ]

View File

@@ -3158,6 +3158,29 @@ SfxVoidItem TTestDialog SID_TTEST_DIALOG
GroupId = GID_OPTIONS;
]
SfxVoidItem FTestDialog SID_FTEST_DIALOG
()
[
/* flags: */
AutoUpdate = FALSE,
Cachable = Cachable,
FastCall = FALSE,
HasCoreId = FALSE,
HasDialog = TRUE,
ReadOnlyDoc = TRUE,
Toggle = FALSE,
Container = FALSE,
RecordAbsolute = FALSE,
RecordPerSet;
Synchron;
/* config: */
AccelConfig = TRUE,
MenuConfig = TRUE,
StatusBarConfig = FALSE,
ToolBoxConfig = TRUE,
GroupId = GID_OPTIONS;
]
SfxVoidItem SolverDialog SID_OPENDLG_OPTSOLVER
()

View File

@@ -0,0 +1,203 @@
/* -*- 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 "random.hxx"
#include "docfunc.hxx"
#include "StatisticsDialogs.hrc"
#include "TableFillingAndNavigationTools.hxx"
#include "FTestDialog.hxx"
namespace
{
static const OUString strWildcardVariable1Range("%VAR1_RANGE%");
static const OUString strWildcardVariable2Range("%VAR2_RANGE%");
}
ScFTestDialog::ScFTestDialog(
SfxBindings* pSfxBindings, SfxChildWindow* pChildWindow,
Window* pParent, ScViewData* pViewData ) :
ScStatisticsTwoVariableDialog(
pSfxBindings, pChildWindow, pParent, pViewData,
"TTestDialog", "modules/scalc/ui/ttestdialog.ui" )
{}
ScFTestDialog::~ScFTestDialog()
{}
bool ScFTestDialog::Close()
{
return DoClose( ScFTestDialogWrapper::GetChildWindowId() );
}
sal_Int16 ScFTestDialog::GetUndoNameId()
{
return STR_FTEST_UNDO_NAME;
}
ScRange ScFTestDialog::ApplyOutput(ScDocShell* pDocShell)
{
AddressWalkerWriter aOutput(mOutputAddress, pDocShell, mDocument,
formula::FormulaGrammar::mergeToGrammar(formula::FormulaGrammar::GRAM_ENGLISH, mAddressDetails.eConv));
FormulaTemplate aTemplate(mDocument, mAddressDetails);
boost::scoped_ptr<DataRangeIterator> pVariable1Iterator;
if (mGroupedBy == BY_COLUMN)
pVariable1Iterator.reset(new DataRangeByColumnIterator(mVariable1Range));
else
pVariable1Iterator.reset(new DataRangeByRowIterator(mVariable1Range));
boost::scoped_ptr<DataRangeIterator> pVariable2Iterator;
if (mGroupedBy == BY_COLUMN)
pVariable2Iterator.reset(new DataRangeByColumnIterator(mVariable2Range));
else
pVariable2Iterator.reset(new DataRangeByRowIterator(mVariable2Range));
aTemplate.autoReplaceRange(strWildcardVariable1Range, pVariable1Iterator->get());
aTemplate.autoReplaceRange(strWildcardVariable2Range, pVariable2Iterator->get());
aOutput.writeBoldString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_FTEST_UNDO_NAME));
aOutput.resetColumn();
aOutput.nextRow();
aOutput.writeString("Alpha");
aOutput.nextColumn();
aOutput.writeValue(0.05);
aTemplate.autoReplaceAddress("%ALPHA%", aOutput.current());
aOutput.resetColumn();
aOutput.nextRow();
aOutput.nextColumn();
aOutput.writeBoldString("Variable 1");
aOutput.nextColumn();
aOutput.writeBoldString("Variable 2");
aOutput.resetColumn();
aOutput.nextRow();
aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STRID_CALC_MEAN));
aOutput.nextColumn();
aTemplate.setTemplate("=AVERAGE(%VAR1_RANGE%)");
aOutput.writeFormula(aTemplate.getTemplate());
aOutput.nextColumn();
aTemplate.setTemplate("=AVERAGE(%VAR2_RANGE%)");
aOutput.writeFormula(aTemplate.getTemplate());
aOutput.resetColumn();
aOutput.nextRow();
aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STRID_CALC_VARIANCE));
aOutput.nextColumn();
aTemplate.setTemplate("=VAR(%VAR1_RANGE%)");
aOutput.writeFormula(aTemplate.getTemplate());
aTemplate.autoReplaceAddress("%VAR1_VARIANCE%", aOutput.current());
aOutput.nextColumn();
aTemplate.setTemplate("=VAR(%VAR2_RANGE%)");
aOutput.writeFormula(aTemplate.getTemplate());
aTemplate.autoReplaceAddress("%VAR2_VARIANCE%", aOutput.current());
aOutput.resetColumn();
aOutput.nextRow();
aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_FTEST_OBSERVATIONS_LABEL));
aOutput.nextColumn();
aTemplate.setTemplate("=COUNT(%VAR1_RANGE%)");
aOutput.writeFormula(aTemplate.getTemplate());
aTemplate.autoReplaceAddress("%VAR1_OBSERVATIONS%", aOutput.current());
aOutput.nextColumn();
aTemplate.setTemplate("=COUNT(%VAR2_RANGE%)");
aOutput.writeFormula(aTemplate.getTemplate());
aTemplate.autoReplaceAddress("%VAR2_OBSERVATIONS%", aOutput.current());
aOutput.resetColumn();
aOutput.nextRow();
aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_ANOVA_LABEL_DF));
aOutput.nextColumn();
aTemplate.setTemplate("=%VAR1_OBSERVATIONS% - 1");
aOutput.writeFormula(aTemplate.getTemplate());
aTemplate.autoReplaceAddress("%VAR1_DEGREE_OF_FREEDOM%", aOutput.current());
aOutput.nextColumn();
aTemplate.setTemplate("=%VAR2_OBSERVATIONS% - 1");
aOutput.writeFormula(aTemplate.getTemplate());
aTemplate.autoReplaceAddress("%VAR2_DEGREE_OF_FREEDOM%", aOutput.current());
aOutput.resetColumn();
aOutput.nextRow();
aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_ANOVA_LABEL_F));
aOutput.nextColumn();
aTemplate.setTemplate("=%VAR1_VARIANCE% / %VAR2_VARIANCE%");
aOutput.writeFormula(aTemplate.getTemplate());
aTemplate.autoReplaceAddress("%F_VALUE%", aOutput.current());
aOutput.resetColumn();
aOutput.nextRow();
aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_FTEST_P_RIGHT_TAIL));
aOutput.nextColumn();
aTemplate.setTemplate("=FDIST(%F_VALUE%; %VAR1_DEGREE_OF_FREEDOM%; %VAR2_DEGREE_OF_FREEDOM%)");
aOutput.writeFormula(aTemplate.getTemplate());
aTemplate.autoReplaceAddress("%P_RIGHT_TAIL_VALUE%", aOutput.current());
aOutput.resetColumn();
aOutput.nextRow();
aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_FTEST_F_CRITICAL_RIGHT_TAIL));
aOutput.nextColumn();
aTemplate.setTemplate("=FINV(%ALPHA%; %VAR1_DEGREE_OF_FREEDOM%; %VAR2_DEGREE_OF_FREEDOM%)");
aOutput.writeFormula(aTemplate.getTemplate());
aOutput.resetColumn();
aOutput.nextRow();
aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_FTEST_P_LEFT_TAIL));
aOutput.nextColumn();
aTemplate.setTemplate("=1 - %P_RIGHT_TAIL_VALUE%");
aOutput.writeFormula(aTemplate.getTemplate());
aTemplate.autoReplaceAddress("%P_LEFT_TAIL_VALUE%", aOutput.current());
aOutput.resetColumn();
aOutput.nextRow();
aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_FTEST_F_CRITICAL_LEFT_TAIL));
aOutput.nextColumn();
aTemplate.setTemplate("=FINV(1-%ALPHA%; %VAR1_DEGREE_OF_FREEDOM%; %VAR2_DEGREE_OF_FREEDOM%)");
aOutput.writeFormula(aTemplate.getTemplate());
aOutput.resetColumn();
aOutput.nextRow();
aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_FTEST_P_TWO_TAIL));
aOutput.nextColumn();
aTemplate.setTemplate("=2*MIN(%P_RIGHT_TAIL_VALUE%; %P_LEFT_TAIL_VALUE%)");
aOutput.writeFormula(aTemplate.getTemplate());
aOutput.resetColumn();
aOutput.nextRow();
aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_FTEST_F_CRITICAL_TWO_TAIL));
aOutput.nextColumn();
aTemplate.setTemplate("=FINV(1-(%ALPHA%/2); %VAR1_DEGREE_OF_FREEDOM%; %VAR2_DEGREE_OF_FREEDOM%)");
aOutput.writeFormula(aTemplate.getTemplate());
aOutput.nextColumn();
aTemplate.setTemplate("=FINV(%ALPHA%/2; %VAR1_DEGREE_OF_FREEDOM%; %VAR2_DEGREE_OF_FREEDOM%)");
aOutput.writeFormula(aTemplate.getTemplate());
return ScRange(aOutput.mMinimumAddress, aOutput.mMaximumAddress);
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View File

@@ -54,25 +54,34 @@
#define STR_EXPONENTIAL_SMOOTHING_UNDO_NAME 38
#define STR_MOVING_AVERAGE_UNDO_NAME 39
#define STR_TTEST_UNDO_NAME 40
#define STR_FTEST_UNDO_NAME 41
#define STR_COLUMN_LABEL_TEMPLATE 41
#define STR_ROW_LABEL_TEMPLATE 42
#define STR_COLUMN_LABEL_TEMPLATE 60
#define STR_ROW_LABEL_TEMPLATE 61
#define STR_ANOVA_SINGLE_FACTOR_LABEL 43
#define STR_ANOVA_LABEL_GROUPS 44
#define STR_ANOVA_LABEL_BETWEEN_GROUPS 45
#define STR_ANOVA_LABEL_WITHIN_GROUPS 46
#define STR_ANOVA_LABEL_SOURCE_OF_VARIATION 47
#define STR_ANOVA_LABEL_SS 48
#define STR_ANOVA_LABEL_DF 49
#define STR_ANOVA_LABEL_MS 50
#define STR_ANOVA_LABEL_F 51
#define STR_ANOVA_LABEL_P_VALUE 52
#define STR_ANOVA_LABEL_F_CRITICAL 53
#define STR_ANOVA_LABEL_TOTAL 54
#define STR_ANOVA_SINGLE_FACTOR_LABEL 62
#define STR_ANOVA_LABEL_GROUPS 63
#define STR_ANOVA_LABEL_BETWEEN_GROUPS 64
#define STR_ANOVA_LABEL_WITHIN_GROUPS 65
#define STR_ANOVA_LABEL_SOURCE_OF_VARIATION 66
#define STR_ANOVA_LABEL_SS 67
#define STR_ANOVA_LABEL_DF 68
#define STR_ANOVA_LABEL_MS 69
#define STR_ANOVA_LABEL_F 70
#define STR_ANOVA_LABEL_P_VALUE 71
#define STR_ANOVA_LABEL_F_CRITICAL 72
#define STR_ANOVA_LABEL_TOTAL 73
#define STR_CORRELATION_LABEL 55
#define STR_COVARIANCE_LABEL 56
#define STR_LABEL_ALPHA 57
#define STR_CORRELATION_LABEL 80
#define STR_COVARIANCE_LABEL 81
#define STR_LABEL_ALPHA 82
#define STR_FTEST_OBSERVATIONS_LABEL 90
#define STR_FTEST_P_RIGHT_TAIL 91
#define STR_FTEST_F_CRITICAL_RIGHT_TAIL 92
#define STR_FTEST_P_LEFT_TAIL 93
#define STR_FTEST_F_CRITICAL_LEFT_TAIL 94
#define STR_FTEST_P_TWO_TAIL 95
#define STR_FTEST_F_CRITICAL_TWO_TAIL 96
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View File

@@ -268,6 +268,11 @@ Resource RID_STATISTICS_DLGS
Text [ en-US ] = "t-test";
};
String STR_FTEST_UNDO_NAME
{
Text [ en-US ] = "F-test";
};
/* Common */
String STR_COLUMN_LABEL_TEMPLATE
{
@@ -281,6 +286,36 @@ Resource RID_STATISTICS_DLGS
{
Text [ en-US ] = "Alpha";
};
/*F Test */
String STR_FTEST_OBSERVATIONS_LABEL
{
Text [ en-US ] = "Observations";
};
String STR_FTEST_P_RIGHT_TAIL
{
Text [ en-US ] = "P (F<=f) right-tail";
};
String STR_FTEST_F_CRITICAL_RIGHT_TAIL
{
Text [ en-US ] = "F Critical right-tail";
};
String STR_FTEST_P_LEFT_TAIL
{
Text [ en-US ] = "P (F<=f) left-tail";
};
String STR_FTEST_F_CRITICAL_LEFT_TAIL
{
Text [ en-US ] = "F Critical left-tail";
};
String STR_FTEST_P_TWO_TAIL
{
Text [ en-US ] = "P two-tail";
};
String STR_FTEST_F_CRITICAL_TWO_TAIL
{
Text [ en-US ] = "F Critical two-tail";
};
};
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View File

@@ -270,6 +270,7 @@ void ScDLL::Init()
ScExponentialSmoothingDialogWrapper ::RegisterChildWindow(false, pMod);
ScMovingAverageDialogWrapper ::RegisterChildWindow(false, pMod);
ScTTestDialogWrapper ::RegisterChildWindow(false, pMod);
ScFTestDialogWrapper ::RegisterChildWindow(false, pMod);
// First docking Window for Calc
ScFunctionChildWindow ::RegisterChildWindow(false, pMod);

View File

@@ -0,0 +1,35 @@
/* -*- 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/.
*
*/
#ifndef F_TEST_DIALOG_HXX
#define F_TEST_DIALOG_HXX
#include "StatisticsTwoVariableDialog.hxx"
class ScFTestDialog : public ScStatisticsTwoVariableDialog
{
public:
ScFTestDialog(
SfxBindings* pB, SfxChildWindow* pCW,
Window* pParent, ScViewData* pViewData );
virtual ~ScFTestDialog();
virtual bool Close() SAL_OVERRIDE;
protected:
virtual sal_Int16 GetUndoNameId() SAL_OVERRIDE;
virtual ScRange ApplyOutput(ScDocShell* pDocShell) SAL_OVERRIDE;
};
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View File

@@ -114,6 +114,13 @@ private:
ScTTestDialogWrapper() SAL_DELETED_FUNCTION;
};
class ScFTestDialogWrapper :
public ChildWindowWrapper<SID_FTEST_DIALOG>
{
private:
ScFTestDialogWrapper() SAL_DELETED_FUNCTION;
};
class ScAcceptChgDlgWrapper: public SfxChildWindow
{
public:

View File

@@ -984,6 +984,16 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq )
}
break;
case SID_FTEST_DIALOG:
{
sal_uInt16 nId = ScFTestDialogWrapper::GetChildWindowId();
SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
pScMod->SetRefDialog( nId, pWnd ? false : sal_True );
}
break;
// disposal (Outlines)

View File

@@ -95,7 +95,7 @@ void ScTabViewShell::InitInterface_Impl()
GetStaticInterface()->RegisterChildWindow(ScExponentialSmoothingDialogWrapper::GetChildWindowId());
GetStaticInterface()->RegisterChildWindow(ScMovingAverageDialogWrapper::GetChildWindowId());
GetStaticInterface()->RegisterChildWindow(ScTTestDialogWrapper::GetChildWindowId());
GetStaticInterface()->RegisterChildWindow(ScFTestDialogWrapper::GetChildWindowId());
}
SFX_IMPL_NAMED_VIEWFACTORY( ScTabViewShell, "Default" )

View File

@@ -67,6 +67,7 @@
#include "ExponentialSmoothingDialog.hxx"
#include "MovingAverageDialog.hxx"
#include "TTestDialog.hxx"
#include "FTestDialog.hxx"
#include "PivotLayoutDialog.hxx"
@@ -374,6 +375,12 @@ SfxModelessDialog* ScTabViewShell::CreateRefDialog(
}
break;
case SID_FTEST_DIALOG:
{
pResult = new ScFTestDialog( pB, pCW, pParent, GetViewData() );
}
break;
case SID_OPENDLG_OPTSOLVER:
{
ScViewData* pViewData = GetViewData();

View File

@@ -492,6 +492,7 @@
<menu:menuitem menu:id=".uno:ExponentialSmoothingDialog"/>
<menu:menuitem menu:id=".uno:MovingAverageDialog"/>
<menu:menuitem menu:id=".uno:TTestDialog"/>
<menu:menuitem menu:id=".uno:FTestDialog"/>
</menu:menupopup>
</menu:menu>
</menu:menupopup>