View source: R/unroll.function.R
unroll.function  R Documentation 
Given a function with matrix arguments, construct an equivalent function
which takes vector arguments defined by the columns of the matrix. The new
function simply uses cbind
on the vector arguments to make a matrix,
and calls the old one.
unroll.function(mat.fn, ...)
mat.fn 
A function with any number of arguments, some of which are matrices. 
... 
A series of other arguments. Their names define which
arguments of
will make a new function Calling
should give the same answer as

The new function, with vector arguments.
This is used by flexsurvspline
to allow spline models, which
have an arbitrary number of parameters, to be fitted using
flexsurvreg
.
The “custom distributions” facility of flexsurvreg
expects the usersupplied probability density and distribution
functions to have one explicitly named argument for each scalar
parameter, and given R vectorisation, each of those arguments
could be supplied as a vector of alternative parameter values.
However, spline models have a varying number of scalar parameters,
determined by the number of knots in the spline.
dsurvspline
and psurvspline
have an
argument called gamma
. This can be supplied as a matrix,
with number of columns n
determined by the number of knots
(plus 2), and rows referring to alternative parameter values. The
following statements are used in the source of
flexsurvspline
:
dfn < unroll.function(dsurvspline, gamma=0:(nk1)) pfn < unroll.function(psurvspline, gamma=0:(nk1))
to convert these into functions with arguments gamma0
,
gamma1
,...,gamman
, corresponding to the columns
of gamma
, where n = nk1
, and with other arguments
in the same format.
Christopher Jackson <chris.jackson@mrcbsu.cam.ac.uk>
flexsurvspline
,flexsurvreg
fn < unroll.function(ncol, x=1:3)
fn(1:3, 1:3, 1:3) # equivalent to...
ncol(cbind(1:3,1:3,1:3))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.