Home button Search button Dr. Hain buttonClinic website Information for Dizzy Patients Fun Various and Sundry

Dr. Hain's various/sundry has helpful information about things that Dr. Hain has discovered by trial and error.


R is an immensely popular and powerful programming language, that seems to be a viable alternative to Matlab for many data analysis tasks. Dr. Hain decided to learn R, mainly in an attempt to produce graphics from his large collection of clinical data stored in a mysql database.

Some general observations.

Getting Data into R.

The way things work with R is that you put stuff into R, you fiddle around with it for a while, and then you save some sort of graph or numerical output.

My data is in mysql, and it comes out in rows, with one row each for a combination of a test:dos:patient_id. (DOS means date of service).

I save my data (using PHP) to a "csv" file, including the msyql field names in a header, and then I import the data using an R function. This produces rows with multiple column names.

R mainly wants a "dataframe" type construct. The workflow described above works fine if you want to process data based on field values -- for example, plot PTA (average hearing) values vs date of service.

Restructuring R data to plot an audiogram.

An audiogram is basically two scatterplots, one for each ear, plotting the threshold against frequency.

The typical audiogram record has a test:dos:patient_id identifier, and 7 threshold measurements for each ear.

Because R graphic functions expect data to be in columns of dataframes, this doesn't work very well for audiograms, because the thresholds are along the X axis. This means you have to flip the data on it's side, so that thresholds become a column rather than a subset of a row.


© Copyright October 1, 2019 , Timothy C. Hain, M.D. All rights reserved.
Dr Hain's CV Clinic dizziness-and-hearing.com FLW Rant-Rave