Linear Regression

Discussion

introduction

Given a pile of data …

x1x2x3, … xn and y1y2y3, … yn

Find the line of best fit.

y = mx + b

We are shooting for a minimal amount of error as measured by the sum of the squares of the residuals. This method is called a least squares fit and is probably the most common form of best fit line.

 n  n
R2 =  yi)2 =  [(mxi + b) − yi]2 = minimum
i = 1 i = 1

This occurs where each of the partial derivatives is zero. (The limits on the summations will be omitted out of laziness from now on.)

 R2 = 2 ∑{[(mxi + b) − yi ] xi} = 0
m
and
 R2 = 2 ∑[(mxi + b) − yi ] = 0
b

After a bit of algebra, you get these equations …

m =  n∑(xiyi) − ∑xi ∑yi
n ∑(xi2) − (∑xi)2
and
b =  ∑(xi2) ∑yi − ∑xi ∑(xiyi)
n ∑(xi2) − (∑xi)2

or, if you work a bit more algebra, these equations …

m =  ∑(xiyi) − n x y
∑(xi2) − n (x)2
and
b =  y ∑(xi2) − x ∑(xiyi)
∑(xi2) − n (x)2

How good is the line of best fit? Are some bests better than others? Here's one way to decide. Swap the explanatory and response variables.

x = m'y + b'

