plotBetas: Plot the coefficients from glmnet

Description Usage Arguments Examples

View source: R/plotGlmnet.R

Description

Take a glmnet object and plot out the path of the coefficient for each variable as model complexity increases.

Usage

1
2
3
4
plotBetas(glmnet, labelLambda = 0, ylab = "Coefficient",
  transformFunc = function(x) x, minBeta = 0,
  xlim = rev(range(log10(glmnet$lambda))) + c(0, -0.2), ylim = range(betas[,
  inXlim]), ...)

Arguments

glmnet

a glmet object from glmnet

labelLambda

label all variables that are not 0 at this the closest lambda <= labelLambda

ylab

label for y axis

transformFunc

a functions to adjust y-axis labels (e.g. exp to show the axis as e^beta or function(x)x^2 for 2^beta)

minBeta

the minimum absolute necessary to count beta as different from zero

xlim

minimum and maximum for limits of the x axis. Leave empty to set automatically

ylim

minimum and maximum for limits of the y axis. Leave empty to set automatically

...

additional arguments for plot

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
#example from cv.glmet
set.seed(1010)
n=1000;p=100
nzc=trunc(p/10)
x=matrix(rnorm(n*p),n,p)
beta=rnorm(nzc)
fx= x[,seq(nzc)] %*% beta
eps=rnorm(n)*5
y=drop(fx+eps)
px=exp(fx)
px=px/(1+px)
ly=rbinom(n=length(px),prob=px,size=1)
set.seed(1011)
cvob1=glmnet::cv.glmnet(x,y)
plotBetas(cvob1$glmnet.fit,cvob1$lambda.1se)

sherrillmix/glmnetPlotR documentation built on May 29, 2019, 9:24 p.m.