Hverdag · verktøy

Kalkulator for lineær regresjon og korrelasjon

Skriv inn minst to numeriske x,y-par, ett per linje eller atskilt med komma.

Kjøres i nettleseren. Ingen opplasting.

Values are processed locally in this browser.

Result

—

Om verktøyet

Kalkulator for lineær regresjon og korrelasjon sem complicação.

Dette er en beskrivende lineær regresjon. Korrelasjon fastslår ikke årsakssammenheng, og tilpasningen kan være misvisende for ikke-lineære eller avhengige data.

Veiledning

Slik bruker du Kalkulator for lineær regresjon og korrelasjon

The Linear Regression and Correlation Calculator draws the best-fitting straight line through a list of x and y pairs. You paste your pairs, one per line, and the tool gives the equation of the least-squares line, the Pearson correlation r, R squared and the number of pairs. It describes the data you typed. It does not test whether a pattern is real, it does not predict the future, and it cannot tell you that one thing causes another.

Slik gjør du

  1. Type or paste your data in the box, one x,y pair per line, for example 3, 7. A comma or a space can separate the two numbers.
  2. Use at least 2 pairs and at most 10,000. You can also separate pairs with a semicolon instead of a new line.
  3. Make sure the x values are not all the same number, or the tool cannot draw a line.
  4. Press Calculate. Read the line y = slope times x plus intercept, then r, R squared and the pair count.
  5. Use Copy result to keep the four lines, or Clear to empty the box.

Eksempler

Three points on a perfect line

Du skriver inn
Par
0, 1 1, 3 2, 5
Du får
Linje
y = 2x + 1
r
1
R i andre
1
Par
3

Each step of 1 in x adds 2 to y, and the line passes through y = 1 at x = 0. Every point sits exactly on the line, so r and R squared are both 1.

Kjørt med verktøyets egen kode.

Five points with some scatter

Du skriver inn
Par
1, 2 2, 4 3, 5 4, 4 5, 5
Du får
Linje
y = 0.6x + 2.2
r
0.774597
R i andre
0.6
Par
5

The means are 3 for x and 4 for y. The sums are 6 for the cross products, 10 for x and 6 for y, so the slope is 6 / 10 = 0.6 and r is 6 divided by the square root of 60.

Kjørt med verktøyets egen kode.

A line that goes down

Du skriver inn
Par
1, 10 2, 8 3, 7 4, 3
Du får
Linje
y = -2.2x + 12.5
r
-0.964764
R i andre
0.930769
Par
4

As x rises, y falls, so the slope and r are negative. R squared has no sign. It is the square of r, here 0.930769.

Kjørt med verktøyets egen kode.

All y values are the same

Du skriver inn
Par
1, 5 2, 5 3, 5
Du får
Linje
y = 0x + 5
r
0
R i andre
0
Par
3

The line is flat at 5. The tool shows r as 0 here, although correlation is not really defined when y never changes. Treat that 0 as a missing value.

Kjørt med verktøyets egen kode.

Når det er nyttig

  • Fit a trend line to a small lab or science-class data set and read the slope.
  • Check how closely two columns from a spreadsheet move together.
  • Check homework that asks for a least-squares line and a correlation.
  • Get quick numbers to describe a scatter plot in a report.
  • Compare two small data sets by their slope and r.

Begrensninger

  • You need 2 to 10,000 pairs, each with exactly two numbers. A single line such as 1,2,3,4 is refused, even though the page text says commas can separate pairs.
  • If every x is the same, the tool stops with an error, because the slope would be undefined.
  • If every y is the same, the tool shows r as 0 and R squared as 0, although correlation is undefined in that case.
  • The results are rounded to six decimals. The tool gives no p-value, no confidence interval, no residual list and no chart.
  • It fits only a straight line and treats every point equally. A curve, a group effect or one far-out point can make the line misleading.

Tips

  • Plot your data in a chart first. If the points curve, a straight line is the wrong shape.
  • With only 2 points, r is 1 or -1 (or 0 if both y values match), so use more points before you read anything into it.
  • Check for one extreme point by removing it and calculating again to see how much the line moves.
  • Keep the x and y columns in the same order on every line.

Kilder

Vanlige spørsmål

Sobre Kalkulator for lineær regresjon og korrelasjon.

What formulas does this calculator use?

It finds the mean of x and of y, then sums the squared x gaps (Sxx), the squared y gaps (Syy) and the products of the gaps (Sxy). The slope is Sxy divided by Sxx, the intercept is mean y minus slope times mean x, and r is Sxy divided by the square root of Sxx times Syy.

What does the correlation r tell me?

It runs from -1 to 1. A positive r means y tends to rise with x, a negative r means y tends to fall, and a value near 0 means a straight line describes the points poorly. It measures a straight-line pattern only.

What does R squared mean?

In a fit with one x, R squared is r squared. It is the share of the ups and downs in y that the straight line accounts for in your data, between 0 and 1. It describes the fit, not the reason behind it.

Does a high R squared prove that x causes y?

No. Two things can move together because of a third factor, by chance, or because the cause runs the other way. A high R squared says the points hug a line. It does not say why. To argue for a cause you need a careful study design.

How should I type my data?

Put one pair per line, with the x value first and the y value second, separated by a comma or a space. A semicolon also separates pairs. Use plain numbers with a dot for decimals, and no units or text.

Why do two points give r of 1 or -1?

Two points always lie exactly on one straight line, so the fit is perfect whatever the numbers are. If both y values match, the tool shows 0 instead. Such a result says nothing about a real pattern, so use more points first.

Why does it say the x values must not all be identical?

If every x is the same, the points stand on a vertical line. A line of the form y = slope times x plus intercept cannot describe that, because the slope would need a division by zero.

Will the line work for curved data or outliers?

It will give numbers, but they can mislead. A curve, separate groups or one very far point can pull the line away from the rest. Look at a scatter plot, and think about your data before you rely on the fit.

Is my data uploaded?

No. The calculation runs in your browser, and the pairs you type are not uploaded.

Hvordan bruker du Kalkulator for lineær regresjon?

Skriv inn minst to numeriske x,y-par, ett per linje eller atskilt med komma.

Lastes dataene mine opp til en server?

Nei. Behandlingen skjer i nettleseren din, og opplysningene dine lastes ikke opp.