Learn R Programming

CSUV (version 0.1.1)

lm.cv: Get a fitted model selected by cross validation

Description

Get a fitted model selected by cross validation

Usage

lm.cv(
  X,
  Y,
  intercept,
  fit.percent,
  num.repeat,
  method.names = NULL,
  num.core = 1,
  log.level = NULL
)

Arguments

X

covariates (n times p matrix, n: number of entries, p: number of covariates)

Y

response (vector with n entries)

intercept

TRUE to fit the data with an intercept, FALSE to fit the data without an intercept

fit.percent

percentage of observations used in fitting in cross validation. Each set of subsampling data will have (n times fit.percent) observations for fitting and n times (1-fit.percent) observations for calculating the mse

num.repeat

number of sets of subsampling data used in cross validation

method.names

vector of method names to be used in cross validation. Choose among "lasso", "elastic", "relaxo", "mcp" and "scad". Default is to use all methods listed above

num.core

number of cores to use. Default is 1 (i.e. no parallel running)

log.level

log level to set. Default is NULL, which means no change in log level. See the function CSUV::set.log.level for more details

Value

a list which includes the estimated coefficients (est.b) and the corresponding ordinary least square fit from stats::lm()

Examples

Run this code
# NOT RUN {
set.log.level(futile.logger::WARN)
X = matrix(rnorm(1000), nrow = 100)
Y = rowSums(X[,1:3])+rnorm(100)
cv.mod = lm.cv(X, Y, intercept = FALSE, fit.percent = 0.5, num.repeat = 50)
print(cv.mod$est.b)
# }

Run the code above in your browser using DataLab