mkM2U: Makes a Smooth Function Mapping a Data Frame Variable Onto a...

Description Usage Arguments Details Value Note Author(s) See Also Examples

View source: R/variableTransformation.R

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

1
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.

Author(s)

Christophe Pouzat [email protected]

See Also

ssden, dssden, integrate, uniroot, mkGLMdf

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
## Not run: 
require(STAR)
data(e060824spont)
DFA <- subset(mkGLMdf(e060824spont,0.004,0,59),neuron==1)
DFA <- within(DFA,i1 <- isi(DFA,lag=1))
DFA <- DFA[complete.cases(DFA),]
m2u1 <- mkM2U(DFA,"lN.1",0,29)
m2ui <- mkM2U(DFA,"i1",0,29,maxiter=200)
DFA <- within(DFA,e1t <- m2u1(lN.1))
DFA <- within(DFA,i1t <- m2ui(i1))
with(DFA,plot(ecdf(e1t[time>29]),pch="."))
abline(a=0,b=1,col=2,lty=2)
with(DFA,plot(ecdf(i1t[time>29]),pch="."))
abline(a=0,b=1,col=2,lty=2)
## End(Not run)

STAR documentation built on May 30, 2017, 3:06 a.m.