|
|
Thinking inside the box | |||||
|
Bio
Code Linux Quantian About Blog |
R/Finance conference in Chicago in April: Call for Papers
Call for PapersSee you in Chicago in April! Tue, 23 Dec 2008
Updated 'Introduction to High-Performance Computing with R'
I just posted the updated slides from this talk, and there is also an updated live cdrom on the Alioth server. Also, it looks like the tutorial will be held again at UseR 2009 in Rennes, see here for a brief synopsis. It was nice to get back to Canada, even if it was a 24 hour whirlwind trip. Ottaws looked quite pretty in all the snow. And it seems that I got rather lucky with the travel dates as both the days before and after my trip had a large number of flight cancellations and delays due to snow storms. Mon, 01 Dec 2008
CRANberries prettified
So I quickly put together some simple css formatting to make it look a little better than the default blosxom theme it sported previously. That said, you probably should read the rss version (more about rss here) anyway! Update: Oops. And it even works with a correct path to the css file. Now fixed. Tue, 19 Aug 2008
UseR! 2008 talk
The talk introduces and extends an example related to some of the material from the tutorial itself. The slides from the talk are a little rough as the talk was somewhat ad-hoc: As session chair, I was confronted with a fairly last-minute cancellation and a 15 minute hole, and thought this would make a good little talk. It does show a nice trick for using littler with Open MPI (via snow) under the powerful slurm resource manager and batch/queue engine. Tue, 12 Aug 2008
UseR! 2008 tutorial
In a nutshell, the tutorial covered
how to measure / profile R performance for
speed and memory use, how to accelerate R using vectorised expression and
tools like Ra / jit, how to add compiled code to R using either
the The final version of the slides is now available via my presentations page, and the live cdrom with software support for all the software used is at Alioth. Update: Corrected link to presentations page thanks to heads-up by Charles. Thanks! Sat, 16 Feb 2008
CRANberries updated
But these changes also affected my my CRANberries (see the html or better yet rss view) summaries of new packages as some of the source information moved. So I just updated the (surprisingly short at 189 lines including plenty of whitespace and comments) script, and things should work now come the next update. While updating the 'more info' link for new and updates posts to point to the new-style entry at CRAN, I also took the opportunity to update the format of the `blog' entry for updates where we now show title and description along with the diffstat output,
I also manually copied in two of the recent entries: the new package
emu where CRANberries had fallen over as we
could not find the package description (in the new spot), and the existing package
GEOmap where
The amazing Prof. Ripley (cont'ed)
x <- readLines("http://developer.r-project.org/R.svnlog.2007")
rx <- x[grep("^r",x)]
who <- gsub(" ","",sapply(strsplit(rx,"\\|"),"[",2))
twho <- table(who)
twho["ripley"]/sum(twho)
In five lines (that could be shortened to three at the expense of some
readibility), the SVN log for R is
downloaded directly from the website, the revision authors are extraced and then
tabulated by submitter. The relative percentage of Brian Ripley is found
to be a staggering 74.8% -- or about three times as much as the other fifteen
committers combined. Smokes.
[ Oh, and for those who don't know him, he's also got a day job which presumably entails looking after his graduate students at Oxford. Who knows, he may even teach. Kidding aside, he's actually one of the nicest persons you'll ever meet in real life. ] Now yesterday, Simon Jackman who had at first simply repeated Ben's analysis on his own blog followed up with a nice analysis (albeit typeset in a way that rendered the code inoperational, which has now been fixes) that creates both a histogram and a dotplot of commits per hour of the day. Omitting Ben's code which Simon reuses, we have the following for histogram and dotchart:
tod <- unlist(sapply(rx,function(x)strsplit(x,split=" ")[[1]][6]))
tod <- tod[who=="ripley"]
tz <- sub(pattern=".*(-[0-9]{4}).*",replacement="\\1",x=rx)
tz <- tz[who=="ripley"]
tz <- as.numeric(tz)/100
offset <- 3600*tz
z <- strptime(tod,format="%H:%M:%S")
hist(z,"hours",main="Ripley Commit Times in SVN TZ")
h <- z - offset
h <- format(h,format="%H")
h <- factor(as.numeric(h), levels=0:23)
dotchart(table(h), main="Ripley Commit Times, By Hour in GMT",
labels=paste(0:23,1:24,sep=":"))
This extracts the commit times, subsets to the ones by Prof. Ripley, extracts
the timezones component (as strptime seemingly doesn't do that
which is a pain), extracts the tz-less time via strptime into a
variable 'z' for which the histogram is drawn. He then corrects the times by
the tz offset expressed in seconds, formats is as hour of the day and turns
it into a 'factor' (an R data type for qualitative variables which may be
ordered as is the case here) and draws a dotplot. This results in the
following chart:
Now, nobody has looked at the time series. So we correct this and add the following:
## rather extract both date and time
dat <- unlist(sapply(rx, function(x) {
txt <- strsplit(x,split=" ")[[1]]
paste(txt[5], txt[6])
}))
## subset on Prof Ripley
dat <- dat[who == "ripley"]
## and convert to POSIXct, correcting by tz as well
datpt <- as.POSIXct(strptime(dat,format="%Y-%m-%d %H:%M:%S")) - offset
## turn into zoo -- we use a constant series of ones as each
## committ is taken as a timestamped event
datzoo <- zoo(1, order.by=datpt)
## and use zoo to aggregate into commits per date
daily <- aggregate(datzoo, as.Date(index(datzoo)), sum)
## now plot as grey bars
plot(daily, col='darkgrey', type='h', lwd=2,
ylab="Nb of SVN commits, three-week median",
xlab="R release dates 2.5.0 and 2.5.1 shown in orange",
main="The amazing Prof. Ripley")
## mark the two R releases of 2007
abline(v=c(as.Date("2007-04-24"),as.Date("2007-06-28")),col='orange',lwd=1.5)
## and do a quick centered rolling median
lines(rollmedian(daily, 21, align="center"), lwd=3)
This extracts both date and time, creates a proper R time object (a so-called
POSIXct type) from it, fills a zoo ('the' magic class for time series) object
with it, uses zoo to aggregate commits per day and plots those in a
barchart-alike (I know, I know, ...) plot to which we add the two releases as
well as a rolling and centered three-week median (as a real quick hack rather
than a proper smooth).
This shows that Prof Ripley averaged about ten commits a day before and after the release of R 2.5.0, and that he has slowed down ever so slightly since then to end up at around a mere seven commits a day. Every day. For the seven-plus months we looked at. So, anyone for analysing his r-help posting frequencies ? Mon, 09 Jul 2007
Announcing CRANberries
The hope is that this proves helpful for keeping tabs on the amazing growth of CRAN (which is now at over one thousand packages) as well as the number of updates to existing packages. The feed(s) can be consumed standalone, or via the brand new Planet R aggregator that Elijah announced today too. Mon, 02 Jul 2007
More on 'nicer charts'
As some of my points didn't seem to make it across, I will reiterate them more plainly:
Sven also addresses the fact that what we really want is to see the quantiles
of the data set. Quite right, and taking logs makes that easier. Consider
the two charts below which plot the 'package age in days' as an empirical
cumulative distribution function using built-in R functions
While it is close to impossible to find the 25 or 50 percentile on the first
chart, it becomes a lot easier on the second chart because the x-axis is
'stretched' using the log transform. About one quarters of the distribution appears
to be rebuild within 1.5 months old, and about half is younger than four
months (as a quick call to
Improving simple charts
Lucas included a URL to the data. The first nice thing to note that we can read the data directly from the URL -- no need to copy the file:
pkgAge <- read.table(file="http://people.debian.org/~lucas/arch-age/arch-age.log", col.names=c("pkg","yyyymmdd"))
read the data into a data.frame which we have given two column names.
pkgAge[,"date"] <- as.Date(as.character(pkgAge[,"yyyymmdd"]), "%Y%m%d") pkgAge[,"age"] <- as.numeric(difftime(Sys.Date(), pkgAge[,"date"], units="day")) pkgAge[,"prop"] <- (1:nrow(pkgAge)) / nrow(pkgAge) * 100We then create three new columns. First is a date, by parsing the (integer) dates (after first casting them into characters) by supplying the format in standard C notation: "%Y%m%d" for year, date and month without
any separators or formatters. Now, having the date as an actual date
object inside a real data analysis language we can do
things as e.g. computing date differences. The difftime function
does just that, using the current date as other point. We ask for the return
to be in days, and cast this down to a purely numeric vector (instead of
datediff object). Lastly, we quickly compute the date proportion in
percentages.
We can then view the date. Before we plot,
png("packageAges.png", quality=100, width=640, height=480, pointsize=10)
oldpar <- par(mfrow=c(2,2), mar=c(2.5,2.5,3,1))
we direct the charts to a png file of given dimensions, and ask for all
plots in one figure (using mfrow with two rows by two) with
somewhat smaller figure margins using the mar argument to par.
The first chart shows again proportion over date: with(pkgAge, plot(date, prop, type='l', main="Standard Plot"))(The with() function simply allows us to refer to the columns by their names without explicit subsetting. plot(pkgAge[,"date",],
pkgAge[,"prop"]) is equivalent, but more cumbersome.)
As it clear that the data has a fairly long tail in the older dates, we can also try to plot the plot over logarithmic time differences. This doesn't work for dates, but it works for our (positive-valued) age variable: with(pkgAge, plot(age, prop, type='l', log="x", main="More linear as log(age in days)")) The very far left tail below 0.5 percent is interesting as the one very old package is clearly an outlier within an outlier region. We use the subset function to take just one portion of the data, use logs, and explicit plotting symbols '+' in a points-and-lines plot: with(subset(pkgAge, prop<0.5), plot(date, prop, type='b', log="y", pch="+", main="Detail in left tail, up to 0.5%")) Lastly, the upper quartile is fairly linear. with(subset(pkgAge, prop>75), plot(date, prop, type='l', pch=".", main="Yet fairly linear in top 25%")) At the end oldpar <- par(mfrow=c(2,3)) dev.off()we restore the graphics paramters and close the device (here the file). All this then yields the following chart:
Updated to correctly display the assignment operator
RGtk2 packages in Debian
For an two interesting applications using RGtk2, look at Graham William's rattle, a glade-based data-mining user-interface to several R functions, and at John Verzani's PMG (aka Poor Man's GUI) generic GUI for R. Thu, 02 Feb 2006
RGtk2 packages available
RGtk2 is, as the name suggests, an update of the older RGtk package (that I'd been maintaining in Debian as r-omegahat-rgtk) to the 'newer' version 2 of Gtk (aka The GIMP Toolkit). It provides Gtk goodies for the amazing R language and environment many of us dig for its use in statistical computing, visualization, data analysis, estimation and more. RGtk2 is quite an achievement. The source package is huge at 1.9mb, the resulting Debian package even huger at 5.3mb, and it all seems to work fine based on some initial tests of running the demos. Based on the two source packages, I created two packages of RGtk2 (as r-omegahat-rgtk2) and the Cairo device (as r-omegahat-cairodevice) which you can fetch from here. Not sure if I feel the urge to maintain them, but if someone else wants to step forward, let me know. Sources and diffs are in the same directory. Feedback welcome.
Update: By the way, what do we need to build with
First `r-devel' builds leading up to R 2.1.0
I have built an initial set of packages, mostly to convince myself that
nothing too drastic was needed inside the I tend not to install any locales packages on my machines, so I can't really test if the localisation support works -- configure and friends certainly suggest it based on the compile-time messages. So my dear reader, if you are into non-default locales and R, and have a minute, grab the package and try something like
$ LANGUAGE=de LC_all=de LC_MESSAGES=de LANG=de LOCALE=de R
R : Copyright 2005, The R Foundation for Statistical Computing
Version 2.1.0 Under development (unstable) (2005-02-27), ISBN 3-900051-07-0
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for a HTML browser interface to help.
Type 'q()' to quit R.
> Sys.getlocale()
[1] "C"
> q("no")
As is plain from the above, I somehow failed to tell R about 'de' as an
alternative. However, capabilities() does report
TRUE for attribute iconv, so this should work
... Feedback welcome -- right now, R has po files for de and it so no need
to test other languages.
Mon, 21 Feb 2005
Nicer charts
In an effort of true R evangelism, I bugged Wouter about the gnuplot ugliness in those charts and offered an R script as an alternate. Per his reply, he seemed please with the output [1] -- click on the png for a nicer pdf:
For anybody interested, the
R code is available. It provides two simple functions. The first actually
creates the 4x1 chart. The second loops over all datafiles ending in
R CMD BATCH debian_bts_chart.Rwhich will create R CMD BATCH debian_bts_chart.Rout in the current
directory.
Lastly, I should note that I do think that the underlying data is wrongly classified. Counting a bug as 'active' even when it has been closed, but is not yet archived merely because the 28 days period hasn't passed is plain wrong. In my book, a closed bug cannot count as an active one. [1] This is my own data, and it shows the drop-off a few weeks ago when I passed maintainership of a good dozen packages on to others. Sun, 20 Feb 2005
Truly random numbers
Mads' service samples atmospheric noise -- see his background essay for more details --
which gets aggregated and can then be had via Corba, HTTP or SOAP. Given how R has such a wonderful (and probably
little know)
> X <- read.table(url(paste("http://www.random.org/cgi-bin/randnum",
"?num=10000&min=-1000000000&max=1000000000&col=2",
sep="")),
header=FALSE)
> plot(X, pch=".")
(The paste() is used to split the overly long line for the full
URL.) The arguments to the interface at random.org are hopefully
self-explanatory. Otherwise, full details are available.
As repeated simulations are often rather time-intensive, downloading random
sequences may not be the fasted way to go about things. However, this method
would provide a portable way to seed a pseudo
random number generator in a portable fashion for platforms that do not
have an entropy provider under
Three-character patch for Rpy to build under R 2.0.0
--- rpy-0.3.5.orig/setup.py
+++ rpy-0.3.5/setup.py
@@ -54,7 +54,7 @@
RHOME = get_R_HOME()
DEFINE.append(('R_HOME', '"%s"' %RHOME))
-r_libs = os.path.join(RHOME, 'bin')
+r_libs = os.path.join(RHOME, 'lib') # edd 11 Oct 2004: changed to 'lib' for 2.0.0
source_files = ["src/rpymodule.c", "src/R_eval.c",
"src/io.c"]
if sys.platform=='win32':
which may be useful to someone else trying to update RPy.
Update: Greg just told me by email that the fix is in CVS too, so a new RPy will have it. Thu, 07 Oct 2004
R 2.0.0 now in Debian
So after some further testing, packages of R 2.0.0 are now on the Debian
servers and should be in unstable tomorrow. Because of the new internal
interface to R packages, older packages will not load. Users can either call
New 'R in Finance' list up and running
Thanks again to everybody who participated in the finance sessions at the recent useR! 2004 conference. During the discussions, the idea of a mailing list for R and Finance came up. Thanks to Martin, such a list has now been created and can be accessed via the pageSubscriptions are trickling in at a steady rate, let's hope we get this list to be a helpful and lively forum. Wed, 26 May 2004
Slides for my useR! 2004 presentations are up
(And no, I cannot distribute the two packages described in the main talk as they were done at work where open source releases are not yet an accepted methodology. Hopefully one day.) Tue, 30 Dec 2003
Debian R Policy draft released
Accelerating plotOHLC by a few orders of magnitude
--- plotOHLC.R.orig 2003-12-14 12:02:20.000000000 -0600
+++ plotOHLC.R 2003-12-14 12:03:42.000000000 -0600
@@ -21,14 +21,9 @@
ylim <- range(x[is.finite(x)])
plot.new()
plot.window(xlim, ylim, ...)
- for (i in 1:NROW(x)) {
- segments(time.x[i], x[i, "High"], time.x[i], x[i, "Low"],
- col = col[1], bg = bg)
- segments(time.x[i] - dt, x[i, "Open"], time.x[i], x[i,
- "Open"], col = col[1], bg = bg)
- segments(time.x[i], x[i, "Close"], time.x[i] + dt, x[i,
- "Close"], col = col[1], bg = bg)
- }
+ segments(time.x, x[, "High"], time.x, x[, "Low"], col = col[1], bg = bg)
+ segments(time.x - dt, x[, "Open"], time.x, x[, "Open"], col = col[1], bg =$
+ segments(time.x, x[, "Close"], time.x + dt, x[, "Close"], col = col[1], bg$
if (ann)
title(main = main, xlab = xlab, ylab = ylab, ...)
if (axes) {
decrease the time spent on a series of ~500 points by a factor of sixty:
> IBM<-get.hist.quote("IBM", "2001-12-14")
trying URL
http://chart.yahoo.com/table.csv?s=IBM&a=11&b=13&c=2001&d=11&e=12&f=2003&g=d&q=$
Content type application/octet-stream' length unknown
opened URL
.......... .......... ...
downloaded 23Kb
time series starts 2001-12-12
time series ends 2003-12-11
> system.time(plotOHLC(IBM)) # original
[1] 1.56 0.26 5.11 0.00 0.00
> system.time(fastplotOHLC(IBM)) # patched
[1] 0.02 0.00 0.05 0.00 0.00
Fri, 12 Dec 2003
Small patch for Rpy and recent R versions
To make life easier for everybody, and as the patch is so simple, here it comes:
--- rpy-0.3.1.orig/src/RPy.h
+++ rpy-0.3.1/src/RPy.h
@@ -90,7 +90,8 @@
PyOS_sighandler_t python_sigint;
/* R function for jumping to toplevel context */
-extern void jump_now(void);
+/* extern void jump_now(void); */
+extern void Rf_onintr(void);
/* Global interpreter */
PyInterpreterState *my_interp;
--- rpy-0.3.1.orig/src/R_eval.c
+++ rpy-0.3.1/src/R_eval.c
@@ -65,7 +65,8 @@
void interrupt_R(int signum)
{
interrupted = 1;
- jump_now();
+ /* jump_now(); */
+ Rf_onintr();
}
Thanks to Luke Tierney for the hint regarding
Announcement for useR! 2004 is out
|
|||||