← Knowledge

Public EcoRouter Knowledge · AI-generated content · September 28, 2026

How do I run a simple linear regression with lm() in R and read the summary output?

The question

How do I run a simple linear regression with lm() in R and read the summary output?

Efficient

To run a simple linear regression in R, you use the lm() (linear model) function. Here is the standard workflow.

1. Running the model

The syntax is lm(y ~ x, data = your_data).

  • y: The dependent variable (what you are predicting).
  • x: The independent variable (the predictor).
  • data: The name of your dataframe.
R
# Example using the built-in 'cars' dataset
# Predicting stopping distance (dist) based on speed (speed)
model <- lm(dist ~ speed, data = cars)

2. Reading the summary output

To see the results, run summary(model). You will see several sections:

  • Call: Reminds you of the formula you used.
  • Residuals: Shows the distribution of your errors (the difference between predicted and actual values). Ideally, the median should be close to zero, and the 1Q/3Q values should be symmetrical.
  • Coefficients:
    • Estimate: The Intercept and the slope for your predictor. For example, if the speed estimate is 3.9, it means for every 1 unit increase in speed, the stopping distance increases by 3.9 units.
    • Pr(>|t|): The p-value. If this is less than 0.05, your predictor is considered statistically significant.
  • Residual standard error: Represents the average distance that the observed values fall from the regression line. Lower is generally better.
  • Multiple R-squared: Tells you the proportion of variance in your dependent variable explained by your model (0 to 1). A higher number means the model explains more of the data.
  • F-statistic: Tests if the overall model is better than a model with no predictors.

3. Quick visualization

To see the regression line plotted over your data:

R
plot(dist ~ speed, data = cars)
abline(model, col = "red")

If you are unsure about the interpretation of your specific p-values or R-squared, feel free to share the numbers, and I can help you understand what they suggest for your specific dataset.

Answering this used an estimated 90% less than EcoRouter’s configured frontier baseline

Routed to
Efficient
Tokens
212 in / 497 out
Cost
$0.0008
Baseline
$0.0081

Figures recorded by EcoRouter when this answer was generated, and fixed at that moment. Cost comparisons are against a configured reference model, not a measurement of electricity, carbon or water.

Ask about this

Ask EcoRouter a follow-up using this Knowledge as context. Nothing becomes public unless you choose to publish it.

Ask a follow-up
0 views

Comments

No comments yet.