### Archive

Posts Tagged ‘user2011’

## Nomograms everywhere!

At useR!, Jonty Rougier talked about nomograms, a once popular visualisation that has fallen by the wayside with the rise of computers. I’d seen a few before, but hadn’t understood how they worked or why you’d want to use them. Anyway, since that talk I’ve been digging around in biology books from the 60s and 70s, and it seems they are full of them. So for those of you who haven’t seen the talk, here’s how they work.

A basic nomogram consists of three scales. By reading off known values from two of the scales, you can estimate a third one. Here’s an example I found in the ICRP‘s reference manual.

It’s difficult to measure people’s skin surface area, but height and bodyweight are very straightforward. To use the nomogram, you place a ruler (or other straight edge) on the height* and weight scales and read of the point where the ruler crosses the surface area scale. I’m 177cm tall and weigh 72kg, so according to this, my estimated skin surface area is 1.89m2.

Of course nowadays, the standard way to solve this sort of problem is to write a function. Jonty suggested that the main modern use of nomograms is in fieldwork situations, where computers aren’t handily available. (His case study was Kenyan vets trying to estimate the weight of donkeys form there height and girth.)

Altman and Dittmer’s Respiration and Circulation has many more pretty nomograms. I was particularly impressed by those on blood pH, reproduced below for your pleasure.

Your homework is to dig out a pre-1980 textbook and hunt for more nomograms.

*Gruesomely, the fact that the scale is labelled “length” rather than “height” makes me suspect that the bodies that provided the data were in a permanent lying down position – that is, they were corpses.

## useR2011 highlights

useR has been exhilarating and exhausting. Now it’s finished, I wanted to share my highlights.

10. My inner twelve year old schoolgirl swooning and fainting with excitement every time I chatted with a member of R-core.

9. Patrick Burns declaring that his company consists of himself and his two cats. And that one of the cats keeps changing the settings on his mail reader to spite him.

8. Søren Højsgaard and Robert Goudie both patiently answering my bazillion stupid questions on Bayesian networks.

7. Audience members high-fiving each other during my talk.

6. Peter Baker coming up with ideas for a don’t-repeat-yourself workflow, so I can spend more time doing analysis that matters.

5. Peter Baker coming up with ideas for a don’t-repeat-yourself workflow. Oh, wait.

4. Jason and Tobias from OpenAnalytics talking about lab automation, so I can get those darned chemists off my back. (Just kidding, chemists; I love your data.)

3. Blogist Tal Galili volunteering as my speaking coach. (The big secret: talking really slowly to yourself before a presentation stops you overloading on adrenalin before you get up.)

2. Jonathan Rougier getting the audience to go “ah” every time he mentioned donkeys. And getting me to understand what the point of nomograms are.

1. Ben French teaching me that there is a third joke about stats. (I’ll tell you the other two another time.) It goes like this:

An engineer, a chemist and a statistician are staying in a hotel. (It’s a triple room, very cosy.) The first night they are there, a fire breaks out and wakes them up. The engineer gets up, grabs the fire extinguisher and puts out the fire. Later, they’re all woken by another fire (very dodgy health and safety). The chemist thinks “the fire reaction requires oxygen”, grabs a fire blanket and smothers the flames until they go out. Even later, the engineer and the chemist are woken by the statistician lighting a series of fires in the corner. “What are you doing?”, they cry in unison. “Increasing the sample size”, replies the statistician.

## useR2011 Easy interactive ggplots talk

I’m talking tomorrow at useR! on making ggplots interactive with the gWidgets GUI framework. For those of you at useR, here is the code and data, so you can play along on your laptops. For everyone else, I’ll make the slides available in the next few days so you can see what you missed. Note that for confidentiality reasons, I’ve added some random junk to the sample values, so please don’t use this data for actual research. (If you are interested in chemical exposure data, contact the lab.)

Chromium data. Nickel data. Code for examples 1 to 4. Once we introduce example 5, the rest of the code needs a little reworking.

Update: The permissions on the code files were blocking downloads from people who aren’t me. My bad. It should be fixed now.

Another update: By popular demand, here are the code chunks.

