SSGLcv: Find optimal lambda0 value using cross validation

Description Usage Arguments Value Examples

View source: R/Main.R

Description

This function takes in an outcome and covariates, and uses cross validation to find the best lambda0 value.

Usage

1
2
3
SSGLcv(Y, X, lambda1, lambda0seq = seq(1, 100, by = 1), groups, a = 1,
  b = length(unique(groups)), nFolds = 5, M = 10, error = 0.001,
  forceGroups = c())

Arguments

Y

The outcome to be analyzed

X

An n by p matrix of covariates

lambda1

Prior parameter for the slab component of the prior

lambda0seq

Sequence of lambda0 values to consider

groups

A vector of length p denoting which group each covariate is in

a

First hyperparameter for the beta prior denoting the prior probability of being in the slab

b

Second hyperparameter for the beta prior denoting the prior probability of being in the slab

nFolds

The number of folds to run cross validation on

M

Positive number less than p indicating how often to update theta and sigma. There is no need to change this unless trying to optimize computation time

forceGroups

A vector containing the indices of any groups you wish to automatically include in the model and not penalize

Value

A list of values containing the lambda0 that minimizes the cross-validated error, the vector of cross validated errors for each lambda0 in the sequence, and the lambda0 sequence looked at

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
## Here we generate 200 samples from 100 covariates
n = 200
G = 100
x = mvtnorm::rmvnorm(n, sigma=diag(G))


X = matrix(NA, nrow=n, ncol=G*2)
for (g in 1 : G) {
  X[,2*(g-1) + 1] = x[,g]
  X[,2*g] = x[,g]^2
}


Y = x[,1] + x[,2] + 0.6*x[,2]^2 + rnorm(n, sd=1)

## Now find the best lambda0 using cross-validation
modSSGLcv = SSGLcv(Y=Y, X=X, lambda1=.1, 
lambda0seq = seq(1,100, by=2),
groups = rep(1:G, each=2),
nFolds = 5)

modSSGL = SSGL(Y=Y, X=X, lambda1=.1, lambda0=modSSGLcv$lambda0, 
               groups = rep(1:G, each=2))

modSSGL

jantonelli111/SSGL documentation built on March 9, 2020, 9:45 p.m.