15#include <document.hxx>
100 enum class ScRegType {
109 STR_LABEL_LOGARITHMIC,
113 OUString constTemplateLINEST[] =
115 "=LINEST(%VARIABLE2_RANGE% ; %VARIABLE1_RANGE% ; %CALC_INTERCEPT% ; TRUE)",
116 "=LINEST(%VARIABLE2_RANGE% ; LN(%VARIABLE1_RANGE%) ; %CALC_INTERCEPT% ; TRUE)",
117 "=LINEST(LN(%VARIABLE2_RANGE%) ; LN(%VARIABLE1_RANGE%) ; %CALC_INTERCEPT% ; TRUE)"
120 OUString constRegressionFormula[] =
122 "=MMULT(%XDATAMATRIX_RANGE% ; %SLOPES_RANGE%) + %INTERCEPT_ADDR%",
123 "=MMULT(LN(%XDATAMATRIX_RANGE%) ; %SLOPES_RANGE%) + %INTERCEPT_ADDR%",
124 "=EXP(MMULT(LN(%XDATAMATRIX_RANGE%) ; %SLOPES_RANGE%) + %INTERCEPT_ADDR%)"
141 pSfxBindings, pChildWindow, pParent, rViewData,
142 "modules/scalc/ui/regressiondialog.ui",
"RegressionDialog")
144 , mnNumIndependentVars(1)
145 , mnNumObservations(0)
146 , mbUse3DAddresses(false)
147 , mbCalcIntercept(true)
148 , mxWithLabelsCheckBox(m_xBuilder->weld_check_button(
"withlabels-check"))
149 , mxLinearRadioButton(m_xBuilder->weld_radio_button(
"linear-radio"))
150 , mxLogarithmicRadioButton(m_xBuilder->weld_radio_button(
"logarithmic-radio"))
151 , mxErrorMessage(m_xBuilder->weld_label(
"error-message"))
152 , mxConfidenceLevelField(m_xBuilder->weld_spin_button(
"confidencelevel-spin"))
153 , mxCalcResidualsCheckBox(m_xBuilder->weld_check_button(
"calcresiduals-check"))
154 , mxNoInterceptCheckBox(m_xBuilder->weld_check_button(
"nointercept-check"))
171 return STR_REGRESSION_UNDO_NAME;
196 ScRegType eRegType =
static_cast<ScRegType
>(nRegressionIndex);
197 bool bTakeLogX = eRegType == ScRegType::LOGARITHMIC || eRegType == ScRegType::POWER;
207 aMaxAddress.
SetCol(std::max(aMaxAddress.
Col(), nOutputMaxCol));
233 if ( fConfidenceLevel <= 0.0 || fConfidenceLevel >= 100.0 )
245 bool bYHasSingleDim = (
248 (!bGroupedByColumn &&
253 if (bGroupedByColumn)
312 return "=\"" +
ScResId(STR_LABEL_INTERCEPT) +
"\"";
323 return bWithLog ? OUString(
"=CONCAT(\"LN(\";" +
328 OUString aDefaultVarName;
331 aDefaultVarName =
"X" + OUString::number(
nIndex);
333 aDefaultVarName =
"Y";
335 return bWithLog ? OUString(
"=\"LN(" + aDefaultVarName +
")\"") :
336 OUString(
"=\"" + aDefaultVarName +
"\"");
351 size_t nRegressionIndex)
366 rTemplate.
setTemplate(constTemplateLINEST[nRegressionIndex].
367 replaceFirst(
"%CALC_INTERCEPT%",
368 mbCalcIntercept ? std::u16string_view(
u"TRUE") : std::u16string_view(
u"FALSE")));
401 STRID_CALC_STD_ERROR,
402 STR_LABEL_XVARIABLES_COUNT,
403 STR_OBSERVATIONS_LABEL,
404 STR_LABEL_ADJUSTED_RSQUARED
407 OUString aMeasureFormulas[] =
414 "=1 - (1 - %RSQUARED_ADDR%)*(%NUMOBS_ADDR% - 1)/(%NUMOBS_ADDR% - %NUMXVARS_ADDR%") +
421 for (
size_t nIdx = 0; nIdx <
SAL_N_ELEMENTS(aMeasureNames); ++nIdx)
437 const size_t nColsInTable = 6;
438 const size_t nRowsInTable = 4;
439 OUString aTable[nRowsInTable][nColsInTable] =
447 ScResId(STR_ANOVA_LABEL_SIGNIFICANCE_F)
453 "=%SSREG_ADDR% / %DoFREG_ADDR%",
454 "=%FSTATISTIC_ADDR%",
455 "=FDIST(%FSTATISTIC_ADDR% ; %DoFREG_ADDR% ; %DoFRESID_ADDR%)"
461 "=%SSRESID_ADDR% / %DoFRESID_ADDR%",
466 ScResId(STR_ANOVA_LABEL_TOTAL),
467 "=%DoFREG_ADDR% + %DoFRESID_ADDR%",
468 "=%SSREG_ADDR% + %SSRESID_ADDR%",
478 std::function<CellValueGetter> aCellGetterFunc = [&aTable](
size_t nRowIdx,
size_t nColIdx) ->
const OUString&
480 return aTable[nRowIdx][nColIdx];
484 std::function<CellWriter> aCellWriterFunc = [&rOutput, &rTemplate]
485 (
const OUString& rContent,
size_t ,
size_t )
487 if (!rContent.isEmpty())
489 if (rContent.startsWith(
"="))
499 WriteTable(aCellGetterFunc, nRowsInTable, nColsInTable, rOutput, aCellWriterFunc);
538 const size_t nColsInTable = 7;
539 const size_t nRowsInTable = 2;
540 OUString aTable[nRowsInTable][nColsInTable] =
544 ScResId(STR_LABEL_COEFFICIENTS),
549 "=CONCAT(\"" +
ScResId(STR_LABEL_LOWER) +
550 " \" ; INT(%CONFIDENCE_LEVEL_ADDR% * 100) ; \"%\")",
552 "=CONCAT(\"" +
ScResId(STR_LABEL_UPPER) +
553 " \" ; INT(%CONFIDENCE_LEVEL_ADDR% * 100) ; \"%\")",
560 "=INDEX(%COEFFICIENTS_REV_RANGE%; 1 ; ROW(" + aCoeffAddr +
")+1 - ROW())",
562 "=INDEX(%SERRORSX_REV_RANGE%; 1 ; ROW(" + aStErrAddr +
")+1 - ROW())",
564 "=%COEFFICIENTS_RANGE% / %SERRORSX_RANGE%",
566 "=TDIST(ABS(%TSTAT_RANGE%) ; %DoFRESID_ADDR% ; 2 )",
568 "=%COEFFICIENTS_RANGE% - %SERRORSX_RANGE% * "
569 "TINV(1 - %CONFIDENCE_LEVEL_ADDR% ; %DoFRESID_ADDR%)",
571 "=%COEFFICIENTS_RANGE% + %SERRORSX_RANGE% * "
572 "TINV(1 - %CONFIDENCE_LEVEL_ADDR% ; %DoFRESID_ADDR%)"
577 std::function<CellValueGetter> aCellGetterFunc = [&aTable](
size_t nRowIdx,
size_t nColIdx) ->
const OUString&
579 return aTable[nRowIdx][nColIdx];
584 std::function<CellWriter> aCellWriterFunc = [&rOutput, &rTemplate, nNumIndependentVars]
585 (
const OUString& rContent,
size_t nRowIdx,
size_t )
587 if (!rContent.isEmpty())
589 if (rContent.startsWith(
"="))
602 WriteTable(aCellGetterFunc, nRowsInTable, nColsInTable, rOutput, aCellWriterFunc);
618 size_t nRegressionIndex)
639 OUString aDataMatrixFormula = bGroupedByColumn ? OUString(
"=%VARIABLE1_RANGE%") : OUString(
"=TRANSPOSE(%VARIABLE1_RANGE%)");
647 rTemplate.
setTemplate(constRegressionFormula[nRegressionIndex]);
655 OUString aYVectorFormula = bGroupedByColumn ? OUString(
"=%VARIABLE2_RANGE%") : OUString(
"=TRANSPOSE(%VARIABLE2_RANGE%)");
664 rTemplate.
setTemplate(
"=%ACTUALY_RANGE% - %PREDICTEDY_RANGE%");
670 size_t nRowsInTable,
size_t nColsInTable,
672 const std::function<CellWriter>& rFunc)
674 for (
size_t nRowIdx = 0; nRowIdx < nRowsInTable; ++nRowIdx)
676 for (
size_t nColIdx = 0; nColIdx < nColsInTable; ++nColIdx)
678 rFunc(rCellGetter(nRowIdx, nColIdx), nRowIdx, nColIdx);
687 ValidateDialogInput();
692 ValidateDialogInput();
static size_t lcl_GetNumRowsColsInRange(const ScRange &rRange, bool bRows)
IMPL_LINK_NOARG(ScRegressionDialog, CheckBoxHdl, weld::Toggleable &, void)
void writeMatrixFormula(const OUString &aFormula, SCCOL nCols=1, SCROW nRows=1)
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()
SC_DLLPUBLIC void Format(OStringBuffer &r, ScRefFlags nFlags, const ScDocument *pDocument=nullptr, const Details &rDetails=detailsOOOa1) const
void IncCol(SCCOL nDelta=1)
void IncRow(SCROW nDelta=1)
SC_DLLPUBLIC formula::FormulaGrammar::AddressConvention GetAddressConvention() const
bool DoClose(sal_uInt16 nId)
virtual void Close() override
virtual TranslateId GetUndoNameId() override
std::unique_ptr< weld::RadioButton > mxLinearRadioButton
void WritePredictionsWithResiduals(AddressWalkerWriter &rOutput, FormulaTemplate &rTemplate, size_t nRegressionIndex)
ScRegressionDialog(SfxBindings *pB, SfxChildWindow *pCW, weld::Window *pParent, ScViewData &rViewData)
std::unique_ptr< weld::RadioButton > mxLogarithmicRadioButton
void WriteRegressionEstimatesWithCI(AddressWalkerWriter &rOutput, FormulaTemplate &rTemplate, bool bTakeLogX)
std::unique_ptr< weld::SpinButton > mxConfidenceLevelField
size_t GetRegressionTypeIndex() const
virtual ~ScRegressionDialog() override
void WriteRegressionStatistics(AddressWalkerWriter &rOutput, FormulaTemplate &rTemplate)
OUString GetXVariableNameFormula(size_t nIndex, bool bWithLog)
void WriteRegressionANOVAResults(AddressWalkerWriter &rOutput, FormulaTemplate &rTemplate)
static void WriteTable(const std::function< CellValueGetter > &rCellGetter, size_t nRowsInTable, size_t nColsInTable, AddressWalkerWriter &rOutput, const std::function< CellWriter > &rFunc)
virtual bool InputRangesValid() override
std::unique_ptr< weld::CheckButton > mxCalcResidualsCheckBox
ScRange GetDataRange(const ScRange &rRange)
std::unique_ptr< weld::Label > mxErrorMessage
size_t mnNumIndependentVars
void WriteRawRegressionResults(AddressWalkerWriter &rOutput, FormulaTemplate &rTemplate, size_t nRegressionIndex)
OUString GetVariableNameFormula(bool bXVar, size_t nIndex, bool bWithLog)
std::unique_ptr< weld::CheckButton > mxNoInterceptCheckBox
virtual ScRange ApplyOutput(ScDocShell *pDocShell) override
OUString GetYVariableNameFormula(bool bWithLog)
std::unique_ptr< weld::CheckButton > mxWithLabelsCheckBox
ScAddress::Details const mAddressDetails
#define LINK(Instance, Class, Member)
#define SAL_N_ELEMENTS(arr)
OUString ScResId(TranslateId aId)
formula::FormulaGrammar::AddressConvention eConv