Find the line of best fit and R-squared
The **Linear Regression Calculator** is a powerful statistical analysis tool that finds the line of best fit for your data using the least squares method. Whether you're a data scientist building predictive models, a business analyst forecasting sales trends, a researcher analyzing experimental relationships, or a student learning statistics, this calculator provides instant, accurate linear regression analysis with complete statistical metrics. **Linear regression** is one of the most fundamental techniques in statistics and machine learning. It models the relationship between an independent variable (X) and a dependent variable (Y) as a straight line: y = mx + b. This simple yet powerful method allows you to make predictions, identify trends, and quantify relationships between variables. It's used everywhere from predicting house prices to analyzing scientific experiments. ### The Linear Regression Equation **y = mx + b** Where: - **y** = Predicted value (dependent variable) - **x** = Input value (independent variable) - **m** = Slope (rate of change) - **b** = Y-intercept (value when x = 0) ### Key Statistical Outputs **Slope (m):** The slope tells you how much Y changes for every 1-unit increase in X. Calculated as: m = (nΣxy - ΣxΣy) / (nΣx² - (Σx)²) **Y-Intercept (b):** The starting value of Y when X equals zero. Calculated as: b = (Σy - mΣx) / n **Correlation Coefficient (r):** Measures the strength and direction of the linear relationship (-1 to +1). - r = +1: Perfect positive correlation - r = 0: No linear correlation - r = -1: Perfect negative correlation **Coefficient of Determination (R²):** Shows what percentage of Y's variation is explained by X (0 to 1). - R² = 0.9 means 90% of variation is explained by the model - R² = 0.5 means only 50% is explained (weak model) ### Real-World Applications **Business & Finance:** - Forecast sales based on advertising spend - Predict revenue from customer acquisition - Analyze pricing strategies and demand - Project future growth trends **Scientific Research:** - Model experimental relationships - Create calibration curves for instruments - Analyze dose-response relationships - Study climate and environmental trends **Real Estate & Economics:** - Predict house prices from square footage - Analyze income vs. education levels - Model supply and demand relationships - Forecast economic indicators **Education & Social Sciences:** - Predict test scores from study hours - Analyze grade trends over time - Study demographic relationships - Model behavioral patterns **Engineering & Quality Control:** - Calibrate sensors and instruments - Predict material properties - Analyze process optimization - Model system performance ### Practical Examples **Example 1: Sales Forecasting** Advertising spend (X): 1000, 2000, 3000, 4000, 5000 Sales (Y): 15000, 22000, 28000, 35000, 41000 Result: y = 5.2x + 9800 - Slope: Every $1 in ads generates $5.20 in sales - Intercept: Base sales of $9,800 with no advertising - Prediction: With $6,000 in ads → 5.2(6000) + 9800 = $41,000 **Example 2: Study Time vs. Test Score** Study hours (X): 2, 4, 6, 8, 10 Test scores (Y): 65, 75, 82, 88, 95 Result: y = 3.5x + 58 - Slope: Each hour of study adds 3.5 points - Intercept: Base score of 58 with no study - Prediction: 12 hours → 3.5(12) + 58 = 100 points **Example 3: Temperature vs. Ice Cream Sales** Temperature °F (X): 60, 70, 80, 90, 100 Sales (Y): 200, 350, 500, 650, 800 Result: y = 15x - 700 - Slope: Each degree increase adds 15 sales - Intercept: -700 (not meaningful below 47°F) - Prediction: 85°F → 15(85) - 700 = 575 sales