Publications by aghaynes

Calculating confidence intervals for proportions

09.04.2014

Heres a couple of functions for calculating the confidence intervals for proportions. Firstly I give you the Simple Asymtotic Method: simpasym <- function(n, p, z=1.96, cc=TRUE){   out <- list()   if(cc){     out$lb <- p - z*sqrt((p*(1-p))/n) - 0.5/n     out$ub <- p + z*sqrt((p*(1-p))/n) + 0.5/n   } else {     out$lb <- p - z*sqrt((p*...

1370 sym R (890 sym/4 pcs) 4 img

“Pretty” table columns

10.04.2014

Every now and then you might want to make a nice table to include directly in your documents without having to faff about with columns later in excel or word. Typical issues might be the specification of decimal places, converting a value and proportion/SE column into one to take the form of n (x) or a value and CIs into x (x_min – x_max). I ne...

1279 sym R (1083 sym/3 pcs) 4 img

Emails from R

21.04.2017

There are a few packages for sending email directly from R, but I work in a place where none of these work due to strict network settings. To at least partially circumvent this, here’s some code to produce a PowerShell script to send email(s) via Outlook. The PowerShell script can then be run either by a shell call (again, not possible in my wo...

913 sym R (1430 sym/1 pcs) 4 img

Count models in JAGS

17.05.2017

Looks like I’ll be diving into some Bayesian analyses using JAGS. This post is primarily intended as a collection of links to [potentially] useful information, but also includes a few initial thoughts (I might update it occasionally with new links). In terms of R packages, a very brief play suggests that R2jags is more user friendly than rjags ...

2786 sym R (230 sym/1 pcs) 4 img

Flow charts in R

09.05.2018

Flow charts are an important part of a clinical trial report. Making them can be a pain though. One good way to do it seems to be with the grid and Gmisc packages in R. X and Y coordinates can be designated based on the center of the boxes in normalized device coordinates (proportions of the device space – 0.5 is this middle) which saves a lot ...

1116 sym R (1247 sym/1 pcs) 2 img

grconvertX and grconvertY

15.05.2018

These two functions are unbelievably useful for positioning graphical elements (text, axes, labels, …) in R. They allow one to convert coordinates between various different formats. For instance, you can convert your user coordinate (say 5 where x ranges from 0 to 200) to normalized device coordinates (proportional distance across the device) a...

1190 sym R (327 sym/3 pcs) 2 img

openrouteservice – geodata!

19.05.2018

The openrouteservice provides a new method to get geodata into R. It has an API (or a set of them) and an R package has been written to communicate with said API(s) and is available from GitHub. I’ve just been playing around with the examples on this page, in the thought of using it for a project (more on that later if I get anywhere with it). ...

2467 sym R (1829 sym/9 pcs) 2 img

Tips for great graphics

26.05.2018

R is a great program for generating top-notch graphics. But to get the best out of it, you need to put in a little more work. Here are a few tips for adapting your R graphics to make them look a little better. 1) Dont use the “File/Save as…/” menu. If you set up your graphic in the first place then theres no need to post-process (eg crop, s...

3342 sym R (522 sym/4 pcs) 4 img

Intersecting points and overlapping polygons

27.05.2018

I’ve been doing some spatial stuff of late and the next little step will involve intersecting points with possibly many overlapping polygons. The sp package has a function called over which returns the polygons that points intersects with. The catch though, is that it only returns the last (highest numerical value) polygon a point overlaps with...

1502 sym R (691 sym/6 pcs)

Merging spatial buffers in R

11.06.2018

I’m sure there’s a better way out there, but I struggled to find a way to dissolve polygons that touched/overlapped each other (the special case being buffers). For example,  using the osmdata package, we can download the polygons representing hospital buildings in Bern, Switzerland. library(osmdata) library(rgdal) ; library(maptools) ; libr...

1533 sym R (1393 sym/4 pcs) 6 img