R: Makes a Smooth Function Mapping a Data Frame Variable Onto a...
mkM2U
R Documentation
Makes a Smooth Function Mapping a Data Frame Variable Onto a Variable
Uniform on Its Definition Domain
Description
The smooth transformation function is a smooth version of the
ecdf. A smooth density estimate as well as the inverse
transformation (the quantile function) are also returned as attributes.
Usage
mkM2U(df, vN, low, high, delta, alpha=2, ...)
Arguments
df
a data frame. This data frame should contain a variable
time like data frames returned by mkGLMdf.
vN
a character string corresponding to the name of one of the
variables of df or an integer, its index. Variable vN is
the one for which the mapping to uniform is looked for.
low
a numeric, the smallest value of variable time from
which the transformation is looked for. If missing defaults to the
smallest time.
high
a numeric, the largest value of variable time up to
which the transformation is looked for. If missing defaults to the
largest time.
delta
a numeric, the bin width used to build the variable
values histogram. This histogram is subsequently smoothed. Default
provided if missing.
alpha
see ssden.
...
additional arguments passed to ssden called
internally by the function
Details
The smooth mapping to uniform function returned by mkM2U is
obtained by first selecting a subset of the variable values for which
the variable time of df is between low and
high. The values are then binned between the min and the
max of the (complete) variable values with a bin width
delta. Function ssden is then called on the
histogram and the result is stored in object ii.fit (This
object is stored in the closure of the returned function). The returned
function is the result of a call of pssden on
ii.fit and the argument.
A function inverting the "mapping to uniform function", that is, a
quantile function, is also returned as attributes
qFct. This
inverse function is obtained by numerical inversion, calling
uniroot internally. Additional arguments can be passed
to uniroot via the ... argument of the function.
A function returning the smooth density estimate is returned as
attributes dFct.
Value
A function returning the probability for vN random variable to
have a value smaller or equal to its first argument. The returned
function calls internally integrate. Additional
arguments can be passed to the latter via the ... argument of the
returned function.
As explained in the details section, the returned function has
the smooth density function, dFct, as well as the inverse
function, qFct, as attributes. Attribute call contains
the matched call and range contains the full range of the
mapped variable.
Note
Since the density returned by dssden can sometime
integrate to a value slightly different from 1 on its definition
domain, the actual integral is evaluated with integrate
and the returned density is renormalised. A look-up table of 101
regularly spaced quantiles and the corresponding probabilities is also
created and stored in the returned function closure. This look-up
table is used to speed up the computations performed by the returned
function which uses integrate and not
pssden. It is also used to speed up the
computations of the inverse function (returned as attribute
qFct) which uses uniroot and not
qssden.