liang.che at us.pwc.com
2012-Oct-08 19:11 UTC
[R] How to use Lines function to draw the error bars?
fit lwr upr 1 218.4332 90.51019 346.3561 2 218.3906 90.46133 346.3198 3 218.3906 90.46133 346.3198 4 161.3982 44.85702 277.9394 5 192.4450 68.39903 316.4909 6 179.8056 56.49540 303.1158 7 219.5406 91.52707 347.5542 8 162.6761 46.65760 278.6945 9 193.8506 70.59838 317.1029 10 181.3816 58.11305 304.6502 11 221.2871 92.14366 350.4305 12 164.2947 47.91081 280.6785 13 195.3415 72.04109 318.6418 14 182.7447 58.68660 306.8028 15 222.5223 91.86550 353.1791 I have tried new<-data.frame(newdata$Unemployment) prd<-predict.lm(fit,newdata,interval=c("confidence"),level=0.95) lines (new,prd[,3],col="red",lty=2) but it didn't give me anything. thanks ______________________________________________________________________ The information transmitted, including any attachments, is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited, and all liability arising therefrom is disclaimed. If you received this in error, please contact the sender and delete the material from any computer. PricewaterhouseCoopers LLP is a Delaware limited liability partnership. This communication may come from PricewaterhouseCoopers LLP or one of its subsidiaries. [[alternative HTML version deleted]]
liang.che at us.pwc.com
2012-Oct-08 19:52 UTC
[R] How to use Lines function to draw the error bars?
Thanks -- I got this message: Error in stripchart.default(x1, ...) : invalid plotting method From: Bita Shams <shams.bita@yahoo.com> To: Liang Che/US/TLS/PwC@Americas-US Date: 10/08/2012 03:41 PM Subject: Re: [R] How to use Lines function to draw the error bars? try this : plot(new,prd[,3],col="red",lty=2,type=c("l")) type = c("l") is used to draw a line. function " lines" usually is used to add more lines to the plot. From: "liang.che@us.pwc.com" <liang.che@us.pwc.com> To: r-help@r-project.org Sent: Monday, October 8, 2012 10:41 PM Subject: [R] How to use Lines function to draw the error bars? fit lwr upr 1 218.4332 90.51019 346.3561 2 218.3906 90.46133 346.3198 3 218.3906 90.46133 346.3198 4 161.3982 44.85702 277.9394 5 192.4450 68.39903 316.4909 6 179.8056 56.49540 303.1158 7 219.5406 91.52707 347.5542 8 162.6761 46.65760 278.6945 9 193.8506 70.59838 317.1029 10 181.3816 58.11305 304.6502 11 221.2871 92.14366 350.4305 12 164.2947 47.91081 280.6785 13 195.3415 72.04109 318.6418 14 182.7447 58.68660 306.8028 15 222.5223 91.86550 353.1791 I have tried new<-data.frame(newdata$Unemployment) prd<-predict.lm(fit,newdata,interval=c("confidence"),level=0.95) lines (new,prd[,3],col="red",lty=2) but it didn't give me anything. thanks ______________________________________________________________________ The information transmitted, including any attachments, is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited, and all liability arising therefrom is disclaimed. If you received this in error, please contact the sender and delete the material from any computer. PricewaterhouseCoopers LLP is a Delaware limited liability partnership. This communication may come from PricewaterhouseCoopers LLP or one of its subsidiaries. [[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. ______________________________________________________________________ The information transmitted, including any attachments, is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited, and all liability arising therefrom is disclaimed. If you received this in error, please contact the sender and delete the material from any computer. PricewaterhouseCoopers LLP is a Delaware limited liability partnership. This communication may come from PricewaterhouseCoopers LLP or one of its subsidiaries. [[alternative HTML version deleted]]
Hello, Do you want to use the lines function or do you want to draw error bars? The two are not the same, error bars are usualy drawn with function arrows(). The trick is in argument 'angle', set it to 90 degreesand have square arrow heads. dat <- read.table(text=" fit lwr upr 1 218.4332 90.51019 346.3561 2 218.3906 90.46133 346.3198 3 218.3906 90.46133 346.3198 4 161.3982 44.85702 277.9394 5 192.4450 68.39903 316.4909 6 179.8056 56.49540 303.1158 7 219.5406 91.52707 347.5542 8 162.6761 46.65760 278.6945 9 193.8506 70.59838 317.1029 10 181.3816 58.11305 304.6502 11 221.2871 92.14366 350.4305 12 164.2947 47.91081 280.6785 13 195.3415 72.04109 318.6418 14 182.7447 58.68660 306.8028 15 222.5223 91.86550 353.1791 ", header = TRUE) dat ylm <- with(dat, range(range(fit), range(lwr), range(upr))) plot(dat$fit, ylim = ylm, xlim = c(0, 16)) with(dat, arrows(1:15, fit, 1:15, lwr, angle = 90, length = 0.1)) with(dat, arrows(1:15, fit, 1:15, upr, angle = 90, length = 0.1)) Hope this helps, Rui Barradas Em 08-10-2012 20:11, liang.che at us.pwc.com escreveu:> fit lwr upr > 1 218.4332 90.51019 346.3561 > 2 218.3906 90.46133 346.3198 > 3 218.3906 90.46133 346.3198 > 4 161.3982 44.85702 277.9394 > 5 192.4450 68.39903 316.4909 > 6 179.8056 56.49540 303.1158 > 7 219.5406 91.52707 347.5542 > 8 162.6761 46.65760 278.6945 > 9 193.8506 70.59838 317.1029 > 10 181.3816 58.11305 304.6502 > 11 221.2871 92.14366 350.4305 > 12 164.2947 47.91081 280.6785 > 13 195.3415 72.04109 318.6418 > 14 182.7447 58.68660 306.8028 > 15 222.5223 91.86550 353.1791 > > > I have tried > > new<-data.frame(newdata$Unemployment) > prd<-predict.lm(fit,newdata,interval=c("confidence"),level=0.95) > lines (new,prd[,3],col="red",lty=2) > > but it didn't give me anything. > > thanks > > ______________________________________________________________________ > The information transmitted, including any attachments, is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited, and all liability arising therefrom is disclaimed. If you received this in error, please contact the sender and delete the material from any computer. PricewaterhouseCoopers LLP is a Delaware limited liability partnership. This communication may come from PricewaterhouseCoopers LLP or one of its subsidiaries. > > [[alternative HTML version deleted]] > > ______________________________________________ > 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.
I typically use the function "plotCI" from the "plotrix" package for confidence intervals or error bars.The code would be: library(plotrix)plotCI( x=1:15, y=fit, ui=upr, li=lwr) // joseph w. clark , visiting research associate \\ university of nebraska at omaha - school of IS&T > To: r-help@r-project.org> From: liang.che@us.pwc.com > Date: Mon, 8 Oct 2012 15:11:53 -0400 > Subject: [R] How to use Lines function to draw the error bars? > > fit lwr upr > 1 218.4332 90.51019 346.3561 > 2 218.3906 90.46133 346.3198 > 3 218.3906 90.46133 346.3198 > 4 161.3982 44.85702 277.9394 > 5 192.4450 68.39903 316.4909 > 6 179.8056 56.49540 303.1158 > 7 219.5406 91.52707 347.5542 > 8 162.6761 46.65760 278.6945 > 9 193.8506 70.59838 317.1029 > 10 181.3816 58.11305 304.6502 > 11 221.2871 92.14366 350.4305 > 12 164.2947 47.91081 280.6785 > 13 195.3415 72.04109 318.6418 > 14 182.7447 58.68660 306.8028 > 15 222.5223 91.86550 353.1791 > > > I have tried > > new<-data.frame(newdata$Unemployment) > prd<-predict.lm(fit,newdata,interval=c("confidence"),level=0.95) > lines (new,prd[,3],col="red",lty=2) > > but it didn't give me anything. > > thanks > > ______________________________________________________________________ > The information transmitted, including any attachments, is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited, and all liability arising therefrom is disclaimed. If you received this in error, please contact the sender and delete the material from any computer. PricewaterhouseCoopers LLP is a Delaware limited liability partnership. This communication may come from PricewaterhouseCoopers LLP or one of its subsidiaries. > > [[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.[[alternative HTML version deleted]]
liang.che at us.pwc.com
2012-Oct-09 00:49 UTC
[R] How to use Lines function to draw the error bars?
one extra question How do I export the final image (with plots and lines added) into files in a batch mode for a bunch of regressions? thanks ----- Forwarded by Liang Che/US/TLS/PwC on 10/08/2012 08:48 PM ----- From: Liang Che/US/TLS/PwC To: Joseph Clark <joeclark77@hotmail.com>@INTL Cc: r-help@r-project.org Date: 10/08/2012 08:44 PM Subject: RE: [R] How to use Lines function to draw the error bars? thank you all for your answers i have figured out the plot i wanted - it was actually pretty easy lines(x=20:34,prd[,1],col="red",Ity=1) lines(x=20:34,prd[,2],lty=2) lines(x=20:34,prd[,3],lty=2) From: Joseph Clark <joeclark77@hotmail.com> To: Liang Che/US/TLS/PwC@Americas-US Cc: <r-help@r-project.org> Date: 10/08/2012 05:30 PM Subject: RE: [R] How to use Lines function to draw the error bars? I don't have any experience with "predict", but if it returns a data frame, just capture that data frame and refer to the columns as vectors. mydata <- predict(...) plotCI( 1:nrow(mydata), y=mydata$fit, ui=mydata$upr, li=mydata$lwr ) That seems easier to me. // joseph w. clark , visiting research associate \\ university of nebraska at omaha - school of IS&T To: joeclark77@hotmail.com CC: r-help@r-project.org Subject: RE: [R] How to use Lines function to draw the error bars? From: liang.che@us.pwc.com Date: Mon, 8 Oct 2012 17:16:12 -0400 Thanks since the 'lwr' and 'upr' are produced from the 'predict' function, do I need to convert the table into a data frame, then define the 'lwr' and 'upr' as the objects? upr<-data.frame(prd[,3]) fix(upr) lwr<-data.frame(prd[,2]) fix(lwr) y<-data.frame(prd[,1]) fix(y) plotCI(x=1:15,y=y,uiw=upr,liw=lwr,err=x) but I got the following error message: Error in xy.coords(x, y, xlabel, ylabel, log) : 'x' and 'y' lengths differ In addition: Warning message: In if (err == "y") z <- y else z <- x : the condition has length > 1 and only the first element will be used From: Joseph Clark <joeclark77@hotmail.com> To: Liang Che/US/TLS/PwC@Americas-US Cc: <r-help@r-project.org> Date: 10/08/2012 05:06 PM Subject: RE: [R] How to use Lines function to draw the error bars? In my example code, 'fit' and 'upr' and 'lwr' are just the names of the data vectors you gave as an example. If those names aren't correct, change them to what you're actually using. You can also assign your x values to x. // joseph w. clark , visiting research associate \\ university of nebraska at omaha - school of IS&T To: joeclark77@hotmail.com CC: r-help@r-project.org Subject: RE: [R] How to use Lines function to draw the error bars? From: liang.che@us.pwc.com Date: Mon, 8 Oct 2012 17:00:56 -0400 thank you all plotCI is probably the closest to what I wanted to do -- draw the Confidence Interval curves around the fitted values (fit) but I got the following wrong message while I tried plotCI? Error in plotCI(x = 1:15, y = fit, ui = upr, li = lwr) : object 'upr' not found From: Joseph Clark <joeclark77@hotmail.com> To: Liang Che/US/TLS/PwC@Americas-US, <r-help@r-project.org> Date: 10/08/2012 04:03 PM Subject: RE: [R] How to use Lines function to draw the error bars? I typically use the function "plotCI" from the "plotrix" package for confidence intervals or error bars. The code would be: library(plotrix) plotCI( x=1:15, y=fit, ui=upr, li=lwr) // joseph w. clark , visiting research associate \\ university of nebraska at omaha - school of IS&T> To: r-help@r-project.org > From: liang.che@us.pwc.com > Date: Mon, 8 Oct 2012 15:11:53 -0400 > Subject: [R] How to use Lines function to draw the error bars? > > fit lwr upr > 1 218.4332 90.51019 346.3561 > 2 218.3906 90.46133 346.3198 > 3 218.3906 90.46133 346.3198 > 4 161.3982 44.85702 277.9394 > 5 192.4450 68.39903 316.4909 > 6 179.8056 56.49540 303.1158 > 7 219.5406 91.52707 347.5542 > 8 162.6761 46.65760 278.6945 > 9 193.8506 70.59838 317.1029 > 10 181.3816 58.11305 304.6502 > 11 221.2871 92.14366 350.4305 > 12 164.2947 47.91081 280.6785 > 13 195.3415 72.04109 318.6418 > 14 182.7447 58.68660 306.8028 > 15 222.5223 91.86550 353.1791 > > > I have tried > > new<-data.frame(newdata$Unemployment) > prd<-predict.lm(fit,newdata,interval=c("confidence"),level=0.95) > lines (new,prd[,3],col="red",lty=2) > > but it didn't give me anything. > > thanks > > ______________________________________________________________________ > The information transmitted, including any attachments, is intended onlyfor the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited, and all liability arising therefrom is disclaimed. If you received this in error, please contact the sender and delete the material from any computer. PricewaterhouseCoopers LLP is a Delaware limited liability partnership. This communication may come from PricewaterhouseCoopers LLP or one of its subsidiaries.> > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code.The information transmitted, including any attachments, is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited, and all liability arising therefrom is disclaimed. If you received this in error, please contact the sender and delete the material from any computer. PricewaterhouseCoopers LLP is a Delaware limited liability partnership. This communication may come from PricewaterhouseCoopers LLP or one of its subsidiaries. The information transmitted, including any attachments, is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited, and all liability arising therefrom is disclaimed. If you received this in error, please contact the sender and delete the material from any computer. PricewaterhouseCoopers LLP is a Delaware limited liability partnership. This communication may come from PricewaterhouseCoopers LLP or one of its subsidiaries. ______________________________________________________________________ The information transmitted, including any attachments, is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited, and all liability arising therefrom is disclaimed. If you received this in error, please contact the sender and delete the material from any computer. PricewaterhouseCoopers LLP is a Delaware limited liability partnership. This communication may come from PricewaterhouseCoopers LLP or one of its subsidiaries. [[alternative HTML version deleted]]
David Winsemius
2012-Oct-09 01:31 UTC
[R] How to use Lines function to draw the error bars?
On Oct 8, 2012, at 5:49 PM, liang.che at us.pwc.com wrote:> one extra question > > How do I export the final image (with plots and lines added) into files in > a batch mode for a bunch of regressions?You probably need to review: ?Devices ?BATCH -- David.> > thanks > > > ----- Forwarded by Liang Che/US/TLS/PwC on 10/08/2012 08:48 PM ----- > > From: Liang Che/US/TLS/PwC > To: Joseph Clark <joeclark77 at hotmail.com>@INTL > Cc: r-help at r-project.org > Date: 10/08/2012 08:44 PM > Subject: RE: [R] How to use Lines function to draw the error bars? > > > thank you all for your answers > > i have figured out the plot i wanted - it was actually pretty easy > > lines(x=20:34,prd[,1],col="red",Ity=1) > lines(x=20:34,prd[,2],lty=2) > lines(x=20:34,prd[,3],lty=2) > > > > > > > From: Joseph Clark <joeclark77 at hotmail.com> > To: Liang Che/US/TLS/PwC at Americas-US > Cc: <r-help at r-project.org> > Date: 10/08/2012 05:30 PM > Subject: RE: [R] How to use Lines function to draw the error bars? > > > > I don't have any experience with "predict", but if it returns a data > frame, just capture that data frame and refer to the columns as vectors. > > mydata <- predict(...) > plotCI( 1:nrow(mydata), y=mydata$fit, ui=mydata$upr, li=mydata$lwr ) > > That seems easier to me. > > > // joseph w. clark , visiting research associate > \\ university of nebraska at omaha - school of IS&T > > To: joeclark77 at hotmail.com > CC: r-help at r-project.org > Subject: RE: [R] How to use Lines function to draw the error bars? > From: liang.che at us.pwc.com > Date: Mon, 8 Oct 2012 17:16:12 -0400 > > Thanks > > since the 'lwr' and 'upr' are produced from the 'predict' function, do I > need to convert the table into a data frame, then define the 'lwr' and > 'upr' as the objects? > > upr<-data.frame(prd[,3]) > fix(upr) > lwr<-data.frame(prd[,2]) > fix(lwr) > y<-data.frame(prd[,1]) > fix(y) > plotCI(x=1:15,y=y,uiw=upr,liw=lwr,err=x) > > > but I got the following error message: > > Error in xy.coords(x, y, xlabel, ylabel, log) : > 'x' and 'y' lengths differ > In addition: Warning message: > In if (err == "y") z <- y else z <- x : > the condition has length > 1 and only the first element will be used > > > > > From: Joseph Clark <joeclark77 at hotmail.com> > To: Liang Che/US/TLS/PwC at Americas-US > Cc: <r-help at r-project.org> > Date: 10/08/2012 05:06 PM > Subject: RE: [R] How to use Lines function to draw the error bars? > > > > In my example code, 'fit' and 'upr' and 'lwr' are just the names of the > data vectors you gave as an example. If those names aren't correct, > change them to what you're actually using. You can also assign your x > values to x. > > // joseph w. clark , visiting research associate > \\ university of nebraska at omaha - school of IS&T > > To: joeclark77 at hotmail.com > CC: r-help at r-project.org > Subject: RE: [R] How to use Lines function to draw the error bars? > From: liang.che at us.pwc.com > Date: Mon, 8 Oct 2012 17:00:56 -0400 > > thank you all > > plotCI is probably the closest to what I wanted to do -- draw the > Confidence Interval curves around the fitted values (fit) > > but I got the following wrong message while I tried plotCI? > > Error in plotCI(x = 1:15, y = fit, ui = upr, li = lwr) : > object 'upr' not found > > > > > > > From: Joseph Clark <joeclark77 at hotmail.com> > To: Liang Che/US/TLS/PwC at Americas-US, <r-help at r-project.org> > Date: 10/08/2012 04:03 PM > Subject: RE: [R] How to use Lines function to draw the error bars? > > > > I typically use the function "plotCI" from the "plotrix" package for > confidence intervals or error bars. > The code would be: > > library(plotrix) > plotCI( x=1:15, y=fit, ui=upr, li=lwr) > > > // joseph w. clark , visiting research associate > \\ university of nebraska at omaha - school of IS&T > >> To: r-help at r-project.org >> From: liang.che at us.pwc.com >> Date: Mon, 8 Oct 2012 15:11:53 -0400 >> Subject: [R] How to use Lines function to draw the error bars? >> >> fit lwr upr >> 1 218.4332 90.51019 346.3561 >> 2 218.3906 90.46133 346.3198 >> 3 218.3906 90.46133 346.3198 >> 4 161.3982 44.85702 277.9394 >> 5 192.4450 68.39903 316.4909 >> 6 179.8056 56.49540 303.1158 >> 7 219.5406 91.52707 347.5542 >> 8 162.6761 46.65760 278.6945 >> 9 193.8506 70.59838 317.1029 >> 10 181.3816 58.11305 304.6502 >> 11 221.2871 92.14366 350.4305 >> 12 164.2947 47.91081 280.6785 >> 13 195.3415 72.04109 318.6418 >> 14 182.7447 58.68660 306.8028 >> 15 222.5223 91.86550 353.1791 >> >> >> I have tried >> >> new<-data.frame(newdata$Unemployment) >> prd<-predict.lm(fit,newdata,interval=c("confidence"),level=0.95) >> lines (new,prd[,3],col="red",lty=2) >> >> but it didn't give me anything. >> >> thanks >> >> ______________________________________________________________________ >> The information transmitted, including any attachments, is intended only > for the person or entity to which it is addressed and may contain > confidential and/or privileged material. Any review, retransmission, > dissemination or other use of, or taking of any action in reliance upon, > this information by persons or entities other than the intended recipient > is prohibited, and all liability arising therefrom is disclaimed. If you > received this in error, please contact the sender and delete the material > from any computer. PricewaterhouseCoopers LLP is a Delaware limited > liability partnership. This communication may come from > PricewaterhouseCoopers LLP or one of its subsidiaries. >> >> [[alternative HTML version deleted]] >> >> ______________________________________________ >> 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. > > The information transmitted, including any attachments, is intended only > for the person or entity to which it is addressed and may contain > confidential and/or privileged material. Any review, retransmission, > dissemination or other use of, or taking of any action in reliance upon, > this information by persons or entities other than the intended recipient > is prohibited, and all liability arising therefrom is disclaimed. If you > received this in error, please contact the sender and delete the material > from any computer. PricewaterhouseCoopers LLP is a Delaware limited > liability partnership. This communication may come from > PricewaterhouseCoopers LLP or one of its subsidiaries. > > The information transmitted, including any attachments, is intended only > for the person or entity to which it is addressed and may contain > confidential and/or privileged material. Any review, retransmission, > dissemination or other use of, or taking of any action in reliance upon, > this information by persons or entities other than the intended recipient > is prohibited, and all liability arising therefrom is disclaimed. If you > received this in error, please contact the sender and delete the material > from any computer. PricewaterhouseCoopers LLP is a Delaware limited > liability partnership. This communication may come from > PricewaterhouseCoopers LLP or one of its subsidiaries. > > > ______________________________________________________________________ > The information transmitted, including any attachments, is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited, and all liability arising therefrom is disclaimed. If you received this in error, please contact the sender and delete the material from any computer. PricewaterhouseCoopers LLP is a Delaware limited liability partnership. This communication may come from PricewaterhouseCoopers LLP or one of its subsidiaries. > > [[alternative HTML version deleted]] > > ______________________________________________ > 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.David Winsemius, MD Alameda, CA, USA
Hi> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On Behalf Of liang.che at us.pwc.com > Sent: Tuesday, October 09, 2012 2:50 AM > To: r-help at r-project.org > Subject: Re: [R] How to use Lines function to draw the error bars? > > one extra question > > How do I export the final image (with plots and lines added) into files > in a batch mode for a bunch of regressions?I usually use for cycle and pdf device as it is suitable to make multipage file. ?for ?pdf Regards Petr> > thanks > > > ----- Forwarded by Liang Che/US/TLS/PwC on 10/08/2012 08:48 PM ----- > > From: Liang Che/US/TLS/PwC > To: Joseph Clark <joeclark77 at hotmail.com>@INTL > Cc: r-help at r-project.org > Date: 10/08/2012 08:44 PM > Subject: RE: [R] How to use Lines function to draw the error > bars? > > > thank you all for your answers > > i have figured out the plot i wanted - it was actually pretty easy > > lines(x=20:34,prd[,1],col="red",Ity=1) > lines(x=20:34,prd[,2],lty=2) > lines(x=20:34,prd[,3],lty=2) > > > > > > > From: Joseph Clark <joeclark77 at hotmail.com> > To: Liang Che/US/TLS/PwC at Americas-US > Cc: <r-help at r-project.org> > Date: 10/08/2012 05:30 PM > Subject: RE: [R] How to use Lines function to draw the error > bars? > > > > I don't have any experience with "predict", but if it returns a data > frame, just capture that data frame and refer to the columns as > vectors. > > mydata <- predict(...) > plotCI( 1:nrow(mydata), y=mydata$fit, ui=mydata$upr, li=mydata$lwr ) > > That seems easier to me. > > > // joseph w. clark , visiting research associate \\ university of > nebraska at omaha - school of IS&T > > To: joeclark77 at hotmail.com > CC: r-help at r-project.org > Subject: RE: [R] How to use Lines function to draw the error bars? > From: liang.che at us.pwc.com > Date: Mon, 8 Oct 2012 17:16:12 -0400 > > Thanks > > since the 'lwr' and 'upr' are produced from the 'predict' function, do > I need to convert the table into a data frame, then define the 'lwr' > and 'upr' as the objects? > > upr<-data.frame(prd[,3]) > fix(upr) > lwr<-data.frame(prd[,2]) > fix(lwr) > y<-data.frame(prd[,1]) > fix(y) > plotCI(x=1:15,y=y,uiw=upr,liw=lwr,err=x) > > > but I got the following error message: > > Error in xy.coords(x, y, xlabel, ylabel, log) : > 'x' and 'y' lengths differ > In addition: Warning message: > In if (err == "y") z <- y else z <- x : > the condition has length > 1 and only the first element will be used > > > > > From: Joseph Clark <joeclark77 at hotmail.com> > To: Liang Che/US/TLS/PwC at Americas-US > Cc: <r-help at r-project.org> > Date: 10/08/2012 05:06 PM > Subject: RE: [R] How to use Lines function to draw the error > bars? > > > > In my example code, 'fit' and 'upr' and 'lwr' are just the names of the > data vectors you gave as an example. If those names aren't correct, > change them to what you're actually using. You can also assign your x > values to x. > > // joseph w. clark , visiting research associate > \\ university of nebraska at omaha - school of IS&T > > To: joeclark77 at hotmail.com > CC: r-help at r-project.org > Subject: RE: [R] How to use Lines function to draw the error bars? > From: liang.che at us.pwc.com > Date: Mon, 8 Oct 2012 17:00:56 -0400 > > thank you all > > plotCI is probably the closest to what I wanted to do -- draw the > Confidence Interval curves around the fitted values (fit) > > but I got the following wrong message while I tried plotCI? > > Error in plotCI(x = 1:15, y = fit, ui = upr, li = lwr) : > object 'upr' not found > > > > > > > From: Joseph Clark <joeclark77 at hotmail.com> > To: Liang Che/US/TLS/PwC at Americas-US, <r-help at r-project.org> > Date: 10/08/2012 04:03 PM > Subject: RE: [R] How to use Lines function to draw the error > bars? > > > > I typically use the function "plotCI" from the "plotrix" package for > confidence intervals or error bars. > The code would be: > > library(plotrix) > plotCI( x=1:15, y=fit, ui=upr, li=lwr) > > > // joseph w. clark , visiting research associate > \\ university of nebraska at omaha - school of IS&T > > > To: r-help at r-project.org > > From: liang.che at us.pwc.com > > Date: Mon, 8 Oct 2012 15:11:53 -0400 > > Subject: [R] How to use Lines function to draw the error bars? > > > > fit lwr upr > > 1 218.4332 90.51019 346.3561 > > 2 218.3906 90.46133 346.3198 > > 3 218.3906 90.46133 346.3198 > > 4 161.3982 44.85702 277.9394 > > 5 192.4450 68.39903 316.4909 > > 6 179.8056 56.49540 303.1158 > > 7 219.5406 91.52707 347.5542 > > 8 162.6761 46.65760 278.6945 > > 9 193.8506 70.59838 317.1029 > > 10 181.3816 58.11305 304.6502 > > 11 221.2871 92.14366 350.4305 > > 12 164.2947 47.91081 280.6785 > > 13 195.3415 72.04109 318.6418 > > 14 182.7447 58.68660 306.8028 > > 15 222.5223 91.86550 353.1791 > > > > > > I have tried > > > > new<-data.frame(newdata$Unemployment) > > prd<-predict.lm(fit,newdata,interval=c("confidence"),level=0.95) > > lines (new,prd[,3],col="red",lty=2) > > > > but it didn't give me anything. > > > > thanks > > > > > ______________________________________________________________________ > > The information transmitted, including any attachments, is intended > only > for the person or entity to which it is addressed and may contain > confidential and/or privileged material. Any review, retransmission, > dissemination or other use of, or taking of any action in reliance > upon, > this information by persons or entities other than the intended > recipient > is prohibited, and all liability arising therefrom is disclaimed. If > you > received this in error, please contact the sender and delete the > material > from any computer. PricewaterhouseCoopers LLP is a Delaware limited > liability partnership. This communication may come from > PricewaterhouseCoopers LLP or one of its subsidiaries. > > > > [[alternative HTML version deleted]] > > > > ______________________________________________ > > 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. > > The information transmitted, including any attachments, is intended > only > for the person or entity to which it is addressed and may contain > confidential and/or privileged material. Any review, retransmission, > dissemination or other use of, or taking of any action in reliance > upon, > this information by persons or entities other than the intended > recipient > is prohibited, and all liability arising therefrom is disclaimed. If > you > received this in error, please contact the sender and delete the > material > from any computer. PricewaterhouseCoopers LLP is a Delaware limited > liability partnership. This communication may come from > PricewaterhouseCoopers LLP or one of its subsidiaries. > > The information transmitted, including any attachments, is intended > only > for the person or entity to which it is addressed and may contain > confidential and/or privileged material. Any review, retransmission, > dissemination or other use of, or taking of any action in reliance > upon, > this information by persons or entities other than the intended > recipient > is prohibited, and all liability arising therefrom is disclaimed. If > you > received this in error, please contact the sender and delete the > material > from any computer. PricewaterhouseCoopers LLP is a Delaware limited > liability partnership. This communication may come from > PricewaterhouseCoopers LLP or one of its subsidiaries. > > > ______________________________________________________________________ > The information transmitted, including any attachments, is intended > only for the person or entity to which it is addressed and may contain > confidential and/or privileged material. Any review, retransmission, > dissemination or other use of, or taking of any action in reliance > upon, this information by persons or entities other than the intended > recipient is prohibited, and all liability arising therefrom is > disclaimed. If you received this in error, please contact the sender > and delete the material from any computer. PricewaterhouseCoopers LLP > is a Delaware limited liability partnership. This communication may > come from PricewaterhouseCoopers LLP or one of its subsidiaries. > > [[alternative HTML version deleted]] > > ______________________________________________ > 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.