uni_fun: Univariate regressions

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

View source: R/utility_functions.R

Description

Function used to create initial estimates in fitting algorithm of the strong heredity interaction model implemented in the shim function

Usage

1
2
uni_fun(x, y, type = c("ridge", "univariate"), variables,
  include.intercept = FALSE)

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

type

The procedure used to estimate the regression coefficients. 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".

variables

character vector of variable names for which you want the univariate regression estimate. Must be contained in the column names of x. This only applies if type="univariate".

include.intercept

Should intercept be fitted (default is FALSE). Should be set to TRUE if y is not centered

Value

Regression coefficients as a q x 1 data.frame

Note

p is defined as the number of main effects. I have introduced q as being the total number of variables (e.g. the number of columns in the design matrix).

Author(s)

Sahir Bhatnagar

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

See Also

shim, cv.glmnet

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
# 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(paste0("x",1:p), "e")

# 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)

uni_fun(X, Y)

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