Principal components regression | R Documentation |

Principal components regression.

```
pcr(y, x, k = 1, xnew = NULL)
```

`y` |
A real values vector. |

`x` |
A matrix with the predictor variable(s), they have to be continuous. |

`k` |
The number of principal components to use. This can be a single number or a vector starting from 1. In the second case you get results for the sequence of principal components. |

`xnew` |
If you have new data use it, otherwise leave it NULL. |

The principal components of the cross product of the independent variables are obtained and classical regression is performed.

A list including:

`be` |
The beta coefficients of the predictor variables computed via the principcal components. |

`per` |
The percentage of variance of the cross product of the independent variables explained by the k components. |

`vec` |
The principal components, the loadings. |

`est` |
The fitted or the predicted values (if xnew is not NULL). |

Michail Tsagris.

R implementation and documentation: Michail Tsagris mtsagris@uoc.gr.

Jolliffe I.T. (2002). Principal Component Analysis.

```
pca
```

```
y <- as.vector(iris[, 1])
x <- as.matrix(iris[, 2:4])
mod1 <- pcr(y, x, 1)
mod2 <- pcr(y, x, 2)
mod <- pcr(y, x, k = 1:3) ## all results at once
```

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.