Description Usage Arguments Details Value Author(s) References Examples
View source: R/utility_functions.R
uses ridge regression from glmnet
package to calculate
the adaptive weights used in the fitting algorithm implemented in the
shim
function.
1 2 | ridge_weights(x, y, main.effect.names, interaction.names,
include.intercept = F)
|
x |
Design matrix of dimension |
y |
response variable (matrix form) of dimension |
main.effect.names |
character vector of main effects names |
interaction.names |
character vector of interaction names. MUST be
separated by a colon (e.g. |
include.intercept |
logical if intercept should be fitted. Default is
|
Ridge regression is performed using the
cv.glmnet
function and the tuning parameter is chosen
using 10 fold cross validation
q x 1
matrix of weights for the main effects and interaction
terms
Sahir Bhatnagar
Maintainer: Sahir Bhatnagar sahir.bhatnagar@mail.mcgill.ca
Friedman, J., Hastie, T. and Tibshirani, R. (2008) Regularization Paths for Generalized Linear Models via Coordinate Descent, http://www.stanford.edu/~hastie/Papers/glmnet.pdf Journal of Statistical Software, Vol. 33(1), 1-22 Feb 2010 http://www.jstatsoft.org/v33/i01/
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 | # number of observations
n <- 100
# number of predictors
p <- 5
# environment variable
e <- sample(c(0,1), n, replace = T)
# main effects
x <- cbind(matrix(rnorm(n*p), ncol = p), e)
# need to label columns
main_effect_names <- c(paste0("x",1:p), "e")
interaction_names <- paste0("x",1:p, ":e")
dimnames(x)[[2]] <- main_effect_names
# design matrix without intercept
X <- model.matrix(~(x1+x2+x3+x4+x5)*e-1, data = as.data.frame(x))
# response
Y <- X %*% rbinom(ncol(X), 1, 0.2) + 3*rnorm(n)
# standardize data
data_std <- standardize(X,Y)
ridge_weights(x = data_std$x, y = data_std$y,
main.effect.names = main_effect_names,
interaction.names = interaction_names)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.