[R-lang] Plotting CI from Mixed Effects Model

Austin F. Frank afrank at bcs.rochester.edu
Fri Sep 21 11:56:48 PDT 2007


Corey--

Your logic for calculating the estimated value for each cell in your
design looks right to me.  I believe that treating the HPD confidence
intervals in the same way is correct.

While it's not exactly what you're looking for, I thought I'd provide
some related code for plotting pvals.fnc-based confidence intervals
around parameter estimates.  These functions just plot each contrast
individually rather than combining them as you're attempting to do.
Still, I hope these will be useful to someone on the list.

If anyone has cleaner code or prettier plots to show off, I know I'd
appreciate seeing them.

Thanks,
/au



For this plot, you'll need to have the Design package loaded to use the
Dotplot and Cbind functions.

  a.lat.p <- pvals.fnc(a.lat.l, withMCMC=TRUE)
  a.lat.fixed <- a.lat.p$fixed

  a.lat.lowers <- as.numeric(a.lat.fixed[2:10, 3])
  a.lat.uppers <- as.numeric(a.lat.fixed[2:10, 4])
  a.lat.names <- labels(a.lat.fixed)[[1]][2:10]

  factors <- as.factor(a.lat.names)
  Dotplot(factors ~ Cbind(a.lat.estimates, a.lat.lowers, a.lat.uppers),
          data = a.lat.p$fixed,
          ylab = NULL, xlab = "change in latency (ms)",
          panel = function (x, y, ...) {
            panel.Dotplot(x,y, ...)
            panel.abline(v=0)
          })
  dev.off()

And here's some code for more traditional bar plots, again based on
pvals.fnc.

  lat.p <- pvals.fnc(lat.m, withMCMC=TRUE)

  lat.estimates <- as.numeric(as.matrix(lat.p$fixed[2:4, 2]))
  lat.lowers <- as.numeric(lat.p$fixed[2:4, 3])
  lat.uppers <- as.numeric(lat.p$fixed[2:4, 4])
  
  lat.param.plot <- barplot(lat.estimates,
    beside=TRUE,
    ylim=c(min(lat.lowers)-1, max(lat.uppers)+1),
    ylab="Change in latency (ms)")
  
  segments(x0=lat.param.plot,
           x1=lat.param.plot,
           y0=lat.lowers,
           y1=lat.uppers)
           
  segments(x0=lat.param.plot-.1,
           x1=lat.param.plot+.1,
           y0=lat.lowers,
           y1=lat.lowers)
           
  segments(x0=lat.param.plot-.1,
           x1=lat.param.plot+.1,
           y0=lat.uppers,
           y1=lat.uppers)
           
  abline(0,0)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 185 bytes
Desc: not available
Url : http://pidgin.ucsd.edu/pipermail/r-lang/attachments/20070921/c879070a/attachment.pgp 


More information about the R-lang mailing list