Re: [R] [GGplot] Geom_smooth with formula "power"?
See section 8.4-8.5 of MASS 4th Ed. (the book) and the use of profile.nls() and friends for profiling the log likelihhood surface. Warning: standard F,t approximations may be poor if the log likelihood is not nearly enough quadratic. The whole issue of what df to use is also contentious/unresolved. -- Bert Bert Gunter "Data is not information. Information is not knowledge. And knowledge is certainly not wisdom." -- Clifford Stoll On Tue, Nov 10, 2015 at 9:47 AM, David Winsemius wrote: > >> On Nov 9, 2015, at 7:19 AM, Catarina Silva >> wrote: >> >> I've tried others initial solutions and the adjustement was done to power >> model in ggplot - geom_smooth. >> But, with "nls" I can't do the confidence interval with ggplot - >> geom_smooth? I read that with "nls" we have to force "se=FALSE". Is this >> true? > > Well, sort of. Setting `se = FALSE` prevents the ggplot2 functions from > trying to force nls and nls.predict to do something that is not in their > design. > >> How can I draw confidence interval in the plot? >> >> I've done this: >>> ggplot(data,aes(x = idade,y = v_mt)) + >> + geom_point(alpha=2/10, shape=21,fill="darkgray", colour="black", size=3) >> + >> + geom_smooth(method = 'nls', formula = y ~ a * x^b, start = >> list(a=1,b=2),se=FALSE) >>> >> And then I don't have the confidence interval. >> >> If I do: >>> ggplot(data,aes(x = idade,y = v_mt)) + >> + geom_point(alpha=2/10, shape=21,fill="darkgray", colour="black", size=3) >> + >> + geom_smooth(method = 'nls', formula = y ~ a * x^b, start = list(a=1,b=2)) >> Error in pred$fit : $ operator is invalid for atomic vectors >>> >> >> Return error… >> > Read the help page for nls. The ‘se.fit' parameter is set to FALSE and > efforts to make it TRUE will be ignored. So `predict.nls` simply does not > return std-error estimates in the typical manner of other predict.* > functions. I believe this is because the authors of `nls` did not think there > was a clear answer to the question of what confidence bounds should be > returned. > > If you want to add confidence bounds to an nls, then you need to decide what > bounds to add, and then use the ggplot2 line-drawing functions to overlay > them on your own. I found posts in Rhelp that pointed me to the ‘nls2' > package, but when I tried to run the code I got messages saying that the > `as.lm` function could not be found. > > http://markmail.org/message/7kvolf5zzpqyb7l2?q=list:org%2Er-project%2Er-help+as%2Elm+is+a+linear+model+between+the+response+variable+and+the+gradient > >> require(nls2) > Loading required package: nls2 > Loading required package: proto >> fm <- nls(demand ~ SSasympOrig(Time, A, lrc), data = BOD) >> predict(as.lm(fm), interval = "confidence") > Error in predict(as.lm(fm), interval = "confidence") : > could not find function "as.lm" >> getAnywhere(as.lm) > no object named ‘as.lm’ was found > > > I also found a couple of posts on R-bloggers pointing me to the ‘propagate' > package which has two different methods for constructing confidence intervals. > > http://rmazing.wordpress.com/2013/08/14/predictnls-part-1-monte-carlo-simulation-confidence-intervals-for-nls-models/ > http://rmazing.wordpress.com/2013/08/26/predictnls-part-2-taylor-approximation-confidence-intervals-for-nls-models/ > > > > — > David. > >> Ty, >> Catarina Silva >> >> -Original Message- >> From: Jeff Newmiller [mailto:jdnew...@dcn.davis.ca.us] >> Sent: sábado, 7 de Novembro de 2015 01:09 >> To: bolseiro.raiz.csi...@portucelsoporcel.com; R mailling list >> Subject: Re: [R] [GGplot] Geom_smooth with formula "power"? >> >> Does [1] help? >> >> [1] >> http://stackoverflow.com/questions/10528631/add-exp-power-trend-line-to-a-ggplot >> --- >> Jeff NewmillerThe . . Go Live... >> DCN:Basics: ##.#. ##.#. Live Go... >> Live: OO#.. Dead: OO#.. Playing >> Research Engineer (Solar/BatteriesO.O#. #.O#. with >> /Software/Embedded Controllers) .OO#. .OO#. rocks...1k >> --- >> Sent from my phone. Please excuse my brevity. >> >> On November 6, 2015 2:41:18 AM PST, Catarina Silva
Re: [R] [GGplot] Geom_smooth with formula "power"?
> On Nov 9, 2015, at 7:19 AM, Catarina Silva > wrote: > > I've tried others initial solutions and the adjustement was done to power > model in ggplot - geom_smooth. > But, with "nls" I can't do the confidence interval with ggplot - geom_smooth? > I read that with "nls" we have to force "se=FALSE". Is this true? Well, sort of. Setting `se = FALSE` prevents the ggplot2 functions from trying to force nls and nls.predict to do something that is not in their design. > How can I draw confidence interval in the plot? > > I've done this: >> ggplot(data,aes(x = idade,y = v_mt)) + > + geom_point(alpha=2/10, shape=21,fill="darkgray", colour="black", size=3) > + > + geom_smooth(method = 'nls', formula = y ~ a * x^b, start = > list(a=1,b=2),se=FALSE) >> > And then I don't have the confidence interval. > > If I do: >> ggplot(data,aes(x = idade,y = v_mt)) + > + geom_point(alpha=2/10, shape=21,fill="darkgray", colour="black", size=3) > + > + geom_smooth(method = 'nls', formula = y ~ a * x^b, start = list(a=1,b=2)) > Error in pred$fit : $ operator is invalid for atomic vectors >> > > Return error… > Read the help page for nls. The ‘se.fit' parameter is set to FALSE and efforts to make it TRUE will be ignored. So `predict.nls` simply does not return std-error estimates in the typical manner of other predict.* functions. I believe this is because the authors of `nls` did not think there was a clear answer to the question of what confidence bounds should be returned. If you want to add confidence bounds to an nls, then you need to decide what bounds to add, and then use the ggplot2 line-drawing functions to overlay them on your own. I found posts in Rhelp that pointed me to the ‘nls2' package, but when I tried to run the code I got messages saying that the `as.lm` function could not be found. http://markmail.org/message/7kvolf5zzpqyb7l2?q=list:org%2Er-project%2Er-help+as%2Elm+is+a+linear+model+between+the+response+variable+and+the+gradient > require(nls2) Loading required package: nls2 Loading required package: proto > fm <- nls(demand ~ SSasympOrig(Time, A, lrc), data = BOD) > predict(as.lm(fm), interval = "confidence") Error in predict(as.lm(fm), interval = "confidence") : could not find function "as.lm" > getAnywhere(as.lm) no object named ‘as.lm’ was found I also found a couple of posts on R-bloggers pointing me to the ‘propagate' package which has two different methods for constructing confidence intervals. http://rmazing.wordpress.com/2013/08/14/predictnls-part-1-monte-carlo-simulation-confidence-intervals-for-nls-models/ http://rmazing.wordpress.com/2013/08/26/predictnls-part-2-taylor-approximation-confidence-intervals-for-nls-models/ — David. > Ty, > Catarina Silva > > -Original Message- > From: Jeff Newmiller [mailto:jdnew...@dcn.davis.ca.us] > Sent: sábado, 7 de Novembro de 2015 01:09 > To: bolseiro.raiz.csi...@portucelsoporcel.com; R mailling list > Subject: Re: [R] [GGplot] Geom_smooth with formula "power"? > > Does [1] help? > > [1] > http://stackoverflow.com/questions/10528631/add-exp-power-trend-line-to-a-ggplot > --- > Jeff NewmillerThe . . Go Live... > DCN:Basics: ##.#. ##.#. Live Go... > Live: OO#.. Dead: OO#.. Playing > Research Engineer (Solar/BatteriesO.O#. #.O#. with > /Software/Embedded Controllers) .OO#. .OO#. rocks...1k > --- > Sent from my phone. Please excuse my brevity. > > On November 6, 2015 2:41:18 AM PST, Catarina Silva > wrote: >> Hi, >> >> It's possible to use ggplot and geom_smooth to adjust a power curve to >> the data? >> >> Initially i have done the adjustement with nls and the formula 'a*x^b', >> but resulted the singular matrix error for start solution. >> Alternatively I used the log transformation and i had correct results, >> but I can't draw a power curve on the graphic. >> >> Someone know how to solve this problem? >> >> David Winsemius Alameda, CA, USA __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] [GGplot] Geom_smooth with formula "power"?
I've tried others initial solutions and the adjustement was done to power model in ggplot - geom_smooth. But, with "nls" I can't do the confidence interval with ggplot - geom_smooth? I read that with "nls" we have to force "se=FALSE". Is this true? How can I draw confidence interval in the plot? I've done this: > ggplot(data,aes(x = idade,y = v_mt)) + + geom_point(alpha=2/10, shape=21,fill="darkgray", colour="black", size=3) + + geom_smooth(method = 'nls', formula = y ~ a * x^b, start = list(a=1,b=2),se=FALSE) > And then I don't have the confidence interval. If I do: > ggplot(data,aes(x = idade,y = v_mt)) + + geom_point(alpha=2/10, shape=21,fill="darkgray", colour="black", size=3) + + geom_smooth(method = 'nls', formula = y ~ a * x^b, start = list(a=1,b=2)) Error in pred$fit : $ operator is invalid for atomic vectors > Return error... Ty, Catarina Silva -Original Message- From: Jeff Newmiller [mailto:jdnew...@dcn.davis.ca.us] Sent: sábado, 7 de Novembro de 2015 01:09 To: bolseiro.raiz.csi...@portucelsoporcel.com; R mailling list Subject: Re: [R] [GGplot] Geom_smooth with formula "power"? Does [1] help? [1] http://stackoverflow.com/questions/10528631/add-exp-power-trend-line-to-a-ggplot --- Jeff NewmillerThe . . Go Live... DCN:Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. On November 6, 2015 2:41:18 AM PST, Catarina Silva wrote: >Hi, > >It's possible to use ggplot and geom_smooth to adjust a power curve to >the data? > >Initially i have done the adjustement with nls and the formula 'a*x^b', >but resulted the singular matrix error for start solution. >Alternatively I used the log transformation and i had correct results, >but I can't draw a power curve on the graphic. > >Someone know how to solve this problem? > > > >Ty, > > > >Catarina Silva > > >Imprima no nosso papel - Cuide do ambiente >-- >Print on our paper - Care for the environment. >-- >http://backoffice.portucelsoporcel.net/dynamic-media/files/utilizar_papel_e_promover_o_desenvolvimento_da_floresta.pdf > >__ >R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >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. Imprima no nosso papel - Cuide do ambiente -- Print on our paper - Care for the environment. -- http://backoffice.portucelsoporcel.net/dynamic-media/files/utilizar_papel_e_promover_o_desenvolvimento_da_floresta.pdf __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] [GGplot] Geom_smooth with formula "power"?
Does [1] help? [1] http://stackoverflow.com/questions/10528631/add-exp-power-trend-line-to-a-ggplot --- Jeff NewmillerThe . . Go Live... DCN:Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. On November 6, 2015 2:41:18 AM PST, Catarina Silva wrote: >Hi, > >It's possible to use ggplot and geom_smooth to adjust a power curve to >the >data? > >Initially i have done the adjustement with nls and the formula 'a*x^b', >but >resulted the singular matrix error for start solution. Alternatively I >used >the log transformation and i had correct results, but I can't draw a >power >curve on the graphic. > >Someone know how to solve this problem? > > > >Ty, > > > >Catarina Silva > > >Imprima no nosso papel - Cuide do ambiente >-- >Print on our paper - Care for the environment. >-- >http://backoffice.portucelsoporcel.net/dynamic-media/files/utilizar_papel_e_promover_o_desenvolvimento_da_floresta.pdf > >__ >R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >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 -- To UNSUBSCRIBE and more, see 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] [GGplot] Geom_smooth with formula "power"?
Hi, It's possible to use ggplot and geom_smooth to adjust a power curve to the data? Initially i have done the adjustement with nls and the formula 'a*x^b', but resulted the singular matrix error for start solution. Alternatively I used the log transformation and i had correct results, but I can't draw a power curve on the graphic. Someone know how to solve this problem? Ty, Catarina Silva Imprima no nosso papel - Cuide do ambiente -- Print on our paper - Care for the environment. -- http://backoffice.portucelsoporcel.net/dynamic-media/files/utilizar_papel_e_promover_o_desenvolvimento_da_floresta.pdf __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.