/
README.Rmd
144 lines (107 loc) · 4.93 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# plsdof <img src="man/figures/logo.png" align="right" width="200"/>
# Degrees of Freedom and Statistical Inference for Partial Least Squares Regression
## Maintainer: Frédéric Bertrand
<!-- badges: start -->
[![Lifecycle: stable](https://img.shields.io/badge/lifecycle-stable-green.svg)](https://lifecycle.r-lib.org/articles/stages.html)
[![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)
[![R-CMD-check](https://github.com/fbertran/plsdof/workflows/R-CMD-check/badge.svg)](https://github.com/fbertran/plsdof/actions)
[![Codecov test coverage](https://codecov.io/gh/fbertran/plsdof/branch/master/graph/badge.svg)](https://app.codecov.io/gh/fbertran/plsdof?branch=master)
[![CRAN status](https://www.r-pkg.org/badges/version/plsdof)](https://cran.r-project.org/package=plsdof)
[![CRAN RStudio mirror downloads](https://cranlogs.r-pkg.org/badges/plsdof)](https://cran.r-project.org/package=plsdof)
[![GitHub Repo stars](https://img.shields.io/github/stars/fbertran/plsdof?style=social)](https://github.com/fbertran/plsdof)
[![DOI](https://zenodo.org/badge/167805443.svg)](https://zenodo.org/badge/latestdoi/167805443)
<!-- badges: end -->
The plsdof package provides Degrees of Freedom estimates
for Partial Least Squares (PLS) Regression. Model selection for
PLS is based on various information criteria (aic, bic, gmdl)
or on cross-validation. Estimates for the mean and covariance
of the PLS regression coefficients are available. They allow
the construction of approximate confidence intervals and the
application of test procedures.
Further, cross-validation procedures for Ridge Regression and
Principal Components Regression are available.
The plsdof package was fully coded and developped by Nicole Kraemer and Mikio L. Braun. It is mainly based on the article by N. Kraemer, M. Sugiyama (2012): "The Degrees of Freedom of Partial Least Squares Regression", *Journal of the American Statistical Association*, **106**(494):697-705, [doi:10.1198/jasa.2011.tm10107](http://dx.doi.org/doi:10.1198/jasa.2011.tm10107).
Yet due to the regular updates in CRAN policies, it was removed from the CRAN and orphaned since the former maintainer had stopped updating the package. The plsdof package is required by several packages of Frédéric Bertrand who was then selected as the new maintainer since late 2018.
This website and these examples were created by F. Bertrand.
## Installation
You can install the released version of plsdof from [CRAN](https://CRAN.R-project.org) with:
```{r, eval = FALSE}
install.packages("plsdof")
```
You can install the development version of plsdof from [github](https://github.com) with:
```{r, eval = FALSE}
devtools::install_github("fbertran/plsdof")
```
## Example
### PLS model example.
The pls.model function computes the Partial Least Squares fit.
```{r plsmodel}
n<-50 # number of observations
p<-15 # number of variables
X<-matrix(rnorm(n*p),ncol=p)
y<-rnorm(n)
ntest<-200 #
Xtest<-matrix(rnorm(ntest*p),ncol=p) # test data
ytest<-rnorm(ntest) # test data
library(plsdof)
# compute PLS + degrees of freedom + prediction on Xtest
first.object<-pls.model(X,y,compute.DoF=TRUE,Xtest=Xtest,ytest=NULL)
# compute PLS + test error
second.object=pls.model(X,y,m=10,Xtest=Xtest,ytest=ytest)
```
### Model selection for Partial Least Squares based on information criteria
The pls.ic function computes the optimal model parameters using one of three different model selection criteria (aic, bic, gmdl) and based on two different Degrees of Freedom estimates for PLS.
```{r plsic}
n<-50 # number of observations
p<-5 # number of variables
X<-matrix(rnorm(n*p),ncol=p)
y<-rnorm(n)
# compute linear PLS
pls.object<-pls.ic(X,y,m=ncol(X))
```
### Boston Housing data
Creating response vector and predictors' matrix
```{r bhd}
data(Boston)
X<-as.matrix(Boston[,-14])
y<-as.vector(Boston[,14])
```
Compute PLS coefficients for the first 5 components.
```{r pls1}
my.pls1<-pls.model(X,y,m=5,compute.DoF=TRUE)
my.pls1
```
Plot Degrees of Freedom and add naive estimate.
```{r pls1pnaive}
plot(0:5,my.pls1$DoF,pch="*",cex=3,xlab="components",ylab="DoF",ylim=c(0,14))
lines(0:5,1:6,lwd=3)
```
Model selection with the Bayesian Information criterion
```{r pls2}
my.pls2<-pls.ic(X,y,criterion="bic")
my.pls2
```
Model selection based on cross-validation.
```{r pls3}
my.pls3<-pls.cv(X,y,compute.covariance=TRUE)
my.pls3
```
Returns the estimated covariance matrix of the regression coefficients
```{r pls3cov}
my.vcov<-vcov(my.pls3)
my.vcov
```
Standard deviation of the regression coefficients
```{r pls3sd}
my.sd<-sqrt(diag(my.vcov))
my.sd
```