{"success":true,"version":"v1","request":{"tool":"get_calculator_schema","calculator_id":"linear-regression"},"result":{"entity_type":"calculator","id":"linear-regression","calculator_id":"linear-regression","canonical_url":"https://tttkmbb.com/statistics/linear-regression","name":"Linear Regression Calculator","title":"Linear Regression Calculator – Least-Squares Line y = a + bx, R² and Prediction","category":"statistics","category_name":"Statistics & Probability","tool_name":"calculate_linear_regression","featured_mcp_tool":false,"description":"Fits an ordinary least-squares line to paired (x, y) data and returns the slope, intercept, equation, Pearson r, R², the standard error of the estimate and an optional prediction for a new x.","use_when":"You want the best-fit straight line through paired data, its equation, or a predicted y for a given x (trend lines, calibration curves, simple forecasting).","do_not_use_when":"The relationship is curved or has several predictors (needs polynomial or multiple regression), or you only need the strength of association (use correlation).","inputs":[{"name":"x_values","label":"x values","type":"number_list","required":true,"description":"Independent (explanatory) variable, one number per observation.","example":[1,2,3,4,5]},{"name":"y_values","label":"y values","type":"number_list","required":true,"description":"Dependent (response) variable, in the same order as x_values.","example":[2,4,5,4,5]},{"name":"x_new","label":"x to predict","type":"number","required":false,"description":"Optional x value at which to evaluate the fitted line.","example":6}],"outputs":[{"name":"slope","label":"Slope (b)","type":"number","decimals":4,"description":"Change in y per unit change in x."},{"name":"intercept","label":"Intercept (a)","type":"number","decimals":4,"description":"Fitted y at x = 0."},{"name":"equation","label":"Equation","type":"string","decimals":4,"description":"Fitted line as y = bx + a with coefficients rounded to 4 decimals."},{"name":"pearson_r","label":"Pearson r","type":"number","decimals":4,"description":"Correlation coefficient of x and y (omitted when y is constant)."},{"name":"r_squared","label":"R²","type":"number","decimals":4,"description":"Fraction of the variance in y explained by the line (omitted when y is constant)."},{"name":"standard_error_of_estimate","label":"Standard error of the estimate","type":"number","decimals":4,"description":"√(Σ(y − ŷ)² / (n − 2)): typical vertical distance of the points from the line (needs n ≥ 3)."},{"name":"sample_size","label":"Number of pairs (n)","type":"integer","decimals":4,"description":"Number of (x, y) pairs used."},{"name":"predicted_y","label":"Predicted y at x_new","type":"number","decimals":4,"description":"intercept + slope × x_new (only when x_new is given)."}],"input_schema":{"type":"object","properties":{"x_values":{"description":"Independent (explanatory) variable, one number per observation.","type":"array","items":{"type":"number"},"minItems":2,"examples":[[1,2,3,4,5]]},"y_values":{"description":"Dependent (response) variable, in the same order as x_values.","type":"array","items":{"type":"number"},"minItems":2,"examples":[[2,4,5,4,5]]},"x_new":{"description":"Optional x value at which to evaluate the fitted line.","type":"number","examples":[6]}},"additionalProperties":false,"required":["x_values","y_values"]},"output_schema":{"type":"object","properties":{"slope":{"description":"Change in y per unit change in x.","type":"number"},"intercept":{"description":"Fitted y at x = 0.","type":"number"},"equation":{"description":"Fitted line as y = bx + a with coefficients rounded to 4 decimals.","type":"string"},"pearson_r":{"description":"Correlation coefficient of x and y (omitted when y is constant).","type":"number"},"r_squared":{"description":"Fraction of the variance in y explained by the line (omitted when y is constant).","type":"number"},"standard_error_of_estimate":{"description":"√(Σ(y − ŷ)² / (n − 2)): typical vertical distance of the points from the line (needs n ≥ 3).","type":"number"},"sample_size":{"description":"Number of (x, y) pairs used.","type":"integer"},"predicted_y":{"description":"intercept + slope × x_new (only when x_new is given).","type":"number"}}},"formula":"slope = Σ(x − x̄)(y − ȳ) / Σ(x − x̄)²; intercept = ȳ − slope · x̄; r = Σ(x − x̄)(y − ȳ) / √(Σ(x − x̄)² Σ(y − ȳ)²); ŷ(x_new) = intercept + slope · x_new","method":"Ordinary least squares minimises the sum of squared vertical residuals; it assumes x is measured without error and residuals have constant variance. Predictions outside the observed x range are extrapolations.","sources":[{"name":"NIST/SEMATECH e-Handbook of Statistical Methods, 4.1.4.1 Linear Least Squares Regression","url":"https://www.itl.nist.gov/div898/handbook/pmd/section1/pmd141.htm","type":"government","retrieved_at":"2026-09-23"},{"name":"Wikipedia – Simple linear regression","url":"https://en.wikipedia.org/wiki/Simple_linear_regression","type":"reference","retrieved_at":"2026-09-23"}],"freshness":{"type":"static","max_age_seconds":null,"note":"Deterministic formula with fixed constants; results never go stale. Inputs supplied by the caller determine the output."},"examples":[{"name":"x = 1..5, y = 2, 4, 5, 4, 5, predict x = 6","inputs":{"x_values":[1,2,3,4,5],"y_values":[2,4,5,4,5],"x_new":6},"expected":{"slope":0.6,"intercept":2.2,"equation":"y = 0.6x + 2.2","pearson_r":0.7746,"r_squared":0.6,"standard_error_of_estimate":0.8944,"sample_size":5,"predicted_y":5.8},"url":"https://tttkmbb.com/api/v1/calculate/linear-regression?x_values=1%2C2%2C3%2C4%2C5&y_values=2%2C4%2C5%2C4%2C5&x_new=6"},{"name":"Exact line y = 2x + 1","inputs":{"x_values":[0,1,2,3],"y_values":[1,3,5,7]},"expected":{"slope":2,"intercept":1,"equation":"y = 2x + 1","pearson_r":1,"r_squared":1,"standard_error_of_estimate":0},"url":"https://tttkmbb.com/api/v1/calculate/linear-regression?x_values=0%2C1%2C2%2C3&y_values=1%2C3%2C5%2C7"}],"faq":[{"q":"How good is the fit?","a":"R² near 1 means the line explains most of the variation in y; the standard error of the estimate gives the typical residual in y units. Always inspect the residuals for curvature or outliers as well."},{"q":"Which variable goes on x?","a":"x is the predictor (the variable you control or know first) and y the response; swapping them gives a different line because least squares minimises vertical distances only."}],"tags":["linear regression","least squares","line of best fit","trend line","slope and intercept","regression equation"],"related":[{"calculator_id":"correlation","reason":"Only the strength of the linear association."},{"calculator_id":"slope","reason":"Slope of a line through two known points."}],"links":{"html":"https://tttkmbb.com/statistics/linear-regression","markdown":"https://tttkmbb.com/statistics/linear-regression.md","json":"https://tttkmbb.com/statistics/linear-regression.json","api":"https://tttkmbb.com/api/v1/calculate/linear-regression","schema":"https://tttkmbb.com/api/v1/calculators/linear-regression","openapi":"https://tttkmbb.com/openapi.json","mcp":"https://tttkmbb.com/mcp"},"version":"v1","updated_at":"2026-09-23"},"timestamp":"2026-09-23T23:23:49Z"}