Publications by Dan Kelley Blog/R

Improved filtfilt() for R

19.02.2014

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 an open question. Matlab does one thing, Octave does another. Both seem to ...

3216 sym R (3174 sym/7 pcs) 4 img 2 tbl

Oce translations

26.02.2014

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, using the GNU gettext scheme. Gettext being unfamiliar to me, I stumbled a bit at fir...

5474 sym R (1077 sym/20 pcs) 80 img 10 tbl

Error bars in R

05.03.2014

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 fact that area under a normal distribution is 0.68 whe...

1857 sym R (1316 sym/15 pcs) 6 img 6 tbl

Digitizing plots

12.03.2014

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 that do this well, it is also possible to use the loc...

2062 sym R (1774 sym/6 pcs) 2 img 3 tbl

Box models in R

16.03.2014

Introduction Box models are popular in some branches of oceanography and other geophysical disciplines, partly because they are simple to construct and to solve. This posting shows how to solve a box model in R, using the lsoda() function in the deSolve package. The basic ideas can be explained in the context of riverine input into a lake that c...

5575 sym R (595 sym/12 pcs) 2 img 6 tbl

Sun and moon paths in daily sky

22.03.2014

Introduction This blog started because I was interested in the sunrise position on the winter solstice of 2013. With the Spring equinox, I’m trying something different: plotting the paths of the sun and moon through the day. The code shown here produces a daily graph, and I have a cron job running on a machine so that this graph is visible to ...

1216 sym R (2269 sym/5 pcs) 2 img 2 tbl

Using memoise to cache R values

12.04.2014

Introduction The memoise package can be very handy for caching the results of slow calculations. In interactive work, the slowest calculations can be reading data, so that is demonstrated here. The microbenchmark package shows timing results. Methods and results Setup First, load the package being tested, and also a benchmarking package. 1 2lib...

1499 sym R (864 sym/13 pcs) 5 tbl

colormap

30.04.2014

Introduction Over the past month or so I have been trying different ways of handling GMT-style colormaps in Oce. I think my present solution is on the right track, but I am posting here to get more eyes on the problem. Note that the function called Colormap() here will be called colormap() if I decided to incorporate it into Oce. That will mean...

1227 sym R (1876 sym/13 pcs) 10 img 6 tbl

using C++ within R

08.06.2014

Introduction Quite often I write which(...)[1] to find the first element of a vector matching some condition. One has to wonder whether that’s wasteful, though, since there is no need to do any tests once one works. I decided to try using C++, using Rcpp, to see if speed advances could be made. Procedure 1 2 3 4 5 6library(Rcpp) library(micro...

1515 sym R (782 sym/6 pcs) 2 tbl

slumping model

08.06.2014

Introduction I got interested in layered sedimentation from viewing a video and decided it would be interesting to code this into R. More on that in due course, but my first step was to code a syatem with one sediment “type”. Procedure The following code drops sediment particles at x=1, and lets them roll downhill until they reach the bottom...

1554 sym R (1609 sym/2 pcs) 2 img 1 tbl