Learn R Programming

AMIAS (version 1.1.0)

coef.amias: Extract cefficients from a amias or samias object

Description

This function extracts coefficients from a amias or samias object.

Usage

# S3 method for amias
coef(object, type=c("coef","primal", "dual", "active"), ...)
# S3 method for samias
coef(object, type = c("coef","primal", "dual", "active"), k, ...)

Arguments

object

A list with class attribute 'amias' or 'samias'.

type

A character string, one of "coef", "primal", "dual", or "active", indicating whether generalized \(l_0\) coefficients, primal coefficients, dual coefficients, or active sets, should be returned. Default is "coef", which corresponds to the solution of the original generalized \(l_0\) problem.

k

An integer vector of numbers of knots at which coefficients should be calculated. The user can choose to a subset of index from \(1,2,\dots, kmax\); none are specified, then it returns the optimal coefficient determined by miniming the BIC value.

...

additional arguments passed to coef.

Value

Returns a list with the following components:

alpha

If the type is "coef", a matrix containing the generalized \(l_0\) coefficients, each column corresponding to a value of k.

v

If the type is "primal", a matrix containing the primal variables, each column corresponding to a value of k.

u

If the type is "dual", a matrix containing the dual variables, each column corresponding to a value of k.

A

If the type is "active", a list containing the active sets, each sublist corresponding to a value of k.

k

An integer that specifies the optimal k or an integer vector containing the sequence of k values corresponding to the columns of beta, v, and u.

See Also

amias, samias.

Examples

Run this code
# NOT RUN {
  ##----- A toy example -------
  set.seed(0)
  n <- 100
  x = seq(1/n, 1,length.out = n)
  y0 = 0*x; y0[x>0.5] = 1
  y = y0 + rnorm(n, sd = 0.1)
  
  
  # For 'amias' object
  fit <- amias(y, k = 1) 
  coef(fit)                # extract the fitting coefficients
  coef(fit, type="active") # extract the detected knots
  
  # For 'samias' object
  fit <- samias(y, kmax = 6)
  coef(fit)                         # get the coefficients with the minimum BIC value
  coef(fit, k = 3:5)                # get the coefficients that number of knots being 3, 4, and 5 
  
  coef(fit, type="active")          # get the active set with minimum BIC value
  coef(fit, type="active", k = 3:5) # get the active sets that number of knots being 3, 4, and 5 
# }

Run the code above in your browser using DataLab