Getting JDK on mac OS X to work

How frustrating – trying to get the current Java Development Kit working on a mac! It shouldn’t be so hard, but if you are on the command line it is possible that Java is already installed in a number of places, but the JDK is not on the PATH. I’m not necessarily a fan of the whole Java environment, but it is necessary!

Don’t forget to download the latest installer from Oracle!

For example, look in:

/System/Library/Frameworks/JavaVM.framework/Home/
or
/usr/bin

After multiple attempts I eventually found that the JDK (that I wanted) was in:

/Library/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home

so adding

export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home

to my /etc/profile (reloading, or closing the current terminal window and opening a new window) was required. I’m presuming if you made it this far, you can work out the JDK numbers will probably not be the same as mine.

Apple Carplay first impressions

I have a Pioneer AVH-8650 and an iPhone 5 (iOS 8.1). It is a great system, but as I presume I am an early adopter, I wonder if there is anywhere to feed back a couple of aspects of the system operation that are (obviously in my opinion) less than ideal. Apple is not renowned for responding to consumer feedback directly, but they do have a feedback area on their site. You just can’t feedback on Carplay?

Presuming that the concept is to reduce distraction when driving, the interface should be as ‘simple’ as possible, how can I :

1) Stop the message popping up every time I get in the car that says I know that the radio can be distracting. I opted for Carplay to reduce the time I needed to spend pushing buttons and looking at my phone, but this just adds one more step. Surely this sort of legal rubbish could be once per phone, not every single time I start the car? (seems like a simple fix?)

2) And then, after years of being told I should put in a passcode on my phone, every time I go somewhere in the car I can’t do anything until I pick up the phone (which the installers have put in the glove box, since I don’t need to actually handle the phone any more…) and put in my passcode. At the very least, surely I could enter the passcode on the screen of the radio (in front of me) rather than on the phone (inviting police interest). (maybe more complex, but hey, pressing buttons on a touch screen to make driving safer… should be achievable)

3) Listen to a message, then go back to what I was listening to before? If I’m listening to the SD card, then listen to a message, once I’ve finished it starts playing the first song in my song list on my phone (probably the ABC song from Sesame Street). It should surely return to the SD card song, or at least to the last song I was playing on my iPhone. That must be able to be changed. (if I can hand-off a presentation between iOS devices, surely I can ‘hand back’ to the carplay unit).

4) See my message before I send it. Siri is certainly better than ever, but my messages are not always translated back to what I meant… Maybe once I’ve dictated it it could be displayed on the screen, as some similar sounding words can read very differently. (I’m sure this will be argued against on safety grounds, but coming home after inadvertently sending the ‘wrong’ message may also be very dangerous)

Anyhow, a few thoughts after a few weeks. Other than that it is truly great, and I’m sure that both vendors (the system and the hardware) will be able to argue who should be responsible. But, without question, 1,2 and 3 cause me to have to spend more time fiddling with the radio or phone, not less, so should be sorted out.

PLR and PostgreSQL 9.3 on Ubuntu 12.04

A couple of notes that eventually worked!

need postgresql, R and the developer installs of each:

~$ sudo apt-get install postgresql-9.3 postgresql-9.3-dev r-base r-base-dev

plr.h:89:15: fatal error: R.h: No such file or directory

R_HOME != /usr/lib/R … R_HOME = /usr/share/R

~$ export R_HOME = '/usr/share/R'

You might want to change this in /etc/profile or somewhere.

This needs to also be set for the postgresql environment

~$ vi /etc/postgresql/9.3/main/environment

R_HOME = '/usr/share/R'

~$ sudo service postgresql restart

the DLSUFFIX error:

pg_backend_support.c:296:2: error: #error “DLSUFFIX must be defined to compile this file.”
pg_backend_support.c: In function ‘expand_dynamic_library_name’:
pg_backend_support.c:333:37: error: ‘DLSUFFIX’ undeclared (first use in this function)
pg_backend_support.c:333:37: note: each undeclared identifier is reported only once for each function it appears in

No idea what this means, but in frustration I tried make as root:

~$ wget http://www.joeconway.com/plr/plr-8.3.0.15.tar.gz
~$ tar -xzf plr-8.3.0.15.tar.gz
~$ cd plr

or this might be better:

~$ wget https://github.com/jconway/plr/archive/master.zip
~$ unzip master.zip
~$ cd plr-master

Then:

~/plr$ sudo USE_PGXS=1 make
~/plr$ sudo USE_PGXS=1 make install
~/plr$ psql
=# CREATE EXTENSION plr;
CREATE EXTENSION
=# \q
<\pre>

PL/R function example – outbreak detection methods

Dynamic Cluster Detection using pl/r functions

The ability to detect clusters of outbreaks as soon as possible was investigated. Cluster detection methods were coded as procedural language functions in the database and made available through a web interface6. Methods available through this interface include CUSUM (Rossi et al., 1999), log-linear regression (Farrington et al., 1996), generalised likelihood ratio (Höhle et al., 2009) and Bayesian (Reibler, 2004 in German, cited in Höhle, 2007) algorithms provided through the R package Surveillance (Höhle, 2007).

The example code below illustrates the code for the Farrington log-linear regression model.

PL/R Function

