[R] constraints again

Simon Wood snw at mcs.st-and.ac.uk
Tue Oct 22 16:29:59 CEST 2002


Since your model seems to be linear (in the paramters) you could impose
the constraint approximately using quadratic programming. i.e. fit it as a
linear model subject to linear constraints. Writing your model as
z=f(dat,AgeS)+error
the constraint is just 
df/ddat >0 
for all dat AgeS combinations. You (probably) can't do all dat/AgeS
combinations and retain linearity off the model, but instead you could
impose this constraint at each point on a mesh covering the relevant part
of the AgeS-dat plane. The key bit to recognise is that the partial of f
w.r.t. dat is just a linear transformation of the model parameters, so
that at any dat,AgeS: 
df/ddat = \sum_i c_i p_i     
for some constants c_i that you can easily obtain. Hence your constraint
is just a set of linear constraints of the form:

\sum_i c_i p_i >0

- you can easily apply constraints like this to  the least squares fitting
problem for your model. Routine pcls() in package mgcv will do this for
example, or see package quadprog. 

Simon

  ______________________________________________________________________
> Simon Wood  snw at st-and.ac.uk  http://www.ruwpa.st-and.ac.uk/simon.html
> CREEM, The Observatory, Buchanan Gardens, St Andrews, Fife KY16 9LZ UK
> Direct telephone: (0)1334 461844          Indirect fax: (0)1334 463748 


> I would like to fit the following function on my data. 
> 
>     out.nls<-nls(z ~ p1+
>  
> (p2*dat)+(p3*dat^2)+(p4*dat^3)+(p5*AgeS)+(p6*AgeS^2)+(p7*AgeS^3)+
>                     (p8*(dat*AgeS))+(p9*(dat^2*AgeS))+(p10*(dat^3*AgeS))+
>  
> (p11*(dat*AgeS^2))+(p12*(dat*AgeS^3))+(p13*(dat^2*AgeS^2))+
>                     (p14*(dat^2*AgeS^3))+(p15*(dat^3*AgeS^3)),
>  
> start=list(p1=0,p2=0,p3=0,p4=0,p5=0,p6=0,p7=0,p8=0,p9=0,p10=0,p11=0,p12=0,p1
> 3=0,p14=0,p15=0),trace=trace,
>         control=control)
> 
> which relates the z-score on a IQ subtest to Age (AgeS) and Raw Score (dat).
> Allthough the dataset is quite large, older subjects usually do not provide
> large 'raw scores', and young subjects do not provide low scores. This leads
> to incorrect fits for large raw scores for older subjects and low raw scores
> for young subjects. I would like to constrain the fit so, that the 'link'
> between raw score and z-score for all ages is monotonical. Can anybody
> direct me to an answer? 
> 
> Looking through FAQ and list, I realize that there is no 'easy way'. So
> presumably I am looking for directions...
> 
> Mark M. Span
> 
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
> -.-
> r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> Send "info", "help", or "[un]subscribe"
> (in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._.
> _._
> 
> 
> ----------------------------------------------------------------------
> If you have received this e-mail in error or wish to read our e-mail 
> disclaimer statement and monitoring policy, please refer to 
> http://www.drkw.com/disc/email/ or contact the sender.
> ----------------------------------------------------------------------
> 
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> Send "info", "help", or "[un]subscribe"
> (in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
> 

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list