Learn R Programming

spareg (version 1.1.1)

constructor_sparmodel: Constructor Function for Building 'sparmodel' Object

Description

The created function will return a object of class 'sparmodel' which constitutes of a list.

Usage

constructor_sparmodel(name, model_fun, update_fun = NULL)

Value

a function which in turn creates an object of class 'sparmodel'.

Arguments

name

character

model_fun

function for estimating the marginal models which returns the function should have arguments and y (vector of responses -- standardized for Gaussian family), z (the matrix of projected predictors) and a 'sparmodel' object.

update_fun

optional function for updating the 'sparmodel' object before the start of the algorithm.

Details

Creates an object of class 'sparmodel' using arguments passed by user.

Examples

Run this code
model_glmrob <- function(y, z, object) {
  requireNamespace("robustbase")
  fam <- object$control$family
  glmrob_res <- do.call(function(...)
    robustbase::glmrob(y ~ as.matrix(z), ...),
    object$control)
  intercept <- coef(glmrob_res)[1]
  gammas <- coef(glmrob_res)[-1]
  list(gammas = gammas, intercept = intercept)
}
spar_glmrob <- constructor_sparmodel(name = "glmrob",
  model_fun = model_glmrob)
example_data <- simulate_spareg_data(n = 100, p = 400, ntest = 100)
spar_res <- spar(example_data$x, example_data$y, xval = example_data$xtest,
  yval = example_data$ytest,
  model = spar_glmrob())
spar_res

Run the code above in your browser using DataLab