Direct Variation Calculator & Through-Origin Fit
Paste x and y pairs to find the constant of variation or the closest least-squares rule through zero. Compare it with a fitted intercept, inspect prediction errors one row at a time, and evaluate either rule at a given x.
Does one constant explain the pairs?
Check direct variation and compare a through-origin line with a free intercept.
Pairs and prediction
Enter x and y on each line, separated by a comma or tab. Keep units consistent within each column.
The points do not follow one exact proportional rule.
Compare the two rules
The free-intercept fit has lower matched held-out error.
5 of 5 held-out rows were scored by both fits.
Through origin
y = 2.228070175439 × x
- Slope
- 2.228070175439
- Intercept
- 0
- In-sample sum of squared errors
- 2.035087719298
- Matched held-out mean squared error
- 0.594866734051
Free intercept
y = 2 × x + 1
- Slope
- 2
- Intercept
- 1
- In-sample sum of squared errors
- 0
- Matched held-out mean squared error
- 0
Fit and held-out errors
Observed x from 0 to 6.
- Observed
- Through origin
- Free intercept
Pair 1
- Observed x
- 0
- Observed y
- 1
- Ratio y/x
- Unavailable
- Through-origin residual
- 1
- Free-intercept residual
- 0
Predictions at x = 3
This x is inside the observed range.
- Through origin
- 6.684210526316
- Free intercept
- 7
Export the direct variation worksheet
Save both fitted rules, exact residuals and held-out scores for each pair.
View CSV text
How to use this calculator
- Paste one x and y pair per line. Use commas or tabs between the two values.
- Read whether all pairs follow one exact nonzero rule y = kx. Compare the through-origin fit and the free-intercept fit.
- Switch to Held-out errors to see which rows drive the prediction comparison. The slider keeps your inspection on the same pair.
- Enter x to evaluate both rules. Download the exact equations and per-pair audit as CSV.
The Formula
The mathematical logic powering this calculation is:
The through-origin line has equation y = kx. When Σx² is positive, k = Σxy/Σx² minimizes squared vertical residuals. An exact proportional relationship requires zero residual at every row and k ≠ 0. At x = 0 the predicted response is always zero and the point ratio y/x is undefined. If every x is zero, no unique constant can be recovered. With nonzero x and all responses zero, the fitted through-origin slope is zero.
The free-intercept equation is y = mx + b. Its slope is m = [nΣxy − (Σx)(Σy)]/[nΣx² − (Σx)²] and b = [Σy − mΣx]/n. It needs at least two distinct x values. Both fits use ordinary least squares with equally weighted observations. In-sample residuals are observed minus fitted responses. The free-intercept fit can match or improve in-sample squared error because the through-origin line is one of the lines it can fit.
For leave-one-out comparison, remove one observed pair, fit each line to the remaining pairs and predict the withheld y from its x. Calculate observed minus predicted and square the error. Matched mean squared error divides by the number of rows both models could predict. Showing a held-out residual for only one model does not add that row to either matched mean. These scores compare the entered dataset and do not quantify uncertainty in future predictions.
Use 1–24 pairs and one consistent unit per column. Enter normal decimals from −1 billion to 1 billion, with up to six places. A prediction outside the observed x range is labeled. Both fits, residuals, and scores use exact fractions before display rounding.Worked Example
If you input:
- x: 0, 1, 2, 4, 6
- y: 1, 3, 5, 9, 13
- Query x: 3
Result:
The through-origin slope is 127/57. The free-intercept line is y = 2x + 1 with zero matched held-out mean squared error. At x = 3 the two predictions are 127/19 and 7.
Frequently Asked Questions
How can I tell if a table shows direct variation?
The ratios y/x at all nonzero x values must equal the same nonzero constant. Any row with x = 0 must also have y = 0.
What if every x is the same?
A nonzero repeated x still gives a through-origin slope. A free-intercept slope requires varying x values. If every x is zero, no unique slope can be estimated.
Why compare held-out errors when the free-intercept fit has lower training error?
The extra intercept can improve agreement with the entered pairs automatically. Withholding a pair checks how each model predicts data that it did not use to fit that iteration.
Why were some pairs excluded from the matched error score?
Removing a pair may leave too little variation to estimate one of the slopes. A row only counts when both fits can make a held-out prediction.
Can I use it to estimate k from one pair?
Yes. A single nonzero x identifies the rule through zero. An intercept and held-out comparison need additional observations.
Similar Calculators
Slope & Line Equation Calculator
Find slope, intercepts and exact line equations from two points or known coefficients. Graph parallel and perpendicular lines and find the shortest distance from a point.
Linear Regression Calculator
Fit a least-squares line, inspect scatter and residual plots, and calculate Student-t confidence and prediction intervals. Paste paired data and export the full ledger.
Ratio Calculator
Simplify ratios, find equivalent ratios, and solve for a missing value in a proportion.
