cv.sparse.mediation: Conduct K-fold cross validation for sparse mediation with...

Description Usage Arguments Value Author(s) References Examples

View source: R/cv.sparse.mediation.R

Description

Conduct K-fold cross validation for sparse mediation with elastic net with multiple tuning parameters

Usage

1
2
3
cv.sparse.mediation(X, M, Y, tol = 10^(-10), K = 5, max.iter = 100,
  lambda = log(1 + (1:15)/50), alpha = (0:4)/4, tau = c(0.5, 1, 2),
  multicore = 1, seednum = 1e+06)

Arguments

X

One-dimensional predictor

M

Multivariate mediator

Y

Outcome

tol

(default -10^(-10)) convergence criterion

K

(default=5) number of cross-validation folds

max.iter

(default=100) maximum iteration

lambda

(default=log(1+(1:30)/100)) tuning parameter for L1 penalization

alpha

(defult=c(1:4)/4) tuning parameter for L2 penalization

multicore

(default=1) number of multicore

seednum

(default=10000) seed number for cross validation

figure

(defult=NULL) print figures for mean predictive errors by tuning parameters alpha and lambda

glmnet.penalty.factor

(default=c(0,rep(1,2*V))) give different weight of penalization for the 2V mediation paths.

disply

devault=FALSE

Value

cv.lambda: optimal lambda

cv.tau: optimal tau

cv.alpha: optimal tau

cv.mse: minimum MSE value

mse: Array of MSE, length(alpha) x length(lambda) x length (tau)

lambda: vector of lambda

tau: vector of tau used

alpha: vector of alpha used

z: cross-valication results

Author(s)

Seonjoo Lee, [email protected]

References

TBA

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
N=200
V=50
set.seed(1234)
a = rbinom(V,1,0.1)*5;b<-a
X = rnorm(N)
M =  X %*% t(a)+ matrix(rnorm(N*V),N,V)
Y =  as.vector(X + M %*% b + rnorm(N))
system.time(cvfit<-cv.sparse.mediation(X, M, Y, tol = 10^(-10), K = 8, max.iter = 100,lambda = log(1 + (1:10)/25), alpha = 1, tau=c(0.25,0.5,1,2,4,8),multicore = 8, seednum = 1e+06))
cvfit$cv.lambda
cvfit$cv.tau
fit<-sparse.mediation(X,M,Y,tol=10^(-10),max.iter=100,lambda = cvfit$cv.lambda, alpha=cvfit$cv.alpha,tau=cvfit$cv.tau)
nonzerolist = c(0,as.numeric(abs(c(fit[[1]]$hatb, fit[[1]]$hata))<0.0001))
refit=sparse.mediation.old(X,M,Y,lambda = 100000,alpha=cvfit$cv.alpha, glmnet.penalty.factor=nonzerolist)
cbind(a*b,refit$medest)

seonjoo/sparsemediation documentation built on May 13, 2018, 2:53 a.m.