24struct StatisticCalculation {
27 const char* aResultRangeName;
30StatisticCalculation
const lclBasicStatistics[] =
32 { STR_ANOVA_LABEL_GROUPS,
nullptr,
nullptr },
33 { STRID_CALC_COUNT,
"=COUNT(%RANGE%)",
"COUNT_RANGE" },
34 { STRID_CALC_SUM,
"=SUM(%RANGE%)",
"SUM_RANGE" },
35 { STRID_CALC_MEAN,
"=AVERAGE(%RANGE%)",
"MEAN_RANGE" },
36 { STRID_CALC_VARIANCE,
"=VAR(%RANGE%)",
"VAR_RANGE" },
37 { {},
nullptr,
nullptr }
42 STR_ANOVA_LABEL_SOURCE_OF_VARIATION,
47 STR_ANOVA_LABEL_P_VALUE,
48 STR_ANOVA_LABEL_F_CRITICAL,
52constexpr OUStringLiteral strWildcardRange =
u"%RANGE%";
54OUString lclCreateMultiParameterFormula(
55 ScRangeList& aRangeList,
const OUString& aFormulaTemplate,
56 std::u16string_view aWildcard,
const ScDocument& rDocument,
59 OUStringBuffer aResult;
60 for (
size_t i = 0;
i < aRangeList.
size();
i++)
63 OUString aFormulaString = aFormulaTemplate.replaceAll(aWildcard, aRangeString);
64 aResult.append(aFormulaString);
65 if(i != aRangeList.
size() - 1)
68 return aResult.makeStringAndClear();
73 std::unique_ptr<DataRangeIterator> pIterator;
79 for( ; pIterator->hasNext(); pIterator->next() )
81 ScRange aRange = pIterator->get();
92 pSfxBindings, pChildWindow, pParent, rViewData,
93 "modules/scalc/ui/analysisofvariancedialog.ui",
94 "AnalysisOfVarianceDialog")
95 , meFactor(SINGLE_FACTOR)
96 , mxAlphaField(m_xBuilder->weld_spin_button(
"alpha-spin"))
97 , mxSingleFactorRadio(m_xBuilder->weld_radio_button(
"radio-single-factor"))
98 , mxTwoFactorRadio(m_xBuilder->weld_radio_button(
"radio-two-factor"))
99 , mxRowsPerSampleField(m_xBuilder->weld_spin_button(
"rows-per-sample-spin"))
121 return STR_ANALYSIS_OF_VARIANCE_UNDO_NAME;
150 if (pResultRange !=
nullptr)
154 for (
size_t i = 0;
i < rRangeList.
size();
i++)
156 ScRange const & rRange = rRangeList[
i];
158 aTemplate.
applyRange(strWildcardRange, rRange);
160 if (pResultRange !=
nullptr)
167 TranslateId pLabelId = (aGroupedBy ==
BY_COLUMN) ? STR_COLUMN_LABEL_TEMPLATE : STR_ROW_LABEL_TEMPLATE;
168 OUString aLabelTemplate(
ScResId(pLabelId));
170 for (
size_t i = 0;
i < rRangeList.
size();
i++)
175 if (pResultRange !=
nullptr)
196 for(sal_Int32
i = 0; lclBasicStatistics[
i].aLabelId;
i++)
210 for(sal_Int32
i = 0; lclBasicStatistics[
i].aLabelId;
i++)
214 OUString
sFormula = OUString::createFromAscii(lclBasicStatistics[
i].aFormula);
217 if (lclBasicStatistics[
i].aResultRangeName !=
nullptr)
219 OUString sResultRangeName = OUString::createFromAscii(lclBasicStatistics[
i].aResultRangeName);
228 for(sal_Int32
i = 0; lclAnovaLabels[
i];
i++)
245 aTemplate.
setTemplate(
"=SUMPRODUCT(%SUM_RANGE%;%MEAN_RANGE%)-SUM(%SUM_RANGE%)^2/SUM(%COUNT_RANGE%)");
257 aTemplate.
setTemplate(
"=%BETWEEN_SS% / %BETWEEN_DF%");
263 aTemplate.
setTemplate(
"=%BETWEEN_MS% / %WITHIN_MS%");
270 aTemplate.
setTemplate(
"=FDIST(%F_VAL%; %BETWEEN_DF%; %WITHIN_DF%");
276 aTemplate.
setTemplate(
"=FINV(%ALPHA%; %BETWEEN_DF%; %WITHIN_DF%");
290 OUString aSSPart = lclCreateMultiParameterFormula(aRangeList,
"DEVSQ(%RANGE%)", strWildcardRange,
mDocument,
mAddressDetails);
298 aTemplate.
setTemplate(
"=SUM(%COUNT_RANGE%)-COUNT(%COUNT_RANGE%)");
304 aTemplate.
setTemplate(
"=%WITHIN_SS% / %WITHIN_DF%");
343 for(sal_Int32
i = 0; lclBasicStatistics[
i].aLabelId;
i++)
358 for(sal_Int32
i = 0; lclBasicStatistics[
i].aLabelId;
i++)
362 OUString
sFormula = OUString::createFromAscii(lclBasicStatistics[
i].aFormula);
364 if (lclBasicStatistics[
i].aResultRangeName !=
nullptr)
366 OUString sResultRangeName = OUString::createFromAscii(lclBasicStatistics[
i].aResultRangeName);
367 aTemplate.
autoReplaceRange(
"%" + sResultRangeName +
"_COLUMN%", aResultRange);
375 for(sal_Int32
i = 0; lclBasicStatistics[
i].aLabelId;
i++)
379 OUString
sFormula = OUString::createFromAscii(lclBasicStatistics[
i].aFormula);
382 if (lclBasicStatistics[
i].aResultRangeName !=
nullptr)
384 OUString sResultRangeName = OUString::createFromAscii(lclBasicStatistics[
i].aResultRangeName);
392 for(sal_Int32
i = 0; lclAnovaLabels[
i];
i++)
412 aTemplate.
setTemplate(
"=SUMPRODUCT(%SUM_RANGE_ROW%;%MEAN_RANGE_ROW%) - SUM(%RANGE%)^2 / COUNT(%RANGE%)");
418 aTemplate.
setTemplate(
"=MAX(%COUNT_RANGE_COLUMN%) - 1");
437 aTemplate.
setTemplate(
"=FDIST(%F_ROW%; %ROW_DF%; %ERROR_DF%");
443 aTemplate.
setTemplate(
"=FINV(%ALPHA%; %ROW_DF%; %ERROR_DF%");
458 aTemplate.
setTemplate(
"=SUMPRODUCT(%SUM_RANGE_COLUMN%;%MEAN_RANGE_COLUMN%) - SUM(%RANGE%)^2 / COUNT(%RANGE%)");
464 aTemplate.
setTemplate(
"=MAX(%COUNT_RANGE_ROW%) - 1");
470 aTemplate.
setTemplate(
"=%COLUMN_SS% / %COLUMN_DF%");
476 aTemplate.
setTemplate(
"=%MS_COLUMN% / %MS_ERROR%");
483 aTemplate.
setTemplate(
"=FDIST(%F_COLUMN%; %COLUMN_DF%; %ERROR_DF%");
489 aTemplate.
setTemplate(
"=FINV(%ALPHA%; %COLUMN_DF%; %ERROR_DF%");
504 aTemplate.
setTemplate(
"=SUMSQ(%RANGE%)+SUM(%RANGE%)^2/COUNT(%RANGE%) - (SUMPRODUCT(%SUM_RANGE_ROW%;%MEAN_RANGE_ROW%) + SUMPRODUCT(%SUM_RANGE_COLUMN%;%MEAN_RANGE_COLUMN%))");
510 aTemplate.
setTemplate(
"=%TOTAL_DF% - %ROW_DF% - %COLUMN_DF%");
530 aTemplate.
setTemplate(
"=SUM(%ROW_SS%;%COLUMN_SS%;%ERROR_SS%)");
IMPL_LINK_NOARG(ScAnalysisOfVarianceDialog, FactorChanged, weld::Toggleable &, void)
void writeFormula(const OUString &aFormula)
void writeBoldString(const OUString &aString)
void writeValue(double aValue)
void writeString(const OUString &aString)
ScAddress current(SCCOL aRelativeCol=0, SCROW aRelativeRow=0, SCTAB aRelativeTab=0)
void push(SCCOL aRelativeCol=0, SCROW aRelativeRow=0, SCTAB aRelativeTab=0)
ScAddress mMaximumAddress
ScAddress mMinimumAddress
static sal_uInt16 GetChildWindowId()
virtual ScRange ApplyOutput(ScDocShell *pDocShell) override
std::unique_ptr< weld::RadioButton > mxTwoFactorRadio
ScAnalysisOfVarianceDialog(SfxBindings *pB, SfxChildWindow *pCW, weld::Window *pParent, ScViewData &rViewData)
void AnovaTwoFactor(AddressWalkerWriter &output, FormulaTemplate &aTemplate)
std::unique_ptr< weld::SpinButton > mxRowsPerSampleField
virtual ~ScAnalysisOfVarianceDialog() override
virtual void Close() override
static void RowColumn(ScRangeList &rRangeList, AddressWalkerWriter &aOutput, FormulaTemplate &aTemplate, const OUString &sFormula, GroupedBy aGroupedBy, ScRange *pResultRange)
std::unique_ptr< weld::RadioButton > mxSingleFactorRadio
std::unique_ptr< weld::SpinButton > mxAlphaField
void AnovaSingleFactor(AddressWalkerWriter &output, FormulaTemplate &aTemplate)
virtual TranslateId GetUndoNameId() override
void push_back(const ScRange &rRange)
bool DoClose(sal_uInt16 nId)
#define LINK(Instance, Class, Member)
OUString ScResId(TranslateId aId)
formula::FormulaGrammar::AddressConvention eConv