## Plotting contours

March 18, 2008
By

Plenty of packages allow you to plot contours of a "z" value; however, I wanted to be able to plot a specific density contour of a sample from a bivariate distribution over a plot that was a function of the x and y parameters. The example only plots th...

## Plotting contours

March 18, 2008
By

Plenty of packages allow you to plot contours of a "z" value; however, I wanted to be able to plot a specific density contour of a sample from a bivariate distribution over a plot that was a function of the x and y parameters. The example only plots th...

## An Example for Just Another Gibbs Sampler (JAGS)

March 4, 2008
By

JAGS is a cross platform BUGS. Because it runs in a command mode, it is somewhat faster than other BUGS. However, I found it is a bit tacky to use it as a Windows/PC user. I found the manual very useful but some of the language is a bit uncommon to regular users. For instance, compile [,nthins( < n...

## An Example for Just Another Gibbs Sampler (JAGS)

March 4, 2008
By

JAGS is a cross platform BUGS. Because it runs in a command mode, it is somewhat faster than other BUGS. However, I found it is a bit tacky to use it as a Windows/PC user. I found the manual very useful but some of the language is a bit uncommon to regular users. For instance, compile [,nthins( < n...

## Writing Rd files in Vim

March 3, 2008
By

I have made a small “translation” of a portion of “Writing R Extensions” manual about the Rd files to a vimhelp format. You can find it on vim.org, under this link http://www.vim.org/scripts/script.php?script_id=2177. If that does not work just search for a script “rd” there. The script itself is called “rdhelp.txt”.

## Ordered logistic model with varying intercepts (random effects)

March 2, 2008
By

I coauthor a paper with Ozan, a friend who I know when I was TAing Bayesian Methods in ICPSR. The paper tries to see if the 9/11 has any effect on American's attitudes on Muslim. We have dataset from different years: 2 from pre-9/11 periods and 2 from ...

## Ordered logistic model with varying intercepts (random effects)

March 2, 2008
By

I coauthor a paper with Ozan, a friend who I know when I was TAing Bayesian Methods in ICPSR. The paper tries to see if the 9/11 has any effect on American's attitudes on Muslim. We have dataset from different years: 2 from pre-9/11 periods and 2 from ...

## Find type of variables in a data frame

February 20, 2008
By

sapply(a,class) gives type of field (character, numeric, or factor) for each variable in the data frame a.

## A wraper function to convert coda files into a BUGS object

February 11, 2008
By

I used to fit Bayesian model using WinBUGS via R a lot. But now I am more and more prone to run models on OpenBUGS directly. I have document the reason why I like OpenBUGS and wrote a auto OpenBUGS function here. In short, I like to be able to know wha...

## A wraper function to convert coda files into a BUGS object

February 11, 2008
By

I used to fit Bayesian model using WinBUGS via R a lot. But now I am more and more prone to run models on OpenBUGS directly. I have document the reason why I like OpenBUGS and wrote a auto OpenBUGS function here. In short, I like to be able to know wha...

## R graph with two y-axes

February 4, 2008
By

I’ve been asked how to do this several times, so I thought it might help to put an example online. x <- 1:5 y1 <- rnorm(5) y2 <- rnorm(5,20) par(mar=c(5,4,4,5)+.1) plot(x,y1,type="l",col="red") par(new=TRUE) plot(x, y2,,type="l",col="blue",xaxt="n",yaxt="n",xlab="",ylab="") axis(4) mtext("y2",side=4,line=3) legend("topleft",col=c("red","blue"),lty=1,legend=c("y1","y2"))

## R graph with two y-axes

February 4, 2008
By

I’ve been asked how to do this several times, so I thought it might help to put an example online. x <- 1:5 y1 <- rnorm(5) y2 <- rnorm(5,20) par(mar=c(5,4,4,5)+.1) plot(x,y1,type="l",col="red") par(new=TRUE) plot(x, y2,,t...

## Drop unused factor levels

February 4, 2008
By

When creating a subset of a dataframe, I often exclude rows based on the level of a factor. However, the "levels" of the factor remain intact. This is the intended behavior of R, but it can cause problems in some cases. I finally discovered how to clean up levels in this post to R-Help. Here is an example:>...

## Drop unused factor levels

February 4, 2008
By

When creating a subset of a dataframe, I often exclude rows based on the level of a factor. However, the "levels" of the factor remain intact. This is the intended behavior of R, but it can cause problems in some cases. I finally discovered how to clean up levels in this post to R-Help. Here is an example: >...

## R package: codetools

February 4, 2008
By

Since the release of R_2.6.0, R package developers were advised to use the codetools" package to check potential bugs. However, as I am not familiar with computer language, I found the warning messages a bit confusing. For example:> checkUsage(glm.fit): no visible binding for global variable ‘n’I don't understand what it really means. Apparently, `n' was not globally defined but...

## Paper on the Gillespie Stochastic Simulation Algorithm in press

February 1, 2008
By

Just got news that my revisions to the reviewer’s comments on my paper GillespieSSA: Implementing the Gillespie Stochastic Simulation Algorithm in R were accepted. Hence, this paper is not officially in press in the Journal of Statistical Software. Here’s the … Continue reading →

## New material on the GGobi book web page

January 30, 2008
By

The GGobi book is now available from Springer and Amazon, after quite a delay. Getting the figures printed correctly was difficult. Solutions to the exercises in the back of each chapter are available for instructors by emailing Springer.The movies on ...

## New material on the GGobi book web page

January 30, 2008
By

The GGobi book is now available from Springer and Amazon, after quite a delay. Getting the figures printed correctly was difficult. Solutions to the exercises in the back of each chapter are available for instructors by emailing Springer.The movies on ...

## The hammer, or the sledgehammer? A small study in simulation

January 29, 2008
By

RKN over at Epidemiology blog had a small problem he solved using simulation:I have been interested in the following question: if there are, let's say, 5 genes involved in the liability of fx risk, and each gene has two alleles with one of them conferr...

## Shading overlapping area of curves in R

January 28, 2008
By

I was trying to plot figure in R like the one below, which is basically the veto player model of Tsebelis. Based on my knowledge of R now, I encountered 2 major problems:I don't know if there is a function that can draw archs, or at least partial curves from circles.I don't know if there is a good way...

## Heuristics for statistics

January 28, 2008
By

SIMPLE WAYS TO DETECT AND COMMUNICATE STATISTICAL EFFECTS Decision Science News is fond of heuristics and the Simonian view that for many problems organisms face, optimization is a fiction and satisficing makes us smart. Statistics is an area in which it is easy to see precision that isn’t there and find “optima” in problems that

## Hack-at-it 2007

January 28, 2008
By

The GGobi Hack-at-it 2007 was held just before useR! 2007 in Ames Iowa.The main focus this year was on the data pipeline again, and on pipelines in other software.Several projects were discussed: the geometric shapes, high-dimensional games, local neig...

## Hack-at-it 2007

January 28, 2008
By

The GGobi Hack-at-it 2007 was held just before useR! 2007 in Ames Iowa.The main focus this year was on the data pipeline again, and on pipelines in other software.Several projects were discussed: the geometric shapes, high-dimensional games, local neig...

## ERGMs in R

January 23, 2008
By

Developers of statnet, a collection of packages for R for fitting Exponential Random Graph Models (ERGM), issued a major update. First change is that the main package is now called ergm. Secondly, a set of additional packages has been made available. Apart from package network, that provides a class system for relational data on which

## Resources for S4 classes and methods

January 23, 2008
By

Learning the programming in the new S4 system of classes and methods in R can be quite cumbersome, even though the methods package is very well documented. That is why I collected some of the info and materials that I am aware of on a separate page here. I warmly welcome any suggestions for extending

## GillespieSSA 0.5-1 is released

January 15, 2008
By

I just uploaded GillespieSSA 0.5-1 to CRAN. Now it’s just a matter of days before it has propagated itself across all CRAN mirrors. This version consists primarily of revisions I made in response to the reviewer comments on the paper … Continue reading →

## Moving average/median

January 7, 2008
By

?rollmean (package=zoo)?rollmedian (package=zoo)?runmed (package=stats)

## Quantile regression in R

January 5, 2008
By

Roger Koenker, a quantile regression crusader, has an R package that implements the procedure. It is called quantreg, and it is documented here. This package has apparently been around for quite some time, but I was only recently turned on to quantile ...