Hat Matrix Calculator

Build regression projection matrices with precise matrix inputs. Inspect leverage, fitted values, and residual patterns. Understand influential observations through clear diagnostics and visual outputs.

Calculator Form

Enter Matrix X row by row. Use spaces or commas.
Provide one y value per observation to calculate fitted responses and residuals.
Reset

Example Data Table

Observation x1 x2 y
1125
2216
33411
44312
55516

This sample uses two predictors and an optional response vector. Turn on the intercept option to create a standard regression projection matrix.

Formula Used

Hat matrix formula: H = X(X′X)-1X′

Leverage values: hii are the diagonal elements of H.

Fitted response: ŷ = Hy

Residual vector: e = y - ŷ

Here, X is the design matrix. X′ is its transpose. The matrix X′X must be invertible. The hat matrix is symmetric and idempotent, meaning H = H′ and H2 = H.

How to Use This Calculator

  1. Enter the number of observations and predictor columns.
  2. Paste Matrix X using one observation per line.
  3. Choose whether to add an intercept automatically.
  4. Optionally paste vector y to compute fitted values.
  5. Select decimal precision and a leverage rule.
  6. Press Compute Hat Matrix to view results above the form.
  7. Use the CSV buttons for spreadsheet exports.
  8. Use the PDF button to save the result panel.

FAQs

1) What does the hat matrix represent?

It projects observed response values onto the column space of the design matrix. This projection creates fitted values in linear regression and reveals how strongly each observation influences its own fitted value.

2) Why are leverage values important?

Leverage values identify observations with unusual predictor patterns. High leverage points can pull the fitted model and deserve closer review, especially when they also have large residuals.

3) What does trace(H) tell me?

The trace equals the number of model columns in X, including any intercept. It is also the sum of all leverage values and helps verify that calculations are consistent.

4) Why might X′X be singular?

Singularity usually means one predictor column is an exact linear combination of others. Remove duplicate or dependent columns, or revise the matrix so the model columns are independent.

5) Do I need a response vector y?

No. The hat matrix depends only on the design matrix X. Vector y is optional and is used only when you want fitted responses, residuals, and PRESS-style residual diagnostics.

6) What does idempotence error mean?

A true hat matrix satisfies H² = H. Small numerical differences appear because computers round decimals. A very small error suggests the projection matrix was computed correctly.

7) Should I use 2p/n or 3p/n?

Both are common screening rules. The 2p/n rule is stricter, while 3p/n is more conservative. They are guides, not absolute proof of problematic observations.

8) Can this calculator handle an intercept automatically?

Yes. Enable the intercept checkbox to prepend a column of ones to Matrix X. This is useful for standard linear regression models that include a constant term.

Related Calculators

Linear Regression CalculatorMultiple Regression CalculatorLogistic Regression CalculatorSimple Regression CalculatorPower Regression CalculatorLogarithmic Regression CalculatorR Squared CalculatorAdjusted R SquaredSlope Intercept CalculatorCorrelation Coefficient Calculator

Important Note: All the Calculators listed in this site are for educational purpose only and we do not guarentee the accuracy of results. Please do consult with other sources as well.