# Blog Archives

## “Pretty” table columns

April 10, 2014
By

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

## Calculating confidence intervals for proportions

April 9, 2014
By

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

## Import/Export data to and from xlsx files

April 5, 2013
By

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

## Mixed model R2 (UPDATED)

March 28, 2013
By

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

## R-Studio

August 28, 2012
By

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

## Importing data directly from MS Excel

August 10, 2012
By

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

## The inner workings of R objects

June 29, 2012
By

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)

## Grouped means (again)

June 26, 2012
By

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,

## Grouped means (or anything else…)

June 25, 2012
By

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

## Normalising data within groups

June 21, 2012
By

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