Articles by Dan Kelley Blog/R

Digitizing plots

March 12, 2014 | 0 Comments

Introduction It is not uncommon to want to digitize values from a graph in a paper, whether to do some initial analysis without bothering an author, or to get data from a paper published so long ago that the data are available only graphically. Although there are several software applications ... [Read more...]

Error bars in R

March 5, 2014 | 0 Comments

Introduction Error propagation can be a fair bit of work with a calculator, but it’s easy with R. Just use R in repeated calculation with perturbed quantities, and inspect the range of results. Two methods are shown below for inspecting the range: sd() and quantile(), the latter using the ... [Read more...]

Oce translations

February 26, 2014 | 0 Comments

A new Oce user wondered how to get Spanish labels on axes. This is easy for some plot types because xlab and ylab arguments are obeyed, but in many cases the labels are generated by the code. That meant that it was finally time for me to start localizing Oce, ... [Read more...]

Improved filtfilt() for R

February 19, 2014 | 0 Comments

The filtfilt function in R is supposedly based on the Matlab one, but it does quite badly on endpoints. My goal here is to explore alternatives, with a focus on the Octave method. NOTE: I may also try scipy for hints.) The best method of dealing with endpoints is still ... [Read more...]

demodulating time series

February 17, 2014 | 0 Comments

This posting shows how one might perform demodulation in R. It is assumed that readers are generally familiar tith the procedure. First, create some fake data, a carrier signal with period 10, modulated over a long timescale, and with phase drifting linearly over time. 1 2 3 4 5 6 7 8 9 10 period [Read more...]

Valentines-day full moon

February 13, 2014 | 0 Comments

Introduction A wise person told me that it will be a full moon on the upcoming Valentine’s Day, but that it will be a long time until another one. I decided to check this with astronomical calculation. Procedure The Oce package has a function called moonAngle() that returns, among ... [Read more...]

oce runlm function

February 11, 2014 | 0 Comments

Introduction As was expected, the runderiv() function has been both useful and deficient. Useful because it offers a good replacement for smooth.spline() calculations of derivatives for things like N^2. And deficient because it only calculated derivatives, not values! Both an extension and a renaming were called for. The result ... [Read more...]

oce map projection

February 10, 2014 | 0 Comments

Introduction Soon after map projections were added to Oce, bug reports showed that coastline plots in some projections were subject to anomalous lines that run horizontally on the plot. A ad-hoc scheme was code to try to prevent this, but it does not always work. Problems are compounded for filled ... [Read more...]

N2 with runlm()

February 9, 2014 | 0 Comments

Introduction The default swN2() calculation in Oce uses a smoothing spline. One disadvantage of this is that few readers will know how it works. A possible alternative is to compute d(rho)/dz using the slope inferred from a running-window linear regression. Such a slope is provided by the new ... [Read more...]

Hodograph drawing

February 8, 2014 | 0 Comments

Introduction The polar graph known as a hodograph can be useful for vector plots, and also for showing varition within nearly-cyclical time series data. The Oce R package should have a function to create hodographs, but as usual my first step is to start by writing isolated code, testing to ... [Read more...]

Spline wiggles (II)

February 4, 2014 | 0 Comments

Introduction This follows up on the previous posting, using data provided by Akima (1972). The four panels of the plot produced by the following code compare the original Akima spline formula with an improved version, and three styles of spline() fits. As noted in the code, two spline() methods are useless ... [Read more...]

Spline wiggles (I)

February 3, 2014 | 0 Comments

Introduction An interesting paper (Smith and Wessel, 1990) points out a weakness in using splines in cases with data gaps. Their illustration of the problem with isobaths was particularly compelling. I cannot reproduce their Fig 1b here, owing to copyright problems, but I digitized the data so I could test two ... [Read more...]

GMT topography colours (I)

January 30, 2014 | 0 Comments

I enjoyed the blog posting by “me nugget”, which I ran across on R-bloggers, and so I decided to try that author’s GMT colourscheme. This revealed some intriguing patterns in the Oce dataset named topoWorld. The following code produces a graph to illustrate. 1. Set up colours as suggested on ... [Read more...]

GMT topography colours (II)

January 30, 2014 | 0 Comments

This follows an item about GMT colours. In the meantime I have found a website illustrating the colours, and also the definition files for those palettes. The palette in question is named GMT_relief, and it is defined in a file that is as follows. # $Id: GMT_relief.cpt,v 1.1 2001/09/23 23:11:20 ... [Read more...]

Vote splitting in Canada

January 25, 2014 | 0 Comments

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 ... [Read more...]

1D optimization in R

January 22, 2014 | 0 Comments

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 ... [Read more...]

Using the plyr package

January 18, 2014 | 0 Comments

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 ... [Read more...]

Colourizing a trajectory

January 15, 2014 | 0 Comments

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. ... [Read more...]

Butterworth filter overshoot

January 15, 2014 | 0 Comments

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 ... [Read more...]

Cabelling calculations

January 15, 2014 | 0 Comments

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 ... [Read more...]
1 2 3

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)