Publications by Dan Kelley Blog/R

Installing oce in R

30.12.2013

Several of the blog items have used the oce package. The official version of this can be installed from within R by 1install.packages("oce") and more up-to-date versions can be installed using the devtools package written by Hadley Wickham, which is itself installed with 1install.packages("devtools") after which installing the latest developme...

1098 sym R (173 sym/6 pcs) 3 tbl

PISA scores

06.01.2014

The Guardian Newspaper has an interesting article about the Pisa (Program for International Student Assessment) scores for 2012, and it includes data. Since I was interested to see how my own region scored, I downloaded the data into a file called PISA-summary-2012.csv and created a plot summarizing scores in all the sampled regions, with Canada ...

1521 sym R (5155 sym/11 pcs) 2 img 5 tbl

Inferring halocline depth

11.01.2014

Introduction There are no agreed-upon methods for inferring halocline depth, but a reasonable method might involve locating the depth at which dS/dp is largest, where S is salinity and p is pressure (Kelley 2014 chapter 5). Calculating the derivative using e.g. diff(S)/diff(p) can be problematic because of sensitivity to noise, especially for da...

1874 sym R (995 sym/2 pcs) 2 img 1 tbl

Smoothing CTD profiles

11.01.2014

Introduction Smoothing hydrographic profiles with conventional time-series methods is problematic for two reasons: (a) the data are commonly not equi-spaced in depth and (b) the data seldom lack trends in depth. The issues and their solutions are illustrated without much discussion here. The first step in making the graph shown above is to load ...

3029 sym R (929 sym/14 pcs) 2 img 7 tbl

Cabelling calculations

15.01.2014

Abstract R code is provided in aide of laboratory demonstration of cabelling. Introduction Setting up a cabelling experiment requires creating two watermasses of equal density, and if only S and T can be measured, that means calculating densities. Using a TS diagram and graphical interpolation is one approach to that task, but another is to use ...

1803 sym R (1006 sym/2 pcs) 2 img 1 tbl

Butterworth filter overshoot

15.01.2014

Introduction Butterworth filters with order other than 1 have an overshoot phenomenon that can be problematic in some cases. For example, if smoothing is used on an estimate of kinetic energy, overshoots might yield negative values that are nonphysical. This post simply illustrates this with made-up data that the reader can experiment with. M...

1254 sym R (643 sym/6 pcs) 2 img 3 tbl

Colourizing a trajectory

15.01.2014

Introduction In Oceanography it can be useful to use colour to display z values along an (x,y) trajectory. For example, CTD data might be displayed in this way, with x being distance along track, y being depth, and z being temperature. This post shows how one might do this. Methods The R code given below demonstrates this with fake data. The co...

1301 sym R (445 sym/2 pcs) 2 img 1 tbl

Using the plyr package

18.01.2014

Introduction The base R system provides lapply() and related functions, and the package plyr provides alternatives that are worth considering. It will be assumed that readers are familiar with lapply() and are willing to spend a few moments reading the plyr documentation, to see why the illustration here will use the ldply() function. The test t...

1975 sym R (978 sym/14 pcs) 2 img 7 tbl

1D optimization in R

22.01.2014

Introduction R provides functions for both one-dimensional and multi-dimensional optimization. The second topic is much more complicated than the former (see e.g. Nocedal 1999) and will be left for another day. A convenient function for 1D optimization is optimize(), also known as optimise(). Its first argument is a function whose minimum (or m...

2544 sym R (419 sym/6 pcs) 2 img 3 tbl

Vote splitting in Canada

25.01.2014

Analysis District-by-district data reveal that if the Bloc Quebecois, Green, Liberal, and NDP parties were to have been united, the Conservative party would have lost the 41st Canadian election by a dramatic measure, instead of winning a majority. The graph given below shows the results by naming the ridings. Clicking on the graph will let you s...

1261 sym R (3873 sym/2 pcs) 2 img 1 tbl