diff --git a/src/hypothesistestdock.ui b/src/hypothesistestdock.ui
new file mode 100644
index 000000000..bc5260a7a
--- /dev/null
+++ b/src/hypothesistestdock.ui
@@ -0,0 +1,483 @@
+
+
+ HypothesisTestDock
+
+
+
+ 0
+ 0
+ 557
+ 1293
+
+
+
+ Form
+
+
+ -
+
+
+ Qt::Horizontal
+
+
+
+ 150
+ 20
+
+
+
+
+ -
+
+
+ -
+
+
+ Qt::Vertical
+
+
+ QSizePolicy::Fixed
+
+
+
+ 32
+ 18
+
+
+
+
+ -
+
+
+
+ 0
+ 0
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+ 0
+ 0
+
+
+
+
+ -
+
+
+
+
+
+
+ -
+
+
+ Qt::Vertical
+
+
+
+ 18
+ 38
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ Qt::Vertical
+
+
+ QSizePolicy::Fixed
+
+
+
+ 32
+ 18
+
+
+
+
+ -
+
+
+ -
+
+
+ QFrame::NoFrame
+
+
+ QFrame::Raised
+
+
+
+ 0
+
+
+ 0
+
+
+ 0
+
+
+ 0
+
+
+ 0
+
+
-
+
+
+ mu > muo
+
+
+
+ -
+
+
+ mu < muo
+
+
+
+ -
+
+
+ mu != muo
+
+
+
+
+
+
+ -
+
+
+ Qt::Vertical
+
+
+ QSizePolicy::Fixed
+
+
+
+ 32
+ 18
+
+
+
+
+ -
+
+
+ QFrame::NoFrame
+
+
+ QFrame::Raised
+
+
+
+ 0
+
+
+ 0
+
+
+ 0
+
+
+ 0
+
+
-
+
+
+ mu <= muo
+
+
+
+ -
+
+
+ mu >= muo
+
+
+
+ -
+
+
+ mu == muo
+
+
+
+
+
+
+ -
+
+
+ Qt::Vertical
+
+
+ QSizePolicy::Fixed
+
+
+
+ 32
+ 18
+
+
+
+
+ -
+
+
+
+ 0
+ 0
+
+
+
+
+
+
+
+ -
+
+
+ Recalculate
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ Qt::Horizontal
+
+
+ QSizePolicy::Fixed
+
+
+
+ 13
+ 23
+
+
+
+
+ -
+
+
+ Qt::Horizontal
+
+
+
+ -
+
+
+ Independent Var. 1
+
+
+ Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter
+
+
+
+ -
+
+
+
+ 0
+ 0
+
+
+
+ Name:
+
+
+
+ -
+
+
+ Comment:
+
+
+
+ -
+
+
+
+ 75
+ true
+
+
+
+ Data
+
+
+
+ -
+
+
+ Source:
+
+
+
+ -
+
+
+ Spreadsheet:
+
+
+
+ -
+
+
+ Connection:
+
+
+
+ -
+
+
+ Table:
+
+
+
+ -
+
+
+
+ 75
+ true
+
+
+
+ Test
+
+
+
+ -
+
+
+ Type
+
+
+
+ -
+
+
+ Sub-type
+
+
+
+ -
+
+
+
+ 75
+ true
+
+
+
+ Variables
+
+
+
+ -
+
+
+ Independent Var. 2
+
+
+
+ -
+
+
+ Variable
+
+
+
+ -
+
+
+ Equal Variance
+
+
+
+ -
+
+
+
+ 75
+ true
+
+
+
+ Hypothesis
+
+
+
+ -
+
+
+ Null
+
+
+ Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop
+
+
+
+ -
+
+
+ Alternate
+
+
+ Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop
+
+
+
+ -
+
+
+ muo
+
+
+
+ -
+
+
+ alpha
+
+
+
+
+
+
+
+
diff --git a/src/kdefrontend/dockwidgets/HypothesisTestDock.cpp b/src/kdefrontend/dockwidgets/HypothesisTestDock.cpp
index 531b86434..c020df275 100644
--- a/src/kdefrontend/dockwidgets/HypothesisTestDock.cpp
+++ b/src/kdefrontend/dockwidgets/HypothesisTestDock.cpp
@@ -1,781 +1,779 @@
/***************************************************************************
File : HypothesisTestDock.cpp
Project : LabPlot
Description : widget for hypothesis test properties
--------------------------------------------------------------------
Copyright : (C) 2019 Devanshu Agarwal(agarwaldevanshu8@gmail.com)
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the Free Software *
* Foundation, Inc., 51 Franklin Street, Fifth Floor, *
* Boston, MA 02110-1301 USA *
* *
***************************************************************************/
#include "HypothesisTestDock.h"
#include "backend/core/AspectTreeModel.h"
#include "backend/core/AbstractAspect.h"
#include "backend/core/Project.h"
#include "backend/spreadsheet/Spreadsheet.h"
#include "commonfrontend/widgets/TreeViewComboBox.h"
#include "kdefrontend/datasources/DatabaseManagerDialog.h"
#include "kdefrontend/datasources/DatabaseManagerWidget.h"
//#include "kdefrontend/pivot/hypothesisTestView.h"
#include "kdefrontend/TemplateHandler.h"
#include
#include
#include
#include
#include
#include
#include
#include
#include
/*!
\class HypothesisTestDock
\brief Provides a dock (widget) for hypothesis testing:
\ingroup kdefrontend
*/
//TOOD: Make this dock widget scrollable and automatic resizeable for different screens.
HypothesisTestDock::HypothesisTestDock(QWidget* parent) : QWidget(parent) {
ui.setupUi(this);
ui.cbDataSourceType->addItem(i18n("Spreadsheet"));
ui.cbDataSourceType->addItem(i18n("Database"));
cbSpreadsheet = new TreeViewComboBox;
- ui.gridLayout->addWidget(cbSpreadsheet, 1, 1);
+ ui.gridLayout->addWidget(cbSpreadsheet, 5, 4, 1, 3);
ui.bDatabaseManager->setIcon(QIcon::fromTheme("network-server-database"));
ui.bDatabaseManager->setToolTip(i18n("Manage connections"));
m_configPath = QStandardPaths::standardLocations(QStandardPaths::AppDataLocation).constFirst() + "sql_connections";
// adding item to tests and testtype combo box;
ui.cbTest->addItem(i18n("T Test"));
ui.cbTest->addItem(i18n("Z Test"));
ui.cbTest->addItem(i18n("Anova"));
test_type_t_z.append( i18n( "Two Sample Independent"));
test_type_t_z.append( i18n("Two Sample Paired"));
test_type_t_z.append( i18n("One Sample"));
test_type_anova.append( i18n("One Way"));
test_type_anova.append( i18n("Two Way"));
// making all test blocks invisible at starting.
- ui.pbLeveneTest->setVisible(false);
- ui.chbCategorical->setVisible(false);
- ui.lCol1->setVisible(false);
- ui.cbCol1->setVisible(false);
- ui.lCol2->setVisible(false);
- ui.cbCol2->setVisible(false);
- ui.chbEqualVariance->setVisible(false);
+ ui.pbLeveneTest->hide();
+ ui.lCategorical->hide();
+ ui.chbCategorical->hide();
+ ui.lCol1->hide();
+ ui.cbCol1->hide();
+ ui.lCol2->hide();
+ ui.cbCol2->hide();
+ ui.lEqualVariance->hide();
+ ui.chbEqualVariance->hide();
ui.chbEqualVariance->setChecked(true);
ui.pbPerformTest->setEnabled(false);
- ui.rbH1OneTail2->setVisible(false);
- ui.rbH1OneTail1->setVisible(false);
- ui.rbH1TwoTail->setVisible(false);
- ui.rbH0OneTail1->setVisible(false);
- ui.rbH0OneTail2->setVisible(false);
- ui.rbH0TwoTail->setVisible(false);
- ui.lH0->setVisible(false);
- ui.lH1->setVisible(false);
+ ui.rbH1OneTail2->hide();
+ ui.rbH1OneTail1->hide();
+ ui.rbH1TwoTail->hide();
+ ui.rbH0OneTail1->hide();
+ ui.rbH0OneTail2->hide();
+ ui.rbH0TwoTail->hide();
+ ui.lH0->hide();
+ ui.lH1->hide();
QString mu = UTF8_QSTRING("μ");
QString mu0 = UTF8_QSTRING("μₒ");
// radio button for null and alternate hypothesis
// for alternative hypothesis (h1)
// one_tail_1 is mu > mu0; one_tail_2 is mu < mu0; two_tail = mu != mu0;
ui.rbH1OneTail1->setText( i18n("%1 %2 %3", mu, UTF8_QSTRING(">"), mu0));
ui.rbH1OneTail2->setText( i18n("%1 %2 %3", mu, UTF8_QSTRING("<"), mu0));
ui.rbH1TwoTail->setText( i18n("%1 %2 %3", mu, UTF8_QSTRING("≠"), mu0));
ui.rbH0OneTail1->setText( i18n("%1 %2 %3",mu, UTF8_QSTRING("≤"), mu0));
ui.rbH0OneTail2->setText( i18n("%1 %2 %3", mu, UTF8_QSTRING("≥"), mu0));
ui.rbH0TwoTail->setText( i18n("%1 %2 %3", mu, UTF8_QSTRING("="), mu0));
ui.rbH0TwoTail->setEnabled(false);
ui.rbH0OneTail1->setEnabled(false);
ui.rbH0OneTail2->setEnabled(false);
// setting muo and alpha buttons
ui.lMuo->setText( i18n("%1", mu0));
ui.lAlpha->setText( i18n("%1", UTF8_QSTRING("α")));
ui.leMuo->setText( i18n("%1", population_mean));
ui.leAlpha->setText( i18n("%1", significance_level));
- ui.lMuo->setVisible(false);
- ui.lAlpha->setVisible(false);
- ui.leMuo->setVisible(false);
- ui.leAlpha->setVisible(false);
+ ui.lMuo->hide();
+ ui.lAlpha->hide();
+ ui.leMuo->hide();
+ ui.leAlpha->hide();
+
+ ui.pbPerformTest->setIcon(QIcon::fromTheme("run-build"));
+
// readConnections();
// auto* style = ui.bAddRow->style();
// ui.bAddRow->setIcon(style->standardIcon(QStyle::SP_ArrowRight));
// ui.bAddRow->setToolTip(i18n("Add the selected field to rows"));
// ui.bRemoveRow->setIcon(style->standardIcon(QStyle::SP_ArrowLeft));
// ui.bRemoveRow->setToolTip(i18n("Remove the selected field from rows"));
// ui.bAddColumn->setIcon(style->standardIcon(QStyle::SP_ArrowRight));
// ui.bAddColumn->setToolTip(i18n("Add the selected field to columns"));
// ui.bRemoveColumn->setIcon(style->standardIcon(QStyle::SP_ArrowLeft));
// ui.bRemoveColumn->setToolTip(i18n("Remove the selected field from columns"));
// //add/remove buttons only enabled if something was selected
// ui.bAddRow->setEnabled(false);
// ui.bRemoveRow->setEnabled(false);
// ui.bAddColumn->setEnabled(false);
// ui.bRemoveColumn->setEnabled(false);
// connect(ui.leName, &QLineEdit::textChanged, this, &HypothesisTestDock::nameChanged);
// connect(ui.leComment, &QLineEdit::textChanged, this, &HypothesisTestDock::commentChanged);
connect(ui.cbDataSourceType, static_cast(&QComboBox::currentIndexChanged),
this, &HypothesisTestDock::dataSourceTypeChanged);
connect(cbSpreadsheet, &TreeViewComboBox::currentModelIndexChanged, this, &HypothesisTestDock::spreadsheetChanged);
// connect(ui.cbConnection, static_cast(&QComboBox::currentIndexChanged),
// this, &HypothesisTestDock::connectionChanged);
// connect(ui.cbTable, static_cast(&QComboBox::currentIndexChanged),
// this, &HypothesisTestDock::tableChanged);
// connect(ui.bDatabaseManager, &QPushButton::clicked, this, &HypothesisTestDock::showDatabaseManager);
// connect(ui.bAddRow, &QPushButton::clicked, this, &HypothesisTestDock::addRow);
// connect(ui.bRemoveRow, &QPushButton::clicked, this,&HypothesisTestDock::removeRow);
// connect(ui.bAddColumn, &QPushButton::clicked, this, &HypothesisTestDock::addColumn);
// connect(ui.bRemoveColumn, &QPushButton::clicked, this,&HypothesisTestDock::removeColumn);
// connect(ui.cbCol1, static_cast(&QComboBox::currentIndexChanged), this, &HypothesisTestDock::doTTest);
// connect(ui.cbCol2, static_cast(&QComboBox::currentIndexChanged), this, &HypothesisTestDock::doTTest);
// connect(ui.lwFields, &QListWidget::itemSelectionChanged, this, [=]() {
// bool enabled = !ui.lwFields->selectedItems().isEmpty();
// ui.bAddRow->setEnabled(enabled);
// ui.bAddColumn->setEnabled(enabled);
// });
// connect(ui.lwRows, &QListWidget::doubleClicked, this,&HypothesisTestDock::removeRow);
// connect(ui.lwRows, &QListWidget::itemSelectionChanged, this, [=]() {
// ui.bRemoveRow->setEnabled(!ui.lwRows->selectedItems().isEmpty());
// });
// connect(ui.lwColumns, &QListWidget::doubleClicked, this,&HypothesisTestDock::removeColumn);
// connect(ui.lwColumns, &QListWidget::itemSelectionChanged, this, [=]() {
// ui.bRemoveColumn->setEnabled(!ui.lwColumns->selectedItems().isEmpty());
// });
connect(ui.cbTest, static_cast(&QComboBox::activated), this, &HypothesisTestDock::showTestType);
connect(ui.cbTestType, static_cast(&QComboBox::activated), this, &HypothesisTestDock::showHypothesisTest);
// connect(ui.cbTest, static_cast(&QComboBox::currentIndexChanged), this, &HypothesisTestDock::showHypothesisTest);
// connect(ui.cbTestType, static_cast(&QComboBox::currentIndexChanged), this, &HypothesisTestDock::showHypothesisTest);
connect(ui.pbPerformTest, &QPushButton::clicked, this, &HypothesisTestDock::doHypothesisTest);
connect(ui.pbLeveneTest, &QPushButton::clicked, this, &HypothesisTestDock::performLeveneTest);
//connecting null hypothesis and alternate hypothesis radio button
connect(ui.rbH1OneTail1, &QRadioButton::toggled, this, &HypothesisTestDock::onRbH1OneTail1Toggled);
connect(ui.rbH1OneTail2, &QRadioButton::toggled, this, &HypothesisTestDock::onRbH1OneTail2Toggled);
connect(ui.rbH1TwoTail, &QRadioButton::toggled, this, &HypothesisTestDock::onRbH1TwoTailToggled);
connect(ui.cbCol1, static_cast(&QComboBox::currentIndexChanged), this, &HypothesisTestDock::col1IndexChanged);
}
void HypothesisTestDock::setHypothesisTest(HypothesisTest* HypothesisTest) {
- // m_initializing = true;
+ m_initializing = true;
m_hypothesisTest = HypothesisTest;
- //// m_aspectTreeModel = new AspectTreeModel(m_hypothesisTest->project());
+ m_aspectTreeModel = new AspectTreeModel(m_hypothesisTest->project());
- // QList list;
- // list << "Folder" << "Workbook" << "Spreadsheet" << "LiveDataSource";
- // cbSpreadsheet->setTopLevelClasses(list);
+ QList list;
+ list << "Folder" << "Workbook" << "Spreadsheet" << "LiveDataSource";
+ cbSpreadsheet->setTopLevelClasses(list);
- // list.clear();
- // list << "Spreadsheet" << "LiveDataSource";
- //// m_aspectTreeModel->setSelectableAspects(list);
+ list.clear();
+ list << "Spreadsheet" << "LiveDataSource";
+ m_aspectTreeModel->setSelectableAspects(list);
- //// cbSpreadsheet->setModel(m_aspectTreeModel);
+ cbSpreadsheet->setModel(m_aspectTreeModel);
//show the properties
ui.leName->setText(m_hypothesisTest->name());
ui.leComment->setText(m_hypothesisTest->comment());
ui.cbDataSourceType->setCurrentIndex(m_hypothesisTest->dataSourceType());
- // if (m_hypothesisTest->dataSourceType() == HypothesisTest::DataSourceSpreadsheet)
- // setModelIndexFromAspect(cbSpreadsheet, m_hypothesisTest->dataSourceSpreadsheet());
- // else
- // ui.cbConnection->setCurrentIndex(ui.cbConnection->findText(m_hypothesisTest->dataSourceConnection()));
+ if (m_hypothesisTest->dataSourceType() == HypothesisTest::DataSourceSpreadsheet)
+ setModelIndexFromAspect(cbSpreadsheet, m_hypothesisTest->dataSourceSpreadsheet());
+// else
+// ui.cbConnection->setCurrentIndex(ui.cbConnection->findText(m_hypothesisTest->dataSourceConnection()));
setColumnsComboBoxModel(m_hypothesisTest->dataSourceSpreadsheet());
this->dataSourceTypeChanged(ui.cbDataSourceType->currentIndex());
- // setting rows and columns in combo box;
-
-
- // //available dimensions and measures
- // ui.lwFields->clear();
- // for (auto dimension : m_hypothesisTest->dimensions())
- // ui.lwFields->addItem(new QListWidgetItem(QIcon::fromTheme("draw-text"), dimension));
+ //setting rows and columns in combo box;
- // for (auto measure : m_hypothesisTest->measures())
- // ui.lwFields->addItem(new QListWidgetItem(measure));
+ //undo functions
+ connect(m_hypothesisTest, SIGNAL(aspectDescriptionChanged(const AbstractAspect*)), this, SLOT(hypothesisTestDescriptionChanged(const AbstractAspect*)));
+ //TODO:
- // //undo functions
- // connect(m_hypothesisTest, SIGNAL(aspectDescriptionChanged(const AbstractAspect*)), this, SLOT(hypothesisTestDescriptionChanged(const AbstractAspect*)));
- // //TODO:
-
- // m_initializing = false;
+ m_initializing = false;
}
void HypothesisTestDock::showTestType() {
ttest = ui.cbTest->currentText() == "T Test";
ztest = ui.cbTest->currentText() == "Z Test";
anova = ui.cbTest->currentText() == "Anova";
ui.cbTestType->clear();
if (ttest || ztest)
ui.cbTestType->addItems(test_type_t_z);
if (anova)
ui.cbTestType->addItems(test_type_anova);
showHypothesisTest();
}
void HypothesisTestDock::showHypothesisTest() {
one_way = ui.cbTestType->currentText() == "One Way";
two_way = ui.cbTestType->currentText() == "Two Way";
two_sample_independent = ui.cbTestType->currentText() == "Two Sample Independent";
two_sample_paired = ui.cbTestType->currentText() == "Two Sample Paired";
one_sample = ui.cbTestType->currentText() == "One Sample";
ui.lCol1->setVisible(anova || two_sample_independent || two_sample_paired);
ui.cbCol1->setVisible(anova || two_sample_independent || two_sample_paired);
ui.lCol2->setVisible(anova || two_sample_independent || two_sample_paired || one_sample);
ui.cbCol2->setVisible(anova || two_sample_independent || two_sample_paired || one_sample);
+ ui.lEqualVariance->setVisible(ttest && two_sample_independent);
ui.chbEqualVariance->setVisible(ttest && two_sample_independent);
+ ui.lCategorical->setVisible(ttest && two_sample_independent);
ui.chbCategorical->setVisible(ttest && two_sample_independent);
ui.pbLeveneTest->setVisible(anova || (ttest && two_sample_independent));
ui.chbEqualVariance->setChecked(true);
ui.rbH1OneTail2->setVisible(two_sample_independent || two_sample_paired || one_sample);
ui.rbH1OneTail1->setVisible(two_sample_independent || two_sample_paired || one_sample);
ui.rbH1TwoTail->setVisible(two_sample_independent || two_sample_paired || one_sample);
ui.rbH0OneTail1->setVisible(two_sample_independent || two_sample_paired || one_sample);
ui.rbH0OneTail2->setVisible(two_sample_independent || two_sample_paired || one_sample);
ui.rbH0TwoTail->setVisible(two_sample_independent || two_sample_paired || one_sample);
ui.lH0->setVisible(two_sample_independent || two_sample_paired || one_sample);
ui.lH1->setVisible(two_sample_independent || two_sample_paired || one_sample);
ui.rbH1TwoTail->setChecked(true);
ui.lMuo->setVisible(one_sample);
ui.leMuo->setVisible(one_sample);
ui.lAlpha->setVisible(anova || two_sample_independent || two_sample_paired || one_sample);
ui.leAlpha->setVisible(anova || two_sample_independent || two_sample_paired || one_sample);
ui.leMuo->setText( i18n("%1", population_mean));
ui.leAlpha->setText( i18n("%1", significance_level));
setColumnsComboBoxView();
ui.pbPerformTest->setEnabled(nonEmptySelectedColumns() &&
(anova ||
two_sample_independent || two_sample_paired || one_sample));
}
void HypothesisTestDock::doHypothesisTest() {
m_hypothesisTest->setPopulationMean(ui.leMuo->text());
m_hypothesisTest->setSignificanceLevel(ui.leAlpha->text());
QStringList cols;
if(ttest) {
if(two_sample_independent) {
cols << ui.cbCol1->currentText() << ui.cbCol2->currentText();
m_hypothesisTest->setColumns(cols);
m_hypothesisTest->performTwoSampleIndependentTTest(ui.chbCategorical->isChecked(), ui.chbEqualVariance->isChecked());
}
else if(two_sample_paired) {
cols << ui.cbCol1->currentText();
cols << ui.cbCol2->currentText();
m_hypothesisTest->setColumns(cols);
m_hypothesisTest->performTwoSamplePairedTTest();
}
else if(one_sample){
cols << ui.cbCol1->currentText();
m_hypothesisTest->setColumns(cols);
m_hypothesisTest->performOneSampleTTest();
}
}
else if(ztest) {
if(two_sample_independent) {
cols << ui.cbCol1->currentText();
cols << ui.cbCol2->currentText();
m_hypothesisTest->setColumns(cols);
m_hypothesisTest->performTwoSampleIndependentZTest();
}
else if(two_sample_paired) {
cols << ui.cbCol1->currentText();
cols << ui.cbCol2->currentText();
m_hypothesisTest->setColumns(cols);
m_hypothesisTest->performTwoSamplePairedZTest();
}
else if(one_sample){
cols << ui.cbCol1->currentText();
m_hypothesisTest->setColumns(cols);
m_hypothesisTest->performOneSampleZTest();
}
}
else if(anova) {
QStringList cols;
if(one_way) {
cols << ui.cbCol1->currentText() << ui.cbCol2->currentText();
m_hypothesisTest->setColumns(cols);
m_hypothesisTest->performOneWayAnova();
}
}
}
void HypothesisTestDock::performLeveneTest() {
QStringList cols;
cols << ui.cbCol1->currentText() << ui.cbCol2->currentText();
m_hypothesisTest->setColumns(cols);
m_hypothesisTest->setSignificanceLevel(ui.leAlpha->text());
m_hypothesisTest->performLeveneTest(ui.chbCategorical->isChecked());
}
-//void HypothesisTestDock::setModelIndexFromAspect(TreeViewComboBox* cb, const AbstractAspect* aspect) {
-// if (aspect)
-// cb->setCurrentModelIndex(m_aspectTreeModel->modelIndexOfAspect(aspect));
-// else
-// cb->setCurrentModelIndex(QModelIndex());
-//}
+void HypothesisTestDock::setModelIndexFromAspect(TreeViewComboBox* cb, const AbstractAspect* aspect) {
+ if (aspect)
+ cb->setCurrentModelIndex(m_aspectTreeModel->modelIndexOfAspect(aspect));
+ else
+ cb->setCurrentModelIndex(QModelIndex());
+}
///*!
// shows the database manager where the connections are created and edited.
// The selected connection is selected in the connection combo box in this widget.
//**/
//void HypothesisTestDock::showDatabaseManager() {
// DatabaseManagerDialog* dlg = new DatabaseManagerDialog(this, ui.cbConnection->currentText());
// if (dlg->exec() == QDialog::Accepted) {
// //re-read the available connections to be in sync with the changes in DatabaseManager
// m_initializing = true;
// ui.cbConnection->clear();
// readConnections();
// //select the connection the user has selected in DatabaseManager
// const QString& conn = dlg->connection();
// ui.cbConnection->setCurrentIndex(ui.cbConnection->findText(conn));
// m_initializing = false;
// connectionChanged();
// }
// delete dlg;
//}
///*!
// loads all available saved connections
//*/
//void HypothesisTestDock::readConnections() {
// DEBUG("ImportSQLDatabaseWidget: reading available connections");
// KConfig config(m_configPath, KConfig::SimpleConfig);
// for (const auto& name : config.groupList())
// ui.cbConnection->addItem(name);
//}
///*!
// * adds the selected field to the rows
// */
//void HypothesisTestDock::addRow() {
// QString field = ui.lwFields->currentItem()->text();
// ui.lwRows->addItem(field);
// ui.lwFields->takeItem(ui.lwFields->currentRow());
// m_hypothesisTest->addToRows(field);
//}
///*!
// * removes the selected field from the rows
// */
//void HypothesisTestDock::removeRow() {
// const QString& field = ui.lwRows->currentItem()->text();
// ui.lwRows->takeItem(ui.lwRows->currentRow());
// m_hypothesisTest->removeFromRows(field);
// updateFields();
//}
///*!
// * adds the selected field to the columns
// */
//void HypothesisTestDock::addColumn() {
// QString field = ui.lwFields->currentItem()->text();
// ui.lwColumns->addItem(field);
// ui.lwFields->takeItem(ui.lwFields->currentRow());
// m_hypothesisTest->addToColumns(field);
//}
///*!
// * removes the selected field from the columns
// */
//void HypothesisTestDock::removeColumn() {
// const QString& field = ui.lwColumns->currentItem()->text();
// ui.lwColumns->takeItem(ui.lwColumns->currentRow());
// m_hypothesisTest->removeFromColumns(field);
// updateFields();
//}
///*!
// * re-populates the content of the "Fields" list widget by adding the non-selected fields only.
// * called when a selected field is removed from rows or columns.
// */
//void HypothesisTestDock::updateFields() {
// ui.lwFields->clear();
// for (auto dimension : m_hypothesisTest->dimensions())
// if (!fieldSelected(dimension))
// ui.lwFields->addItem(new QListWidgetItem(QIcon::fromTheme("draw-text"), dimension));
// for (auto measure : m_hypothesisTest->measures())
// if (!fieldSelected(measure))
// ui.lwFields->addItem(new QListWidgetItem(measure));
//}
///*!
// * return \c true if the field name \c field was selected among rows or columns,
// * return \c false otherwise.
// * */
//bool HypothesisTestDock::fieldSelected(const QString& field) {
// for (int i = 0; icount(); ++i)
// if (ui.lwRows->item(i)->text() == field)
// return true;
// for (int i = 0; icount(); ++i)
// if (ui.lwColumns->item(i)->text() == field)
// return true;
// return false;
//}
////*************************************************************
////****** SLOTs for changes triggered in HypothesisTestDock *******
////*************************************************************
//void HypothesisTestDock::nameChanged() {
// if (m_initializing)
// return;
// m_hypothesisTest->setName(ui.leName->text());
//}
//void HypothesisTestDock::commentChanged() {
// if (m_initializing)
// return;
// m_hypothesisTest->setComment(ui.leComment->text());
//}
void HypothesisTestDock::dataSourceTypeChanged(int index) {
HypothesisTest::DataSourceType type = static_cast(index);
bool showDatabase = (type == HypothesisTest::DataSourceDatabase);
ui.lSpreadsheet->setVisible(!showDatabase);
cbSpreadsheet->setVisible(!showDatabase);
ui.lConnection->setVisible(showDatabase);
ui.cbConnection->setVisible(showDatabase);
ui.bDatabaseManager->setVisible(showDatabase);
ui.lTable->setVisible(showDatabase);
ui.cbTable->setVisible(showDatabase);
- // if (m_initializing)
- // return;
+ if (m_initializing)
+ return;
m_hypothesisTest->setComment(ui.leComment->text());
}
void HypothesisTestDock::spreadsheetChanged(const QModelIndex& index) {
auto* aspect = static_cast(index.internalPointer());
Spreadsheet* spreadsheet = dynamic_cast(aspect);
setColumnsComboBoxModel(spreadsheet);
m_hypothesisTest->setDataSourceSpreadsheet(spreadsheet);
}
// currently no need of this slot
void HypothesisTestDock::col1IndexChanged(int index) {
if (index < 0) return;
if (two_sample_paired) {
- ui.lCol2->setText( i18n("Independent Variable"));
+ ui.lCol2->setText( i18n("Independent Var. 2"));
return;
}
QString selected_text = ui.cbCol1->currentText();
Column* col1 = m_hypothesisTest->dataSourceSpreadsheet()->column(selected_text);
if (col1->columnMode() == AbstractColumn::Integer || col1->columnMode() == AbstractColumn::Numeric) {
- ui.lCol2->setText( i18n("Independent Variable"));
+ ui.lCol2->setText( i18n("Independent Var. 2"));
ui.chbCategorical->setChecked(false);
ui.chbCategorical->setEnabled(true);
}
else {
- ui.lCol2->setText( i18n("Dependent Variable"));
+ ui.lCol2->setText( i18n("Dependent Var. 1"));
ui.chbCategorical->setChecked(true);
ui.chbCategorical->setEnabled(false);
}
}
//void HypothesisTestDock::connectionChanged() {
// if (ui.cbConnection->currentIndex() == -1) {
// ui.lTable->hide();
// ui.cbTable->hide();
// return;
// }
// //clear the previously shown tables
// ui.cbTable->clear();
// ui.lTable->show();
// ui.cbTable->show();
// const QString& connection = ui.cbConnection->currentText();
// //connection name was changed, determine the current connections settings
// KConfig config(m_configPath, KConfig::SimpleConfig);
// KConfigGroup group = config.group(connection);
// //close and remove the previos connection, if available
// if (m_db.isOpen()) {
// m_db.close();
// QSqlDatabase::removeDatabase(m_db.driverName());
// }
// //open the selected connection
// QDEBUG("HypothesisTestDock: connecting to " + connection);
// const QString& driver = group.readEntry("Driver");
// m_db = QSqlDatabase::addDatabase(driver);
// const QString& dbName = group.readEntry("DatabaseName");
// if (DatabaseManagerWidget::isFileDB(driver)) {
// if (!QFile::exists(dbName)) {
// KMessageBox::error(this, i18n("Couldn't find the database file '%1'. Please check the connection settings.", dbName),
// appendRow i18n("Connection Failed"));
// return;
// } else
// m_db.setDatabaseName(dbName);
// } else if (DatabaseManagerWidget::isODBC(driver)) {
// if (group.readEntry("CustomConnectionEnabled", false))
// m_db.setDatabaseName(group.readEntry("CustomConnectionString"));
// else
// m_db.setDatabaseName(dbName);
// } else {
// m_db.setDatabaseName(dbName);
// m_db.setHostName( group.readEntry("HostName") );
// m_db.setPort( group.readEntry("Port", 0) );
// m_db.setUserName( group.readEntry("UserName") );
// m_db.setPassword( group.readEntry("Password") );
// }
// WAIT_CURSOR;
// if (!m_db.open()) {
// RESET_CURSOR;
// KMessageBox::error(this, i18n("Failed to connect to the database '%1'. Please check the connection settings.", ui.cbConnection->currentText()) +
// QLatin1String("\n\n") + m_db.lastError().databaseText(),
// i18n("Connection Failed"));
// return;
// }
// //show all available database tables
// if (m_db.tables().size()) {
// for (auto table : m_db.tables())
// ui.cbTable->addItem(QIcon::fromTheme("view-form-table"), table);
// ui.cbTable->setCurrentIndex(0);
// }
// RESET_CURSOR;
// if (m_initializing)
// return;
//// m_hypothesisTest->setDataSourceConnection(connection);
//}
//void HypothesisTestDock::tableChanged() {
// const QString& table = ui.cbTable->currentText();
// //show all attributes of the selected table
//// for (const auto* col : spreadsheet->children()) {
//// QListWidgetItem* item = new QListWidgetItem(col->icon(), col->name());
//// ui.lwFields->addItem(item);
//// }
// if (m_initializing)
// return;
//// m_hypothesisTest->setDataSourceTable(table);
//}
////*************************************************************
////******** SLOTs for changes triggered in Matrix *********
////*************************************************************
//void HypothesisTestDock::hypothesisTestDescriptionChanged(const AbstractAspect* aspect) {
// if (m_hypothesisTest != aspect)
// return;
// m_initializing = true;
// if (aspect->name() != ui.leName->text())
// ui.leName->setText(aspect->name());
// else if (aspect->comment() != ui.leComment->text())
// ui.leComment->setText(aspect->comment());
// m_initializing = false;
//}
////*************************************************************
////******************** SETTINGS *******************************
////*************************************************************
//void HypothesisTestDock::load() {
//}
//void HypothesisTestDock::loadConfigFromTemplate(KConfig& config) {
// Q_UNUSED(config);
//}
///*!
// loads saved matrix properties from \c config.
// */
//void HypothesisTestDock::loadConfig(KConfig& config) {
// Q_UNUSED(config);
//}
///*!
// saves matrix properties to \c config.
// */
//void HypothesisTestDock::saveConfigAsTemplate(KConfig& config) {
// Q_UNUSED(config);
//}
//TODO: Rather than inbuilt slots use own decided slots for checked rather than clicked
// for alternate hypothesis
// one_tail_1 is mu > mu0; one_tail_2 is mu < mu0; two_tail = mu != mu0;
void HypothesisTestDock::onRbH1OneTail1Toggled(bool checked) {
if (!checked) return;
ui.rbH0OneTail1->setChecked(true);
m_hypothesisTest->setTailType(HypothesisTest::TailPositive);
}
void HypothesisTestDock::onRbH1OneTail2Toggled(bool checked) {
if (!checked) return;
ui.rbH0OneTail2->setChecked(true);
m_hypothesisTest->setTailType(HypothesisTest::TailNegative);
}
void HypothesisTestDock::onRbH1TwoTailToggled(bool checked) {
if (!checked) return;
ui.rbH0TwoTail->setChecked(true);
m_hypothesisTest->setTailType(HypothesisTest::TailTwo);
}
/**************************************Helper Functions********************************************/
void HypothesisTestDock::countPartitions(Column *column, int &np, int &total_rows) {
total_rows = column->rowCount();
np = 0;
QString cell_value;
QMap discovered_categorical_var;
AbstractColumn::ColumnMode original_col_mode = column->columnMode();
column->setColumnMode(AbstractColumn::Text);
for (int i = 0; i < total_rows; i++) {
cell_value = column->textAt(i);
if (cell_value.isEmpty()) {
total_rows = i;
break;
}
if (discovered_categorical_var[cell_value])
continue;
discovered_categorical_var[cell_value] = true;
np++;
}
column->setColumnMode(original_col_mode);
}
void HypothesisTestDock::setColumnsComboBoxModel(Spreadsheet* spreadsheet) {
only_values_cols.clear();
two_categorical_cols.clear();
more_than_two_categorical_cols.clear();
for (auto* col : spreadsheet->children()) {
if (col->columnMode() == AbstractColumn::Integer || col->columnMode() == AbstractColumn::Numeric)
only_values_cols.append(col->name());
else {
int np = 0, n_rows = 0;
countPartitions(col, np, n_rows);
if (np <= 1)
continue;
else if (np == 2)
two_categorical_cols.append(col->name());
else
more_than_two_categorical_cols.append(col->name());
}
}
setColumnsComboBoxView();
showHypothesisTest();
}
void HypothesisTestDock::setColumnsComboBoxView() {
ui.cbCol1->clear();
ui.cbCol2->clear();
if (two_sample_independent) {
ui.cbCol1->addItems(only_values_cols);
ui.cbCol1->addItems(two_categorical_cols);
ui.cbCol2->addItems(only_values_cols);
} else if (two_sample_paired) {
ui.cbCol1->addItems(only_values_cols);
ui.cbCol2->addItems(only_values_cols);
} else if (one_sample)
ui.cbCol1->addItems(only_values_cols);
else if (anova) {
ui.cbCol1->addItems(two_categorical_cols);
ui.cbCol1->addItems(more_than_two_categorical_cols);
ui.cbCol2->addItems(only_values_cols);
}
}
bool HypothesisTestDock::nonEmptySelectedColumns() {
if (ui.cbCol1->isVisible() && ui.cbCol1->count() < 1)
return false;
if (ui.cbCol2->isVisible() && ui.cbCol2->count() < 1)
return false;
return true;
}
diff --git a/src/kdefrontend/dockwidgets/HypothesisTestDock.h b/src/kdefrontend/dockwidgets/HypothesisTestDock.h
index d0784c3ca..4e2a31cd0 100644
--- a/src/kdefrontend/dockwidgets/HypothesisTestDock.h
+++ b/src/kdefrontend/dockwidgets/HypothesisTestDock.h
@@ -1,128 +1,128 @@
/***************************************************************************
File : HypothesisTestDock.h
Project : LabPlot
Description : widget for hypothesis testing properties
--------------------------------------------------------------------
Copyright : (C) 2019 Devanshu Agarwal(agarwaldevanshu8@gmail.com)
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the Free Software *
* Foundation, Inc., 51 Franklin Street, Fifth Floor, *
* Boston, MA 02110-1301 USA *
* *
***************************************************************************/
#ifndef HYPOTHESISTESTDOCK_H
#define HYPOTHESISTESTDOCK_H
#include "backend/hypothesis_test/HypothesisTest.h"
#include "ui_hypothesistestdock.h"
#include
class AbstractAspect;
class AspectTreeModel;
class HypothesisTest;
class TreeViewComboBox;
class KConfig;
class QScrollArea;
class QStandardItemModel;
class QStandardItem;
class HypothesisTestDock : public QWidget {
Q_OBJECT
public:
explicit HypothesisTestDock(QWidget*);
void setHypothesisTest(HypothesisTest*);
private slots:
void onRbH1OneTail1Toggled(bool checked);
void onRbH1OneTail2Toggled(bool checked);
void onRbH1TwoTailToggled(bool checked);
private slots:
private:
Ui::HypothesisTestDock ui;
- // bool m_initializing{false};
+ bool m_initializing{false};
TreeViewComboBox* cbSpreadsheet{nullptr};
HypothesisTest* m_hypothesisTest{nullptr};
- //// AspectTreeModel* m_aspectTreeModel{nullptr};
+ AspectTreeModel* m_aspectTreeModel{nullptr};
QSqlDatabase m_db;
QString m_configPath;
double population_mean{0};
double significance_level{0.05};
// void load();
// void loadConfig(KConfig&);
- // void setModelIndexFromAspect(TreeViewComboBox*, const AbstractAspect*);
+ void setModelIndexFromAspect(TreeViewComboBox*, const AbstractAspect*);
// void readConnections();
// void updateFields();
// bool fieldSelected(const QString&);
bool ttest{false};
bool ztest{false};
bool two_sample_independent{false};
bool two_sample_paired{false};
bool one_sample{false};
bool anova{false};
bool one_way{false};
bool two_way{false};
QScrollArea* scroll_dock;
void countPartitions(Column *column, int &np, int &total_rows);
void setColumnsComboBoxModel(Spreadsheet* spreadsheet);
void setColumnsComboBoxView();
bool nonEmptySelectedColumns();
QStringList test_type_t_z;
QStringList test_type_anova;
QStringList only_values_cols;
QStringList two_categorical_cols;
QStringList more_than_two_categorical_cols;
private slots:
//SLOTs for changes triggered in PivotTableDock
// void nameChanged();
// void commentChanged();
void dataSourceTypeChanged(int);
void showTestType();
void showHypothesisTest();
void doHypothesisTest();
void performLeveneTest();
void spreadsheetChanged(const QModelIndex&);
void col1IndexChanged(int index);
// void connectionChanged();
// void tableChanged();
// void showDatabaseManager();
// //SLOTs for changes triggered in PivotTable
// void pivotTableDescriptionChanged(const AbstractAspect*);
// void addRow();
// void removeRow();
// void addColumn();
// void removeColumn();
// //save/load template
// void loadConfigFromTemplate(KConfig&);
// void saveConfigAsTemplate(KConfig&);
signals:
// void info(const QString&);
};
#endif // PIVOTTABLEDOCK_H
diff --git a/src/kdefrontend/ui/dockwidgets/hypothesistestdock.ui b/src/kdefrontend/ui/dockwidgets/hypothesistestdock.ui
index 0b9abcae6..672b91bbd 100644
--- a/src/kdefrontend/ui/dockwidgets/hypothesistestdock.ui
+++ b/src/kdefrontend/ui/dockwidgets/hypothesistestdock.ui
@@ -1,423 +1,494 @@
HypothesisTestDock
0
0
- 588
- 996
+ 557
+ 1293
Form
-
-
-
- 9
- 255
- 73
- 17
-
-
-
-
- 75
- true
-
-
-
- Structure:
-
-
-
-
-
- 280
- 740
- 77
- 23
-
-
-
- Do Test
-
-
-
-
-
- 10
- 510
- 341
- 106
-
-
-
- Qt::Horizontal
-
-
-
- -
-
-
- Alternate Hypothesis
-
-
-
- -
-
-
- mu > muo
-
-
-
- -
-
-
- mu < muo
-
-
-
- -
-
-
- mu != muo
-
-
-
-
-
-
-
- -
-
-
- Null Hypothesis
-
-
-
- -
-
-
- mu <= muo
-
-
-
- -
-
-
- mu >= muo
-
-
-
- -
-
-
- mu == muo
-
-
-
-
-
-
-
-
-
- 10
- 640
- 217
- 81
-
-
-
- -
-
-
- muo
+
+
-
+
+
+ Qt::Horizontal
+
+
+ QSizePolicy::Fixed
+
+
+
+ 13
+ 23
+
+
+
+
+ -
+
+
+ Independent Var. 1
+
+
+ Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter
+
+
+
+ -
+
+
+
+ 75
+ true
+
+
+
+ Hypothesis
+
+
+
+ -
+
+
+ Comment:
+
+
+
+ -
+
+
+ Alternate
+
+
+ Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop
+
+
+
+ -
+
+
+ Qt::Vertical
+
+
+ QSizePolicy::Fixed
+
+
+
+ 32
+ 18
+
+
+
+
+ -
+
+
+ -
+
+
+
+ 0
+ 0
+
+
+
+
+ -
+
+
+ Spreadsheet:
+
+
+
+ -
+
+
+
+ 75
+ true
+
+
+
+ Data
+
+
+
+ -
+
+
+ alpha
+
+
+
+ -
+
+
+ Qt::Horizontal
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ Type
+
+
+
+ -
+
+
+
+
+
+
+ -
+
+
+
+ 75
+ true
+
+
+
+ Test
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ Levene's Test
+
+
+
+ -
+
+
+
+ 0
+ 0
+
+
+
+ Name:
+
+
+
+ -
+
+
+ Qt::Vertical
+
+
+ QSizePolicy::Fixed
+
+
+
+ 32
+ 18
+
+
+
+
+ -
+
+
+
+ 0
+ 0
+
+
+
+
+ -
+
+
+ Table:
+
+
+
+ -
+
+
+
+ 0
+ 0
+
+
+
+
+
+
+
+ -
+
+
+ muo
+
+
+
+ -
+
+
+ Null
+
+
+ Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop
+
+
+
+ -
+
+
+ -
+
+
+ Qt::Vertical
+
+
+ QSizePolicy::Fixed
+
+
+
+ 32
+ 18
+
+
+
+
+ -
+
+
+ Variable
+
+
+
+ -
+
+
+ Qt::Horizontal
+
+
+
+ 150
+ 20
+
+
+
+
+ -
+
+
+ QFrame::NoFrame
+
+
+ QFrame::Raised
+
+
+
+ 0
-
-
- -
-
-
- -
-
-
- alpha
+
+ 0
-
-
- -
-
-
-
-
-
-
-
- 15
- 12
- 90
- 25
-
-
-
-
- 0
- 0
-
-
-
- Name:
-
-
-
-
-
- 15
- 43
- 90
- 25
-
-
-
- Comment:
-
-
-
-
-
- 130
- 43
- 401
- 25
-
-
-
-
-
-
- 130
- 12
- 401
- 25
-
-
-
-
-
-
- 15
- 93
- 42
- 17
-
-
-
-
- 75
- true
-
-
-
- Data
-
-
-
-
-
- 15
- 116
- 531
- 112
-
-
-
- -
-
-
- Source:
+
+ 0
-
-
- -
-
-
-
- 0
- 0
-
+
+ 0
-
-
- -
-
-
- Spreadsheet:
+
-
+
+
+ mu <= muo
+
+
+
+ -
+
+
+ mu >= muo
+
+
+
+ -
+
+
+ mu == muo
+
+
+
+
+
+
+ -
+
+
+ Recalculate
+
+
+
+ -
+
+
+ Connection:
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ Sub-type
+
+
+
+ -
+
+
+
+ 75
+ true
+
+
+
+ Variables
+
+
+
+ -
+
+
+ QFrame::NoFrame
+
+
+ QFrame::Raised
+
+
+
+ 0
-
-
- -
-
-
- Connection:
+
+ 0
-
-
- -
-
-
-
- 0
- 0
-
+
+ 0
-
-
- -
-
-
-
- 0
- 0
-
+
+ 0
-
-
+
+ 0
-
-
- -
-
-
- Table:
-
-
-
- -
-
-
-
-
-
-
-
- 20
- 460
- 125
- 23
-
-
-
- Equal Variance
-
-
-
-
-
- 13
- 288
- 341
- 50
-
-
-
- -
-
-
- -
-
-
- Test
-
-
-
- -
-
-
- Test type
-
-
-
- -
-
-
-
-
-
-
-
- 20
- 350
- 394
- 73
-
-
-
- -
-
-
- -
-
-
- Independent Variable
-
-
-
- -
-
-
- -
-
-
- Independent Variable
-
-
-
-
-
-
-
-
- 570
- 10
- 16
- 981
-
-
-
- Qt::Vertical
-
-
-
-
-
- 20
- 430
- 158
- 25
-
-
-
- Categorical Variable
-
-
-
-
-
- 270
- 430
- 121
- 25
-
-
-
- Levene's Test
-
-
+ -
+
+
+ mu > muo
+
+
+
+ -
+
+
+ mu < muo
+
+
+
+ -
+
+
+ mu != muo
+
+
+
+
+
+
+ -
+
+
+ Qt::Vertical
+
+
+
+ 18
+ 38
+
+
+
+
+ -
+
+
+ Equal Variance
+
+
+
+ -
+
+
+ Source:
+
+
+
+ -
+
+
+ Qt::Vertical
+
+
+ QSizePolicy::Fixed
+
+
+
+ 32
+ 18
+
+
+
+
+ -
+
+
+ Independent Var. 1 Cateogical
+
+
+
+ -
+
+
+
+
+
+
+