I'd like to use R to fit a cdf to a set of data points of the form ${ (x_i, y_i) }_{i=1}^N$, where the cdf is taken from a parametric family. (For the sake of illustration, imagine, say, the Beta family of cdfs.)
Ordinarily when fitting a distribution parametrically, one would perhaps use MLE. However, instead of choosing the parameters of the distribution family such that the (log-)likelihood is maximized, I would like to choose them such that a different, arbitrary (non-standard) loss function is minimized.
My overall loss function is still additively separable in that it has the form $\mathcal L = \sum_{i=1}^N \ell(y_i, \hat y_i)$, where $\ell$ measures loss for each observation and where $\hat y_i = F(x_i; \hat{\mathbf\theta})$ is the fitted value obtained from fitting the parametric cdf (with parameter vector $\mathbf\theta$).
Some googling suggests that this is basically M-estimation. So my question is, how do I do this in R? The function $\ell$ can be implemented, but I'm unsure as to how to proceed from there. Are there any packages for this, or should I, for a given parametric family $F(\cdot, \mathbf\theta)$, simply plug $F$ into $\ell$ and use optim()
or an alternative (which?) to choose the parameters $\mathbf\theta$ minimizing overall loss?
Thank you!
Edit: I forgot to mention I found this function, but it doesn't allow for arbitrary loss functions.
Side note: it seems that SO, unlike other SX sites, does not support embedded TeX for math. Apologies; I could edit this post, but I feel it's actually easier to mentally parse the TeX commands than to try to recreate the formulas poorly using Markdown.