The simplest solution would be to just paste the code as plain text, which will look like this:
x <- rnorm(100, mean = 2, sd = 3)
plot(x, xlab = “index”, main = “Example code”)
But if you would like to help our readers orient themselves inside your code by giving different colors to different commands in the code (a.k.a: syntax highlighting). So it would like something like this:
x <-rnorm(100, mean=2, sd=3)# Creating a vectorplot(x, xlab ="index", main ="Example code")# Plotting it
WP-Syntax provides clean syntax highlighting using GeSHi — supporting a wide range of popular languages (including R). It supports highlighting with or without line numbers and maintains formatting while copying snippets of code from the browser.
But there is a problem. The current WP-Syntax version is using an old version of GeSHi, and only the newer version (currently GeSHi version 126.96.36.199) includes support for R syntax. In order to solve this I patched the plugin and I encourage you to download (the fixed version of) WP-Syntax from here, which will allow you to highlight your R code.
After installing (and activating) the plugin, in order to add R code to your post you will need to:
1) Only work in HTML mode (not the Visual mode). Or else, the code you will paste will be messed up.
2) Put your code between the <pre> tag, like this:
(Note: make sure that you rewrite the ” – so it will work.)
<pre lang=”rsplus” line=”1″>
…Your R code here…
Final note: R Syntax highlight in other ways
If you wish to have R syntax higlight inside an HTML file, I encourage you can have a look at the highlight package, by Romain Francois.
If you want to higlight your R syntax inside wordpress.com, here is a blog post by Erik Iverson showing how to do that using Emacs.
p.s: If you have a blog in which you write about R, please let me know about it in the comments (Or just join R-bloggers.com) – I’d love to follow you 🙂
About half a year ago, I was studying various statistical methods to employ on contingency tables. I came across a promising method for 2×2 contingency tables called “Barnard’s exact test“. Barnard’s test is a non-parametric alternative to Fisher’s exact test which can be more powerful (for 2×2 tables) but is also more time-consuming to compute (References can be found in the Wikipedia article on the subject).
When comparing Fisher’s and Barnard’s exact tests, the loss of power due to the greater discreteness of the Fisher statistic is somewhat offset by the requirement that Barnard’s exact test must maximize over all possible p-values, by choice of the nuisance parameter, π. For 2 × 2 tables the loss of power due to the discreteness dominates over the loss of power due to the maximization, resulting in greater power for Barnard’s exact test. But as the number of rows and columns of the observed table increase, the maximizing factor will tend to dominate, and Fisher’s exact test will achieve greater power than Barnard’s.
About the R implementation of Barnard’s exact test
After finding about Barnard’s test I was sad to discover that (at the time) there had been no R implementation of it. But last week, I received a surprising e-mail with good news. The sender, Peter Calhoun, currently a graduate student at the University of Florida, had implemented the algorithm in R. Peter had found my posting on the R mailing list (from almost half a year ago) and was so kind as to share with me (and the rest of the R community) his R code for computing Barnard’s exact test. Here is some of what Peter wrote to me about his code:
On a side note, I believe there are more efficient codes than this one. For example, I’ve seen codes in Matlab that run faster and display nicer-looking graphs. However, this code will still provide accurate results and a plot that gives the p-value based on the nuisance parameter. I did not come up with the idea of this code, I simply translated Matlab code into R, occasionally using different methods to get the same result. The code was translated from:
Trujillo-Ortiz, A., R. Hernandez-Walls, A. Castro-Perez, L. Rodriguez-Cardozo. Probability Test. A MATLAB file. URL
My goal was to make this test accessible to everyone. Although there are many ways to run this test through Matlab, I hadn’t seen any code to implement this test in R. I hope it is useful for you, and if you have any questions or ways to improve this code, please contact me at [email protected]
As a statistics (and WordPress) lover myself, I was inspired to extend the list of wordpress statistics plugins for the hope of benefiting the community: Blog Metrics
This plugin is based on ideas in an excellent post by Avinash Kaushik (Whom I consider a Web analytics guru and a brilliant blogger!).
Raw Author Contribution:
average number of posts per month
average number of words per post
average number of comments per postwithout your own comments
average number of words used in comments to posts
Both for all the time you’ve been blogging, and for the last month, it then adds these values in a page on your WordPress dashboard.
If you have a Search box on your blog, Search Meter automatically records what people are searching for — and whether they are finding what they are looking for. Search Meter’s admin interface shows you what people have been searching for in the last couple of days, and in the last week or month. It also shows you which searches have been unsuccessful. If people search your blog and get no results, they’ll probably go elsewhere. With Search Meter, you’ll be able to find out what people are searching for, and give them what they want by creating new posts on those topics. […]
Google Analytics Dashboard gives you the ability to view your Google Analytics data in your WordPress dashboard. You can also alow other users to see the same dashboard information when they are logged in or embed parts of the data into posts or as part of your theme.
The biggest advantage of this plugin in my view is that it adds sparklines in the “posts -> edit” page in the admin area.
I don’t use this one much. But one feature it has that I find interesting is that is adds information of when you posted something with the trend line of the google analytics traffic data. It also mixes data from MailChimp’s, which I don’t use.
MailChimp’s Analytics360 plugin allows you to pull Google Analytics and MailChimp data directly into your dashboard, so you can access robust analytics tools without leaving WordPress.
This plugin adds a Piwik stats site to your WordPress dashboard. It’s also able to add the Piwik tracking code to your blog. Piwik is an open source (GPL licensed) web analytics software program. It provides you with detailed real time reports on your website visitors: the search engines and keywords they used, the language they speak, your popular pages and so on…
You can install Piwik more or less like you install WordPress, and then you are left to integrate it into your blog. The only real down side of it for me (compared to google analytics) is the advanced segmentation and pivoting. But in general it is a free, great (and growing!) Web analytics solution.
Woopra Analytics Plugin
I have been using Woopra since their release thanks to lorelle. I enjoy the ability to follow the live actions that are happening inside the blog. Although since woopra went from BETA to GOLD, I lost most interest because the total blogs I track have more traffic volume then woopra allow tracking in their free account. But small bloggers could find the service gratifying.
Woopra is the world’s most comprehensive, information rich, easy to use, real-time Web tracking and analysis application.
Live Tracking and Web Statistics
A rich user interface and client monitoring application
Manage Multiple Blogs and Websites
Deep analytic and search capabilities
Visitor and member tagging
Easy Installation and Update Notification
If you are into web analytics, I also encourage you to give the following a try: Nuconomy,ClickTale, Crazy Egg. And of course, Google analytics. Each of them (and also Woopra) strips you and your visitors a bit more from their privacy. But that is the ultimate price we pay for the strong Web analytics solutions that exists out there.
If you got any more statistics plugins I missed, feel encouraged to share them with me in the comments 🙂
Duncan Murdoch just posted a youtube video presenting an animation clip of a 3d rgl object.
Duncan even went further and wrote an explanation on how he made the video:
here are the steps I used:
1. Design a shape to be displayed, and then play with the animation functions to make it change over time. Use play3d to do it live in R, movie3d to write the individual frames of the movie to .png files.
2. Use the ffmpeg package (not an R package, a separate project at http://ffmpeg.org) to convert the .png files to an .mp4 file. The individual frames totalled about 1 GB; the compressed movie is about 45 MB.
3. Upload to Youtube. I’m not a musician, so I had to use one of their licensed background tracks, I couldn’t write my own. I spent a lot of time picking one and then adjusting the timing of the video to compensate. Each render/upload cycle at full resolution took about an hour and a half. It’s a lot faster to render in a smaller window with fewer frames per second, but it’s still tedious. It’s easier to synchronize if you actually have a copy of the music locally, but Youtube doesn’t let you download their music. So the timing isn’t perfect, but it’s good enough for me!
I already wrote about R-bloggers on the R mailing list, so it only seems fitting to write about it more here. I will explain what R-bloggers is and then move to explain what I hope it will accomplish.
R-Bloggers.com is a central hub of content collected from bloggers who write about R (in English) and if you are an R blogger you can join it by filling in this form.
I built the site with the aspiration to help R bloggers and users to connect and follow the “R blogosphere”. When I am writing these words, R-bloggers already has 17 blogs in it, and I hope for many (many) more.
How does R-Bloggers operate? This site aggregates feeds (only with permission!) from participating R blogs. The beginnings of each participating blog’s posts will automatically be displayed on the main page with links to the original posts; inside every post there is a link to the original blog and links to other related articles. While all participating blogs have links in the “Contributors” section of our sidebar
What does R-Bloggers offer it’s visitors?
Discover (for all): Find new R blogs you didn’t know about. And Search in them for content you want.
Follow (for people who don’t use RSS): Enter your e-mail and subscribe to receive a daily digest with teasers of new posts from participating blogs. You will more easily get a sense of hot topics in the R blogosphere.
Connect (for facebook users): Click on “Fan this site” to become a “fan” of R Bloggers. You can then “friend” other people and share thoughts on our wall. Or just by leaving comments on the blog.
Participate (for bloggers): Add your R blog to get increased visibility (for readers and search engines) with permanent links on our Contributors sidebar. Your blog will also gain visibility via our e-mail digest and through your presence on the main page with posts.
Who started R-Bloggers (and way)? R Bloggers was started by Tal Galili (well, me). After searching for numerous R blogs I decided that there must be more R blogs our there then he knows about, and maybe the best way for finding them is to make them find him.
After writing about it in the R mailing list, I got some good feedbacks but also questions about why use only R blogs and not all the R feeds that exist. Who is the website actually for (when there are services like Google reader for us to read our feeds with), and what am I hoping it will do. So here is what I answered:
For me there are two audiences: One is that of the web 2.0 power users. That is, people who know what RSS is and use it, maybe evern write their own blogs. These people have only one problem (as I see it) that R-bloggers tries to solve, and that is to know who else lives in their ecosystem. Who else they should follow.
For that, google reader recommendation system is great, but not enough. A much better system is if there was a one place where all R bloggers would go, write down their website, and all of us would know they exist. That is what R-bloggers offers for the power users. I think this is also why over 20 of them subscribed to the site RSS feed.
BTW, The origin of this idea came to me when I was trying to find all the dance bloggers for my wife (who is a dance researcher and blogger herself). After a while we started http://www.dancebloggers.com/ while knowing of only 10 bloggers. They list now has over 80 bloggers, most of which we would have not known about without this hub.
The same thing I am trying to do for the R community, that is way I hope more R bloggers would write about the service – so their network of readers which includes other R bloggers would add themselves and we will all know about them.
If that was my only purpose, a simple directory would have been enough. But I also have a second one and that is to help the second audience.
The second audience I am thinking of are people of our community who are not so much early adopters (and actually quite late adapters) of the new facilities that the new web (a.k.a: web 2.0) provides.
To them the all RSS thing is too much to look at, and they are used to e-mails. And because of that they are (until now) disconected from many of the R bloggers out there, simply because it is in-efficient for them to go through all these blogs each day (or even week). So for them, to see all the content in one place (and even get an e-mail about it) would be (I hope) a service. I believe that’s why 5 of them (so far) has subscribed via e-mail.
I also hope teachers will direct their students to this as a resource for getting a sense of what people who are using R are doing.
Another thing that hints me about the R community is seeing how the “facebook fan box” is still empty. Which tells me that (sadly) very few R users are actively using facebook as a means for connecting with the outer networks of people out there.
All I wrote also explains why R-bloggers will only take feeds of bloggers and only (as much as can be said) their posts that are centered around R (hence the website name 🙂 ).
It both follows what Gabor talked about – having a site who’s content is only about R. But also what I wish, which is to have “content” in the sense of articles to read (mostly). And not so much things like news feeds of wikipedia or new packages published.
I hope this post will both notify people about this new resource, encourage more R bloggers to join, and will help for future people to better understand what this R-Bloggers thing is all about 🙂
One of the exciting new frontiers for R programming is of creating website interfaces to R code. At the forefront of this domain is a young and (very) bright man called Jeroen Ooms, whom I had the pleasure of meeting at useR 2009 (press the link to see his presentation).
New features include 1D geom’s (histogram, density, freqpoly), syntax mode (by clicking the tiny arrow at the bottom), and some additional facet options. And some minor improvements and fixes, most notably for Internet Explorer.
The data upload has not been improved yet, I am working on that. For now, it supports .csv, .sav (spss), and tab delimited data. Please make sure your filename has the appropriate extension and every column has a header in your data. If you export a dataframe from R, use:
write.csv(mydf, ”mydf.csv” , row.names=F). If you upload an spss
datafile, none of this should be a concern.
Supported browsers are IE6-8, FF, Safari, and Chrome, but a recent browser is highly recommended. As always, feedback is more than welcome.
Here is a little demo video that shows how to use the new features:
This post will eventually grow to hold a wide list of books on statistics (e-books, pdf books and so on) that are available for free download. But for now we’ll start off with just one several books:
The Elements of Statistical Learning written by Trevor Hastie, Robert Tibshirani and Jerome Friedman. you can legally download a copy of the book in pdf format from the authors website! Direct download (First discovered on the “one R tip a day” blog)
Introduction to Statistical Thought by Michael Lavine. The book is organized into seven chapters: “Probability,” “Modes of Inference,” “Regression,” “More Probability,” “Special Distributions,” “More Models,” and “Mathematical Statistics.” and makes extensive use of R. Here is a favoring review the book received in JASA. 328 pages. Download link (approx. 40 mbyte)
Using R for Introductory Statistics by John Verzani Publisher: Chapman & Hall/CRC 2004 ISBN/ASIN: 1584884509 ISBN-13: 9781584884507 Number of pages: 114 Description: The author presents a self-contained treatment of statistical topics and the intricacies of the R software. The book treats exploratory data analysis with more attention than is typical, includes a chapter on simulation, and provides a unified approach to linear models. This text lays the foundation for further study and development in statistics using R. Download link
R Graphics (Three chapters only) by Paul Murrell ISBN: 9781584884866 ISBN 10: 158488486X Publication Date: July 29, 2005 Number of Pages: 328 Description: Chapter 1: An Introduction to R Graphics Chapter 4: Trellis Graphics: The Lattice Package Chapter 5: The Grid Graphics Model Download link (see scripts and images here)
Psychometric Theory with Applications in R by William Revelle (a work in progress) Download link
A great long list of R related texts, for free download, can be found here.
Using Graphs Instead of Tableswebsite link (This web page accompanies the article “Using Graphs Instead of Tables in Political Science”, by Jonathan Kastellec and Eduardo Leoni, which appears in the December 2007 issue of Perspectives on Politics. It contains complete replication code for all the graphs that appear in the text)
Today I noticed a call for R users to gather around a single campfire for one hour and share their questions and answers.
The campfire name is stackoverflow.com, a site dedicated for handling programming questions. The event details are bellow:
From: The R Flashmob Project
Subject: R Flashmob #2
You are invited to take part in R Flashmob, the project that makes the
world a better place by posting helpful questions and answers about the
R statistical language to the programmer’s Q & A site stackoverflow.com
Please forward this to other people you know who might like to join.
Q. Why would I want to join an inexplicable R mob?
A. Tons of other people are doing it.
Q. Why else?
A. Stackoverflow was built specifically for handling programming questions.
It’s a better mousetrap. It offers search (and is well indexed by search engines),
tagging, voting, the ability to choose the “best” answer to a question, and the ability to
edit questions and answers as technology progresses. It has a karma system to
reward people who are happy to help and discourage MLJs (mailing list jerks).
Q. Do the organizers of this MOB have any commercial interest in stackoverflow?
A. None at all. We’re just convinced it is the best way to help and promote R. All
the content submitted to stackoverflow is protected by a Creative Commons
CC-Wiki License, meaning anyone is free to copy, distribute, transmit, and
remix the information on stackoverflow. All the content on stackoverflow is
regularly made available for download by the public.
INSTRUCTIONS – R MOB #2
Start Date: Tuesday, September 8th, 2009
10:04 AM – US Pacific
11:04 AM – US Mountain
12:04 PM – US Central
1:04 PM – US Eastern
6:04 PM – UK
7:04 PM – Continental W. Europe
5:04 AM (Weds) – New Zealand (birthplace of R)
Duration: 50 minutes
(1) At some point during the day on September 8th, synchronize your watch to
(2) The mob should form at precisely 4 minutes past the hour and not beforehand.
(3) At 4 minutes past the hour, you should arrive at stackoverflow.com, log in,
and post 3 R questions. Be sure to tag the questions “R”. See the posting
guidelines at http://stackoverflow.com/faq to understand what makes a good
(4) Follow R Flashmob updates at http://twitter.com/rstatsmob
(5) Post twitter messages tagged #rstats and #rstatsmob during the mob,
providing links to your questions.
(6) During the R MOB, you can chat with other participants on the #R channel
on IRC (freenode). To do this, install the Chatzilla extension on Firefox.
Click “freenode” on the main screen. Then type /join #R in the field at the
bottom of the screen. Then chat.
(7) If you finish posting your three questions within the 50 minutes, stick
around to answer questions and give “up votes” to good questions and answers.
(8) IMPORTANT: After posting, sign the R Flashmob guestbook at
(9) Return to what you would otherwise have been doing. Await
instructions for R MOB #3.
This invitation already gained exposure from 3 blogs: