Fast-track publishing using knitr: stitching it together (part V)

Putting all the pieces together can be challenging both for surgeons and researchers. The image is CC by Zac Peckler

Putting all the pieces together can be challenging both for surgeons and researchers. The image is CC by Zac Peckler

Fast-track publishing using knitr is a short series on how I use knitr to speedup publishing in my research. There has been plenty of feedback and interest for the series, and in this post I would like to provide (1) a brief summary and (2) an example showing how to put all the pieces together. Continue reading

Fast-track publishing using knitr: table mania (part IV)

Constructing tables is an art - maximizing readability and information can be challenging. The image is of the Turning Torso in Malmö and is CC by Alan Lam.

Constructing tables is an art – maximizing readability and information can be challenging. The image is of the Turning Torso in Malmö and is CC by Alan Lam.

Fast-track publishing using knitr is a short series on how I use knitr to speedup publishing in my research. While illustrations (previous post) are optional, tables are not, and this fourth article is therefore devoted to tables. Tables through knitr is probably one of the most powerful fast-track publishing tools, in this article I will show (1) how to quickly generate a descriptive table, (2) how to convert your regression model into a table, and (3) worth knowing about table design and anatomy. Continue reading

Fast-track publishing using knitr: exporting images for sharing and press (part III)

Images can be a powerful medium if used right. The photo is CC by alemdag.

Images can be a powerful medium if used right. The image is CC by alemdag.

Fast-track publishing using knitr is a short series on how I use knitr to speedup publishing in my research. This is the third article in the series devoted to plots. Hopefully you will through this post have the need-to-know stuff so that you can (1) add auto-numbering to your figures, (2) decide on image formats, (3) choose image resolution, and (4) get anti-aliasing working. Continue reading

Fast-track publishing using knitr: the setup using .RProfile with custom CSS + some HTML goodies (part II)

Flexing RStudio/knitr where you want can be a challenge. The image is CC by Ben Barnes.

Flexing RStudio/knitr where you want can be a challenge. The image is CC by Ben Barnes.

Fast-track publishing using knitr is a short is a short series on how I use knitr to get my articles faster published. This is part II where I will show how you can tweak RStudio into producing seamless MS Word-integration by using the .RProfile together with CSS, a few basics about HTML that might be good to know, and lastly some special characters that can be useful. In the previous post, part I, I explained some of the more general concepts behind fast-track publishing and why I try to get my manuscript into MS Word instead of using LaTeX or other alternatives. Continue reading

The forestplot of dreams

A forestplot that compares Swedish and Danish EQ-5D outcome predictors

A forestplot that compares Swedish and Danish EQ-5D outcome predictors generated with the forestplot2()-function in the Gmisc-package

Displaying large regression models without overwhelming the reader can be challenging. I believe that forestplots are amazingly well suited for this. The plot gives a quick understanding of the estimates position in comparison to other estimates, while also showcasing the uncertainty. This project started with some minor tweaks to prof. Thomas Lumleys forestplot and ended up in a complete remake of the function. In this post I’ll show you how to tame the plot using data from my latest article. Continue reading

Too crude to be true?

Harvesting the magical update() function. The image is CC by Waldemar Horwat.

Harvesting the magical update() function. The image is CC by Waldemar Horwat.

The key to programming is being lazy; it has actually been called a virtue by some. When I discovered the update() function it blew me away. Within short I had created a monster based upon this tiny function, allowing quick and easy output of regression tables that contain crude and adjusted estimates. In this post I’ll show you how to tame the printCrudeAndAdjusted() function in my Greg-package and show a little behind the scenes. Continue reading

Visualizing transitions with the transitionPlot function

A transition between states - the above is a imaginary plot of before and after surgery, where I've highlighted the large proportion that doesn't improve in the moderate group.

A transition between states – the above is a simulation of before and after surgery where I’ve highlighted the large proportion that doesn’t improve in the moderate group.

As an orthopaedic surgeon I’m often interested in how a patient is doing after surgery compared to before. I call this as a transition between states, e.g. severe pain to moderate pain, and in order to better illustrate these transitions I’ve created something that I call a transition plot. It’s closely related to the plotMat for plotting networks but aimed at less complex relations with only a one-way relation between two groups of states.

This project started by me posting a question on Stack Overflow, the answers were (as always) excellent, but didn’t really satisfy my needs. What I wanted was a graphically appealing plot that I could control in extreme detail. Thanks to Paul Murrell’s excellent grid package I was able to generate a truly customizeable transition plot.

In this post I’ll give a short introduction with examples to what you can do with the transitionPlot()-function. I’ll try to walk you through simple transitions to more complex ones with group proportions and highlighted arrows. Continue reading

Chocolate and the Nobel Prize – a true story?

Chocolate - a close up picture

Few of us can resist chocolate, but the real question is: should we even try to resist it? The image is CC by Tasumi1968.

As a dark chocolate addict I was relieved to see Messerli’s ecological study on chocolate consumption and the relation to the Nobel prize. By scraping various on-line sources he made a robust case for that increased chocolate consumption correlates to the number of Nobel prizes. Combined with that it might have positive impact on blood pressure, the evidence is strong enough for me to avoid changing any habits, at least over Christmas 🙂

Tutorial: Scraping the chocolate data with R

Inspired by Messerli’s article I decided to look into how to repeat the analysis in R. Continue reading

Getting started with Sweave & knitr

Cool woven artwork on the campus of Kansas University. The image is CC by http://www.flickr.com/photos/kansasphoto/4682126666/

Cool woven artwork on the campus of Kansas University. The image is CC by Patrick Emerson

I recently started to work with Sweave (by Friedrich Leisch) and found it a truly awesome package. The ease of use is amazing. In this post I’ll try to get you started with first Sweave and then the knitr (by Yihui Xie). The knitr package is a more advanced version of Sweave, update: Start with knitr as it’s really well integrated into RStudio and is more actively developed.

Reasons for learning LaTeX & Sweave/knitr:

  • You can export formatted tables (ready for publication)
  • You connect the results with the actual calculations, minimizing risk of “copy->paste” errors
  • The code is “automatically documented” as you explain the results in the text
  • You can easily re-run the report on a new dataset

Now lets get started… Continue reading

Creating nice flow diagrams

My favorite tool for creating flow diagram is Dia – it’s easy and open source. It’s homepage is not that impressive but the Facebook group seems to be pretty active. There you can also find that downloads increased by 23 % in 2011 to 1.4 million downloads.

In this tutorial I want to show you how easy you can create a great looking flow diagram like the one CONSORT recommends for publication of RCT:s. Continue reading