## Calculating the Mode in R, missing values edition

It is not difficult to write a function in R to calculate the mode (as a central tendency). The function I have posted a while ago did not work with missing values. Here’s a tweak that does work with NA in the data.
```Mode = function(x) { ux = na.omit(unique(x)) return(ux[which.max(tabulate(match(x, ux)))]) } ```

## Interpolated Median in R

In survey data, actual distributions frequently are non-continuous and non-normal. The mean may thus be inappropriate to summarize the central tendency, and the median too rough because it is constrained to the actual categories in the data. On a five-point scale, the median can only fall on one of these categories, and thus does not reflect smaller changes in the distribution. The interpolated median adjusts the median position to do just that.

The concept of interpolated medians is nicely described at  http://aec.umich.edu/median.php (at the bottom), or at http://www.weekscomputing.com/webhelp/hs520.htm (with a nice graph).

In R, the interpolated median can easily be calculated with the package psych, using the `interp.median` function.

To illustrate the difference, here a simple plot using data from the SOM project. Here I use the positional variable (all actors in Austria combined) by year. It is immediately apparent that the three ways to express central tendency are different. The median position (in blue) is clearly constrained by the categories available (in this case -1, -0.5, 0, 0.5, 1). With its corrections, the interpolated median offers much more details of changes over time.

OK, not a very pretty graph, but it does illustrate the point.