Dear R users,

I am trying to minimize the distance between my data points and theoretical
gamma distribution over shape and scale parameters. the function "mde" from
actuar package does it for empirical distribution function and theoretical
gamma distribution. However, I would like to minimize the distance by using
only the data between 0.1 and 0.9 quantiles. I cannot use ecdf in this case
as my sample is not a whole sample. Therefore I would like to modify the
function ecdf as it gives the ecdf between 0.1 and 0.9 quantiles. I wrote

ecdf1<-

function (x)

{

    x <- sort(x)

    k<-kuantile(x,c(0.1,0.9))

    z<-x[x<=k[2]]

    z<-z[z>=k[1]]

    n <- length(x)

    if (n < 1)

        stop("'x' must have 1 or more non-missing values")

    vals <- unique(z)

    rval <- approxfun(vals, cumsum(tabulate(match(x, vals)))/n,

        method = "constant", yleft = 0.1, yright = 0.9, f = 0, ties =
"ordered")

    class(rval) <- c("ecdf", "stepfun", class(rval))

    attr(rval, "call") <- sys.call()

    rval

}**
(I also tried it with yleft = 0, yright = 1, it gave the same error)
But appearently it is wrong and it gives the error
Error in vector("integer", length) : vector size cannot be NA
(I also tried it with yleft = 0, yright = 1, it gave the same error)

I am not good at programming and I could not understand the mistake. I
checked also the approxfun and I suspect I damage something there by using z
in ecdf1, however I am not sure.

I would like to find that function and use it in "mde" instead of ecdf for
method"CvM". you can see the part I would like to modify in mde function.

....

if (measure == "CvM") {

        G <- fn

        Gn <- if (grouped)

            ogive(x)

        else ecdf(x)

        if (is.null(weights))

            weights <- 1

        Call$x <- knots(Gn)

        Call$par <- start

    }
......

 I'd appreciate if you could suggest a way to create the empirical
distribution function after the 0.1-quantile till 0.9-quantile. So as
opposed to ecdf the y-axis will be from 0.1 to 0.9 rather than 0 to 1. Or, a
way to find the minimum distance between the theoretical gamma distribution
and empirical distribution between 0.1 and 0.9 th percentiles.


Thank you in advance,

Regards,

Evrim

	[[alternative HTML version deleted]]


