Simple Linear Regression

Simple Linear Regression
Loading the math board and drawing, please wait…
2020-01-14 15:40
This example demonstrates how to use GeoGebra to plot a scatter plot of data points and fit the best line using the method of least squares. Key mathematical concepts involved include linear regression, ordinary least squares, Pearson's correlation coefficient, sample mean, covariance, etc. The construction leverages commands and objects such as Length, mean, Zip, PMCC, SampleSDX, SampleSDY, Point, Line, Slope, Sum, Vector, FitLineY, SumSquaredErrors, RSquare. It is suitable for high school and above students learning the basics of data analysis and statistical modeling.

GeoGebra Commands & Parameters

  1. Length(DataPoints) → SampleSize
  2. mean(DataX) → MeanX
  3. mean(DataY) → MeanY
  4. Zip(Vector[(x(A), MeanY), A], A, DataPoints) → FromMeanX
  5. Zip(Vector[(MeanX, y(A)), A], A, DataPoints) → FromMeanY
  6. PMCC(DataPoints) → CorrelationXY
  7. SampleSDX(DataPoints) → SX
  8. SampleSDY(DataPoints) → SY
  9. Zip(Point[{A, B}], A, XZ, B, YZ) → DataPointsZ
  10. Zip(Vector[(x(A), 0), A], A, DataPointsZ) → FromMeanXZ
  11. Zip(Vector[(0, y(A)), A], A, DataPointsZ) → FromMeanYZ
  12. Point(yAxis) → UserPointA
  13. Line(UserPointA, UserPointB) → YourLine
  14. Slope(YourLine) → UserSlope
  15. Zip(Vector[(x(A), YourLine(A)), A], A, DataPoints) → UserResidualVector
  16. Sum((DataY - UserPredictedY)^(2)) → UserSSResidual
  17. Vector(UserParameters, (UserIntercept, UserSlope, UserSSResidual)) → u
  18. FitLineY(DataPoints) → f
  19. Slope(f) → OLSSlope
  20. SumSquaredErrors(DataPoints, f) → OLSSSResidual
  21. Vector(OLSParameters, (OLSIntercept, OLSSlope, OLSSSResidual)) → v
  22. RSquare(DataPoints, f) → OLSRsq
  23. RSquare(DataPoints, YourLine) → UserRsq

AI Drawing Prompt Reference

Plot a scatter plot with data points and fit the best line using least squares. Calculate and label key statistics like sample mean, covariance, and Pearson's correlation coefficient. Show two fitted lines (one based on user input, another via least squares) in different colors, comparing their residual sums of squares and R-squared values to illustrate linear regression concepts.
The prompt above was compiled from the original drawing commands and is for reference only.