stackavg | R Documentation |
Model stacking (here = averaging) for regression (quantitative response) and discrimination (qualitative response) models.
Functions stackavg
and stackavgcla
calculate "averages", eventually with a priori
weighting, of univariate predictions returned by a set of different models:
- Arithmetic mean of the quantitative predictions for regression models;
- Vote of the predicted classes for discrimination models.
A weighting of the predictions in the mean and vote is allowed (argument weights
).
stackavg(fit, y = NULL, formula, nam = NULL, weights = NULL)
stackavgcla(fit, y = NULL, formula, nam = NULL, weights = NULL)
fit |
Data frame of predicted values. |
y |
Data frame of |
formula |
A right-hand-side formula defing the aggregation levels on which the predictions are averaged. |
nam |
Name (character string) of the column to consider in |
weights |
A vector (of length the number of rows in |
A list of outputs (see examples), such as:
y |
Responses for the test data. |
fit |
Predictions for the test data. |
r |
Residuals for the test data. |
############## Regression
data(datcass)
Xr <- datcass$Xr
yr <- datcass$yr
Xu <- datcass$Xu
yu <- datcass$yu
ncomp <- 25
fm <- plsr(Xr, yr, Xu, yu, ncomp = ncomp)
z <- mse(fm, ~ ncomp)
z[z$rmsep == min(z$rmsep), ]
plotmse(z)
w <- ifelse(fm$y$ncomp >= 5 & fm$y$ncomp <= 20, 1, 0)
zfm <- stackavg(fm$fit, fm$y, formula = ~ rownum + rownam, weights = w)
names(zfm)
head(zfm$y)
head(zfm$fit)
head(zfm$r)
mse(zfm)
############## Discrimination
data(datforages)
Xr <- datforages$Xr
yr <- datforages$yr
Xu <- datforages$Xu
yu <- datforages$yu
ncomp <- 20
fm <- plsdalm(Xr, yr, Xu, yu, ncomp = ncomp)
z <- err(fm, ~ ncomp)
z[z$errp == min(z$errp), ]
plotmse(z, nam = "errp")
w <- ifelse(fm$y$ncomp >= 8 & fm$y$ncomp <= 20, 1, 0)
zfm <- stackavgcla(fm$fit, fm$y, formula = ~ rownum + rownam, weights = w)
names(zfm)
head(zfm$y)
head(zfm$fit)
head(zfm$r)
err(zfm)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.