code

Doing Bayesian Data Analysis now in JAGS

January 3, 2012 | Luis

Around Christmas time I presented my first impressions of Kruschke’s Doing Bayesian Data Analysis. This is a very nice book but one of its drawbacks was that part of the code used BUGS, which left mac users like me stuck. … Continue reading → [Read more...]

R pitfall #3: friggin’ factors

December 15, 2011 | Luis

I received an email from one of my students expressing deep frustation with a seemingly simple problem. He had a factor containing names of potato lines and wanted to set some levels to NA. Using simple letters as example names … Continue reading → [Read more...]

Lattice when modeling, ggplot when publishing

October 17, 2011 | Luis

When working in research projects I tend to fit several, sometimes quite a few, alternative models. This model fitting is informed by theoretical considerations (e.g. quantitative genetics, experimental design we used, our understanding of the process under study, etc.) but … Continue reading → [Read more...]

Setting plots side by side

October 11, 2011 | Luis

This is simple example code to display side-by-side lattice plots or ggplot2 plots, using the mtcars dataset that comes with any R installation. We will display a scatterplot of miles per US gallon (mpg) on car weight (wt) next to … Continue reading → [Read more...]

Upgrading R (and packages)

October 10, 2011 | Luis

I tend not to upgrade R very often—running from 6 months to 1 year behind in version numbers—because I had to reinstall all packages: a real pain. A quick search shows that people have managed to come up with good … Continue reading → [Read more...]

Reading HTML pages in R for text processing

October 10, 2011 | Luis

We were talking with one of my colleagues about doing some text analysis—that, by the way, I have never done before—for which the first issue is to get text in R. Not any text, but files that can be accessed … Continue reading → [Read more...]

Operating on datasets inside a function

October 9, 2011 | Luis

There are times when we need to write a function that makes changes to a generic data frame that is passed as an argument. Let’s say, for example, that we want to write a function that converts to factor any … Continue reading → [Read more...]

A brief idea of style

October 8, 2011 | Luis

Once one starts writing more R code the need for consistency increases, as it facilitates managing larger projects and their maintenance. There are several style guides or suggestions for R; for example, Andrew Gelman’s, Hadley Wickham’s, Bioconductor’s and this one. … Continue reading → [Read more...]

All combinations for levelplot

October 7, 2011 | Luis

In a previous post I explained how to create all possible combinations of the levels of two factors using expand.grid(). Another use for this function is to create a regular grid for two variables to create a levelplot or a … Continue reading → [Read more...]

Linear regression with correlated data

October 5, 2011 | Luis

I started following the debate on differential minimum wage for youth (15-19 year old) and adults in New Zealand. Eric Crampton has written a nice series of blog posts, making the data from Statistics New Zealand available. I will use … Continue reading → [Read more...]

Quick labels within figures

August 26, 2011 | Karl Broman

One of the coolest R packages I heard about at the useR! Conference: Toby Dylan Hocking‘s directlabels package for putting labels directly next to the relevant curves or point clouds in a figure. I think I first learned about this idea from Andrew Gelman: that a separate legend requires ... [Read more...]

The stupidest R code ever

August 17, 2011 | Karl Broman

Let’s start this blog off right, with the stupidest R mistake I’ve ever made (I think). In the R package that I write, R/qtl, one of the main file formats is a comma-delimited file, where the blank cells in the second row are important, as they distinguish ... [Read more...]

How to upgrade R on windows 7

April 15, 2011 | Tal Galili

Background – time to upgrade to R 2.13.0 The news of the new release of R 2.13.0 is out, and the R blogosphere is buzzing. Bloggers posting excitedly about the new R compiler package that brings with it the hope to speed up our R code with up to 4 times improvement. So it ... [Read more...]

Code: extended model support for mtable

March 22, 2011 | Jason

I finally got around to organizing and packaging my complete set of extended model support for mtable in Martin Elff’s memisc library. Here is a list of the models supported: coxph, survreg – Cox proportional hazards models and parametric survival … Continue reading → [Read more...]

Code: LaTeX tables for lme4 models

March 13, 2011 | Jason

I have recently discovered memisc, an extremely useful R package by Martin Elff (see his memisc page here). The package contains any number of useful functions, and is particularly good at helping one manage and recode survey data. However, by far my … Continue reading → [Read more...]

Code: parsing Slovenian exchange rate data

January 30, 2011 | Jason

Some time ago I found myself in need of daily exchange rates for the Slovenian Tolar (though I can’t now remember why). Unfortunately, I wasn’t able to find the data in a readily usable format at the Bank of Slovenia … Continue reading → [Read more...]
1 2 3

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)