LCOV - code coverage report
Current view: top level - sc/source/ui/StatisticsDialogs - TTestDialog.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 1 114 0.9 %
Date: 2015-06-13 12:38:46 Functions: 2 8 25.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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 <sfx2/dispatch.hxx>
      12             : #include <svl/zforlist.hxx>
      13             : #include <svl/undo.hxx>
      14             : #include <boost/random.hpp>
      15             : #include <boost/scoped_ptr.hpp>
      16             : 
      17             : #include "formulacell.hxx"
      18             : #include "rangelst.hxx"
      19             : #include "scitems.hxx"
      20             : #include "docsh.hxx"
      21             : #include "document.hxx"
      22             : #include "uiitems.hxx"
      23             : #include "reffact.hxx"
      24             : #include "strload.hxx"
      25             : #include "docfunc.hxx"
      26             : #include "StatisticsDialogs.hrc"
      27             : #include "TableFillingAndNavigationTools.hxx"
      28             : 
      29             : #include "TTestDialog.hxx"
      30             : 
      31           0 : ScTTestDialog::ScTTestDialog(
      32             :                     SfxBindings* pSfxBindings, SfxChildWindow* pChildWindow,
      33             :                     vcl::Window* pParent, ScViewData* pViewData ) :
      34             :     ScStatisticsTwoVariableDialog(
      35             :             pSfxBindings, pChildWindow, pParent, pViewData,
      36           0 :             "TTestDialog", "modules/scalc/ui/ttestdialog.ui" )
      37             : {
      38           0 :     SetText(SC_STRLOAD(RID_STATISTICS_DLGS, STR_TTEST));
      39           0 : }
      40             : 
      41           0 : ScTTestDialog::~ScTTestDialog()
      42           0 : {}
      43             : 
      44           0 : bool ScTTestDialog::Close()
      45             : {
      46           0 :     return DoClose( ScTTestDialogWrapper::GetChildWindowId() );
      47             : }
      48             : 
      49           0 : sal_Int16 ScTTestDialog::GetUndoNameId()
      50             : {
      51           0 :     return STR_TTEST_UNDO_NAME;
      52             : }
      53             : 
      54           0 : ScRange ScTTestDialog::ApplyOutput(ScDocShell* pDocShell)
      55             : {
      56             :     AddressWalkerWriter aOutput(mOutputAddress, pDocShell, mDocument,
      57           0 :             formula::FormulaGrammar::mergeToGrammar( formula::FormulaGrammar::GRAM_ENGLISH, mAddressDetails.eConv));
      58           0 :     FormulaTemplate aTemplate(mDocument);
      59             : 
      60           0 :     boost::scoped_ptr<DataRangeIterator> pVariable1Iterator;
      61           0 :     if (mGroupedBy == BY_COLUMN)
      62           0 :         pVariable1Iterator.reset(new DataRangeByColumnIterator(mVariable1Range));
      63             :     else
      64           0 :         pVariable1Iterator.reset(new DataRangeByRowIterator(mVariable1Range));
      65             : 
      66           0 :     boost::scoped_ptr<DataRangeIterator> pVariable2Iterator;
      67           0 :     if (mGroupedBy == BY_COLUMN)
      68           0 :         pVariable2Iterator.reset(new DataRangeByColumnIterator(mVariable2Range));
      69             :     else
      70           0 :         pVariable2Iterator.reset(new DataRangeByRowIterator(mVariable2Range));
      71             : 
      72           0 :     aTemplate.autoReplaceRange("%VARIABLE1_RANGE%", pVariable1Iterator->get());
      73           0 :     aTemplate.autoReplaceRange("%VARIABLE2_RANGE%", pVariable2Iterator->get());
      74             : 
      75           0 :     aOutput.writeBoldString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_TTEST_UNDO_NAME));
      76           0 :     aOutput.newLine();
      77             : 
      78             :     // Alpha
      79           0 :     aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_LABEL_ALPHA));
      80           0 :     aOutput.nextColumn();
      81           0 :     aOutput.writeValue(0.05);
      82           0 :     aTemplate.autoReplaceAddress("%ALPHA%", aOutput.current());
      83           0 :     aOutput.newLine();
      84             : 
      85             :     // Hypothesized mean difference
      86           0 :     aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_HYPOTHESIZED_MEAN_DIFFERENCE_LABEL));
      87           0 :     aOutput.nextColumn();
      88           0 :     aOutput.writeValue(0);
      89           0 :     aTemplate.autoReplaceAddress("%HYPOTHESIZED_MEAN_DIFFERENCE%", aOutput.current());
      90           0 :     aOutput.newLine();
      91             : 
      92           0 :     aOutput.nextColumn();
      93           0 :     aOutput.writeBoldString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_VARIABLE_1_LABEL));
      94           0 :     aOutput.nextColumn();
      95           0 :     aOutput.writeBoldString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_VARIABLE_2_LABEL));
      96           0 :     aOutput.newLine();
      97             : 
      98           0 :     aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STRID_CALC_MEAN));
      99           0 :     aOutput.nextColumn();
     100           0 :     aTemplate.setTemplate("=AVERAGE(%VARIABLE1_RANGE%)");
     101           0 :     aOutput.writeFormula(aTemplate.getTemplate());
     102           0 :     aOutput.nextColumn();
     103           0 :     aTemplate.setTemplate("=AVERAGE(%VARIABLE2_RANGE%)");
     104           0 :     aOutput.writeFormula(aTemplate.getTemplate());
     105           0 :     aOutput.newLine();
     106             : 
     107           0 :     aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STRID_CALC_VARIANCE));
     108           0 :     aOutput.nextColumn();
     109           0 :     aTemplate.setTemplate("=VAR(%VARIABLE1_RANGE%)");
     110           0 :     aOutput.writeFormula(aTemplate.getTemplate());
     111           0 :     aOutput.nextColumn();
     112           0 :     aTemplate.setTemplate("=VAR(%VARIABLE2_RANGE%)");
     113           0 :     aOutput.writeFormula(aTemplate.getTemplate());
     114           0 :     aOutput.newLine();
     115             : 
     116             :     // Observations
     117           0 :     aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_OBSERVATIONS_LABEL));
     118           0 :     aOutput.nextColumn();
     119           0 :     aTemplate.setTemplate("=COUNT(%VARIABLE1_RANGE%)");
     120           0 :     aOutput.writeFormula(aTemplate.getTemplate());
     121           0 :     aOutput.nextColumn();
     122           0 :     aTemplate.setTemplate("=COUNT(%VARIABLE2_RANGE%)");
     123           0 :     aOutput.writeFormula(aTemplate.getTemplate());
     124           0 :     aOutput.newLine();
     125             : 
     126             :     // Pearson Correlation
     127           0 :     aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_TTEST_PEARSON_CORRELATION));
     128           0 :     aOutput.nextColumn();
     129           0 :     aTemplate.setTemplate("=CORREL(%VARIABLE1_RANGE%;%VARIABLE2_RANGE%)");
     130           0 :     aOutput.writeFormula(aTemplate.getTemplate());
     131           0 :     aOutput.newLine();
     132             : 
     133             :     // Observed mean difference
     134           0 :     aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_OBSERVED_MEAN_DIFFERENCE_LABEL));
     135           0 :     aOutput.nextColumn();
     136           0 :     aTemplate.setTemplate("=AVERAGE(IF(ISODD(IF(ISNUMBER(%VARIABLE1_RANGE%); 1; 0) * IF(ISNUMBER(%VARIABLE2_RANGE%); 1; 0)); %VARIABLE1_RANGE% - %VARIABLE2_RANGE%; \"NA\"))");
     137           0 :     aOutput.writeMatrixFormula(aTemplate.getTemplate());
     138           0 :     aTemplate.autoReplaceAddress("%OBSERVED_MEAN_DIFFERENCE%", aOutput.current());
     139           0 :     aOutput.newLine();
     140             : 
     141             :     // Variance of the Differences
     142           0 :     aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_TTEST_VARIANCE_OF_THE_DIFFERENCES));
     143           0 :     aOutput.nextColumn();
     144           0 :     aTemplate.setTemplate("=VAR(IF(ISODD(IF(ISNUMBER(%VARIABLE1_RANGE%); 1; 0) * IF(ISNUMBER(%VARIABLE2_RANGE%); 1; 0)); %VARIABLE1_RANGE% - %VARIABLE2_RANGE%; \"NA\"))");
     145           0 :     aOutput.writeMatrixFormula(aTemplate.getTemplate());
     146           0 :     aTemplate.autoReplaceAddress("%VARIANCE_OF_DIFFERENCES%", aOutput.current());
     147           0 :     aOutput.newLine();
     148             : 
     149             :     // df
     150           0 :     aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_ANOVA_LABEL_DF));
     151           0 :     aOutput.nextColumn();
     152           0 :     aTemplate.setTemplate("=SUM(IF(ISNUMBER(%VARIABLE1_RANGE%); 1; 0) * IF(ISNUMBER(%VARIABLE2_RANGE%); 1; 0)) - 1");
     153           0 :     aOutput.writeMatrixFormula(aTemplate.getTemplate());
     154           0 :     aTemplate.autoReplaceAddress("%DEGREE_OF_FREEDOM%", aOutput.current());
     155           0 :     aOutput.newLine();
     156             : 
     157             :     // t stat
     158           0 :     aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_TTEST_T_STAT));
     159           0 :     aOutput.nextColumn();
     160           0 :     aTemplate.setTemplate("=(%OBSERVED_MEAN_DIFFERENCE% - %HYPOTHESIZED_MEAN_DIFFERENCE%) / (%VARIANCE_OF_DIFFERENCES% / ( %DEGREE_OF_FREEDOM% + 1)) ^ 0.5");
     161           0 :     aOutput.writeFormula(aTemplate.getTemplate());
     162           0 :     aTemplate.autoReplaceAddress("%T_STAT%", aOutput.current());
     163           0 :     aOutput.newLine();
     164             : 
     165             :     // P one-tail
     166           0 :     aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_TTEST_P_ONE_TAIL));
     167           0 :     aOutput.nextColumn();
     168           0 :     aTemplate.setTemplate("=TDIST(ABS(%T_STAT%); %DEGREE_OF_FREEDOM%; 1)");
     169           0 :     aOutput.writeFormula(aTemplate.getTemplate());
     170           0 :     aOutput.newLine();
     171             : 
     172             :     // T critical one-tail
     173           0 :     aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_TTEST_T_CRITICAL_ONE_TAIL));
     174           0 :     aOutput.nextColumn();
     175           0 :     aTemplate.setTemplate("=TINV(2*%ALPHA%; %DEGREE_OF_FREEDOM%)");
     176           0 :     aOutput.writeFormula(aTemplate.getTemplate());
     177           0 :     aOutput.newLine();
     178             : 
     179             :     // P two-tail
     180           0 :     aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_TTEST_P_TWO_TAIL));
     181           0 :     aOutput.nextColumn();
     182           0 :     aTemplate.setTemplate("=TDIST(ABS(%T_STAT%); %DEGREE_OF_FREEDOM%; 2)");
     183           0 :     aOutput.writeFormula(aTemplate.getTemplate());
     184           0 :     aOutput.newLine();
     185             : 
     186             :     // T critical two-tail
     187           0 :     aOutput.writeString(SC_STRLOAD(RID_STATISTICS_DLGS, STR_TTEST_T_CRITICAL_TWO_TAIL));
     188           0 :     aOutput.nextColumn();
     189           0 :     aTemplate.setTemplate("=TINV(%ALPHA%; %DEGREE_OF_FREEDOM%)");
     190           0 :     aOutput.writeFormula(aTemplate.getTemplate());
     191             : 
     192           0 :     return ScRange(aOutput.mMinimumAddress, aOutput.mMaximumAddress);
     193         156 : }
     194             : 
     195             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11