# How to calculate root mean square error for linear model in R?

## Output

 1.961622

## Example

Live Demo

x2<-rnorm(5000,125,21)
y2<-rnorm(5000,137,10)
M2<-lm(y2~x2)
summary(M2)

## Output

Call:
lm(formula = y2 ~ x2)
Residuals:
Min      1Q    Median    3Q    Max
-37.425  -7.005   -0.231  6.836  36.627
Coefficients:
Estimate      Std.    Error t value Pr(>|t|)
(Intercept) 138.683501 0.851247 162.918 <2e-16 ***
x2     -0.014386 0.006735 -2.136 0.0327 *
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 10.06 on 4998 degrees of freedom
Multiple R-squared: 0.0009121, Adjusted R-squared: 0.0007122
F-statistic: 4.563 on 1 and 4998 DF, p-value: 0.03272

Finding the root mean square error from model M2:

## Output

 3.020734

## Example

Live Demo

x4<-runif(50000,5,10)
y4<-runif(50000,2,10)
M4<-lm(y4~x4)
summary(M4)

## Output

Call:
lm(formula = y4 ~ x4)
Residuals:
Min    1Q      Median 3Q    Max
-4.0007 -1.9934 -0.0063 1.9956 3.9995
Coefficients:
Estimate    Std.    Error t value Pr(>|t|)
(Intercept) 5.9994268 0.0546751 109.729 <2e-16 ***
x4    0.0001572 0.0071579 0.022    0.982
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 2.309 on 49998 degrees of freedom
Multiple R-squared: 9.646e-09, Adjusted R-squared: -1.999e-05
F-statistic: 0.0004823 on 1 and 49998 DF, p-value: 0.9825

Finding the root mean square error from model M4 −

## Output

 2593.709