```library(ggplot2)
library(gWidgetstcltk)

p <- ggplot(chromium, aes(air, bm)) +
geom_point()

win_ctrls <- gwindow("Plot controls 1-4")
grp_ctrls <- ggroup(container = win_ctrls, horizontal = FALSE)

#1 Changing scales
available_scales <- c(
Linear      = "identity",
Log           = "log10"
)

frm_scale_trans_y <- gframe(
"Y scale transformation",
container = grp_ctrls,
expand = TRUE
)

names(available_scales),
container = frm_scale_trans_y,
handler = function(h, ...)
{
scale_trans_y <- available_scales[svalue(h\$obj)]
p <<- p +
scale_y_continuous(
trans = scale_trans_y
)
print(p)
}
)

frm_scale_trans_x <- gframe(
"X scale transformation",
container = grp_ctrls,
expand = TRUE
)

names(available_scales),
container = frm_scale_trans_x,
handler = function(h, ...)
{
scale_trans_x <- available_scales[svalue(h\$obj)]
p <<- p +
scale_x_continuous(
trans = scale_trans_x
)
print(p)
}
)

#2 Changing facets
facet_choices <- list(
None = ". ~ .",
"RPE" = ". ~ rpe",
"Welding type" = ". ~ welding.type",
"RPE and Welding type" = "rpe ~ welding.type"
)

frm_facets <- gframe(
"Faceting",
container = grp_ctrls,
expand = TRUE
)

names(facet_choices),
container = frm_facets,
handler = function(h, ...)
{
facet_formula <-
facet_choices[[svalue(h\$obj)]]
p <<- p +
facet_grid(facet_formula)
print(p)
}
)

#3 Changing the dataset
frm_datasets <- gframe(
"Datasets",
container = grp_ctrls,
expand = TRUE
)

cmb_datasets <- gcombobox(
c("chromium", "nickel"),
container = frm_datasets,
handler = function(h, ...)
{
p <<- p %+% get(svalue(h\$obj))
print(p)
}
)

#4 Changing the title
frm_title <- gframe(
"Plot title",
container = grp_ctrls,
expand = TRUE
)

txt_title <- gedit(
p\$options\$title,
container = frm_title,
handler = function(h, ...)
{
p <<- p + opts(title = svalue(txt_title))
print(p)
}
)
```
```library(ggplot2)
library(gWidgetstcltk)

p <- ggplot(chromium, aes(air, bm)) +
geom_blank()

print_p <- function()
{
pp <- get("p", envir = globalenv())
if(svalue(chk_points)) pp <- pp + geom_point()
if(svalue(chk_smooth)) pp <- pp + geom_smooth()
print(pp)
}

win_ctrls <- gwindow("Plot controls 1-5")
grp_ctrls <- ggroup(container = win_ctrls, horizontal = FALSE)

#1 Changing scales
available_scales <- c(
Linear      = "identity",
Log           = "log10"
)

frm_scale_trans_y <- gframe(
"Y scale transformation",
container = grp_ctrls,
expand = TRUE
)

names(available_scales),
container = frm_scale_trans_y,
handler = function(h, ...)
{
scale_trans_y <- available_scales[svalue(h\$obj)]
p <<- p +
scale_y_continuous(
trans = scale_trans_y
)
print_p()
}
)

frm_scale_trans_x <- gframe(
"X scale transformation",
container = grp_ctrls,
expand = TRUE
)

names(available_scales),
container = frm_scale_trans_x,
handler = function(h, ...)
{
scale_trans_x <- available_scales[svalue(h\$obj)]
p <<- p +
scale_x_continuous(
trans = scale_trans_x
)
print_p()
}
)

#2 Changing facets
facet_choices <- list(
None = ". ~ .",
"RPE" = ". ~ rpe",
"Welding type" = ". ~ welding.type",
"RPE and Welding type" = "rpe ~ welding.type"
)

frm_facets <- gframe(
"Faceting",
container = grp_ctrls,
expand = TRUE
)

names(facet_choices),
container = frm_facets,
handler = function(h, ...)
{
facet_formula <-
facet_choices[[svalue(h\$obj)]]
p <<- p +
facet_grid(facet_formula)
print_p()
}
)

#3 Changing the dataset
frm_datasets <- gframe(
"Datasets",
container = grp_ctrls,
expand = TRUE
)

cmb_datasets <- gcombobox(
c("chromium", "nickel"),
container = frm_datasets,
handler = function(h, ...)
{
p <<- p %+% get(svalue(h\$obj))
print_p()
}
)

#4 Changing the title
frm_title <- gframe(
"Plot title",
container = grp_ctrls,
expand = TRUE
)

txt_title <- gedit(
p\$options\$title,
container = frm_title,
handler = function(h, ...)
{
p <<- p + opts(title = svalue(txt_title))
print_p()
}
)

#5 Changing geoms
frm_geoms <- gframe(
container = grp_ctrls,
expand = TRUE
)

chk_points <- gcheckbox(
"Points",
container = frm_geoms,
handler = function(h, ...) print_p()
)
chk_smooth <- gcheckbox(
"Smooth curve",
container = frm_geoms,
handler = function(h, ...) print_p()
)
```