# [R] fitting a curve according to a custom loss function

Liaw, Andy andy_liaw at merck.com
Thu Feb 20 03:04:03 CET 2003

```Vadim,

> Here is a toy example where such model might make sense.
> Suppose y is the
> total income of an individual over the last two years and x_1
> and x_2 are
> the taxes he paid on each of the two years. If taxes were
> linear in income
> then y ~ a*(x_1 + x_2). With a progressive tax system it is
> y ~ f(x_1) + f(x_2)
>
> Hope it makes more sense now,

Yes, that does make sense.  However, one would then expect x1 and x2 to be
quite highly correlated (and thus make what Kondrin proposed inappropriate).
Also, in this case, you don't need the coefficients a0, a1 and a2.  It was
the original form with both coefficients and f() that made me wonder whether
the model is identifiable.  It's still not clear to me whether the contraint
that both variable go through the same transformation f() was enough to make
it identifiable.

I suppose you might consider something like a nonparametric ANCOVA (analysis
of covariance).  I believe the book by Azzalini and Bowman on smoothing has
some coverage on this, as well as a paper by Bowman and Young.  (There may
be some function for fitting this kind of model in the `sm' package.)
Hopefully others with more expertise in this have something more to say.

Cheers,
Andy

>
> > -----Original Message-----
> > From: Liaw, Andy [mailto:andy_liaw at merck.com]
> > Sent: Wednesday, February 19, 2003 5:33 AM
> > > Vadim Ogranovich wrote:
> > >
> > > >Dear R-Users,
> > > >
> > > >I need to find a smooth function f() and coefficients a_i
> > > that give the best
> > > >fit to
> > > >
> > > >y ~ a_0 + a_1*f(x_1) + a_2*f(x_2)
> > > >
> >
> > The model is very strange (to me, at least).  It's not
> > obvious to me that
> > it's even identifiable.  (Sorry that I don't have anything
> > constructive to
> >
> > Andy
>
> --------------------------------------------------
> DISCLAIMER \ This e-mail, and any attachments thereto, is
> intend ... [[dropped]]
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> http://www.stat.math.ethz.ch/mailman/listinfo/r-help
>

------------------------------------------------------------------------------

```