[R] Generate data - function
Petr Savicky
savicky at cs.cas.cz
Tue Jan 31 20:36:02 CET 2012
On Tue, Jan 31, 2012 at 01:59:13PM -0500, Val wrote:
> Hi petr,
>
> >Can the required density be understood as a piecewise
> >linear function going through 4 or 5 given points?
>
> That is my problem. The function should be nonlinear. However, we can break
> it down to the first 3 or 4 points could be linear and then nonlinear
> function. On the later points can we apply sort of spline function or local
> polynomials?
Hi.
This depends on your requirements on the shape of the function.
However, for generating numbers from the distribution, the
inverse of the distribution function is needed. If the density
is a piecewise linear function, then the distribution function
is piecewise quadratic. So, the inverse is easy to compute.
For higher degree polynomials, the inverse is harder to
compute and possibly an approximation would be better.
Consider also to specify directly the inverse distribution
function using an increasing piecewise polynomial. Generating
numbers from the distribution is then immediate and computing
the graph of the density may be obtained using the formula
for the derivative of the inverse function.
Petr.
More information about the R-help
mailing list