Blog Archives

“Pretty” table columns

April 10, 2014
By
“Pretty” table columns

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

Read more »

Calculating confidence intervals for proportions

April 9, 2014
By
Calculating confidence intervals for proportions

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 <-

Read more »

Import/Export data to and from xlsx files

April 5, 2013
By
Import/Export data to and from xlsx files

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

Read more »

Mixed model R2 (UPDATED)

March 28, 2013
By
Mixed model R2 (UPDATED)

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

Read more »

R-Studio

August 28, 2012
By
R-Studio

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

Read more »

Importing data directly from MS Excel

August 10, 2012
By
Importing data directly from MS Excel

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

Read more »

The inner workings of R objects

June 29, 2012
By
The inner workings of R objects

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) # "integer" attr(i, "name") #NULL dim(i)

Read more »

Grouped means (again)

June 26, 2012
By
Grouped means (again)

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,

Read more »

Grouped means (or anything else…)

June 25, 2012
By
Grouped means (or anything else…)

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

Read more »

Normalising data within groups

June 21, 2012
By
Normalising data within groups

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' = y/sqrt(sum(y^2)) So we square all

Read more »