Skip to content

Instantly share code, notes, and snippets.

@czxttkl
Created March 6, 2015 04:26
Show Gist options
  • Save czxttkl/9fa12ddec5404f0098ab to your computer and use it in GitHub Desktop.
Save czxttkl/9fa12ddec5404f0098ab to your computer and use it in GitHub Desktop.
remove(list=ls())
library(LiblineaR)
library(glmpath)
set.seed(1)
x1 <- rnorm(100, mean = 100, sd=10)
x2 <- rnorm(100, sd=19)
x3 <- -1*(5*x1 - 75*x2)
x4 <- -17*x1 + 2*x2 + 17*x3
x5 <- -1*(30*x1 + 13*x3 - 15*x4)
x7 <- rnorm(100, mean = 150, sd = 10)
x8 <- rnorm(100, mean = 200, sd=10)
y <- 10*x1 + 50*x2 + 30*x7 - 30*x8
# beta0 = -mean(y)
y <- y - mean(y)
x1 <- as.numeric(scale(x1, center = TRUE, scale = TRUE))
x2 <- as.numeric(scale(x2, center = TRUE, scale = TRUE))
x3 <- as.numeric(scale(x3, center = TRUE, scale = TRUE))
x4 <- as.numeric(scale(x4, center = TRUE, scale = TRUE))
x5 <- as.numeric(scale(x5, center = TRUE, scale = TRUE))
x7 <- as.numeric(scale(x7, center = TRUE, scale = TRUE))
x8 <- as.numeric(scale(x8, center = TRUE, scale = TRUE))
x <- model.matrix(y ~ x1 + x2 + x3 + x4 + x5 + x7 + x8)[ , -1 ]
y[y < 0] <- 0
y[y > 0] <- 1
fit <- glmpath(x, y, family = binomial)
plot(fit, xvar = "lambda")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment