Skip to content

Instantly share code, notes, and snippets.

@krishnanraman
Created May 3, 2022 14:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krishnanraman/a253d8bf3d8ea3c0e1aadd6b4019d972 to your computer and use it in GitHub Desktop.
Save krishnanraman/a253d8bf3d8ea3c0e1aadd6b4019d972 to your computer and use it in GitHub Desktop.
poly fit
> x<-runif(100,0,2)
> y<-1+x+x^2+x^3
> summary(lm(y~x))
Call:
lm(formula = y ~ x)
Residuals:
Min 1Q Median 3Q Max
-1.334 -1.018 -0.213 0.677 2.742
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -1.071 0.213 -5.03 2.2e-06 ***
x 6.397 0.206 31.06 < 2e-16 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 1.16 on 98 degrees of freedom
Multiple R-squared: 0.908, Adjusted R-squared: 0.907
F-statistic: 965 on 1 and 98 DF, p-value: <2e-16
> summary(lm(y~poly(x,2)))
Call:
lm(formula = y ~ poly(x, 2))
Residuals:
Min 1Q Median 3Q Max
-0.3308 -0.1444 0.0489 0.1176 0.3394
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 4.4838 0.0153 292.4 <2e-16 ***
poly(x, 2)1 35.9596 0.1533 234.5 <2e-16 ***
poly(x, 2)2 11.3604 0.1533 74.1 <2e-16 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.153 on 97 degrees of freedom
Multiple R-squared: 0.998, Adjusted R-squared: 0.998
F-statistic: 3.02e+04 on 2 and 97 DF, p-value: <2e-16
> summary(lm(y~poly(x,3)))
Call:
lm(formula = y ~ poly(x, 3))
Residuals:
Min 1Q Median 3Q Max
-4.09e-15 -4.61e-16 -8.00e-17 3.45e-16 1.07e-14
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 4.48e+00 1.55e-16 2.90e+16 <2e-16 ***
poly(x, 3)1 3.60e+01 1.55e-15 2.32e+16 <2e-16 ***
poly(x, 3)2 1.14e+01 1.55e-15 7.34e+15 <2e-16 ***
poly(x, 3)3 1.51e+00 1.55e-15 9.75e+14 <2e-16 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 1.55e-15 on 96 degrees of freedom
Multiple R-squared: 1, Adjusted R-squared: 1
F-statistic: 1.98e+32 on 3 and 96 DF, p-value: <2e-16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment