Re: [R] confidence intervals for nls or nls2 model
If you want a confidence based in new x values you can do. I have this post with steps to do this. It's written in Portuguese but the R code is useful. http://ridiculas.wordpress.com/2011/05/19/bandas-de-confianca-para-modelo-de-regressao-nao-linear/ Bests. Walmes. == Walmes Marques Zeviani LEG (Laboratório de Estatística e Geoinformação, 25.450418 S, 49.231759 W) Departamento de Estatística - Universidade Federal do Paraná fone: (+55) 41 3361 3573 VoIP: (3361 3600) 1053 1173 e-mail: wal...@ufpr.br twitter: @walmeszeviani homepage: http://www.leg.ufpr.br/~walmes linux user number: 531218 == [[alternative HTML version deleted]] __ 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] confidence intervals for nls or nls2 model
Thanks! Now it is clear. Francisco On Wed, 16 May 2012 07:32:56 -0400, Gabor Grothendieck wrote > On Tue, May 15, 2012 at 11:20 PM, Gabor Grothendieck > wrote: > > On Tue, May 15, 2012 at 8:08 PM, Francisco Mora Ardila > > wrote: > >> Hi all > >> > >> I have fitted a model usinf nls function to these data: > >> > >>> x > >> [1] 1 0 0 4 3 5 12 10 12 100 100 100 > >> > >>> y > >> [1] 1.281055090 1.563609934 0.001570796 2.291579783 0.841891853 > >> [6] 6.553951324 14.243274230 14.519899320 15.066473610 21.728809880 > >> [11] 18.553054450 23.722637370 > >> > >> The model fitted is: > >> > >> modellogis<-nls(y~SSlogis(x,a,b,c)) > >> > >> It runs OK. Then I calculate confidence intervals for the actual data > >> using: > >> > >> dataci<-predict(as.lm(modellogis), interval = "confidence") > >> > >> BUt I don´t get smooth curves when plotting it, so I want to get other > >> "confidence > >> vectors" based on a new x vector by defining a new data to do predictions: > >> > >> x0 <- seq(0,15,1) > >> dataci<-predict(as.lm(modellogis), newdata=data.frame(x=x0), interval = "confidence") > >> > >> BUt it does not work: I get the same initial confidence interval > >> > >> Any ideas on how to get tconfidence and prediction intervals using new X > >> data on a > >> previous model? > >> > > > > as.lm is a linear model between the response variable and the gradient > > of the nonlinear model and as we see below x is not part of that > > linear model so x can't be in newdata when predicting from the tangent > > model. We can only make predictions at the original x points. For > > other x's we could use Interpolation. See ?approx (?spline can also > > work in smooth cases but in the example provided the function has a > > kink and that won't work well with splines.) > > > >> as.lm(modellogis)$model > > y a b c (offset) > > 1 1.281055090 0.06601796 -4.411829e-01 1.168928e+00 1.397153 > > 2 1.563609934 0.04798815 -3.268846e-01 9.766080e-01 1.015584 > > 3 0.001570796 0.04798815 -3.268846e-01 9.766080e-01 1.015584 > > 4 2.291579783 0.16311227 -9.767241e-01 1.597189e+00 3.451981 > > 5 0.841891853 0.12203013 -7.665928e-01 1.512752e+00 2.582551 > > 6 6.553951324 0.21464369 -1.206154e+00 1.564573e+00 4.542552 > > 7 14.243274230 0.74450055 -1.361047e+00 -1.455630e+00 15.756031 > > 8 14.519899320 0.59707858 -1.721353e+00 -6.770205e-01 12.636107 > > 9 15.066473610 0.74450055 -1.361047e+00 -1.455630e+00 15.756031 > > 10 21.728809880 1. -2.943955e-13 -9.073765e-12 21.163223 > > 11 18.553054450 1. -2.943955e-13 -9.073765e-12 21.163223 > > 12 23.722637370 1. -2.943955e-13 -9.073765e-12 21.163223 > > > > I have added a FAQ to the home page since this isn't the first time > this question has come up: > > http://nls2.googlecode.com#FAQs > > -- > Statistics & Software Consulting > GKX Group, GKX Associates Inc. > tel: 1-877-GKX-GROUP > email: ggrothendieck at gmail.com -- Francisco Mora Ardila Estudiante de Doctorado Centro de Investigaciones en Ecosistemas Universidad Nacional Autónoma de México __ 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] confidence intervals for nls or nls2 model
On Tue, May 15, 2012 at 11:20 PM, Gabor Grothendieck wrote: > On Tue, May 15, 2012 at 8:08 PM, Francisco Mora Ardila > wrote: >> Hi all >> >> I have fitted a model usinf nls function to these data: >> >>> x >> [1] 1 0 0 4 3 5 12 10 12 100 100 100 >> >>> y >> [1] 1.281055090 1.563609934 0.001570796 2.291579783 0.841891853 >> [6] 6.553951324 14.243274230 14.519899320 15.066473610 21.728809880 >> [11] 18.553054450 23.722637370 >> >> The model fitted is: >> >> modellogis<-nls(y~SSlogis(x,a,b,c)) >> >> It runs OK. Then I calculate confidence intervals for the actual data using: >> >> dataci<-predict(as.lm(modellogis), interval = "confidence") >> >> BUt I don´t get smooth curves when plotting it, so I want to get other >> "confidence >> vectors" based on a new x vector by defining a new data to do predictions: >> >> x0 <- seq(0,15,1) >> dataci<-predict(as.lm(modellogis), newdata=data.frame(x=x0), interval = >> "confidence") >> >> BUt it does not work: I get the same initial confidence interval >> >> Any ideas on how to get tconfidence and prediction intervals using new X >> data on a >> previous model? >> > > as.lm is a linear model between the response variable and the gradient > of the nonlinear model and as we see below x is not part of that > linear model so x can't be in newdata when predicting from the tangent > model. We can only make predictions at the original x points. For > other x's we could use Interpolation. See ?approx (?spline can also > work in smooth cases but in the example provided the function has a > kink and that won't work well with splines.) > >> as.lm(modellogis)$model > y a b c (offset) > 1 1.281055090 0.06601796 -4.411829e-01 1.168928e+00 1.397153 > 2 1.563609934 0.04798815 -3.268846e-01 9.766080e-01 1.015584 > 3 0.001570796 0.04798815 -3.268846e-01 9.766080e-01 1.015584 > 4 2.291579783 0.16311227 -9.767241e-01 1.597189e+00 3.451981 > 5 0.841891853 0.12203013 -7.665928e-01 1.512752e+00 2.582551 > 6 6.553951324 0.21464369 -1.206154e+00 1.564573e+00 4.542552 > 7 14.243274230 0.74450055 -1.361047e+00 -1.455630e+00 15.756031 > 8 14.519899320 0.59707858 -1.721353e+00 -6.770205e-01 12.636107 > 9 15.066473610 0.74450055 -1.361047e+00 -1.455630e+00 15.756031 > 10 21.728809880 1. -2.943955e-13 -9.073765e-12 21.163223 > 11 18.553054450 1. -2.943955e-13 -9.073765e-12 21.163223 > 12 23.722637370 1. -2.943955e-13 -9.073765e-12 21.163223 > I have added a FAQ to the home page since this isn't the first time this question has come up: http://nls2.googlecode.com#FAQs -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.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] confidence intervals for nls or nls2 model
On Tue, May 15, 2012 at 11:20 PM, Gabor Grothendieck wrote: > On Tue, May 15, 2012 at 8:08 PM, Francisco Mora Ardila > wrote: >> Hi all >> >> I have fitted a model usinf nls function to these data: >> >>> x >> [1] 1 0 0 4 3 5 12 10 12 100 100 100 >> >>> y >> [1] 1.281055090 1.563609934 0.001570796 2.291579783 0.841891853 >> [6] 6.553951324 14.243274230 14.519899320 15.066473610 21.728809880 >> [11] 18.553054450 23.722637370 >> >> The model fitted is: >> >> modellogis<-nls(y~SSlogis(x,a,b,c)) >> >> It runs OK. Then I calculate confidence intervals for the actual data using: >> >> dataci<-predict(as.lm(modellogis), interval = "confidence") >> >> BUt I don´t get smooth curves when plotting it, so I want to get other >> "confidence >> vectors" based on a new x vector by defining a new data to do predictions: >> >> x0 <- seq(0,15,1) >> dataci<-predict(as.lm(modellogis), newdata=data.frame(x=x0), interval = >> "confidence") >> >> BUt it does not work: I get the same initial confidence interval >> >> Any ideas on how to get tconfidence and prediction intervals using new X >> data on a >> previous model? >> > > as.lm is a linear model between the response variable and the gradient > of the nonlinear model and as we see below x is not part of that > linear model so x can't be in newdata when predicting from the tangent > model. We can only make predictions at the original x points. For > other x's we could use Interpolation. See ?approx (?spline can also > work in smooth cases but in the example provided the function has a > kink and that won't work well with splines.) > >> as.lm(modellogis)$model > y a b c (offset) > 1 1.281055090 0.06601796 -4.411829e-01 1.168928e+00 1.397153 > 2 1.563609934 0.04798815 -3.268846e-01 9.766080e-01 1.015584 > 3 0.001570796 0.04798815 -3.268846e-01 9.766080e-01 1.015584 > 4 2.291579783 0.16311227 -9.767241e-01 1.597189e+00 3.451981 > 5 0.841891853 0.12203013 -7.665928e-01 1.512752e+00 2.582551 > 6 6.553951324 0.21464369 -1.206154e+00 1.564573e+00 4.542552 > 7 14.243274230 0.74450055 -1.361047e+00 -1.455630e+00 15.756031 > 8 14.519899320 0.59707858 -1.721353e+00 -6.770205e-01 12.636107 > 9 15.066473610 0.74450055 -1.361047e+00 -1.455630e+00 15.756031 > 10 21.728809880 1. -2.943955e-13 -9.073765e-12 21.163223 > 11 18.553054450 1. -2.943955e-13 -9.073765e-12 21.163223 > 12 23.722637370 1. -2.943955e-13 -9.073765e-12 21.163223 > Also regarding your comment about not getting smooth curves be sure that you order the x's (and permute the y's the same way) before plotting. -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.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] confidence intervals for nls or nls2 model
On Tue, May 15, 2012 at 8:08 PM, Francisco Mora Ardila wrote: > Hi all > > I have fitted a model usinf nls function to these data: > >> x > [1] 1 0 0 4 3 5 12 10 12 100 100 100 > >> y > [1] 1.281055090 1.563609934 0.001570796 2.291579783 0.841891853 > [6] 6.553951324 14.243274230 14.519899320 15.066473610 21.728809880 > [11] 18.553054450 23.722637370 > > The model fitted is: > > modellogis<-nls(y~SSlogis(x,a,b,c)) > > It runs OK. Then I calculate confidence intervals for the actual data using: > > dataci<-predict(as.lm(modellogis), interval = "confidence") > > BUt I don´t get smooth curves when plotting it, so I want to get other > "confidence > vectors" based on a new x vector by defining a new data to do predictions: > > x0 <- seq(0,15,1) > dataci<-predict(as.lm(modellogis), newdata=data.frame(x=x0), interval = > "confidence") > > BUt it does not work: I get the same initial confidence interval > > Any ideas on how to get tconfidence and prediction intervals using new X data > on a > previous model? > as.lm is a linear model between the response variable and the gradient of the nonlinear model and as we see below x is not part of that linear model so x can't be in newdata when predicting from the tangent model. We can only make predictions at the original x points. For other x's we could use Interpolation. See ?approx (?spline can also work in smooth cases but in the example provided the function has a kink and that won't work well with splines.) > as.lm(modellogis)$model y a b c (offset) 1 1.281055090 0.06601796 -4.411829e-01 1.168928e+00 1.397153 2 1.563609934 0.04798815 -3.268846e-01 9.766080e-01 1.015584 3 0.001570796 0.04798815 -3.268846e-01 9.766080e-01 1.015584 4 2.291579783 0.16311227 -9.767241e-01 1.597189e+00 3.451981 5 0.841891853 0.12203013 -7.665928e-01 1.512752e+00 2.582551 6 6.553951324 0.21464369 -1.206154e+00 1.564573e+00 4.542552 7 14.243274230 0.74450055 -1.361047e+00 -1.455630e+00 15.756031 8 14.519899320 0.59707858 -1.721353e+00 -6.770205e-01 12.636107 9 15.066473610 0.74450055 -1.361047e+00 -1.455630e+00 15.756031 10 21.728809880 1. -2.943955e-13 -9.073765e-12 21.163223 11 18.553054450 1. -2.943955e-13 -9.073765e-12 21.163223 12 23.722637370 1. -2.943955e-13 -9.073765e-12 21.163223 -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.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] confidence intervals for nls or nls2 model
On Tue, 15 May 2012 20:33:02 -0400, David Winsemius wrote > On May 15, 2012, at 8:08 PM, Francisco Mora Ardila wrote: > > > Hi all > > > > I have fitted a model usinf nls function to these data: > > > >> x > > [1] 1 0 0 4 3 5 12 10 12 100 100 100 > > > >> y > > [1] 1.281055090 1.563609934 0.001570796 2.291579783 0.841891853 > > [6] 6.553951324 14.243274230 14.519899320 15.066473610 21.728809880 > > [11] 18.553054450 23.722637370 > > > > The model fitted is: > > > > modellogis<-nls(y~SSlogis(x,a,b,c)) > > > > It runs OK. Then I calculate confidence intervals for the actual > > data using: > > > > dataci<-predict(as.lm(modellogis), interval = "confidence") > > > > BUt I don´t get smooth curves when plotting it, so I want to get > > other "confidence > > vectors" based on a new x vector by defining a new data to do > > predictions: > > > > x0 <- seq(0,15,1) > > dataci<-predict(as.lm(modellogis), newdata=data.frame(x=x0), > > interval = "confidence") > > > > BUt it does not work: > > I am really getting tired of seeing the phrase "doesn't work". And on > my machine it throws an error saying there is no as.lm function> This > seemes to give "smooth results: Sorry for that "doesn't work". Also, I forgot to say function as.lm() is in tha package nls2, which also fit nls models. > > dataci<-predict(as.lm(modellogis), newdata=data.frame(x=x0), interval > = "confidence") > > And notice that this message is in ?predict.nls > > interval > "At present this argument is ignored. Yeah, that´s why I´m using nls2 package > > > I get the same initial confidence interval > > > > Any ideas on how to get tconfidence and prediction intervals using > > new X data on a > > previous model? > > > > Thanks > > > > Francisco > > > > > > > > -- > > Francisco Mora Ardila > > Estudiante de Doctorado > > Centro de Investigaciones en Ecosistemas > > Universidad Nacional Autónoma de México > > > > __ > > 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. > > David Winsemius, MD > West Hartford, CT -- Francisco Mora Ardila Estudiante de Doctorado Centro de Investigaciones en Ecosistemas Universidad Nacional Autónoma de México __ 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] confidence intervals for nls or nls2 model
On May 15, 2012, at 8:08 PM, Francisco Mora Ardila wrote: Hi all I have fitted a model usinf nls function to these data: x [1] 1 0 0 4 3 5 12 10 12 100 100 100 y [1] 1.281055090 1.563609934 0.001570796 2.291579783 0.841891853 [6] 6.553951324 14.243274230 14.519899320 15.066473610 21.728809880 [11] 18.553054450 23.722637370 The model fitted is: modellogis<-nls(y~SSlogis(x,a,b,c)) It runs OK. Then I calculate confidence intervals for the actual data using: dataci<-predict(as.lm(modellogis), interval = "confidence") BUt I don´t get smooth curves when plotting it, so I want to get other "confidence vectors" based on a new x vector by defining a new data to do predictions: x0 <- seq(0,15,1) dataci<-predict(as.lm(modellogis), newdata=data.frame(x=x0), interval = "confidence") BUt it does not work: I am really getting tired of seeing the phrase "doesn't work". And on my machine it throws an error saying there is no as.lm function> This seemes to give "smooth results: dataci<-predict(as.lm(modellogis), newdata=data.frame(x=x0), interval = "confidence") And notice that this message is in ?predict.nls interval "At present this argument is ignored. I get the same initial confidence interval Any ideas on how to get tconfidence and prediction intervals using new X data on a previous model? Thanks Francisco -- Francisco Mora Ardila Estudiante de Doctorado Centro de Investigaciones en Ecosistemas Universidad Nacional Autónoma de México __ 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. David Winsemius, MD West Hartford, CT __ 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] confidence intervals for nls or nls2 model
Hi all I have fitted a model usinf nls function to these data: > x [1] 1 0 0 4 3 5 12 10 12 100 100 100 > y [1] 1.281055090 1.563609934 0.001570796 2.291579783 0.841891853 [6] 6.553951324 14.243274230 14.519899320 15.066473610 21.728809880 [11] 18.553054450 23.722637370 The model fitted is: modellogis<-nls(y~SSlogis(x,a,b,c)) It runs OK. Then I calculate confidence intervals for the actual data using: dataci<-predict(as.lm(modellogis), interval = "confidence") BUt I don´t get smooth curves when plotting it, so I want to get other "confidence vectors" based on a new x vector by defining a new data to do predictions: x0 <- seq(0,15,1) dataci<-predict(as.lm(modellogis), newdata=data.frame(x=x0), interval = "confidence") BUt it does not work: I get the same initial confidence interval Any ideas on how to get tconfidence and prediction intervals using new X data on a previous model? Thanks Francisco -- Francisco Mora Ardila Estudiante de Doctorado Centro de Investigaciones en Ecosistemas Universidad Nacional Autónoma de México __ 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.