User Tools

Site Tools


r-credplot

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

r-credplot [2013/03/19 15:55]
matt fixed naming error
r-credplot [2017/09/24 18:39]
Line 1: Line 1:
-======Credible Interval Plot====== 
-A type of forest plot for credible (and other) intervals 
-=====Code===== 
-<code c> 
-# credplot - a type of forest plot 
-# for credible (and other) intervals ​ 
-# m   - estimates 
-# mlo - lower bound 
-# mhi - upper bound 
-# cen - if(!is.na(cen)) abline(v=cen) 
  
-credplot <- 
-function (m, mlo, mhi, cen = NA, ...)  
-{ 
-    require(lattice) 
-    if(is.null(names(m))) 
-        names(m) <- as.character(1:​length(m)) 
-    rge <- range(c(mlo,​ mhi)) 
-    rge[1] <- rge[1] - 0.05 * diff(rge) 
-    rge[2] <- rge[2] + 0.05 * diff(rge) 
-    dotplot(m, mlo = mlo, mhi = mhi, cen = cen, xlim = rge, ...,  
-        panel = function(x, y, mlo = mlo, mhi = mhi, cen = cen,  
-            horizontal, levels.fos, ...) { 
-            if (missing(levels.fos)) { 
-                if (horizontal) ​ 
-                    levels.fos <- unique(y) 
-                else  
-                    levels.fos <- unique(x) 
-            } 
-            if (horizontal) ​ 
-                panel.segments(x0 = mlo, y0 = levels.fos, 
-                  x1 = mhi, y1 = levels.fos) 
-            else  
-                panel.segments(x0 = levels.fos, y0 = mlo,  
-                  x1 = levels.fos, y1 = mhi) 
-            if (!is.na(cen)) { 
-                if (horizontal) ​ 
-                    panel.abline(v = cen, lty = 2) 
-                else  
-                    panel.abline(h = cen, lty = 2) 
-            } 
-            panel.dotplot(x,​ y, horizontal, ​ 
-                    levels.fos = levels.fos, lty=0,...) 
-        }) 
-} 
-</​code>​ 
-=====Example===== 
-The following code generates a plot similar to that below. 
-<code c> 
-m <- rnorm(10, 0, 1/10) 
-mlo <- m - 1/10 
-mhi <- m + 1/10 
-credplot(m, mlo, mhi, cen=0) 
-</​code>​ 
-{{:​credplot.png|credplot.png}} 
r-credplot.txt ยท Last modified: 2017/09/24 18:39 (external edit)