ridge_weights: Calculate Adaptive Weights based on Ridge Regression

Description Usage Arguments Details Value Author(s) References Examples

View source: R/utility_functions.R

Description

uses ridge regression from glmnet package to calculate the adaptive weights used in the fitting algorithm implemented in the shim function.

Usage

1
2
ridge_weights(x, y, main.effect.names, interaction.names,
  include.intercept = F)

Arguments

x

Design matrix of dimension n x q, where n is the number of subjects and q is the total number of variables; each row is an observation vector. This must include all main effects and interactions as well, with column names corresponding to the names of the main effects (e.g. x1, x2, E) and their interactions (e.g. x1:E, x2:E). All columns should be scaled to have mean 0 and variance 1; this is done internally by the shim function.

y

response variable (matrix form) of dimension n x 1

main.effect.names

character vector of main effects names

interaction.names

character vector of interaction names. MUST be separated by a colon (e.g. x1:e, x2:e)

include.intercept

logical if intercept should be fitted. Default is FALSE. Should be set to TRUE if y is not centered

Details

Ridge regression is performed using the cv.glmnet function and the tuning parameter is chosen using 10 fold cross validation

Value

q x 1 matrix of weights for the main effects and interaction terms

Author(s)

Sahir Bhatnagar

Maintainer: Sahir Bhatnagar sahir.bhatnagar@mail.mcgill.ca

References

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/

Examples

 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)

sahirbhatnagar/eclustProject documentation built on May 29, 2019, 12:58 p.m.