Shravan Vasishth
2001-Nov-29 14:06 UTC
[R] plotting (a) confidence intervals (b) standard error
Hi all, I'm building a plot of the values in tmeant (below) against positions 1 to 5, using matplot. tmeant looks like this: case1 case2 pos1 861.8466 818.5909 pos2 961.2841 976.3466 pos3 878.6080 1262.8523 pos4 950.8011 1129.6080 pos5 968.1080 1063.3920 I also have lower (object tl) and upper (object tu) bounds on the confidence intervals as follows: tl: pos1 pos2 pos3 pos4 pos5 case1 761.4777 872.8367 756.7253 806.7503 849.9667 case2 735.1803 878.2557 1058.0583 991.7346 895.0864 tu: pos1 pos2 pos3 pos4 pos5 case1 962.2155 1049.731 1000.491 1094.852 1086.249 case2 902.0015 1074.437 1467.646 1267.481 1231.698 My R code is given towards the end of this message; it plots the values in tmeantmatrix against positions 1-5, and puts the confidence interval (CI) bars at the right points using tl and tu. However, I can't figure out how to get the CI bars to have those delimiters (a shape like "I"), all I get is a straight line through the relevant point. A related question is: I also have standard errors in a matrix called tse: pos1 pos2 pos3 pos4 pos5 case1 49.76907 43.85765 60.4369 71.42927 58.58170 case2 41.36010 48.63950 101.5495 68.36609 83.45631 Is there some way to plot these (instead of CI bars) without having to first compute lower and upper bounds (i.e., without having to specify x0, y0, and x1, y1 in "segments") for each standard error? I guess this would amount to having a way to refer to each point already plotted, and saying something like: take each point as the dimension of an error bar, and put it at the relevant point (I'm thinking of something like gnuplot, which has a nice semantics for this: if you give it three columns to plot and specify that you want error bars, it will use the third column as the dimensions of the error bars). #----------------The code for the graph with CI bars------------------------ tmeantmatrix<- matrix(tmeant,ncol=2) # make tmeant a 2-column matrix # plot using matplot: matplot(c(1:5), tmeantmatrix, xlab = "Position", ylab = "Mean Reading Time (msecs)", main = "Test") # add lines connecting the points: matplot(tmeantmatrix, pch = 1:2, type = "o", lty=1:2, lwd=3, col rainbow(ncol(tmeantmatrix)),add=TRUE) # add CI bars: xzero <- t(matrix(rep(1:5,2),ncol=2)) xone <- xzero segments(x0=xzero, y0=tl, x1=xone, y1=tu) #-------------------end of code------------------------------ Many thanks in advance, -- Shravan Vasishth Dept. of Linguistics, OSU 222 Oxley Hall, 1712 Neil Ave. Columbus, OH 43210-1298 USA URL: http://ling.ohio-state.edu/~vasishth -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
This is a FAQ (although you've gotten farther than most in figuring out how to do it for yourself): http://www.R-project.org/nocvs/mail/r-help/2000/0451.html http://www.R-project.org/nocvs/mail/r-help/2000/2289.html http://www.R-project.org/nocvs/mail/r-help/2000/3326.html http://www.r-project.org/nocvs/mail/r-help/2001/2050.html In short, you can either use arrows() with angle=90 to construct your own error bars, or look at the code for plotCI contained within http://www.zoo.ufl.edu/bolker/R/{windows,linux}/bbmisc.{tar.gz,zip} (pick your platform). Ben Bolker On Thu, 29 Nov 2001, Shravan Vasishth wrote:> Hi all, > > I'm building a plot of the values in tmeant (below) against positions 1 to > 5, using matplot. > > tmeant looks like this: > > case1 case2 > pos1 861.8466 818.5909 > pos2 961.2841 976.3466 > pos3 878.6080 1262.8523 > pos4 950.8011 1129.6080 > pos5 968.1080 1063.3920 > > I also have lower (object tl) and upper (object tu) bounds on the > confidence intervals as follows: > > tl: > > pos1 pos2 pos3 pos4 pos5 > case1 761.4777 872.8367 756.7253 806.7503 849.9667 > case2 735.1803 878.2557 1058.0583 991.7346 895.0864 > > tu: > > pos1 pos2 pos3 pos4 pos5 > case1 962.2155 1049.731 1000.491 1094.852 1086.249 > case2 902.0015 1074.437 1467.646 1267.481 1231.698 > > My R code is given towards the end of this message; it plots the values in > tmeantmatrix against positions 1-5, and puts the confidence interval (CI) > bars at the right points using tl and tu. > > However, I can't figure out how to get the CI bars to have those > delimiters (a shape like "I"), all I get is a straight line through the > relevant point. > > A related question is: I also have standard errors in a matrix called tse: > > pos1 pos2 pos3 pos4 pos5 > case1 49.76907 43.85765 60.4369 71.42927 58.58170 > case2 41.36010 48.63950 101.5495 68.36609 83.45631 > > Is there some way to plot these (instead of CI bars) without having to > first compute lower and upper bounds (i.e., without having to specify x0, > y0, and x1, y1 in "segments") for each standard error? I guess this would > amount to having a way to refer to each point already plotted, and saying > something like: take each point as the dimension of an error bar, and put > it at the relevant point (I'm thinking of something like gnuplot, which > has a nice semantics for this: if you give it three columns to plot and > specify that you want error bars, it will use the third column as the > dimensions of the error bars). > > > #----------------The code for the graph with CI bars------------------------ > > tmeantmatrix<- matrix(tmeant,ncol=2) # make tmeant a 2-column matrix > > # plot using matplot: > > matplot(c(1:5), tmeantmatrix, xlab = "Position", ylab = "Mean Reading Time > (msecs)", main = "Test") > > # add lines connecting the points: > > matplot(tmeantmatrix, pch = 1:2, type = "o", lty=1:2, lwd=3, col > rainbow(ncol(tmeantmatrix)),add=TRUE) > > # add CI bars: > > xzero <- t(matrix(rep(1:5,2),ncol=2)) > > xone <- xzero > > segments(x0=xzero, y0=tl, x1=xone, y1=tu) > > #-------------------end of code------------------------------ > > Many thanks in advance, > >-- 318 Carr Hall bolker at zoo.ufl.edu Zoology Department, University of Florida http://www.zoo.ufl.edu/bolker Box 118525 (ph) 352-392-5697 Gainesville, FL 32611-8525 (fax) 352-392-3704 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Toby.Patterson@csiro.au
2001-Nov-29 23:24 UTC
[R] plotting (a) confidence intervals (b) standard error
Perhaps this is crude but the way I have got the "I" shape is to use another segments() call. ie.>x<-2 > y<-2 > CI<-0.5 > hseg > segments(x,y+CI,x,y-CI) > segments(x-1,y+CI,x+1,y+CI) > segments(x-hseg,y-CI,x+hseg,y-CI) > segments(x-hseg,y+CI,x+hseg,y+CI)I would put this in a function if you want to repear the process. -----Original Message----- From: Shravan Vasishth [mailto:vasishth at ling.ohio-state.edu] Sent: 30 November, 2001 1:07 AM To: r-help at stat.math.ethz.ch Subject: [R] plotting (a) confidence intervals (b) standard error Hi all, I'm building a plot of the values in tmeant (below) against positions 1 to 5, using matplot. tmeant looks like this: case1 case2 pos1 861.8466 818.5909 pos2 961.2841 976.3466 pos3 878.6080 1262.8523 pos4 950.8011 1129.6080 pos5 968.1080 1063.3920 I also have lower (object tl) and upper (object tu) bounds on the confidence intervals as follows: tl: pos1 pos2 pos3 pos4 pos5 case1 761.4777 872.8367 756.7253 806.7503 849.9667 case2 735.1803 878.2557 1058.0583 991.7346 895.0864 tu: pos1 pos2 pos3 pos4 pos5 case1 962.2155 1049.731 1000.491 1094.852 1086.249 case2 902.0015 1074.437 1467.646 1267.481 1231.698 My R code is given towards the end of this message; it plots the values in tmeantmatrix against positions 1-5, and puts the confidence interval (CI) bars at the right points using tl and tu. However, I can't figure out how to get the CI bars to have those delimiters (a shape like "I"), all I get is a straight line through the relevant point. A related question is: I also have standard errors in a matrix called tse: pos1 pos2 pos3 pos4 pos5 case1 49.76907 43.85765 60.4369 71.42927 58.58170 case2 41.36010 48.63950 101.5495 68.36609 83.45631 Is there some way to plot these (instead of CI bars) without having to first compute lower and upper bounds (i.e., without having to specify x0, y0, and x1, y1 in "segments") for each standard error? I guess this would amount to having a way to refer to each point already plotted, and saying something like: take each point as the dimension of an error bar, and put it at the relevant point (I'm thinking of something like gnuplot, which has a nice semantics for this: if you give it three columns to plot and specify that you want error bars, it will use the third column as the dimensions of the error bars). #----------------The code for the graph with CI bars------------------------ tmeantmatrix<- matrix(tmeant,ncol=2) # make tmeant a 2-column matrix # plot using matplot: matplot(c(1:5), tmeantmatrix, xlab = "Position", ylab = "Mean Reading Time (msecs)", main = "Test") # add lines connecting the points: matplot(tmeantmatrix, pch = 1:2, type = "o", lty=1:2, lwd=3, col rainbow(ncol(tmeantmatrix)),add=TRUE) # add CI bars: xzero <- t(matrix(rep(1:5,2),ncol=2)) xone <- xzero segments(x0=xzero, y0=tl, x1=xone, y1=tu) #-------------------end of code------------------------------ Many thanks in advance, -- Shravan Vasishth Dept. of Linguistics, OSU 222 Oxley Hall, 1712 Neil Ave. Columbus, OH 43210-1298 USA URL: http://ling.ohio-state.edu/~vasishth -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. -.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._. _._ -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._