Letâ€™s generate some data from a linear model.

n=50
x = runif(n,-3,3)
y = .3 * x + rnorm(n,sd=.4)
u = seq(-6,6,.1)
par(mfrow=c(2,2))
plot(x,y,xlim=c(-6,6),ylim=c(-2,2))
lines(u,predict(lm(y ~ x),data.frame(x=u)),col="blue")
plot(x,y,xlim=c(-6,6),ylim=c(-2,2))
lines(u,predict(lm(y ~ x + I(x^2)),data.frame(x=u)),col="blue")
plot(x,y,xlim=c(-6,6),ylim=c(-2,2))
lines(u,predict(lm(y ~ x + I(x^2) + I(x^3)),data.frame(x=u)),col="blue")
plot(x,y,xlim=c(-6,6),ylim=c(-2,2))
lines(u,predict(lm(y ~ x + I(x^2) + I(x^3) + I(x^4)),data.frame(x=u)),col="blue")

n=20
x1 = runif(n,-3,3)
y = .3 * x1 + rnorm(n,sd=.4)
u = seq(-6,6,.1)
x2 = rnorm(n); x3 = rnorm(n)
summary(lm(y ~ x1 + x2 + x3))
##
## Call:
## lm(formula = y ~ x1 + x2 + x3)
##
## Residuals:
##      Min       1Q   Median       3Q      Max
## -0.59567 -0.22701 -0.00116  0.27263  0.42347
##
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)
## (Intercept)  0.25716    0.08889   2.893   0.0106 *
## x1           0.35304    0.05185   6.808  4.2e-06 ***
## x2           0.03128    0.09943   0.315   0.7571
## x3           0.06152    0.07118   0.864   0.4002
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.3485 on 16 degrees of freedom
## Multiple R-squared:  0.7928, Adjusted R-squared:  0.754
## F-statistic: 20.41 on 3 and 16 DF,  p-value: 1.023e-05
plot(x1,y,xlim=c(-6,6),ylim=c(-2,2))
lines(u,predict(lm(y ~ x1 + x2 + x3),data.frame(x1=u,x2=rnorm(length(u)),x3=rnorm(length(u)))),col="blue")

n=10
x1 = runif(n,-3,3)
y = .3 * x1 + rnorm(n,sd=.4)
u = seq(-6,6,.1)
X = matrix(rnorm(n * 7),n)
df = data.frame(cbind(y,x1,X))
summary(lm(y ~ .,data=df))
##
## Call:
## lm(formula = y ~ ., data = df)
##
## Residuals:
##         1         2         3         4         5         6         7
##  0.117636  0.059856 -0.197026 -0.051758 -0.195283 -0.037638  0.008322
##         8         9        10
## -0.040151  0.133805  0.202235
##
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)
## (Intercept) -0.118524   0.146481  -0.809    0.567
## x1           0.213832   0.159473   1.341    0.408
## V3           0.111135   0.414193   0.268    0.833
## V4           0.006828   0.802224   0.009    0.995
## V5          -0.071084   0.533115  -0.133    0.916
## V6          -0.043647   0.222304  -0.196    0.877
## V7          -0.052038   0.618283  -0.084    0.947
## V8           0.069444   0.126608   0.548    0.681
## V9           0.231457   0.356820   0.649    0.634
##
## Residual standard error: 0.3987 on 1 degrees of freedom
## Multiple R-squared:  0.9462, Adjusted R-squared:  0.5156
## F-statistic: 2.197 on 8 and 1 DF,  p-value: 0.4811
plot(x1,y,xlim=c(-6,6),ylim=c(-2,2))

u = seq(-6,6,.1)
X = matrix(rnorm(length(u) * 7),length(u))
df.test = data.frame(cbind(u,x1=u,X))

lines(u,predict(lm(y ~ .,data=df),df.test),col="blue")