[R] plotting (a) confidence intervals (b) standard error
Toby.Patterson@csiro.au
Toby.Patterson at csiro.au
Fri Nov 30 00:24:34 CET 2001
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list