Skip to content

Instantly share code, notes, and snippets.

@emraher
Created October 26, 2017 22:31
Show Gist options
  • Save emraher/5d4c820cce2da1396655bfe39df58914 to your computer and use it in GitHub Desktop.
Save emraher/5d4c820cce2da1396655bfe39df58914 to your computer and use it in GitHub Desktop.
hdm example
set.seed(pi)
n <- 1000 #sample size
p <- 1000 # number of variables
s <- 30 # nubmer of non-zero variables
X <- matrix(rnorm(n * p), ncol = p)
colnames(X) <- paste("X", 1:p, sep = "")
beta <- c(rep(3, s), rep(0, p - s))
y <- 1 + X %*% beta + rnorm(n)
data <- data.frame(cbind(y, X))
colnames(data)[1] <- "y"
fm <- paste("y ~ ", paste(colnames(X), collapse = " + "))
fm <- as.formula(fm)
lasso.effect <- rlassoEffect(X[, -1], y, X[, 1], method = "double selection")
lasso.effect <- rlassoEffect(subset(X, select = -c(X1)), y, X[, "X1"], method = "double selection")
lasso.effects <- rlassoEffects(X, y, index = c(1), method = "double selection")
lasso.effects <- rlassoEffects(X, y, index = "X1", method = "double selection")
lasso.effects.f <- rlassoEffects(fm, I = ~ X1, data = data, method = "double selection")
print(lasso.effect)
print(lasso.effects)
print(lasso.effects.f)
lasso.effect$coefficients.reg
lasso.effects$coef.mat
lasso.effects.f$coef.mat
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment