tag:blogger.com,1999:blog-684119683005319088.post1330680611979165909..comments2021-03-01T07:37:17.793-08:00Comments on Bayes Ball: Fair weather fans? (An R scatter plot matrix)Martin Monkmanhttp://www.blogger.com/profile/05582544453619381290noreply@blogger.comBlogger3125tag:blogger.com,1999:blog-684119683005319088.post-17070575807554277692013-08-19T06:57:10.740-07:002013-08-19T06:57:10.740-07:00Martin, this infographic about predicting baseball...Martin, this infographic about predicting baseball may interest you. Feel free to share on your blog. The graphic is titled Predicting Baseball: Demystifying Bayes' Theorem. http://www.sports-management-degrees.com/baseball/Pamhttps://www.blogger.com/profile/08038925571562350698noreply@blogger.comtag:blogger.com,1999:blog-684119683005319088.post-20724904616771848082013-07-21T06:46:00.835-07:002013-07-21T06:46:00.835-07:00r2evans, thanks for this ... much appreciated.
I&...r2evans, thanks for this ... much appreciated.<br /><br />I've taken the liberty of including your code into the gist for this blog post, which is now here:<br />https://gist.github.com/MonkmanMH/6048590Martin Monkmanhttps://www.blogger.com/profile/05582544453619381290noreply@blogger.comtag:blogger.com,1999:blog-684119683005319088.post-74599146636617192672013-07-19T10:10:04.854-07:002013-07-19T10:10:04.854-07:00I've been using similar plots recently, and ad...I've been using similar plots recently, and adapted panel.cor() to include Spearman's non-parametric test and the number of non-NA samples for each pair-wise comparison. The variably-sized text is good (and I use it periodically), but I chose against it in this adapted version since I was stacking more information.<br /><br />Additionally, since several of the datasets I've been depicting contain lots of samples, I opt to jitter() them and/or use a color of "#00000055" for transparency, as it makes coincident data points much more apparent.<br /><br />I like this kind of visualization technique. Thanks!<br /><br />panel.cor <- function(x, y, digits=3, ..., text.cex, text.col='black') {<br /> par(usr = c(0, 1, 0, 1))<br /> numsamples <- sum(! is.na(x) & ! is.na(y))<br /> r <- cor(x, y, use='complete.obs')<br /> spearman <- cor.test(x, y, method='spearman', continuity=TRUE, exact=FALSE)<br /><br /> if (require(RColorBrewer, quietly=TRUE)) {<br /> colbrew <- 'YlOrRd' ## 9 available colors<br /> ndiv <- 5 ## can be up to 9+1=10 since first cut has no color<br /> colors <- c(NA, brewer.pal(ndiv-1, 'YlOrRd'))<br /> } else {<br /> ## if RColorBrewer is not available, need to define 'colors' manually<br /> ndiv <- 4<br /> colors <- c(NA, 'yellow', 'orange', 'red') ## for ndiv=4<br /> }<br /> ## Could use c(0:ndiv/ndiv), but cut() looks at (0,0.2] so a<br /> ## p-value of 0, though highly unlikely, would break things.<br /> ## Using anything less than 0 side-steps this problem.<br /> cuts <- c(-1, 1:ndiv/ndiv)<br /> if (spearman$p.value <= 0.05)<br /> polygon( c(-2,2,2,-2,-2), c(-2,-2,2,2,-2),<br /> col=colors[ cut(abs(r), breaks=cuts, labels=FALSE) ])<br /> mindig <- max(0.001, 1/10^digits)<br /> if (spearman$p.value < mindig) {<br /> spearman$p.value <- mindig<br /> leq <- '<'<br /> } else leq <- '='<br /> ## Can "arbitrarily" add other info to this list for stacked display.<br /> labels <- list(sprintf('n = %d', numsamples),<br /> sprintf(paste0('%0.', digits, 'f'), r),<br /> sprintf(paste0('p %s %0.', digits, 'f'), leq, spearman$p.value))<br /> nn <- length(labels)<br /> ## Ensure the text isn't too big for the square in height or width.<br /> ## 0.9 is just a factor to give a little bit of buffer.<br /> if (missing(text.cex))<br /> text.cex <- min(0.9/((nn+1) * strheight(labels[[1]]) * 1.3),<br /> 0.9/max(strwidth(labels)))<br /> text(0.5, (nn:1)/(nn+1), labels, cex=text.cex, col=text.col, adj=0.5)<br />}r2evanshttps://www.blogger.com/profile/14241809734844683570noreply@blogger.com