Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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