Learn R Programming

joinet (version 0.0.3)

cv.joinet: Model comparison

Description

Compares univariate and multivariate regression.

Usage

cv.joinet(Y, X, family = "gaussian", nfolds.ext = 5, nfolds.int = 10,
  foldid.ext = NULL, foldid.int = NULL, type.measure = "deviance",
  alpha.base = 1, alpha.meta = 0, mnorm = FALSE, spls = FALSE,
  sier = FALSE, mrce = FALSE, cvpred = FALSE, ...)

Arguments

Y

outputs: numeric matrix with \(n\) rows (samples) and \(q\) columns (variables), with positive correlation (see details)

X

inputs: numeric matrix with \(n\) rows (samples) and \(p\) columns (variables)

family

distribution: vector of length \(1\) or \(q\) with entries "gaussian", "binomial" or "poisson"

nfolds.ext

number of external folds

nfolds.int

number of internal folds

foldid.ext

external fold identifiers: vector of length \(n\) with entries between \(1\) and nfolds.ext; or NULL

foldid.int

internal fold identifiers: vector of length \(n\) with entries between \(1\) and nfolds.int; or NULL

type.measure

loss function: vector of length \(1\) or \(q\) with entries "deviance", "class", "mse" or "mae" (see cv.glmnet)

alpha.base

elastic net mixing parameter for base learners: numeric between \(0\) (ridge) and \(1\) (lasso)

alpha.meta

elastic net mixing parameter for meta learner: numeric between \(0\) (ridge) and \(1\) (lasso)

mnorm, spls, sier, mrce

experimental arguments: logical (requires packages spls, SiER, or MRCE)

cvpred

return cross-validated predicition: logical

...

further arguments passed to glmnet and cv.glmnet

Value

This function returns a matrix with \(q\) columns, including the cross-validated loss from the univariate models (base), the multivariate models (meta), and the intercept-only models (none).

Examples

Run this code
# NOT RUN {
n <- 50; p <- 100; q <- 3
X <- matrix(rnorm(n*p),nrow=n,ncol=p)
Y <- replicate(n=q,expr=rnorm(n=n,mean=rowSums(X[,1:5])))
cv.joinet(Y=Y,X=X)

# }
# NOT RUN {
# correlated features
n <- 50; p <- 100; q <- 3
mu <- rep(0,times=p)
Sigma <- 0.90^abs(col(diag(p))-row(diag(p)))
X <- MASS::mvrnorm(n=n,mu=mu,Sigma=Sigma)
mu <- rowSums(X[,sample(seq_len(p),size=5)])
Y <- replicate(n=q,expr=rnorm(n=n,mean=mu))
#Y <- t(MASS::mvrnorm(n=q,mu=mu,Sigma=diag(n)))
cv.joinet(Y=Y,X=X)
# }
# NOT RUN {
# }
# NOT RUN {
# other distributions
n <- 50; p <- 100; q <- 3
X <- matrix(rnorm(n*p),nrow=n,ncol=p)
eta <- rowSums(X[,1:5])
Y <- replicate(n=q,expr=rbinom(n=n,size=1,prob=1/(1+exp(-eta))))
cv.joinet(Y=Y,X=X,family="binomial")
Y <- replicate(n=q,expr=rpois(n=n,lambda=exp(scale(eta))))
cv.joinet(Y=Y,X=X,family="poisson")
# }
# NOT RUN {
# }
# NOT RUN {
# uncorrelated outcomes
n <- 50; p <- 100; q <- 3
X <- matrix(rnorm(n*p),nrow=n,ncol=p)
y <- rnorm(n=n,mean=rowSums(X[,1:5]))
Y <- cbind(y,matrix(rnorm(n*(q-1)),nrow=n,ncol=q-1))
cv.joinet(Y=Y,X=X)
# }
# NOT RUN {
# }
# NOT RUN {
# sparse and dense models
n <- 50; p <- 100; q <- 3
X <- matrix(rnorm(n*p),nrow=n,ncol=p)
Y <- replicate(n=q,expr=rnorm(n=n,mean=rowSums(X[,1:5])))
set.seed(1) # fix folds
cv.joinet(Y=Y,X=X,alpha.base=1) # lasso
set.seed(1)
cv.joinet(Y=Y,X=X,alpha.base=0) # ridge
# }
# NOT RUN {
# }

Run the code above in your browser using DataLab