Re: [R] Non-linear regression/Quantile regression
The coefficients are different but the predictions are the same. On Tue, Jun 9, 2009 at 12:41 PM, Greg Snow wrote: > poly by default uses orthogonal polynomials which work better mathematically > but are harder to interpret. See ?poly > > -- > Gregory (Greg) L. Snow Ph.D. > Statistical Data Center > Intermountain Healthcare > greg.s...@imail.org > 801.408.8111 > > >> -Original Message- >> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- >> project.org] On Behalf Of despaired >> Sent: Tuesday, June 09, 2009 9:59 AM >> To: r-help@r-project.org >> Subject: Re: [R] Non-linear regression/Quantile regression >> >> >> Hi, >> >> thanks, it works :-) >> But where is the difference between demand ~ Time + I(Time^2) and >> demand ~ >> poly(Time, 2) ? >> Or: How do I have to interpret the results? (I get different results >> for the >> two methods) >> >> Thank you again! >> >> >> Gabor Grothendieck wrote: >> > >> > Those are linear in the coefficients so try these: >> > >> > library(quantreg) >> > >> > rq1 <- rq(demand ~ Time + I(Time^2), data = BOD, tau= 1:3/4); rq1 >> > >> > # or >> > rq2 <- rq(demand ~ poly(Time, 2), data = BOD, tau = 1:3/4); rq2 >> > >> > >> > On Tue, Jun 9, 2009 at 10:55 AM, despaired >> wrote: >> >> >> >> Hi, >> >> >> >> I'm relatively new to R and need to do a quantile regression. Linear >> >> quantile regression works, but for my data I need some quadratic >> >> function. >> >> So I guess, I have to use a nonlinear quantile regression. I tried >> the >> >> example on the help page for nlrq with my data and it worked. But >> the >> >> example there was with a SSlogis model. Trying to write >> >> >> >> dat.nlrq <- nlrq(BM ~ I(Regen100^2), data=dat, tau=0.25, trace=TRUE) >> >> >> >> or >> >> >> >> dat.nlrq <- nlrq(BM ~ poly(Regen100^2), data=dat, tau=0.25, >> trace=TRUE) >> >> >> >> (I don't know the difference) both gave me the following error >> message: >> >> >> >> error in getInitial.default(func, data, mCall = >> as.list(match.call(func, >> >> : >> >> no 'getInitial' method found for "function" objects >> >> >> >> Looking in getInitial, it must have to do something with the >> starting >> >> parameters or selfStart model. But I have no idea, what this is and >> how I >> >> handle this problem. Can anyone please help? >> >> >> >> Thanks a lot in advance! >> >> -- >> >> View this message in context: >> >> http://www.nabble.com/Non-linear-regression-Quantile-regression- >> tp23944530p23944530.html >> >> Sent from the R help mailing list archive at Nabble.com. >> >> >> >> __ >> >> R-help@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. >> >> >> > >> > __ >> > R-help@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. >> > >> > >> >> -- >> View this message in context: http://www.nabble.com/Non-linear- >> regression-Quantile-regression-tp23944530p23945900.html >> Sent from the R help mailing list archive at Nabble.com. >> >> __ >> R-help@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. > __ > R-help@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. > __ R-help@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.
Re: [R] Non-linear regression/Quantile regression
poly by default uses orthogonal polynomials which work better mathematically but are harder to interpret. See ?poly -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.s...@imail.org 801.408.8111 > -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- > project.org] On Behalf Of despaired > Sent: Tuesday, June 09, 2009 9:59 AM > To: r-help@r-project.org > Subject: Re: [R] Non-linear regression/Quantile regression > > > Hi, > > thanks, it works :-) > But where is the difference between demand ~ Time + I(Time^2) and > demand ~ > poly(Time, 2) ? > Or: How do I have to interpret the results? (I get different results > for the > two methods) > > Thank you again! > > > Gabor Grothendieck wrote: > > > > Those are linear in the coefficients so try these: > > > > library(quantreg) > > > > rq1 <- rq(demand ~ Time + I(Time^2), data = BOD, tau= 1:3/4); rq1 > > > > # or > > rq2 <- rq(demand ~ poly(Time, 2), data = BOD, tau = 1:3/4); rq2 > > > > > > On Tue, Jun 9, 2009 at 10:55 AM, despaired > wrote: > >> > >> Hi, > >> > >> I'm relatively new to R and need to do a quantile regression. Linear > >> quantile regression works, but for my data I need some quadratic > >> function. > >> So I guess, I have to use a nonlinear quantile regression. I tried > the > >> example on the help page for nlrq with my data and it worked. But > the > >> example there was with a SSlogis model. Trying to write > >> > >> dat.nlrq <- nlrq(BM ~ I(Regen100^2), data=dat, tau=0.25, trace=TRUE) > >> > >> or > >> > >> dat.nlrq <- nlrq(BM ~ poly(Regen100^2), data=dat, tau=0.25, > trace=TRUE) > >> > >> (I don't know the difference) both gave me the following error > message: > >> > >> error in getInitial.default(func, data, mCall = > as.list(match.call(func, > >> : > >> no 'getInitial' method found for "function" objects > >> > >> Looking in getInitial, it must have to do something with the > starting > >> parameters or selfStart model. But I have no idea, what this is and > how I > >> handle this problem. Can anyone please help? > >> > >> Thanks a lot in advance! > >> -- > >> View this message in context: > >> http://www.nabble.com/Non-linear-regression-Quantile-regression- > tp23944530p23944530.html > >> Sent from the R help mailing list archive at Nabble.com. > >> > >> __ > >> R-help@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. > >> > > > > __ > > R-help@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. > > > > > > -- > View this message in context: http://www.nabble.com/Non-linear- > regression-Quantile-regression-tp23944530p23945900.html > Sent from the R help mailing list archive at Nabble.com. > > __ > R-help@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. __ R-help@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.
Re: [R] Non-linear regression/Quantile regression
Try `poly(Time, 2, raw=TRUE)' Here is an example: Time <- runif(100) demand <- 1 + 0.5 * Time - 1.2 * Time^2 + rt(100, df=4) rq1 <- rq(demand ~ Time + I(Time^2), tau = 1:3/4) rq2 <- rq(demand ~ poly(Time, 2, raw=TRUE), tau = 1:3/4) all.equal(c(rq1$coef), c(rq2$coef)) Ravi. --- Ravi Varadhan, Ph.D. Assistant Professor, The Center on Aging and Health Division of Geriatric Medicine and Gerontology Johns Hopkins University Ph: (410) 502-2619 Fax: (410) 614-9625 Email: rvarad...@jhmi.edu Webpage: http://www.jhsph.edu/agingandhealth/People/Faculty_personal_pages/Varadhan.h tml -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of despaired Sent: Tuesday, June 09, 2009 11:59 AM To: r-help@r-project.org Subject: Re: [R] Non-linear regression/Quantile regression Hi, thanks, it works :-) But where is the difference between demand ~ Time + I(Time^2) and demand ~ poly(Time, 2) ? Or: How do I have to interpret the results? (I get different results for the two methods) Thank you again! Gabor Grothendieck wrote: > > Those are linear in the coefficients so try these: > > library(quantreg) > > rq1 <- rq(demand ~ Time + I(Time^2), data = BOD, tau= 1:3/4); rq1 > > # or > rq2 <- rq(demand ~ poly(Time, 2), data = BOD, tau = 1:3/4); rq2 > > > On Tue, Jun 9, 2009 at 10:55 AM, despaired wrote: >> >> Hi, >> >> I'm relatively new to R and need to do a quantile regression. Linear >> quantile regression works, but for my data I need some quadratic >> function. >> So I guess, I have to use a nonlinear quantile regression. I tried >> the example on the help page for nlrq with my data and it worked. But >> the example there was with a SSlogis model. Trying to write >> >> dat.nlrq <- nlrq(BM ~ I(Regen100^2), data=dat, tau=0.25, trace=TRUE) >> >> or >> >> dat.nlrq <- nlrq(BM ~ poly(Regen100^2), data=dat, tau=0.25, >> trace=TRUE) >> >> (I don't know the difference) both gave me the following error message: >> >> error in getInitial.default(func, data, mCall = >> as.list(match.call(func, >> : >> no 'getInitial' method found for "function" objects >> >> Looking in getInitial, it must have to do something with the starting >> parameters or selfStart model. But I have no idea, what this is and >> how I handle this problem. Can anyone please help? >> >> Thanks a lot in advance! >> -- >> View this message in context: >> http://www.nabble.com/Non-linear-regression-Quantile-regression-tp239 >> 44530p23944530.html Sent from the R help mailing list archive at >> Nabble.com. >> >> __ >> R-help@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. >> > > __ > R-help@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. > > -- View this message in context: http://www.nabble.com/Non-linear-regression-Quantile-regression-tp23944530p2 3945900.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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. __ R-help@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.
Re: [R] Non-linear regression/Quantile regression
Hi, thanks, it works :-) But where is the difference between demand ~ Time + I(Time^2) and demand ~ poly(Time, 2) ? Or: How do I have to interpret the results? (I get different results for the two methods) Thank you again! Gabor Grothendieck wrote: > > Those are linear in the coefficients so try these: > > library(quantreg) > > rq1 <- rq(demand ~ Time + I(Time^2), data = BOD, tau= 1:3/4); rq1 > > # or > rq2 <- rq(demand ~ poly(Time, 2), data = BOD, tau = 1:3/4); rq2 > > > On Tue, Jun 9, 2009 at 10:55 AM, despaired wrote: >> >> Hi, >> >> I'm relatively new to R and need to do a quantile regression. Linear >> quantile regression works, but for my data I need some quadratic >> function. >> So I guess, I have to use a nonlinear quantile regression. I tried the >> example on the help page for nlrq with my data and it worked. But the >> example there was with a SSlogis model. Trying to write >> >> dat.nlrq <- nlrq(BM ~ I(Regen100^2), data=dat, tau=0.25, trace=TRUE) >> >> or >> >> dat.nlrq <- nlrq(BM ~ poly(Regen100^2), data=dat, tau=0.25, trace=TRUE) >> >> (I don't know the difference) both gave me the following error message: >> >> error in getInitial.default(func, data, mCall = as.list(match.call(func, >> : >> no 'getInitial' method found for "function" objects >> >> Looking in getInitial, it must have to do something with the starting >> parameters or selfStart model. But I have no idea, what this is and how I >> handle this problem. Can anyone please help? >> >> Thanks a lot in advance! >> -- >> View this message in context: >> http://www.nabble.com/Non-linear-regression-Quantile-regression-tp23944530p23944530.html >> Sent from the R help mailing list archive at Nabble.com. >> >> __ >> R-help@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. >> > > __ > R-help@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. > > -- View this message in context: http://www.nabble.com/Non-linear-regression-Quantile-regression-tp23944530p23945900.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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.
Re: [R] Non-linear regression/Quantile regression
Those are linear in the coefficients so try these: library(quantreg) rq1 <- rq(demand ~ Time + I(Time^2), data = BOD, tau= 1:3/4); rq1 # or rq2 <- rq(demand ~ poly(Time, 2), data = BOD, tau = 1:3/4); rq2 On Tue, Jun 9, 2009 at 10:55 AM, despaired wrote: > > Hi, > > I'm relatively new to R and need to do a quantile regression. Linear > quantile regression works, but for my data I need some quadratic function. > So I guess, I have to use a nonlinear quantile regression. I tried the > example on the help page for nlrq with my data and it worked. But the > example there was with a SSlogis model. Trying to write > > dat.nlrq <- nlrq(BM ~ I(Regen100^2), data=dat, tau=0.25, trace=TRUE) > > or > > dat.nlrq <- nlrq(BM ~ poly(Regen100^2), data=dat, tau=0.25, trace=TRUE) > > (I don't know the difference) both gave me the following error message: > > error in getInitial.default(func, data, mCall = as.list(match.call(func, : > no 'getInitial' method found for "function" objects > > Looking in getInitial, it must have to do something with the starting > parameters or selfStart model. But I have no idea, what this is and how I > handle this problem. Can anyone please help? > > Thanks a lot in advance! > -- > View this message in context: > http://www.nabble.com/Non-linear-regression-Quantile-regression-tp23944530p23944530.html > Sent from the R help mailing list archive at Nabble.com. > > __ > R-help@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. > __ R-help@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.
[R] Non-linear regression/Quantile regression
Hi, I'm relatively new to R and need to do a quantile regression. Linear quantile regression works, but for my data I need some quadratic function. So I guess, I have to use a nonlinear quantile regression. I tried the example on the help page for nlrq with my data and it worked. But the example there was with a SSlogis model. Trying to write dat.nlrq <- nlrq(BM ~ I(Regen100^2), data=dat, tau=0.25, trace=TRUE) or dat.nlrq <- nlrq(BM ~ poly(Regen100^2), data=dat, tau=0.25, trace=TRUE) (I don't know the difference) both gave me the following error message: error in getInitial.default(func, data, mCall = as.list(match.call(func, : no 'getInitial' method found for "function" objects Looking in getInitial, it must have to do something with the starting parameters or selfStart model. But I have no idea, what this is and how I handle this problem. Can anyone please help? Thanks a lot in advance! -- View this message in context: http://www.nabble.com/Non-linear-regression-Quantile-regression-tp23944530p23944530.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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.