[R] Fitting generalized additive models with constraints?

Simon Wood s.wood at bath.ac.uk
Tue Sep 5 11:57:07 CEST 2006


> I am trying to fit a GAM for a simple model, a simple model, y ~ s(x0) +
> s(x1) ; with a constraint that the fitted smooth functions s(x0) and s(x1)
> have to each always be >0.
>
> >From the library documentation and a search of the R-site and R-help
>
> archives I have not been able to decipher whether the following is possible
> using this, or other GAM libraries, or whether I will have to try to "roll
> my own". I see from the mgcv docs that GAMs need to be constrained such
> that the smooth functions have zero mean. Is there a way around this?
>
> Is such a constraint possible?
It is possible to estimate a GAM subject to this constraint, but be aware that 
the mean levels of your component smooths are not identifiable, so there is 
an unavoidable abitrariness in the estimate....

You have to have some sort of constraint on the smooths in a GAM to ensure 
identifiability, and a convenient way to set the model up is to write it as 
e.g.

E(y) = a + f0(x0) + f1(x1)

where `a' is the intercept and f0 and f1 are smooth functions which sum to 
zero over their respective covariate values. In this parameterization your 
constraint implies that 

a + f0(x0) + f1(x1)  > 0

for all x0, x1. If this constraint is met then you can find constants b and c 
such that b+c=a such that f0(x0)+b>0 and f1(x1)+c>0 for all x0,x1. i.e. you 
redefine f0 as f0+b and f1 as f1+c, and you have a fitted model meeting the 
constraints.

To fit the GAM subject to the constraints you can use mgcv:::pcls... ?pcls has 
some examples, but it does involve moderately low level programming. It's 
hard to impose the constraint exactly, so the usual approach would be to 
impose the constraint over a fairly fine grid of x0, x1 values. Also, you'll 
need to figure out how to select smoothing parameters. For many problems it 
suffices to estimate smoothing parameters on the unconstrained fit, and then 
use these to fit subject to constraints, but it depends on the problem.... 

Hope that's some use.

Simon

> thanks very much for any advice or pointers.
> -David
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html and provide commented, minimal,
> self-contained, reproducible code.

-- 
> Simon Wood, Mathematical Sciences, University of Bath, Bath, BA2 7AY UK
> +44 1225 386603  www.maths.bath.ac.uk/~sw283



More information about the R-help mailing list