Description Usage Arguments Value Author(s) Examples
View source: R/WeightedRidgeRegression.R
By using nnls
, ginv
or glmnet
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | WRRnnls(x, y, xExact = NULL, yExact = NULL, wExact = 1000, lambda = 1e-04^2)
WRRginv(x, y, xExact = NULL, yExact = NULL, wExact = 1000, lambda = 1e-04^2)
WRRglmnet(
x,
y,
xExact = NULL,
yExact = NULL,
wExact = 1000,
lambda = exp(((2 * 12):(-17 * 2))/2),
intercept = FALSE,
standardize = FALSE,
thresh = 1e-10,
lower.limits = 0,
...
)
|
x |
Input matrix, each row is an ordinary observation |
y |
Ordinary response observation (vector or matrix) |
xExact |
Input matrix, each row is a highly weighted observation |
yExact |
Highly weighted response observation (vector or matrix) |
wExact |
Weight for highly weighted observations |
lambda |
Ridge regression penalty parameter (sequence when glmnet) |
intercept |
glmnet parameter |
standardize |
glmnet parameter |
thresh |
glmnet parameter |
lower.limits |
glmnet parameter |
... |
Further glmnet parameters |
Output from nnls
, glmnet
or coefficient estimate calculated using ginv
Øyvind Langsrud
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 | x <- cbind(1:11, -11:-1, c(1, 1, 2, 2, 1, 1, 2, 2, 1, 1, 2))
y <- matrix(5 - sin(2 * (1:11)), dimnames = list(NULL, "y"))
x1 <- x[1:9, ]
x2 <- x[10:11, ]
y1 <- y[1:9, , drop = FALSE]
y2 <- y[10:11, , drop = FALSE]
# Generalized inverse estimation
ginvCoef <- WRRginv(x1, y1, x2, y2)
# Non-negative estimation by nnls
# Coefficients in output element x
nnlsCoef <- WRRnnls(x1, y1, x2, y2)$x
# Non-negative estimation by glmnet
# Take out best fit from matrix of coefficients
gn <- WRRglmnet(x1, y1, x2, y2)
glmnetCoef <- coef(gn)[-1, which.max(gn$dev.ratio), drop = FALSE]
# Another estimation by glmnet (not non-negative)
# Take out best fit from matrix of coefficients
gnInf <- WRRglmnet(x1, y1, x2, y2, lower.limits = -Inf)
glmnetCoefInf <- coef(gnInf)[-1, which.max(gn$dev.ratio), drop = FALSE]
# All coefficients
coef4 <- as.matrix(cbind(ginvCoef, nnlsCoef, glmnetCoef, glmnetCoefInf))
colnames(coef4) <- c("ginv", "nnls", "glmnet", "glmnetInf")
print(coef4)
# Original y and fitted values. Close fit for last two observation.
cbind(y, x %*% coef4)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.