visual3d:documentation:statistics:compute_linear_regression
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | |||
visual3d:documentation:statistics:compute_linear_regression [2024/07/17 15:42] – removed sgranger | visual3d:documentation:statistics:compute_linear_regression [2024/07/17 15:46] (current) – created sgranger | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Compute Linear Regression ====== | ||
+ | |||
+ | Since this page was created a command has been added to Visual3D. | ||
+ | |||
+ | [[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 | ||
+ | |||
+ | Slope: m = (NΣXY - (ΣX)(ΣY)) / (NΣX^2 - (ΣX)^2) | ||
+ | |||
+ | Intercept: b = (ΣY - m(ΣX)) / N | ||
+ | |||
+ | where : | ||
+ | |||
+ | x and y are the variables. | ||
+ | m = The slope of the regression line | ||
+ | b = The intercept point of the regression line and the y axis. | ||
+ | N = Number of values or elements | ||
+ | X = array of x-components | ||
+ | Y = array of y-components | ||
+ | ΣX = Sum of x | ||
+ | ΣY = Sum of y | ||
+ | ΣXY = Sum of xy | ||
+ | ΣX^2 = Sum of x^2 | ||
+ | </ | ||
+ | |||
+ | ==== Example Data ==== | ||
+ | |||
+ | Given the following data: | ||
+ | |||
+ | |5 ||3.1| | ||
+ | |6 ||3.5| | ||
+ | |7 ||3.9| | ||
+ | |9 ||4.1| | ||
+ | |10||4.3| | ||
+ | |11||4.7| | ||
+ | |||
+ | ==== Linear_Regression_Explicit Pipeline Script ==== | ||
+ | |||
+ | 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 | ||
+ | ! will perform a linear regression of data that is placed in the GLOBAL | ||
+ | ! | ||
+ | ! Note: Regression Equation: y = b + mx | ||
+ | ! | ||
+ | ! Slope: m = (NΣXY - (ΣX)(ΣY)) / (NΣX^2 - (ΣX)^2) | ||
+ | ! | ||
+ | ! Intercept: b = (ΣY - m(ΣX)) / N | ||
+ | ! | ||
+ | ! where : | ||
+ | ! | ||
+ | ! x and y are the variables. | ||
+ | ! m = The slope of the regression line | ||
+ | ! b = The intercept point of the regression line and the y axis. | ||
+ | ! N = Number of values or elements | ||
+ | ! X = array of x-components | ||
+ | ! Y = array of y-components | ||
+ | ! ΣX = Sum of x | ||
+ | ! ΣY = Sum of y | ||
+ | ! ΣXY = Sum of xy | ||
+ | ! ΣX^2 = Sum of x^2 | ||
+ | !========================================================================= | ||
+ | |||
+ | ! The GLOBAL needs to be active | ||
+ | Select_Active_File | ||
+ | / | ||
+ | ! /QUERY= | ||
+ | ; | ||
+ | |||
+ | !------------------------------------------------------- | ||
+ | ! Create a signal containing the number of data points | ||
+ | !------------------------------------------------------- | ||
+ | Metric_Explicit | ||
+ | / | ||
+ | / | ||
+ | / | ||
+ | ; | ||
+ | |||
+ | ! create a signal containing the data | ||
+ | Evaluate_Expression | ||
+ | / | ||
+ | / | ||
+ | / | ||
+ | / | ||
+ | ; | ||
+ | |||
+ | !-------------------------------------------------- | ||
+ | ! Call the meta command linear_regression_explicit | ||
+ | !-------------------------------------------------- | ||
+ | linear_regression_explicit | ||
+ | / | ||
+ | / | ||
+ | / | ||
+ | / | ||
+ | / | ||
+ | ; | ||
+ | |||
+ | !-------------------------------------------------------------------------- | ||
+ | ! create signal representing the linear regression | ||
+ | ! 4 temporary signals are created for clarity - STARTX, ENDX, STARTY, ENDY | ||
+ | !-------------------------------------------------------------------------- | ||
+ | |||
+ | ! Create STARTX at the first datapoint | ||
+ | Evaluate_Expression | ||
+ | / | ||
+ | / | ||
+ | / | ||
+ | / | ||
+ | ; | ||
+ | |||
+ | ! Create ENDX at the Nth datapoint | ||
+ | Evaluate_Expression | ||
+ | / | ||
+ | / | ||
+ | / | ||
+ | / | ||
+ | ; | ||
+ | |||
+ | ! Create STARTY from the meta command regression results and STARTX (y = b + mx) | ||
+ | Evaluate_Expression | ||
+ | / | ||
+ | / | ||
+ | / | ||
+ | / | ||
+ | ; | ||
+ | |||
+ | ! Create ENDY from the meta command regression results and ENDX (y = b + mx) | ||
+ | Evaluate_Expression | ||
+ | / | ||
+ | / | ||
+ | / | ||
+ | / | ||
+ | ; | ||
+ | |||
+ | ! Create the line | ||
+ | Evaluate_Expression | ||
+ | / | ||
+ | / | ||
+ | / | ||
+ | / | ||
+ | ; | ||
+ | </ | ||
+ | |||
+ | ==== Graph the Data and Regression Line ==== | ||
+ | |||
+ | The resulting signal **METRIC:: | ||
+ | |||
+ | For example, create a report graph (2D Graph) as follows: | ||
+ | |||
+ | {{: | ||
+ | |||
+ | Now create a second 2D graph at the same location containing the regression line | ||
+ | |||
+ | {{: | ||
+ | |||
+ | The resulting report graph should appear as follows: | ||
+ | |||
+ | {{: | ||
+ | |||
+ | ==== Linear_Regression_Explicit Meta-Command ==== | ||
+ | |||
+ | Below are the commands for the **Linear_Regression_Explicit** Meta-Commands. Go to [[Visual3D: | ||
+ | |||
+ | < | ||
+ | ! BEGIN_META | ||
+ | ! META_CMD_NAME=Linear_Regression_Explicit | ||
+ | ! META_PARAM= SIGNALX : string :: | ||
+ | ! META_PARAM= SIGNALY : string :: | ||
+ | ! META_PARAM= NUM_POINTS : string :: | ||
+ | ! META_PARAM= RESULT_NAME : string :: | ||
+ | ! META_PARAM= RESULT_FOLDER : string :: | ||
+ | ! END_META | ||
+ | |||
+ | !======================================================================== | ||
+ | ! This meta-command will calculate the linear regression of data | ||
+ | ! that is passed to the meta-command | ||
+ | ! | ||
+ | ! Note: Regression Equation: y = b + mx | ||
+ | ! | ||
+ | ! Slope: m = (NΣXY - (ΣX)(ΣY)) / (NΣX^2 - (ΣX)^2) | ||
+ | ! | ||
+ | ! Intercept: b = (ΣY - m(ΣX)) / N | ||
+ | ! | ||
+ | ! where : | ||
+ | ! | ||
+ | ! x and y are the variables. | ||
+ | ! m = The slope of the regression line | ||
+ | ! b = The intercept point of the regression line and the y axis. | ||
+ | ! N = Number of values or elements | ||
+ | ! X = array of x-components | ||
+ | ! Y = array of y-components | ||
+ | ! ΣX = Sum of x | ||
+ | ! ΣY = Sum of y | ||
+ | ! ΣXY = Sum of xy | ||
+ | ! ΣX^2 = Sum of x^2 | ||
+ | !========================================================================== | ||
+ | |||
+ | !--------------------------------------------------------------------------- | ||
+ | ! Create Temporary Variables - TEMPX and TEMPY from SIGNAL::X and SIGNAL::Y | ||
+ | !--------------------------------------------------------------------------- | ||
+ | |||
+ | Set_Pipeline_Parameter | ||
+ | / | ||
+ | / | ||
+ | ; | ||
+ | |||
+ | Set_Pipeline_Parameter | ||
+ | / | ||
+ | / | ||
+ | ; | ||
+ | |||
+ | ! Create TEMPX | ||
+ | Evaluate_Expression | ||
+ | / | ||
+ | / | ||
+ | / | ||
+ | / | ||
+ | ; | ||
+ | |||
+ | ! Create TEMPY | ||
+ | Evaluate_Expression | ||
+ | / | ||
+ | / | ||
+ | / | ||
+ | / | ||
+ | ; | ||
+ | |||
+ | !---------------------------- | ||
+ | ! Sum X and Y | ||
+ | !---------------------------- | ||
+ | |||
+ | ! Sum X | ||
+ | Metric_Sum | ||
+ | / | ||
+ | / | ||
+ | / | ||
+ | / | ||
+ | / | ||
+ | / | ||
+ | / | ||
+ | / | ||
+ | / | ||
+ | / | ||
+ | / | ||
+ | ; | ||
+ | |||
+ | ! Sum Y | ||
+ | Metric_Sum | ||
+ | / | ||
+ | / | ||
+ | / | ||
+ | / | ||
+ | / | ||
+ | / | ||
+ | / | ||
+ | / | ||
+ | / | ||
+ | / | ||
+ | / | ||
+ | ; | ||
+ | |||
+ | !---------------------- | ||
+ | ! Multiply X and Y | ||
+ | !---------------------- | ||
+ | Evaluate_Expression | ||
+ | / | ||
+ | / | ||
+ | / | ||
+ | / | ||
+ | ; | ||
+ | |||
+ | !---------------------- | ||
+ | ! Sum XY | ||
+ | !---------------------- | ||
+ | Metric_Sum | ||
+ | / | ||
+ | / | ||
+ | / | ||
+ | / | ||
+ | / | ||
+ | / | ||
+ | / | ||
+ | / | ||
+ | / | ||
+ | / | ||
+ | / | ||
+ | ; | ||
+ | |||
+ | !--------------- | ||
+ | ! Square X | ||
+ | !--------------- | ||
+ | Evaluate_Expression | ||
+ | / | ||
+ | / | ||
+ | / | ||
+ | / | ||
+ | ; | ||
+ | |||
+ | !----------------- | ||
+ | ! Sum square of X | ||
+ | !----------------- | ||
+ | Metric_Sum | ||
+ | / | ||
+ | / | ||
+ | / | ||
+ | / | ||
+ | / | ||
+ | / | ||
+ | / | ||
+ | / | ||
+ | / | ||
+ | / | ||
+ | / | ||
+ | ; | ||
+ | |||
+ | !------------------ | ||
+ | ! Calculate slope | ||
+ | !------------------ | ||
+ | Evaluate_Expression | ||
+ | / | ||
+ | / | ||
+ | / | ||
+ | / | ||
+ | ; | ||
+ | |||
+ | !---------------------- | ||
+ | ! Calculate intercept | ||
+ | !---------------------- | ||
+ | Evaluate_Expression | ||
+ | / | ||
+ | / | ||
+ | / | ||
+ | / | ||
+ | ; | ||
+ | |||
+ | !-------------------------------------------------------------------------- | ||
+ | ! create the resulting metric signal that contains the slope and intercept | ||
+ | !-------------------------------------------------------------------------- | ||
+ | Evaluate_Expression | ||
+ | / | ||
+ | / | ||
+ | / | ||
+ | / | ||
+ | ; | ||
+ | |||
+ | !----------------------------------------------------------- | ||
+ | ! clean up the temporary signals | ||
+ | ! if you want to see the temporary signals for debugging | ||
+ | ! comment out this next command | ||
+ | !----------------------------------------------------------- | ||
+ | Remove_Signals | ||
+ | / | ||
+ | / | ||
+ | / | ||
+ | ; | ||
+ | </ | ||
+ | |||
+ | |||
visual3d/documentation/statistics/compute_linear_regression.1721230968.txt.gz · Last modified: 2024/07/17 15:42 by sgranger