@@ -269,6 +269,11 @@ void AnalysisTool::on_reconstructionButton_clicked() {
269269// ---------------------------------------------------------------------------
270270int AnalysisTool::get_pca_mode () { return ui_->pcaModeSpinBox ->value () - 1 ; }
271271
272+ // ---------------------------------------------------------------------------
273+ bool AnalysisTool::get_regression_analysis_status () {
274+ return ui_->enableRegressionCheckBox ->isChecked ();
275+ }
276+
272277// ---------------------------------------------------------------------------
273278double AnalysisTool::get_group_ratio () {
274279 double group_slider_value = ui_->group_slider ->value ();
@@ -505,6 +510,35 @@ void AnalysisTool::network_analysis_clicked() {
505510 app_->get_py_worker ()->run_job (network_analysis_job_);
506511}
507512
513+ Eigen::VectorXd load_regression_parameters (std::string filepath) {
514+ std::ifstream infile (slope_file_path);
515+ if (!infile.good ()) {
516+ throw std::runtime_error (" Unable to open regression parameter file: \" " +
517+ filepath + " \" for reading" );
518+ }
519+ try {
520+ std::vector<double > temp_values;
521+ double value;
522+ while (infile >> value) {
523+ temp_values.push_back (value);
524+ }
525+ if (temp_values.empty ()) {
526+ std::cerr << " Error: No data found in file " << slope_file_path
527+ << std::endl;
528+ return Eigen::VectorXd ();
529+ }
530+ Eigen::VectorXd param_vector (temp_values.size ());
531+ for (std::size_t i = 0 ; i < temp_values.size (); ++i) {
532+ param_vector[i] = temp_values[i];
533+ }
534+ return param_vector;
535+
536+ } catch (json::exception& e) {
537+ throw std::runtime_error (" Unabled to parse regression parameter file " +
538+ filepath + " : " + e.what ());
539+ }
540+ }
541+
508542// -----------------------------------------------------------------------------
509543bool AnalysisTool::compute_stats () {
510544 if (stats_ready_) {
@@ -627,6 +661,20 @@ bool AnalysisTool::compute_stats() {
627661 compute_shape_evaluations ();
628662 }
629663
664+ can_run_regression_ = check_explanatory_variable_limits ();
665+ if (can_run_regression_) {
666+ auto slope = load_regression_parameters (
667+ session_->get_regression_param_file (" slope" ));
668+ auto intercept = load_regression_parameters (
669+ session_->get_regression_param_file (" intercept" ));
670+ stats_.import_regression_parameters (slope, intercept);
671+ }
672+ else {
673+ ui_->regression_groupbox ->setVisible (false );
674+ ui_->explanatoryVariableSlider ->setVisible (false );
675+ ui_->enableRegressionCheckBox ->setVisible (false );
676+ }
677+
630678 stats_ready_ = true ;
631679
632680 // / Set this to true to export long format sample data (e.g. for import into R)
@@ -667,6 +715,19 @@ bool AnalysisTool::compute_stats() {
667715 return true ;
668716}
669717
718+ bool check_explanatory_variable_limits () {
719+ auto subjects = session_->get_project ()->get_subjects ();
720+ explanatory_variable_limits_.resize (2 );
721+ explanatory_variable_limits_[0 ] = std::numeric_limits<double >::max ();
722+ explanatory_variable_limits_[1 ] = std::numeric_limits<double >::lowest ();
723+ for (auto sub : subjects) {
724+ double exp_val = sub->get_explanatory_variable ();
725+ if (exp_val == std::numeric_limits<double >::lowest ()) return false ;
726+ explanatory_variable_limits_[0 ] = std::min (explanatory_variable_limits_[0 ], exp_val);
727+ explanatory_variable_limits_[1 ] = std::max (explanatory_variable_limits_[1 ], exp_val);
728+ }
729+ return true ;
730+ }
670731// -----------------------------------------------------------------------------
671732Particles AnalysisTool::get_mean_shape_points () {
672733 if (!compute_stats ()) {
@@ -729,8 +790,8 @@ Particles AnalysisTool::get_shape_points(int mode, double value) {
729790 ui_->explained_variance ->setText (" " );
730791 ui_->cumulative_explained_variance ->setText (" " );
731792 }
732-
733- temp_shape_ = stats_. get_mean () + (e * (value * lambda));
793+ auto mean = !regression_enabled_ ? stats_. get_mean () : stats_. get_regression_mean (ui_-> get_explanatory_variable_value ());
794+ temp_shape_ = mean + (e * (value * lambda));
734795
735796 auto positions = temp_shape_;
736797
@@ -829,11 +890,17 @@ ShapeHandle AnalysisTool::get_current_shape() {
829890 int pca_mode = get_pca_mode ();
830891 double pca_value = get_pca_value ();
831892 auto mca_level = get_mca_level ();
832- if (mca_level == AnalysisTool::McaMode::Vanilla) {
833- return get_mode_shape (pca_mode, pca_value);
893+ bool regression_analysis_enabled = get_regression_analysis_status ();
894+ if (!regression_analysis_enabled) {
895+ if (mca_level == AnalysisTool::McaMode::Vanilla) {
896+ return get_mode_shape (pca_mode, pca_value);
897+ } else {
898+ return get_mca_mode_shape (pca_mode, pca_value, mca_level);
899+ }
834900 } else {
835- return get_mca_mode_shape (pca_mode, pca_value, mca_level);
901+
836902 }
903+
837904}
838905
839906// ---------------------------------------------------------------------------
@@ -1095,6 +1162,13 @@ double AnalysisTool::get_pca_value() {
10951162 return value;
10961163}
10971164
1165+
1166+ double AnalysisTool::get_explanatory_variable_value () {
1167+ int slider_value = ui_->explanatoryVariableSlider ->value ();
1168+ return t_min + (static_cast <double >(slider_value) / 100.0 ) * (t_max - t_min);
1169+
1170+ }
1171+
10981172// ---------------------------------------------------------------------------
10991173void AnalysisTool::pca_labels_changed (QString value, QString eigen, QString lambda) {
11001174 set_labels (QString (" pca" ), value);
0 commit comments