CREATE OR REPLACE FUNCTION outbreak_farr_uni(bound integer, startweek date, endweek date, back integer, wind integer, serotype varchar, directory text) RETURNS text
AS $_$
db<-NA
this_filename = basename(tempfile("outbreak_cdc_uni", directory))
this_file = file.path(directory, this_filename)
library(Cairo)
library(zoo)
library(rgeos)
library(surveillance)
gpclibPermit()
if(serotype=='') {
serotype='all'
}
q <- "SELECT datefrom AS reportdate, count(gid) FROM outbreaks "
if(serotype != 'all') {
q<- paste(q, " WHERE serotype = '",serotype,"' ", sep='')
}
q <- paste(q, "GROUP BY datefrom ORDER BY datefrom")
res <- dbGetQuery(db, q)
rez <- zoo(res$count, res$reportdate)
# Aggregate by week - friday... why not.
aggregate(rez, agg.by.fri, sum) -> rey
# Convert back to ts
tmp <- as.matrix(as.ts(rey))
dates <- as.Date("2000-01-07") + 7 * 0:(nrow(tmp) - 1)
# Create sts class
red <- new("sts",epoch=1:nrow(tmp), start=c(2000,1), freq=52, observed=tmp, state=matrix(0,nrow(tmp), ncol(tmp)), epochAsDate=FALSE)
# Replace NA's with 0
red@observed[is.na(red@observed)]<- 0
# Add a reasonable upper bound?
red@upperbound <- as.matrix(rep(quantile(red@observed, bound/100), length(observed(red))), 1, length(observed(red)))
red@state[red@observed > red@upperbound] <- 1
period <- which(dates >= startweek & dates <= endweek)
red.farr <- farrington(red, control=list(range = period, b=back, w=wind))
Cairo(paste(this_file, ".png", sep = ""), type='png', height=768, width=1024)
plot(red.farr, main = 'Log-linear regression of outbreak reports', sub='after Farrington et al, 1996', xlab='Year / Quarter', ylab='Reports per week', legend.opts=list(horiz=TRUE, bty='n'))
dev.off()
Cairo(paste(this_file, ".pdf", sep = ""), type='pdf', title='Created by ACIAR ULM Project', height=30, width=40, units='cm')
plot(red.farr, main = 'Log-linear regression of outbreak reports', sub='after Farrington et al, 1996', xlab='Year / Quarter', ylab='Reports per week', legend.opts=list(horiz=TRUE, bty='n'))
dev.off()
system(paste("chmod 666 ", this_file, ".png", sep=""), intern = FALSE, ignore.stderr = TRUE)
system(paste("chmod 666 ", this_file, ".pdf", sep=""), intern = FALSE, ignore.stderr = TRUE)
return(this_filename)
$_$ LANGUAGE plr;

If you copy and paste this code into psql it should produce a working function.

I have it embedded in a web page with four other algorithms, where the code (in php) looks a bit like :


/*
* Farrington
*/
echo "<div id='farrington' class='thumbnail'>";
echo "<h3>Log-linear regression model (Farrington et al, 1996)</h3>";
$q= "SELECT outbreak_farr_uni(:bound, :startweek, :endweek, :back, :wind, :serotype, :plr_tmp)";
$iarray=array(":bound" => $bound, ":startweek" => $startweek, ":endweek" => $endweek, ":back" => $back, ":wind" => $wind, ":serotype" => $serotype, ":plr_tmp" => $plr_tmp);
$query = $dpg->prepare($q);
try {
$query->execute($iarray);
$result = $query->fetchColumn();
echo "<a onclick='return bigimage(\"tmp/$result\", 1024,678)'><img src='tmp/".$result.".png' width='320' height='240'></a>";
} catch(exception $e) {
echo "<br><b>There was an error with this algorithm.</b><p>A common cause is a lack of consistent data during the selected date range, please check the parameters (and have a look at the Analysis Range in the Full outbreak listing above).</p><br><br><br>";
}
echo "<p>b: <input type='text' name='back' size='2' maxlength='2' value='$back'> </p>
<p>
m: <input type='text' name='wind' size='2' maxlength='2' value='$wind'></p>";
echo "<br></div>";

Which should produce a thumbnail chart in the page.

Thumbnail embedded in page

Clicking on the plot opens a window with a powerpoint sized (1024 x 768) large png version, and has a link to download a pdf version (for embedding in documents etc).

Window with download link

 

References

Farrington, C., Andrews, N., Beale, A., and Catchpole, M. (1996). A statistical algorithm for the early detection of outbreaks of infectious disease. Journal of the Royal Statistical Society. Series A (Statistics in Society), 159(3):547–563.

Höhle, M. (2007). surveillance: An R package for the monitoring of infectious diseases. Computational Statistics, 22(4):571–582.

Höhle, M., Paul, M., and Held, L. (2009). Statistical approaches to the monitoring and surveillance of infectious diseases for veterinary public health. Preventive Veterinary Medicine, 91(1):2–10.

Rossi, G., Lampugnani, L., and Marchi, M. (1999). An approximate CUSUM procedure for surveillance of health events. Statistics in Medicine, 18(16):2111–2122.

 

 

In Broome veritas

Queuing up for justice@ the Courthouse

Although most people are familiar with queuing when they visit the Broome Courthouse, it is normally for a satay or other market stall. But on Monday mornings, the queue of potential jurors extends back to the road.

Admittedly, it moves a bit quicker than the satay queue…