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,
  ...
)

Arguments

df

data frame

class_var

the name of the class variable in the data frame

y_var

the name of the dependent variable in the data frame

scale

whether or not to scale the predictors (logical, default = TRUE)

center_y

whether or not to center the response (logical, default = TRUE)

...

additional arguments to be passed on to multiclass_reg()

Value

A list with the following components

fit

fitted genlasso object

coef

matrix of estimated coefficients

lambda

vector of regularization parameters along knots of regularization path

K

number of classes

p

number of predictors per class

n

vector of sample sizes for each class

Y

composite Y vector (stacked over the classes)

X

block diagonal X matrix (each block coresponds to a class)

var_indicator

matrix of variable indicators

Examples

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)