Publications by aghaynes

Labelling panels in R graphics

08.03.2012

Labelling a graphics panel in R is easy right? Sure it is, just use text and define the coordinates. text(x=5, y=10, "a") But is there an easy way to get in the same place all the time, even if you have different axis lengths (e.g. 0 to 5 on the x-axis but 0 to 100 on the y-axis)? I don’t know if there was, but there is now!!! Copy and run the ...

1125 sym R (876 sym/4 pcs) 4 img

Twotorials

12.06.2012

Heres a fun little page! http://www.twotorials.com/ About 90 two minute tutorials (twotorials, haha) on various things in R! From “what does object oriented programming […] mean” to calculating the number of days youve been alive. The guy has an amusing voice too!! Great for newbies to R I should imagine!!! Have a look!! Related To leave ...

737 sym 4 img

Normalising data within groups

21.06.2012

Occasionally it proves useful to normalise data. By this I mean to scale it between zero and one. Admittedly, most people frown of this but there are papers out there with this method in use*. How do we go about this? Its a very simple formula to calculate: y'[i] = y[i]/sqrt(sum(y^2)) So we square all of the ys, add them up and take the square ro...

2322 sym R (309 sym/7 pcs) 4 img

Grouped means (or anything else…)

25.06.2012

An easy one today, but something that stumped me for a while* the first time I tried it out. How do you get a group mean (or other summary statistic) from R? Lets say you have a Y variable that represents repetitions for each of however many factors. You could subset the data by each combination of the X variables. Something like trt1alt1 <- mean...

1542 sym R (309 sym/1 pcs) 4 img

Grouped means (again)

26.06.2012

So, the post I did yesterday on aggregate seemed to go down well. One of the comments suggested I add an example. Other comments had other useful hints which I thought I’d pass on more formally. So here goes… The mtcars dataset in base has data on various aspects of cars – miles per gallon, number of cylinders etc etc etc. This makes it a n...

2757 sym R (1136 sym/7 pcs) 4 img

The inner workings of R objects

29.06.2012

R is an object oriented language. You provide a name and R supplies that name with various properties. In the simplest case, you can assign a number to a name. This will only have a few attributes, such as its class, length etc: i <- 5 names(i) #NULL class(i) #[1] "integer" attr(i, "name") #NULL dim(i) #NULL Larger objects have more attributes of...

2475 sym R (1521 sym/5 pcs) 8 img

Importing data directly from MS Excel

10.08.2012

R is great for exploring, analysing and graphing your valuable data. No question about it. Unfortunately though, there’s no base package support for importing data directly from MS Excel. This means that you have to faff about saving it in another format, and THEN import this new file. This just adds another file to your computer, taking up mor...

2848 sym R (998 sym/3 pcs) 4 img

R-Studio

28.08.2012

A post over on Dang, another error (show me yours and I’ll show you mine) has a method of working with R which uses an IDE called Eclipse in conjunction with a plugin called StatET. Eclipse is one of a number of IDEs that I’m aware of (Tinn-R being another, but this Sciviews pages has an enormous list). I like R-Studio and have recommended it...

2228 sym 4 img

Mixed model R2 (UPDATED)

28.03.2013

R2 is a useful tool for determining how strong the relationship between two variables is. Unfortunately, the definition of R2 for mixed effects models is difficult – do you include the random variable or just the fixed effects? Including just the fixed effects is essentially a standard linear model, while including the random effects could conf...

2015 sym R (190 sym/1 pcs) 4 img

Import/Export data to and from xlsx files

05.04.2013

As Ive already written, getting data into R from your precious xlsx files is really handy. No need to clutter up your computer with txt or csv files. The previous post I wrote about the gdata package for importing data from xlsx files and was pointed to, among others, the xlsx package. xlsx seems to be a good package, easy to use and, importantly...

2420 sym R (917 sym/4 pcs) 4 img