visual3d:documentation:statistics:compute_linear_regression
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
visual3d:documentation:statistics:compute_linear_regression [2024/06/19 12:53] – sgranger | visual3d:documentation:statistics:compute_linear_regression [2024/07/17 15:46] (current) – created sgranger | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | {{{{{{since this page was created a command has been added to visual3d. | + | ====== Compute Linear Regression ====== |
- | [[visual3d: | + | Since this page was created |
- | this example uses a command | + | |
- | given the following definition of a linear regression: | + | [[Visual3D: |
+ | This example uses a command script that calls a meta-command that will compute a linear regression of the data identified in the script. See also [[Visual3D: | ||
+ | |||
+ | Given the following definition of a linear regression: | ||
< | < | ||
- | regression equation: y = b + mx | + | Regression Equation: y = b + mx |
- | slope: m = (nσxy - (σx)(σy)) / (nσx^2 - (σx)^2) | + | Slope: m = (NΣXY - (ΣX)(ΣY)) / (NΣX^2 - (ΣX)^2) |
- | intercept: b = (σy - m(σx)) / n | + | Intercept: b = (ΣY - m(ΣX)) / N |
where : | where : | ||
x and y are the variables. | x and y are the variables. | ||
- | m = the slope of the regression line | + | m = The slope of the regression line |
- | b = the intercept point of the regression line and the y axis. | + | b = The intercept point of the regression line and the y axis. |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
</ | </ | ||
- | ===== example data ===== | + | ==== Example Data ==== |
- | given the following data: | + | Given the following data: |
|5 ||3.1| | |5 ||3.1| | ||
Line 38: | Line 40: | ||
|11||4.7| | |11||4.7| | ||
- | ===== linear_regression_explicit pipeline script ===== | + | ==== Linear_Regression_Explicit Pipeline Script |
- | this pipeline command script creates the signals and calls the **linear_regression_explicit** meta command. | + | This pipeline command script creates the signals and calls the **linear_regression_explicit** meta command. |
< | < | ||
!========================================================================= | !========================================================================= | ||
- | ! this script will call the meta-command linear_regression_explicit that | + | ! This script will call the meta-command linear_regression_explicit that |
- | ! will perform a linear regression of data that is placed in the global | + | ! will perform a linear regression of data that is placed in the GLOBAL |
! | ! | ||
- | ! note: regression equation: y = b + mx | + | ! Note: Regression Equation: y = b + mx |
! | ! | ||
- | ! slope: m = (nσxy - (σx)(σy)) / (nσx^2 - (σx)^2) | + | ! Slope: m = (NΣXY - (ΣX)(ΣY)) / (NΣX^2 - (ΣX)^2) |
! | ! | ||
- | ! intercept: b = (σy - m(σx)) / n | + | ! Intercept: b = (ΣY - m(ΣX)) / N |
! | ! | ||
! where : | ! where : | ||
! | ! | ||
! x and y are the variables. | ! x and y are the variables. | ||
- | ! m = the slope of the regression line | + | ! m = The slope of the regression line |
- | ! b = the intercept point of the regression line and the y axis. | + | ! b = The intercept point of the regression line and the y axis. |
- | ! | + | ! |
- | ! | + | ! |
- | ! | + | ! |
- | ! | + | ! |
- | ! | + | ! |
- | ! | + | ! |
- | ! | + | ! |
!========================================================================= | !========================================================================= | ||
- | ! the global | + | ! The GLOBAL |
- | select_active_file | + | Select_Active_File |
- | /file_name=global | + | /FILE_NAME=GLOBAL |
- | ! /query= | + | ! /QUERY= |
; | ; | ||
!------------------------------------------------------- | !------------------------------------------------------- | ||
- | ! create | + | ! Create |
!------------------------------------------------------- | !------------------------------------------------------- | ||
- | metric_explicit | + | Metric_Explicit |
- | /result_metric_name=n | + | /RESULT_METRIC_NAME=N |
- | /result_metric_folder=residual | + | /RESULT_METRIC_FOLDER=RESIDUAL |
- | /metric_value=6 | + | /METRIC_VALUE=6 |
; | ; | ||
! create a signal containing the data | ! create a signal containing the data | ||
- | evaluate_expression | + | Evaluate_Expression |
- | /expression=list(vector(5,3.1),vector(6,3.5),vector(7,3.9),vector(9,4.1),vector(10,4.3),vector(11,4.7)) | + | /EXPRESSION=LIST(VECTOR(5,3.1),VECTOR(6,3.5),VECTOR(7,3.9),VECTOR(9,4.1),VECTOR(10,4.3),VECTOR(11,4.7)) |
- | /result_name=test | + | /RESULT_NAME=TEST |
- | /result_type=derived | + | /RESULT_TYPE=DERIVED |
- | /result_folder=residual | + | /RESULT_FOLDER=RESIDUAL |
; | ; | ||
!-------------------------------------------------- | !-------------------------------------------------- | ||
- | ! call the meta command linear_regression_explicit | + | ! Call the meta command linear_regression_explicit |
!-------------------------------------------------- | !-------------------------------------------------- | ||
linear_regression_explicit | linear_regression_explicit | ||
- | /signalx=derived::residual::test::x | + | /SIGNALX=DERIVED::RESIDUAL::TEST::X |
- | /signaly=derived::residual::test::y | + | /SIGNALY=DERIVED::RESIDUAL::TEST::Y |
- | /num_points= metric::residual::n | + | /NUM_POINTS= METRIC::RESIDUAL::N |
- | /result_name=result | + | /RESULT_NAME=RESULT |
- | /result_folder=residual | + | /RESULT_FOLDER=RESIDUAL |
; | ; | ||
!-------------------------------------------------------------------------- | !-------------------------------------------------------------------------- | ||
! create signal representing the linear regression | ! create signal representing the linear regression | ||
- | ! 4 temporary signals are created for clarity - startx, endx, starty, endy | + | ! 4 temporary signals are created for clarity - STARTX, ENDX, STARTY, ENDY |
!-------------------------------------------------------------------------- | !-------------------------------------------------------------------------- | ||
- | ! create startx | + | ! Create STARTX |
- | evaluate_expression | + | Evaluate_Expression |
- | /expression=derived::residual::test::x[1] | + | /EXPRESSION=DERIVED::RESIDUAL::TEST::X[1] |
- | /result_name=startx | + | /RESULT_NAME=STARTX |
- | /result_type=metric | + | /RESULT_TYPE=METRIC |
- | /result_folder=residual | + | /RESULT_FOLDER=RESIDUAL |
; | ; | ||
- | ! create endx at the nth datapoint | + | ! Create ENDX at the Nth datapoint |
- | evaluate_expression | + | Evaluate_Expression |
- | /expression=derived::residual::test::x[metric::residual::n] | + | /EXPRESSION=DERIVED::RESIDUAL::TEST::X[METRIC::RESIDUAL::N] |
- | /result_name=endx | + | /RESULT_NAME=ENDX |
- | /result_type=metric | + | /RESULT_TYPE=METRIC |
- | /result_folder=residual | + | /RESULT_FOLDER=RESIDUAL |
; | ; | ||
- | ! create starty | + | ! Create STARTY |
- | evaluate_expression | + | Evaluate_Expression |
- | /expression=metric::residual::result::x+metric::residual::result::y*metric::residual::startx | + | /EXPRESSION=METRIC::RESIDUAL::RESULT::X+METRIC::RESIDUAL::RESULT::Y*METRIC::RESIDUAL::STARTX |
- | /result_name=starty | + | /RESULT_NAME=STARTY |
- | /result_type=metric | + | /RESULT_TYPE=METRIC |
- | /result_folder=residual | + | /RESULT_FOLDER=RESIDUAL |
; | ; | ||
- | ! create endy from the meta command regression results and endx (y = b + mx) | + | ! Create ENDY from the meta command regression results and ENDX (y = b + mx) |
- | evaluate_expression | + | Evaluate_Expression |
- | /expression=metric::residual::result::x+metric::residual::result::y*metric::residual::endx | + | /EXPRESSION=METRIC::RESIDUAL::RESULT::X+METRIC::RESIDUAL::RESULT::Y*METRIC::RESIDUAL::ENDX |
- | /result_name=endy | + | /RESULT_NAME=ENDY |
- | /result_type=metric | + | /RESULT_TYPE=METRIC |
- | /result_folder=residual | + | /RESULT_FOLDER=RESIDUAL |
; | ; | ||
- | ! create | + | ! Create |
- | evaluate_expression | + | Evaluate_Expression |
- | /expression=list(vector(metric::residual::startx,metric::residual::starty),vector(metric::residual::endx,metric::residual::endy)) | + | /EXPRESSION=LIST(VECTOR(METRIC::RESIDUAL::STARTX,METRIC::RESIDUAL::STARTY),VECTOR(METRIC::RESIDUAL::ENDX,METRIC::RESIDUAL::ENDY)) |
- | /result_name=result_line | + | /RESULT_NAME=RESULT_LINE |
- | /result_type=metric | + | /RESULT_TYPE=METRIC |
- | /result_folder=residual | + | /RESULT_FOLDER=RESIDUAL |
; | ; | ||
</ | </ | ||
- | ===== graph the data and regression line ===== | + | ==== Graph the Data and Regression Line ==== |
- | the resulting signal **metric::residual::result_line** can be graphed in a report graph with the original data. | + | The resulting signal **METRIC::RESIDUAL::RESULT_LINE** can be graphed in a report graph with the original data. |
- | for example, create a report graph (2d graph) as follows: | + | For example, create a report graph (2D Graph) as follows: |
- | linear_regression1.jpg | + | {{: |
- | now create a second | + | Now create a second |
- | linear_regression2.jpg | + | {{: |
- | the resulting report graph should appear as follows: | + | The resulting report graph should appear as follows: |
- | linear_regression3.jpg | + | {{: |
- | ===== linear_regression_explicit meta-command ===== | + | ==== Linear_Regression_Explicit Meta-Command |
- | below are the commands for the **linear_regression_explicit** meta-commands. go to [[visual3d:documentation:pipeline:meta_commands:meta_commands_overview|pipeline commands:meta commands]] for details on how to use meta-commands. | + | Below are the commands for the **Linear_Regression_Explicit** Meta-Commands. Go to [[Visual3D:Documentation:Pipeline:Meta_Commands:Meta_Commands_Overview|Pipeline Commands:Meta Commands]] for details on how to use Meta-commands. |
< | < | ||
- | ! begin_meta | + | ! BEGIN_META |
- | ! meta_cmd_name=linear_regression_explicit | + | ! META_CMD_NAME=Linear_Regression_Explicit |
- | ! meta_param= signalx | + | ! META_PARAM= SIGNALX |
- | ! meta_param= signaly | + | ! META_PARAM= SIGNALY |
- | ! meta_param= num_points | + | ! META_PARAM= NUM_POINTS |
- | ! meta_param= result_name | + | ! META_PARAM= RESULT_NAME |
- | ! meta_param= result_folder | + | ! META_PARAM= RESULT_FOLDER |
- | ! end_meta | + | ! END_META |
!======================================================================== | !======================================================================== | ||
- | ! this meta-command will calculate the linear regression of data | + | ! This meta-command will calculate the linear regression of data |
! that is passed to the meta-command | ! that is passed to the meta-command | ||
! | ! | ||
- | ! note: regression equation: y = b + mx | + | ! Note: Regression Equation: y = b + mx |
! | ! | ||
- | ! slope: m = (nσxy - (σx)(σy)) / (nσx^2 - (σx)^2) | + | ! Slope: m = (NΣXY - (ΣX)(ΣY)) / (NΣX^2 - (ΣX)^2) |
! | ! | ||
- | ! intercept: b = (σy - m(σx)) / n | + | ! Intercept: b = (ΣY - m(ΣX)) / N |
! | ! | ||
! where : | ! where : | ||
! | ! | ||
! x and y are the variables. | ! x and y are the variables. | ||
- | ! m = the slope of the regression line | + | ! m = The slope of the regression line |
- | ! b = the intercept point of the regression line and the y axis. | + | ! b = The intercept point of the regression line and the y axis. |
- | ! | + | ! |
- | ! | + | ! |
- | ! | + | ! |
- | ! | + | ! |
- | ! | + | ! |
- | ! | + | ! |
- | ! | + | ! |
!========================================================================== | !========================================================================== | ||
!--------------------------------------------------------------------------- | !--------------------------------------------------------------------------- | ||
- | ! create temporary variables | + | ! Create Temporary Variables |
!--------------------------------------------------------------------------- | !--------------------------------------------------------------------------- | ||
- | set_pipeline_parameter | + | Set_Pipeline_Parameter |
- | /parameter_name=name | + | /PARAMETER_NAME=NAME |
- | /parameter_value=::result_name | + | /PARAMETER_VALUE=::RESULT_NAME |
; | ; | ||
- | set_pipeline_parameter | + | Set_Pipeline_Parameter |
- | /parameter_name=folder | + | /PARAMETER_NAME=FOLDER |
- | /parameter_value=::result_folder | + | /PARAMETER_VALUE=::RESULT_FOLDER |
; | ; | ||
- | ! create tempx | + | ! Create TEMPX |
- | evaluate_expression | + | Evaluate_Expression |
- | /expression=::signalx | + | /EXPRESSION=::SIGNALX |
- | /result_name=tempx | + | /RESULT_NAME=TEMPX |
- | /result_type=derived | + | /RESULT_TYPE=DERIVED |
- | /result_folder=residual | + | /RESULT_FOLDER=RESIDUAL |
; | ; | ||
- | ! create tempy | + | ! Create TEMPY |
- | evaluate_expression | + | Evaluate_Expression |
- | /expression=::signaly | + | /EXPRESSION=::SIGNALY |
- | /result_name=tempy | + | /RESULT_NAME=TEMPY |
- | /result_type=derived | + | /RESULT_TYPE=DERIVED |
- | /result_folder=residual | + | /RESULT_FOLDER=RESIDUAL |
; | ; | ||
!---------------------------- | !---------------------------- | ||
- | ! sum x and y | + | ! Sum X and Y |
!---------------------------- | !---------------------------- | ||
- | ! sum x | + | ! Sum X |
- | metric_sum | + | Metric_Sum |
- | /result_metric_name=sumx | + | /RESULT_METRIC_NAME=SUMX |
- | /apply_as_suffix_to_signal_name=false | + | /APPLY_AS_SUFFIX_TO_SIGNAL_NAME=FALSE |
- | /result_metric_folder=residual | + | /RESULT_METRIC_FOLDER=RESIDUAL |
- | /signal_types=derived | + | /SIGNAL_TYPES=DERIVED |
- | /signal_names=tempx | + | /SIGNAL_NAMES=TEMPX |
- | /signal_folder=residual | + | /SIGNAL_FOLDER=RESIDUAL |
- | /signal_components=x | + | /SIGNAL_COMPONENTS=X |
- | /event_sequence= | + | /EVENT_SEQUENCE= |
- | /exclude_events= | + | /EXCLUDE_EVENTS= |
- | /generate_mean_and_stddev=false | + | /GENERATE_MEAN_AND_STDDEV=FALSE |
- | /append_to_existing_values=false | + | /APPEND_TO_EXISTING_VALUES=FALSE |
; | ; | ||
- | ! sum y | + | ! Sum Y |
- | metric_sum | + | Metric_Sum |
- | /result_metric_name=sumy | + | /RESULT_METRIC_NAME=SUMY |
- | /apply_as_suffix_to_signal_name=false | + | /APPLY_AS_SUFFIX_TO_SIGNAL_NAME=FALSE |
- | /result_metric_folder=residual | + | /RESULT_METRIC_FOLDER=RESIDUAL |
- | /signal_types=derived | + | /SIGNAL_TYPES=DERIVED |
- | /signal_names=tempy | + | /SIGNAL_NAMES=TEMPY |
- | /signal_folder=residual | + | /SIGNAL_FOLDER=RESIDUAL |
- | /signal_components=x | + | /SIGNAL_COMPONENTS=X |
- | /event_sequence= | + | /EVENT_SEQUENCE= |
- | /exclude_events= | + | /EXCLUDE_EVENTS= |
- | /generate_mean_and_stddev=false | + | /GENERATE_MEAN_AND_STDDEV=FALSE |
- | /append_to_existing_values=false | + | /APPEND_TO_EXISTING_VALUES=FALSE |
; | ; | ||
!---------------------- | !---------------------- | ||
- | ! multiply x and y | + | ! Multiply X and Y |
!---------------------- | !---------------------- | ||
- | evaluate_expression | + | Evaluate_Expression |
- | /expression=derived::residual::tempx*derived::residual::tempy | + | /EXPRESSION=DERIVED::RESIDUAL::TEMPX*DERIVED::RESIDUAL::TEMPY |
- | /result_name=xy | + | /RESULT_NAME=XY |
- | /result_type=derived | + | /RESULT_TYPE=DERIVED |
- | /result_folder=residual | + | /RESULT_FOLDER=RESIDUAL |
; | ; | ||
!---------------------- | !---------------------- | ||
- | ! sum xy | + | ! Sum XY |
!---------------------- | !---------------------- | ||
- | metric_sum | + | Metric_Sum |
- | /result_metric_name=sumxy | + | /RESULT_METRIC_NAME=SUMXY |
- | /apply_as_suffix_to_signal_name=false | + | /APPLY_AS_SUFFIX_TO_SIGNAL_NAME=FALSE |
- | /result_metric_folder=residual | + | /RESULT_METRIC_FOLDER=RESIDUAL |
- | /signal_types=derived | + | /SIGNAL_TYPES=DERIVED |
- | /signal_names=xy | + | /SIGNAL_NAMES=XY |
- | /signal_folder=residual | + | /SIGNAL_FOLDER=RESIDUAL |
- | /signal_components=x | + | /SIGNAL_COMPONENTS=X |
- | /event_sequence= | + | /EVENT_SEQUENCE= |
- | /exclude_events= | + | /EXCLUDE_EVENTS= |
- | /generate_mean_and_stddev=false | + | /GENERATE_MEAN_AND_STDDEV=FALSE |
- | /append_to_existing_values=false | + | /APPEND_TO_EXISTING_VALUES=FALSE |
; | ; | ||
!--------------- | !--------------- | ||
- | ! square x | + | ! Square X |
!--------------- | !--------------- | ||
- | evaluate_expression | + | Evaluate_Expression |
- | /expression=derived::residual::tempx*derived::residual::tempx | + | /EXPRESSION=DERIVED::RESIDUAL::TEMPX*DERIVED::RESIDUAL::TEMPX |
- | /result_name=xx | + | /RESULT_NAME=XX |
- | /result_type=derived | + | /RESULT_TYPE=DERIVED |
- | /result_folder=residual | + | /RESULT_FOLDER=RESIDUAL |
; | ; | ||
!----------------- | !----------------- | ||
- | ! sum square of x | + | ! Sum square of X |
!----------------- | !----------------- | ||
- | metric_sum | + | Metric_Sum |
- | /result_metric_name=sumxx | + | /RESULT_METRIC_NAME=SUMXX |
- | /apply_as_suffix_to_signal_name=false | + | /APPLY_AS_SUFFIX_TO_SIGNAL_NAME=FALSE |
- | /result_metric_folder=residual | + | /RESULT_METRIC_FOLDER=RESIDUAL |
- | /signal_types=derived | + | /SIGNAL_TYPES=DERIVED |
- | /signal_names=xx | + | /SIGNAL_NAMES=XX |
- | /signal_folder=residual | + | /SIGNAL_FOLDER=RESIDUAL |
- | /signal_components=x | + | /SIGNAL_COMPONENTS=X |
- | /event_sequence= | + | /EVENT_SEQUENCE= |
- | /exclude_events= | + | /EXCLUDE_EVENTS= |
- | /generate_mean_and_stddev=false | + | /GENERATE_MEAN_AND_STDDEV=FALSE |
- | /append_to_existing_values=false | + | /APPEND_TO_EXISTING_VALUES=FALSE |
; | ; | ||
!------------------ | !------------------ | ||
- | ! calculate | + | ! Calculate |
!------------------ | !------------------ | ||
- | evaluate_expression | + | Evaluate_Expression |
- | /expression=(&::num_points&*metric::residual::sumxy-metric::residual::sumx*metric::residual::sumy)/(&::num_points&*metric::residual::sumxx-metric::residual::sumx^2) | + | /EXPRESSION=(&::NUM_POINTS&*METRIC::RESIDUAL::SUMXY-METRIC::RESIDUAL::SUMX*METRIC::RESIDUAL::SUMY)/(&::NUM_POINTS&*METRIC::RESIDUAL::SUMXX-METRIC::RESIDUAL::SUMX^2) |
- | /result_name=slope | + | /RESULT_NAME=SLOPE |
- | /result_type=metric | + | /RESULT_TYPE=METRIC |
- | /result_folder=residual | + | /RESULT_FOLDER=RESIDUAL |
; | ; | ||
!---------------------- | !---------------------- | ||
- | ! calculate | + | ! Calculate |
!---------------------- | !---------------------- | ||
- | evaluate_expression | + | Evaluate_Expression |
- | /expression=(metric::residual::sumy-metric::residual::slope*metric::residual::sumx)/&::num_points | + | /EXPRESSION=(METRIC::RESIDUAL::SUMY-METRIC::RESIDUAL::SLOPE*METRIC::RESIDUAL::SUMX)/&::NUM_POINTS |
- | /result_name=intercept | + | /RESULT_NAME=INTERCEPT |
- | /result_type=metric | + | /RESULT_TYPE=METRIC |
- | /result_folder=residual | + | /RESULT_FOLDER=RESIDUAL |
; | ; | ||
Line 342: | Line 344: | ||
! create the resulting metric signal that contains the slope and intercept | ! create the resulting metric signal that contains the slope and intercept | ||
!-------------------------------------------------------------------------- | !-------------------------------------------------------------------------- | ||
- | evaluate_expression | + | Evaluate_Expression |
- | /expression=vector(metric::residual::intercept,metric::residual::slope) | + | /EXPRESSION=VECTOR(METRIC::RESIDUAL::INTERCEPT,METRIC::RESIDUAL::SLOPE) |
- | /result_name=::name | + | /RESULT_NAME=::NAME |
- | /result_type=metric | + | /RESULT_TYPE=METRIC |
- | /result_folder=::folder | + | /RESULT_FOLDER=::FOLDER |
; | ; | ||
Line 354: | Line 356: | ||
! comment out this next command | ! comment out this next command | ||
!----------------------------------------------------------- | !----------------------------------------------------------- | ||
- | remove_signals | + | Remove_Signals |
- | /signal_types=derived+derived+derived+derived+metric+metric+metric+metric+metric+metric | + | /SIGNAL_TYPES=DERIVED+DERIVED+DERIVED+DERIVED+METRIC+METRIC+METRIC+METRIC+METRIC+METRIC |
- | /signal_names=tempx+tempy+xx+xy+slope+intercept+sumx+sumxx+sumxy+sumy | + | /SIGNAL_NAMES=TEMPX+TEMPY+XX+XY+SLOPE+INTERCEPT+SUMX+SUMXX+SUMXY+SUMY |
- | /signal_folder=residual+residual+residual+residual+residual+residual+residual+residual+residual+residual | + | /SIGNAL_FOLDER=RESIDUAL+RESIDUAL+RESIDUAL+RESIDUAL+RESIDUAL+RESIDUAL+RESIDUAL+RESIDUAL+RESIDUAL+RESIDUAL |
; | ; | ||
</ | </ | ||
- | }}}}}} | + |
visual3d/documentation/statistics/compute_linear_regression.1718801621.txt.gz · Last modified: 2024/06/19 12:53 by sgranger