shim_once: Fit Strong Heredity model with one iteration

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/utility_functions.R

Description

This function runs the first iteration of the fitting algorithm just to get the sequence of lambda_gamma and lambda_beta

Usage

1
2
3
shim_once(x, y, main.effect.names, interaction.names,
  initialization.type = c("ridge", "univariate"), nlambda.gamma = 20,
  nlambda.beta = 20, lambda.factor = ifelse(nobs < nvars, 0.01, 1e-06))

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)

initialization.type

The procedure used to estimate the regression coefficients and used in the uni_fun function. If "univariate" then a series of univariate regressions is performed with the response variable y. If "ridge" then ridge regression is performed using the cv.glmnet function and the tuning parameter is chosen using 10 fold cross validation. The default is "ridge".

nlambda.gamma

number of tuning parameters for gamma

nlambda.beta

number of tuning parameters for beta

lambda.factor

The factor for getting the minimal lambda in lambda sequence, where min(lambda) = lambda.factor * max(lambda). max(lambda) is the smallest value of lambda for which all coefficients are zero. The default depends on the relationship between N (the number of rows in the matrix of predictors) and p (the number of predictors). If N > p, the default is 1e-6, close to zero. If N < p, the default is 0.01. A very small value of lambda.factor will lead to a saturated fit.

Details

A unique sequence of tuning parameters for the main effects (lambda.beta) is calculated for each tuning parameter for the interaction terms (lambda.gamma)

Value

list of length 2, first element is lambda_gamma and second element is lambda_beta

Author(s)

Sahir Bhatnagar

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

See Also

shim

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
30
31
32
# 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
dimnames(x)[[2]] <- c("x1","x2","x3","x4","x5","e")

# design matrix without intercept (can be user defined interactions)
X <- model.matrix(~(x1+x2+x3)*e+x1*x4+x3*x5-1, data = as.data.frame(x))

# names must appear in the same order as X matrix
interaction_names <- grep(":", colnames(X), value = T)
main_effect_names <- setdiff(colnames(X), interaction_names)

# response
Y <- X %*% rbinom(ncol(X), 1, 0.6) + 3*rnorm(n)

# standardize data
data_std <- standardize(X,Y)

shim_once(x = data_std$x, y = data_std$y,
          main.effect.names = main_effect_names,
          interaction.names = interaction_names,
          nlambda.gamma = 5, nlambda.beta = 5)

sahirbhatnagar/shim documentation built on May 29, 2019, 12:59 p.m.