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. Kruschke has now made JAGS code available so I am happy clappy and looking forward… Continue reading Doing Bayesian Data Analysis now in JAGS
Category: code
R pitfall #3: friggin’ factors
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 he was baffled by the result of the following code:
1 2 3 4 5 6 7 8 |
lines = factor(LETTERS) lines # [1] A B C D E F G H... # Levels: A B C D E F G H... linesNA = ifelse(lines %in% c('C', 'G', 'P'), NA, lines) linesNA # [1] 1 2 NA 4 5 6 NA 8... |
The factor has been… Continue reading R pitfall #3: friggin’ factors
Lattice when modeling, ggplot when publishing
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 also by visual inspection of the data. Trellis graphics—where subsets of data are plotted in… Continue reading Lattice when modeling, ggplot when publishing
Setting plots side by side
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 another scatterplot of the same data, but using different colors by number of engine cylinders… Continue reading Setting plots side by side
Upgrading R (and packages)
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 solutions to this problem, as presented in this stackoverflow thread. I used the code in… Continue reading Upgrading R (and packages)