Blog Archives

Call C from R and R from C

November 17, 2008
By

Several years ago, while a research associate at the University of Chicago, I had the privilege of sitting in on a course taught by Peter Rossi: Bayesian Applications in Marketing and MicroEconometrics. This course -- one I recommend to anyone at U Chicago who is interested in statistics -- was an incredibly clear treatment of Bayesian...

Read more »

Call C from R and R from C

November 17, 2008
By

Several years ago, while a research associate at the University of Chicago, I had the privilege of sitting in on a course taught by Peter Rossi: Bayesian Applications in Marketing and MicroEconometrics. This course -- one I recommend to anyone at U Chicago who is interested in statistics -- was an incredibly clear treatment of Bayesian...

Read more »

Error capture

May 6, 2008
By

In a recent post to r-sig-ecology, Mike Colvin suggested the following to capture errors within a loop:for (i in 1:1000){fit<-try(lm(y~x,dataset))results<- ifelse(class(fit)=="try-error", NA, fit$coefficients)}

Read more »

Error capture

May 6, 2008
By

In a recent post to r-sig-ecology, Mike Colvin suggested the following to capture errors within a loop:for (i in 1:1000){fit<-try(lm(y~x,dataset))results<- ifelse(class(fit)=="try-error", NA, fit$coefficients)}

Read more »

Plotting contours

March 18, 2008
By
Plotting contours

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...

Read more »

Plotting contours

March 18, 2008
By
Plotting contours

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...

Read more »

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: >...

Read more »

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:>...

Read more »

Convert factors to numbers

November 29, 2007
By

If you have a vector of factors it is easy to get the factor level; however, I always forget how to extract the factor value. I ran into the answer here.> x<-factor(c(round(rnorm(10),2),"A","B",NA))> x 1.61 1.12 1.26 0.09 -0.13 0.16 -0.03 -0.1 0.09 -0.47 A ...

Read more »

Convert factors to numbers

November 29, 2007
By

If you have a vector of factors it is easy to get the factor level; however, I always forget how to extract the factor value. I ran into the answer here. > x<-factor(c(round(rnorm(10),2),"A","B",NA))> x 1.61 1.12 1.26 0.09 -0.13 0.16 -0.03 -0.1 0.09 -0.47 A ...

Read more »