Linear Regression for CSV
Operator: Abdulla Al Fahad. How tools are built and checked
Linear regression fits a straight-line relationship between one numeric outcome and one or more predictors. You hand it a table, say which column you want to predict, and it finds the intercept and slopes that make the squared gaps between actual and predicted values as small as possible. The slopes read as 'for one more unit of this column, the outcome moves by this much, holding the others fixed'.
This page does that for a CSV or XLSX file and prints the output in the layout most statistics packages use: an estimate, standard error, t value, p value and 95% interval for each term, then R-squared, adjusted R-squared, the F-test, the residual standard error, and a variance inflation factor per column. Text columns can be turned into dummy variables with a reference level you choose, and a plain squared term can be added to a numeric column to catch a simple curve.
There is no account and no row limit beyond the 25 MB file size and the 300,000 rows the page can hold in memory.
Key features
- Multiple regression with any mix of numeric and dummy-coded categorical predictors, with a chosen reference level
- Coefficient table with estimate, standard error, t, p, 95% interval, optional standardised beta and VIF per column
- R-squared, adjusted R-squared, F statistic with degrees of freedom and p-value, residual standard error, in-sample RMSE, AIC and BIC
- Perfectly collinear columns detected, named, explained in terms of the columns that determine them, and dropped instead of breaking the fit
- Residuals-against-fitted plot with a binned trend line, a normal Q-Q plot, and a table of the five most influential rows by Cook's distance
- Leverage, outlier, small-sample and high-VIF warnings in plain wording
- Prediction form with confidence and prediction intervals
- Downloads: the original rows with fitted, residual and standardised residual columns, a coefficients CSV, and an XLSX with Coefficients, Model summary and Data sheets
Dummy coding, QR solving and what each statistic in the table means
Input is a .csv, .tsv or .xlsx file up to 25 MB, with a header row and one observation per row; for an XLSX the first worksheet is used. Numbers are read with thousands commas, currency symbols, percent signs and accounting brackets understood, so $1,250.00, 12% and (300) arrive as 1250, 12 and -300. A cell that is blank, N/A, NA, null or NaN is missing.
Rows are dropped listwise: a row with a missing or non-numeric value in the outcome or in any ticked predictor is left out of the fit entirely. The results card says how many rows went and which column caused most of the losses. The downloaded data file still contains every original row in its original order, with blank fitted and residual cells for the rows that were left out, so it can be joined back to the source.
A predictor can be treated as a number or as a category. Text columns default to category and numeric columns to number, but a numeric code that is really a label, such as plan type 1, 2, 3, can be switched to category. A category with k levels becomes k minus 1 dummy columns holding 1 for that level and 0 otherwise, named like neighbourhood[Oldtown]. The reference level, the one with no dummy column, defaults to the most frequent level and can be changed. A category column with more than 50 distinct values is refused as probably an ID, and a model that would have more than 60 columns after dummy coding is refused too.
Squared terms are plain: the raw column multiplied by itself, added beside the original. They are not centred, so a column with a large mean will show a very high VIF for the pair, which is expected and flagged rather than hidden. An intercept is included unless you switch it off. Without one the line passes through zero and R-squared is computed against zero instead of the mean of the outcome, which makes it look flattering; a warning appears when you do this.
The prediction card builds a new row from your inputs, taking a number for each numeric predictor and a level for each category, and gives the predicted value with two 95% intervals: one for the average outcome at those inputs and a wider one for a single new observation.
How it works
The model matrix is solved by Householder QR decomposition rather than by inverting X-transpose-X. Squaring the matrix squares its condition number, so the normal-equations route loses roughly twice as many digits; QR works on the matrix directly. The coefficients come from back-substitution on the triangular factor, and the covariance matrix from the inverse of that factor, so standard errors are the residual variance times (X'X) inverse without ever forming X'X.
Columns are processed left to right. If, after removing the part explained by the columns already accepted, what remains of a column is smaller than one ten-millionth of its own length, it is a linear combination of earlier columns and is marked aliased, the way R leaves an NA coefficient. The page then solves the coefficients for that combination and prints it, for example 'it is a linear combination of 2 x x1'. The classic dummy-variable trap shows up as 'a linear combination of (Intercept) - 1 x A'.
Residual standard error is the square root of the sum of squared residuals divided by n minus m, where m is the number of estimated coefficients; the in-sample RMSE divides by n instead. R-squared with an intercept is one minus SSE over the total sum of squares about the mean, adjusted R-squared rescales by (n - 1)/(n - m), and the F statistic is explained variation per extra coefficient over unexplained variation per residual degree of freedom, referred to the F distribution.
p-values and intervals use the Student t distribution with n minus m degrees of freedom, implemented with the regularised incomplete beta function, not a normal approximation, so small samples are handled correctly. VIF for a column is the corresponding diagonal entry of the inverse correlation matrix of the non-intercept columns, which equals 1/(1 - R-squared) from regressing that column on the others. Leverage is the diagonal of the hat matrix, and Cook's distance combines leverage with the size of the residual.
Common use cases
- Estimating how much each extra square foot, bedroom or neighbourhood adds to a sale price from a spreadsheet of past sales
- A statistics coursework task that asks for the coefficient table, R-squared, the F-test and VIF for a small dataset without access to SPSS or XLSTAT
- Checking whether advertising spend and a promotion flag explain weekly sales, and by how much sales rise per extra unit of spend
- Fitting a quick trend with a squared term to see whether a relationship bends, then reading the residual plot to confirm
- Adding fitted values and residuals next to the original rows to spot which records the model explains badly
How to use this tool
- Choose a CSV or XLSX file, or press Use sample data for a 40-row house-price table.
- Pick the column to predict. It must hold numbers.
- Tick the predictors. Set each to Number or Category, choose a reference level for categories and tick Add squared term where you want a curve.
- Decide whether to keep the intercept, then press Fit model.
- Read the summary, the coefficient table and the warnings; check the residual plot and the Q-Q plot.
- Try values in the prediction card, then download the data with fitted values, the coefficients, or the workbook.
Example
Five points: x = 1, 2, 3, 4, 5 and y = 1, 3, 2, 5, 4, with an intercept
x,y
1,1
2,3
3,2
4,5
5,4What the page reports, all of which can be checked by hand
Intercept 0.6 std. error 1.1489 t 0.522 p 0.6376 95% CI -3.0564 to 4.2564
x 0.8 std. error 0.3464 t 2.309 p 0.1041 95% CI -0.3024 to 1.9024
R-squared 0.64, adjusted 0.52, F(1, 3) = 5.333, p 0.1041
Residual standard error 1.0954 (SSE 3.6 / 3 df), RMSE 0.8485 (SSE 3.6 / 5)
Prediction at x = 6: 5.4, 95% interval for one new case 0.35 to 10.45
Sample data, price ~ size_sqft + bedrooms + neighbourhood (40 rows):
R-squared 0.963, F(4, 35) = 227.8, size_sqft 106.2 per square foot (t 12.9), Oldtown -49,310 against the Hillcrest baselineTips for best results
- Look at the residual plot before trusting the p-values. A curve in the orange trend line, or a funnel that widens to the right, means the straight-line model is missing something and the standard errors are unreliable.
- Choose the reference level that makes the story easy to tell. 'Compared with the standard plan' reads better than 'compared with the alphabetically first plan'.
- Read adjusted R-squared, not R-squared, when comparing models with different numbers of columns. R-squared can only go up when you add a column; adjusted R-squared can fall.
- When two predictors carry a high VIF, keep the one that is easier to measure or explain, or combine them into one. The overall fit is unaffected but the individual coefficients are not trustworthy.
- Use the 95% interval for one new case, not the average-case interval, when you are asked 'what could this particular house sell for'.
- Turn a numeric code into a category if the numbers are labels. A regression on plan number 1, 2, 3 assumes that plan 3 is exactly twice as far from plan 1 as plan 2 is.
Common pitfalls
Regression shows association, not cause. A big, significant coefficient on bedrooms does not mean adding a bedroom raises a price by that amount.
Predicting far outside the range of the data is extrapolation. The intervals assume the straight line continues, and they widen only modestly even where that assumption is shaky.
Dropping rows with missing values can bias the fit if the missingness is not random. The page tells you how many rows were lost but cannot tell you why.
The p-values assume residuals that are roughly normal, with constant spread and independent of each other. Time-ordered data with autocorrelated errors will give p-values that are too small; this page does not test for that.
A perfect fit, with all residuals zero, usually means the outcome is a formula of the predictors, such as a total built from its parts. The standard errors are then meaningless, and the output notes it.
With a dummy column for each level of a category plus an intercept, one column is redundant. The page drops it and explains why, but the better habit is to leave the reference level out, which is what the dummy coding already does.
Common errors and how to fix them
- There are 2 usable rows for 2 coefficients
- A line needs more rows than coefficients. Remove predictors, drop a category column with many levels, or check that the outcome column is not mostly blank.
- A column is listed as aliased
- That column is perfectly determined by other columns, for example a total beside its parts, a duplicated column, or a full set of dummy columns beside an intercept. Remove one of the columns involved; the explanation names which.
- A category column was refused for having too many values
- A column with more than 50 distinct values is probably an ID or free text. Untick it, or group the values into fewer categories in the source file.
Best practices
- Report n after dropping rows, the coefficient with its interval, and R-squared with the adjusted figure, not a bare p-value.
- Keep at least five rows per coefficient and ideally ten to twenty; a warning appears below five.
- Check the Cook's distance table and refit without a row that stands out to see whether the conclusions change.
- Save the data file with fitted values and residuals alongside your source, so the model's misses can be examined later in a spreadsheet.
Reading the coefficient table
The estimate is the change in the outcome for one more unit of that column with the others held constant; for a dummy column it is the average difference from the reference level. The standard error says how much that estimate would wobble from sample to sample, the t value is the estimate divided by its standard error, and the p-value is the chance of a t that large or larger if the true coefficient were zero.
The 95% interval is the estimate plus and minus the t critical value times the standard error, with n minus m degrees of freedom. An interval that includes zero and a p-value above 0.05 say the same thing. Standardised betas, when switched on, multiply each estimate by the standard deviation of its column and divide by that of the outcome, which puts columns measured in different units on one scale.
In-sample RMSE versus residual standard error
Software uses 'RMSE' for two slightly different numbers. The residual standard error divides the sum of squared residuals by n minus m and is the estimate of the noise level that every standard error and interval is built on. The in-sample RMSE divides by n and is the average miss on the rows you fitted. Both are shown and labelled; they converge as n grows relative to m.
Neither is an out-of-sample error. A model fitted and scored on the same rows looks better than it will on new data, more so when it has many columns for few rows.
Frequently asked questions
Does my data get uploaded?
No. The file is read and the model solved in your browser tab. Nothing is sent to a server, and closing the tab discards it.
How do I add interaction terms?
This page offers squared terms only. For an interaction, add a column to your file that holds the product of the two columns and tick it as a numeric predictor.
Why does R-squared look higher when I remove the intercept?
Without an intercept it is measured against zero rather than against the mean of the outcome, which gives a much larger total to explain. The two values cannot be compared.
Which reference level should I pick?
Pick the baseline you want to compare everything against, usually the standard or most common group. The fitted values do not change with the choice; only how the dummy coefficients read does.