Buried within the glmnet documentation is your answer (type ?predict.glmnet
within R):
Note that for ‘"binomial"’ models, results are returned only for the class corresponding to the second level of the factor response.
If the binary data you described was assigned to y
as a simple numeric vector, then the model will produce a P(y=1) fit.
> x <- matrix(rnorm(100*20),100,20) # create some sample input
> y <- as.factor(sample(0:1, 100, replace=TRUE))
> levels(y)
[1] "0" "1"
> py1_fit <- glmnet(x, y, family="binomial")
To invert and fit against P(y=0) instead, you just have to reorder the levels:
> y0 <- factor(y, levels=rev(levels(y)))
> levels(y0)
[1] "1" "0"
> py0_fit <- glmnet(x, y0, family="binomial")