Web EndMemo

### R Linear Model Function

`lm()` is a linear model function, such like linear regression analysis.

`lm(formula, data, subset, weights, ...)`
`formula`: model description, such as x ~ y
`data`: optional, variables in the model
`subset`: optional, a subset vector of observations to be used in the fitting process
`weights`: optional, a vector of weights to be used in the fitting process

Let's create two vectors, and then fit a linear model:

```>x <- c(rep(1:20))
>y <- x * 2
>f <- lm(x ~ y)
>f
```
```Call:
lm(formula = x ~ y)

Coefficients:
(Intercept)            y
-4.766e-15    5.000e-01
```

We can use `summary()` to see the details:
```>summary(f)
```
```Call:
lm(formula = x ~ y)

Residuals:
Min         1Q     Median         3Q        Max
-6.208e-15  8.400e-18  3.526e-16  6.074e-16  2.038e-15

Coefficients:
Estimate Std. Error    t value Pr(>|t|)
(Intercept) -4.766e-15  7.696e-16 -6.193e+00  7.6e-06 ***
y            5.000e-01  3.212e-17  1.557e+16  < 2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 1.657e-15 on 18 degrees of freedom
Multiple R-squared:     1,      Adjusted R-squared:     1
F-statistic: 2.423e+32 on 1 and 18 DF,  p-value: < 2.2e-16
```

Let's plot the results:
```>plot(f)
``` 