A wrapperfunction that works with data frames, created to not ruin existing code that works directly with the multiclass_reg() function.
mc_reg(
df,
class_var = "class",
y_var = "y",
scale = TRUE,
center_y = TRUE,
lambdas = NULL,
...
)
data frame
the name of the class variable in the data frame
the name of the dependent variable in the data frame
whether or not to scale the predictors (logical, default = TRUE)
whether or not to center the response (logical, default = TRUE)
additional arguments to be passed on to multiclass_reg()
A list with the following components
fitted genlasso
object
matrix of estimated coefficients
vector of regularization parameters along knots of regularization path
number of classes
number of predictors per class
vector of sample sizes for each class
composite Y vector (stacked over the classes)
block diagonal X matrix (each block coresponds to a class)
matrix of variable indicators
p = 7
k = 2
n = 20
beta = c(1,2)
set.seed(1)
X = list(matrix(rnorm(p*n), ncol = p), matrix(rnorm(p*n), ncol = p))
Y = list(rnorm(n), rnorm(n))
df = lists_to_data(Y, X)
Xk <- mvtnorm::rmvnorm(n*2, mean=1:p, sigma=diag(1:p)) %>% round(2)
yk <- Xk %*% c(0,0,4,0,0,8,0) + rnorm(n*2) + rep(c(0,10), each = n) %>% round(2)
df = data.frame(y = yk, Xk, class = rep(c("A", "B"), each = n))
# force a missing predictor
df$X1[df$class == "A"] = NA
df$X7[df$class == "B"] = NA
mc = mc_reg(df)