The slope of this new linear equation is the same as the old one with all the x's replaced by y's and vice versa. (Note that the numerator hasn't really changed.)

m' =  n∑(yixi) − ∑yi ∑xi
n ∑(yi2) − (∑yi)2

Now, multiply this slope by the old slope. Don't ask why, just do it.

m m' = 
n∑(xiyi) − ∑xi ∑yi ⎞⎛
⎠⎝
n∑(yixi) − ∑yi ∑xi
n ∑(xi2) − (∑xi)2 n ∑(yi2) − (∑yi)2

This product is known as the coefficient of determination

r2 =  (n∑(xiyi) − ∑xi ∑yi)2
(n ∑(xi2) − (∑xi)2) (n ∑(yi2) − (∑yi)2)

and its square root is called the coefficient of correlation.

r =  n∑(xiyi) − ∑xi ∑yi
√(n ∑(xi2) − (∑xi)2) √(n ∑(yi2) − (∑yi)2)
 
eglobe logo The Physics Hypertextbook
© 1998–2013 Glenn Elert

No condition is permanent.

  1. Mechanics
    1. Kinematics
      1. Motion
      2. Distance & Displacement
      3. Speed & Velocity
      4. Acceleration
      5. Equations of Motion
      6. Falling Bodies
      7. Graphs of Motion
      8. Kinematics and Calculus
      9. Kinematics in Two Dimensions
      10. Projectiles
      11. Parametric Equations
    2. Dynamics I: Force
      1. Forces
      2. Force & Mass
      3. Action-Reaction
      4. Weight
      5. Friction
      6. Equilibrium
      7. Forces in Two Dimensions
      8. Centripetal Force
      9. Frames of Reference
    3. Energy
      1. Work
      2. Energy
      3. Kinetic Energy
      4. Potential Energy
      5. Conservation of Energy
      6. Power
      7. Simple Machines
    4. Dynamics II: Momentum
      1. Impulse & Momentum
      2. Conservation of Momentum
      3. Momentum & Energy
      4. Momentum in Two Dimensions
    5. Rotational Motion
      1. Rotational Kinematics
      2. Rotational Inertia
      3. Rotational Dynamics
      4. Rotational Equilibrium
      5. Angular Momentum
      6. Rotational Energy
      7. Rolling
      8. Rotation in Two Dimensions
      9. Coriolis Force
    6. Planetary Motion
      1. Geocentrism
      2. Heliocentrism
      3. Universal Gravitation
      4. Orbital Mechanics I
      5. Gravitational Potential Energy
      6. Orbital Mechanics II
      7. Gravity of Extended Bodies
    7. Periodic Motion
      1. Springs
      2. Simple Harmonic Oscillator
      3. Pendulums
      4. Resonance
      5. Elasticity
    8. Fluids
      1. Density
      2. Pressure
      3. Buoyancy
      4. Fluid Flow
      5. Viscosity
      6. Aerodynamic Drag
      7. Flow Regimes
  1. Thermal Physics
    1. Heat & Temperature
      1. Temperature
      2. Thermal Expansion
      3. The Atomic Nature of Matter
      4. Gas Laws
      5. Kinetic-Molecular Theory
      6. Phases
    2. Calorimetry
      1. Sensible Heat
      2. Latent Heat
      3. Chemical Potential Energy
    3. Heat Transfer
      1. Conduction
      2. Convection
      3. Radiation
    4. Thermodynamics
      1. Heat & Work
      2. Pressure-Volume Diagrams
      3. Engines
      4. Refrigerators
      5. Energy & Entropy
      6. Absolute Zero
  2. Waves & Optics
    1. Wave Phenomena
      1. The Nature of Waves
      2. Interference & Superposition
      3. Reflection, Transmission, Absorption
      4. Standing Waves
      5. Diffraction
      6. Interference in Two Dimensions
    2. Sound
      1. The Nature of Sound
      2. Intensity
      3. Beats
      4. Music & Noise
      5. Doppler Effect (Sound)
      6. Shock Waves
    3. Physical Optics
      1. The Nature of Light
      2. Color
      3. Thin Film Interference
      4. Resolving Power
      5. Diffraction & Interference
      6. Doppler Effect (Light)
      7. Cerenkov Radiation
      8. Polarization
    4. Geometric Optics
      1. Reflection
      2. Refraction
      3. Spherical Mirrors
      4. Spherical Lenses
      5. Aberration
  1. Electricity & Magnetism
    1. Electrostatics
      1. Electric Charge
      2. Coulomb's Law
      3. Electric Field
      4. Electric Potential
      5. Gauss's Law
      6. Conductors
    2. Electrostatic Applications
      1. Capacitors
      2. Dielectrics
      3. Batteries
    3. Electric Current
      1. Electric Current
      2. Electric Resistance
      3. Electric Power
    4. DC Circuits
      1. Resistors in Circuits
      2. Batteries in Circuits
      3. Capacitors in Circuits
      4. Kirchhoff's Rules
    5. Magnetostatics
      1. Magnetism
      2. Electromagnetism
      3. Ampère's Law
      4. Magnetic Force
    6. Magnetodynamics
      1. Electromagnetic Induction
      2. Faraday's Law
      3. Lenz' Law
      4. Inductance
    7. AC Circuits
      1. Alternating Current
      2. RC Circuits
      3. RL Circuits
      4. LC Circuits
    8. Electromagnetic Waves
      1. Maxwell's Equations
      2. Electromagnetic Waves
      3. Electromagnetic Spectrum
  1. Modern Physics
    1. Relativity
      1. Space-Time
      2. Mass-Energy
      3. General Relativity
    2. Quanta
      1. Blackbody Radiation
      2. Photoelectric Effect
      3. X‑rays
      4. Antimatter
    3. Wave Mechanics
      1. Matter Waves
      2. Atomic Models
      3. Semiconductors
      4. Condensed Matter
    4. Nuclear Physics
      1. Isotopes
      2. Radioactive Decay
      3. Half Life
      4. Binding Energy
      5. Fission
      6. Fusion
      7. Nucleosynthesis
      8. Nuclear Weapons
      9. Radiobiology
    5. Particle Physics
      1. Quantum Electrodynamics
      2. Quantum Chromodynamics
      3. Quantum Flavordynamics
      4. The Standard Model
      5. Beyond the Standard Model
  2. Foundations
    1. Units
      1. International System of Units
      2. Gaussian System of Units
      3. British-American System of Units
      4. Miscellaneous Units
      5. Time
      6. Unit Conversion
    2. Measurement
      1. Significant Digits
      2. Orders of Magnitude
    3. Graphs
      1. Graphical Representation of Data
      2. Linear Regression
      3. Curve Fitting
      4. Calculus
    4. Vectors
      1. Vector Addition & Subtraction
      2. Vector Resolution & Components
      3. Vector Multiplication
    5. Reference
      1. Special Symbols
      2. Frequently Used Equations
      3. Physical Constants
      4. Astronomical Data
      5. Periodic Table of the Elements
      6. People in Physics
  3. More
    1. More
      1. About
      2. News
      3. Shop
      4. Google+
      5. Even More