[R] using latticeExtra plotting confidence intervals

Deepayan Sarkar deepayan.sarkar at gmail.com
Mon Jun 14 07:15:10 CEST 2010


On Sun, Jun 13, 2010 at 10:10 AM, Joe P King <jp at joepking.com> wrote:
> I am wanting to plot a 95% confidence band using segplot, yet I am wanting
> to have groups. For example if I have males and females, and then I have
> them in different races, I want the racial groups in different panels. I
> have this minor code, completely made up but gets at what I am wanting, 4
> random samples and 4 samples of confidence, I know how to get A & B into one
> panel and C&D in to another but how do I get the x axis to label them
> properly and have it categorized as two. I am not sure what to have to the
> left side of the formula. This is the example code:

(1) Your code results in

> length(categories)
[1] 2
> length(mu)
[1] 4

which makes the formula mu~ci.upper+ci.lower|categories meaningless.

(2) You are effectively plotting xyplot(mu ~ mu | categories), with
additional confidence intervals in one direction. I'm sure that's not
what you want, but it's not clear what it is that you do actually
want.

-Deepayan



>
>
>
> library(lattice)
>
> library(latticeExtra)
>
>
>
> sample1<-rnorm(100,10,2)
>
> sample2<-rnorm(100,50,3)
>
> sample3<-rnorm(100,20,2)
>
> sample4<-rnorm(100,40,1)
>
> mu1<-mean(sample1)
>
> ci.upper1<-mu1+2*2
>
> ci.lower1<-mu1-2*2
>
> mu2<-mean(sample2)
>
> ci.upper2<-mu2+2*3
>
> ci.lower2<-mu2-2*3
>
> mu3<-mean(sample3)
>
> ci.upper3<-mu3+2*2
>
> ci.lower3<-mu3-2*2
>
> mu4<-mean(sample4)
>
> ci.upper4<-mu4+2*1
>
> ci.lower4<-mu4-2*1
>
> categories<-c("A","B")
>
>
>
> mu<-cbind(mu1,mu2,mu3,mu4)
>
> ci.upper<-cbind(ci.upper1,ci.upper2,ci.upper3,ci.upper4)
>
> ci.lower<-cbind(ci.lower1,ci.lower2,ci.lower3,ci.lower4)
>
> segplot(mu~ci.upper+ci.lower|categories, centers = mu, horizontal=FALSE)
>
>
>
> I also tried this
>
>
>
> seq1<-seq(1,4,1)
>
> segplot(seq1~ci.upper+ci.lower|categories, centers = mu,horizontal=FALSE)
>
>
>
> but it also gives poor x axis, I know this is probably an elementary problem
> but any help would be greatly appreciated.
>
>
>
> Heres my data structure, sorry for bombarding with all the code.
>
>
>
> structure(c(9.85647167881417, 50.1856561919426, 19.8477661576365,
>
> 39.8575819498655, 13.8564716788142, 56.1856561919426, 23.8477661576365,
>
> 41.8575819498655, 5.85647167881417, 44.1856561919426, 15.8477661576365,
>
> 37.8575819498655), .Dim = c(1L, 12L), .Dimnames = list(NULL,
>
>    c("mu1", "mu2", "mu3", "mu4", "ci.upper1", "ci.upper2", "ci.upper3",
>
>    "ci.upper4", "ci.lower1", "ci.lower2", "ci.lower3", "ci.lower4"
>
>    )))
>
> -------------------------------------------
>
> Joe King, M.A.
>
> Ph.D. Student
>
> University of Washington - Seattle
>
> Office: 404A
>
> Miller Hall
>
> 206-913-2912
>
>  <mailto:jp at joepking.com> jp at joepking.com
>
> -------------------------------------------
>
> "Never throughout history has a man who lived a life of ease left a name
> worth remembering." --Theodore Roosevelt
>
>
>
>
>        [[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.
>



More information about the R-help mailing list