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

Description Usage Arguments Value Examples

View source: R/compare_method.r

Description

Get a fitted model selected by cross validation

Usage

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

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)

Value

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

Examples

1
2
3
4
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)

christineyuen/VSC documentation built on Oct. 8, 2019, 10:45 a.m.