3

If you remember there is a nice version of table conceived by Tufte that include small quartile plots running next to the corresponding data rows:

enter image description here

There is an implementation of such solution in R using package NMOF and function qTable, which basically creates the table shown above and outputs it as a LaTeX code:

require(NMOF)
x <- rnorm(100, mean = 0, sd = 2)
y <- rnorm(100, mean = 1, sd = 2)
z <- rnorm(100, mean = 1, sd = 0.5)
X <- cbind(x, y, z)
qTable(X,filename="res.tex")#this will save qTable in tex format in current dir

This method of visualization seem to be especially useful if you have a small amount of information to present, and you don't want to waste a space for the full graph. But I would like to hack qTable a bit. Instead of displaying quantile plots, I would prefer to display standard errors of the mean. I am not great in hacking such functions, and I used brute force to do it. I replaced the line from the qTable function which computes quantiles:

A <- apply(X, 2L, quantile, c(0.25, 0.5, 0.75))

with something very brutal, that computes standard errors:

require(psych)#got 'SE' function to compute columns standard deviation     
M = colMeans(X)#column means
SE = SD(X)/sqrt(nrow(X))#standard error
SELo = M-SE#lower bound
SEHi = M+SE#upper bound
A = t(data.frame(SELo,M,SEHi))#combines it together

I know, I know it's possibly unsustainable approach, but it actually works to some extend - it plots standard errors but keeps this gap in the plot:

enter image description here

and I would like this gap to disappear.

Here is a qTable function with modification discussed above.

4

1 回答 1

3

要消除间隙,您可以插入以下两行:

B[2, ] <- B[3, ]
B[4, ] <- B[3, ]

就在for开始的循环之前

for (cc in 1L:dim(X)[2L]) {...

为什么它有效?从左到右读图,五行B对应where

1) the left segments start
2) the left segments ends
3) the dots are
4) the right segments start
5) the right segments end

所以通过强迫B[2, ]和你有效B[4, ]B[3, ]摆脱了差距。

于 2012-07-12T01:45:30.627 回答