Dear R users, I have to fit the non linear regression: y~1-exp(-(k0+k1*p1+k2*p2+ .... +kn*pn)) where ki>=0 for each i in [1 .... n] and pi are on R+. I am using, at the moment, nls, but I would rather use a Maximum Likelhood based algorithm. The error is not necessarily normally distributed. y is approximately beta distributed, and the volume of data is medium to large (the y,pi may have ~ 40,000 elements). I have studied the packages in the task views Optimisation and Robust Statistical Methods, but I did look like what I was looking for was there. Maybe I am wrong. The nearest thing was nlrob, but even that does not allow for constraints, as far as I can understand. Any suggestion? Regards -- Corrado Topi PhD Researcher Global Climate Change and Biodiversity Area 18,Department of Biology University of York, York, YO10 5YW, UK Phone: + 44 (0) 1904 328645, E-mail: ct529 at york.ac.uk
I have an algorithm that can perform nonlinear optimization, with linear/nonlinear, equality and/or inequality constraints. From your description, it seems like this algorithm would work for your problem. Contact me if you are interested and I will send you the code. Ravi. -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Corrado Sent: Tuesday, March 16, 2010 2:59 PM To: r-help at r-project.org Subject: [R] Constrained non linear regression using ML Dear R users, I have to fit the non linear regression: y~1-exp(-(k0+k1*p1+k2*p2+ .... +kn*pn)) where ki>=0 for each i in [1 .... n] and pi are on R+. I am using, at the moment, nls, but I would rather use a Maximum Likelhood based algorithm. The error is not necessarily normally distributed. y is approximately beta distributed, and the volume of data is medium to large (the y,pi may have ~ 40,000 elements). I have studied the packages in the task views Optimisation and Robust Statistical Methods, but I did look like what I was looking for was there. Maybe I am wrong. The nearest thing was nlrob, but even that does not allow for constraints, as far as I can understand. Any suggestion? Regards -- Corrado Topi PhD Researcher Global Climate Change and Biodiversity Area 18,Department of Biology University of York, York, YO10 5YW, UK Phone: + 44 (0) 1904 328645, E-mail: ct529 at york.ac.uk ______________________________________________ R-help at r-project.org 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.
Check out the betareg package. On Tue, Mar 16, 2010 at 2:58 PM, Corrado <ct529 at york.ac.uk> wrote:> Dear R users, > > I have to fit the non linear regression: > > y~1-exp(-(k0+k1*p1+k2*p2+ .... +kn*pn)) > > where ki>=0 for each i in [1 .... n] and pi are on R+. > > I am using, at the moment, nls, but I would rather use a Maximum Likelhood > based algorithm. The error is not necessarily normally distributed. > > y is approximately beta distributed, and the volume of data is medium to > large (the y,pi may have ~ 40,000 elements). > > I have studied the packages in the task views Optimisation and Robust > Statistical Methods, but I did look like what I was looking for was there. > Maybe I am wrong. > > The nearest thing was nlrob, but even that does not allow for constraints, > as far as I can understand. > > Any suggestion? > > Regards > > -- > Corrado Topi > PhD Researcher > Global Climate Change and Biodiversity > Area 18,Department of Biology > University of York, York, YO10 5YW, UK > Phone: + 44 (0) 1904 328645, E-mail: ct529 at york.ac.uk > > ______________________________________________ > R-help at r-project.org 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. >
Dear Gabor, dear R users, I had already read the betareg documentation. As far as I can understand from the help, it does not allow for constrained regression. Regards Gabor Grothendieck wrote:> Check out the betareg package. > > On Tue, Mar 16, 2010 at 2:58 PM, Corrado <ct529 at york.ac.uk> wrote: > >> Dear R users, >> >> I have to fit the non linear regression: >> >> y~1-exp(-(k0+k1*p1+k2*p2+ .... +kn*pn)) >> >> where ki>=0 for each i in [1 .... n] and pi are on R+. >> >> I am using, at the moment, nls, but I would rather use a Maximum Likelhood >> based algorithm. The error is not necessarily normally distributed. >> >> y is approximately beta distributed, and the volume of data is medium to >> large (the y,pi may have ~ 40,000 elements). >> >> I have studied the packages in the task views Optimisation and Robust >> Statistical Methods, but I did look like what I was looking for was there. >> Maybe I am wrong. >> >> The nearest thing was nlrob, but even that does not allow for constraints, >> as far as I can understand. >> >> Any suggestion? >> >> Regards >> >> -- >> Corrado Topi >> PhD Researcher >> Global Climate Change and Biodiversity >> Area 18,Department of Biology >> University of York, York, YO10 5YW, UK >> Phone: + 44 (0) 1904 328645, E-mail: ct529 at york.ac.uk >> >> ______________________________________________ >> R-help at r-project.org 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. >> >>-- Corrado Topi PhD Researcher Global Climate Change and Biodiversity Area 18,Department of Biology University of York, York, YO10 5YW, UK Phone: + 44 (0) 1904 328645, E-mail: ct529 at york.ac.uk
Try it anyways -- maybe none of your constraints are active. On Wed, Mar 17, 2010 at 6:01 AM, Corrado <ct529 at york.ac.uk> wrote:> Dear Gabor, dear R users, > > I had already read the betareg documentation. As far as I can understand > from the help, it does not allow for constrained regression. > > Regards > > > Gabor Grothendieck wrote: >> >> Check out the betareg package. >> >> On Tue, Mar 16, 2010 at 2:58 PM, Corrado <ct529 at york.ac.uk> wrote: >> >>> >>> Dear R users, >>> >>> I have to fit the non linear regression: >>> >>> y~1-exp(-(k0+k1*p1+k2*p2+ .... +kn*pn)) >>> >>> where ki>=0 for each i in [1 .... n] and pi are on R+. >>> >>> I am using, at the moment, nls, but I would rather use a Maximum >>> Likelhood >>> based algorithm. The error is not necessarily normally distributed. >>> >>> y is approximately beta distributed, and the volume of data is medium to >>> large (the y,pi may have ~ 40,000 elements). >>> >>> I have studied the packages in the task views Optimisation and Robust >>> Statistical Methods, but I did look like what I was looking for was >>> there. >>> Maybe I am wrong. >>> >>> The nearest thing was nlrob, but even that does not allow for >>> constraints, >>> as far as I can understand. >>> >>> Any suggestion? >>> >>> Regards >>> >>> -- >>> Corrado Topi >>> PhD Researcher >>> Global Climate Change and Biodiversity >>> Area 18,Department of Biology >>> University of York, York, YO10 5YW, UK >>> Phone: + 44 (0) 1904 328645, E-mail: ct529 at york.ac.uk >>> >>> ______________________________________________ >>> R-help at r-project.org 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. >>> >>> > > > -- > Corrado Topi > PhD Researcher > Global Climate Change and Biodiversity > Area 18,Department of Biology > University of York, York, YO10 5YW, UK > Phone: + 44 (0) 1904 328645, E-mail: ct529 at york.ac.uk > >
For specific questions on the betareg package contact the maintainer. If the likelihood based approaches are giving too much difficulty try moving to a Bayesian framework (WinBUGS/R2WinBUGS, JAGS/r2jags, etc.) On Wed, Mar 17, 2010 at 10:03 AM, Corrado <ct529 at york.ac.uk> wrote:> Dear Arne, Gabor, > > I solved the problem with betareg (downloaded the package). I run it on my > data, and unfortunately the ?constraint is definitively active, if I remove > the active variables, I then remove the most significant variables! > > Of course the error is important, not the distribution of the variable. > > In this case, one of the assumptions is that the error may be distributed ~ > beta. I think that betareg makes this assumption, am I right? > > I am finding it difficult to solve two problems: > > 1) write the maximum likelihood function (what do you suggest?) > 2) deal with the fact that a few factors actually have values of y (the > response) at the extremes: that is 0 and 1. But that mean that the link > function returns Infinite values in that case .... > 3) the error is dependent on E(y). > > PS: Additional silly question: what is the discrete equivalent of beta? > binomial? > > Arne Henningsen wrote: >> >> On 17 March 2010 14:22, Gabor Grothendieck <ggrothendieck at gmail.com> >> wrote: >> >>> >>> Contact the maintainer regarding problems with the package. ?Not sure >>> if this is acceptable but if you get it to run you could consider just >>> dropping the variables from your model that correspond to active >>> constraints. >>> >>> Also try the maxLik package. ?You will have to define the likelihood >>> yourself but it does support constraints. >>> >> >> Yes. And specifying the likelihood function is probably (depending on >> your distributional assumptions) not too complicated. >> >> BTW: Even if your y follows a beta distribution, it does not mean that >> your error term also follows a beta distribution. And it the >> distribution of the error term which is crucial for specifying the >> likelihood function. >> >> /Arne >> > > -- > > Corrado Topi > PhD Researcher > Global Climate Change and Biodiversity > Area 18,Department of Biology > University of York, York, YO10 5YW, UK > Phone: + 44 (0) 1904 328645, E-mail: ct529 at york.ac.uk > >