07 April 2017

How to use Pivot Tables in Excel

Excel can be used to conduct some pretty advanced statistical analyses and data visualisations. My favourite, and most commonly used feature is the Pivot Table. The data in a Pivot Table can be restructured very easily and counts, averages and other calculations can be worked out quickly. It is often desirable to enter data from scientific experiments into a Pivot Table so that different conditions can be compared, some conditions or participants or trials can be excluded, and data can be collapsed or combined in a number of ways. But, for all of their usefulness, getting the data in to a format that can be read by a Pivot Table can be time consuming. Some experiment presentation/management programs, such as E-Prime, generate result files for individual participants. In order to generate a Pivot Table report, all data needs to be entered into a single Excel worksheet. 

Here are the steps necessary to generate a Pivot Table in Excel:

1. Export the results files into a format that can be imported into Excel
Some experimental software outputs results in plain text format or as .csv files. These can be imported into Excel without any extra work. However, some software outputs results in a proprietary format that must be converted  before Excel can read the data.

E-Prime: Open the .edat2 file in E-DataAid, and export to Excel format. For example, you would export participant1.edat2 as participant1.edat2.txt. 

Hint: If you have many E-Prime data files, open these in E-Merge and create a merge file containing data for all of the participants. Then open the merge file using E-DataAid and export it to Excel format.

2. Open the text file in Excel
Open the new .txt files in Excel (you can either select File | Open or drag and drop the file into Excel).

3. Go through the Text Import Wizard




In Step 1, select Delimited and click Next.



In Step 2, check the Tab option from the list of Delimiters and click Finish.

4. Delete Row 1

By default, E-Prime outputs the file path in the first line of the .txt file, which becomes row 1 when you import it into Excel. Delete it. This will cause row 2 to move up. Now row 1 contains your column headings which will become your Pivot Table fields.

5. Create a Pivot Table
Select all active columns. To do this, click on column A (by clicking on the A) and hold down the Shift key and click on the column label of the right most column (mine is HZ). This can be done using the keyboard by pressing Command+Shift+right arrow while column A is selected.


Click on the Insert ribbon and then Pivot Table. When the Create Pivot Table dialog appears, click OK.

6. Build your Pivot Table
Drag the fields that you are interested in into the Rows, Columns or Values areas. Subject/participant normally goes into the Rows area. The measures of interest (e.g., accuracy or reaction time data) usually go into Values.


When you first drag a field into Values, Excel will show you the count of how many data points there are. Click on the "i" next to the field within the Values area to show the Pivot Table Field window.


This gives you options to calculate the sum, average, maximum, minimum, standard deviation and so on. For experimental data, most of the time, we are interested in averages.

Spend time playing around with the fields in the Pivot Table Builder. You can explore your data in powerful ways, such as by isolating particular subjects, conditions, or cases.


Clicking on the inverted triangle next to Row Labels brings up the Row window which permits you to sort the rows, add filters, and exclude individual cases. This can be handy for exploring potential outliers (when looking at subjects), or examining performance for particular conditions or stimulus tokens.

Pivot Tables are great tools for exploring your data. They offer a degree of flexibility that is unmatched. They are very useful for answering "What happens if..." questions, and the calculations can be done very quickly.

25 January 2017

Zotero minimalist referencing style for grant applications

I use a custom Zotero referencing style when writing grant applications. It is designed to save space, and uses the following features:

  • In-text citations are denoted by superscript numerals
  • Reference list has single line spacing
  • No journal article titles
  • Journal names are abbreviated
  • No journal issue numbers
  • ≥ 3 author names are listed as "et al."

After each reference, I have inserted two forward slashes to demarcate separate references. I have also bolded the numeral that precedes each reference.

Once the reference list has been created, you may delete the carriage returns so that each reference does not take a new line.

My grant writing Zotero referencing style can be downloaded here.

19 December 2016

Calculate age in years (and months) in Excel

It is often desirable to calculate a person's age from their date of birth relative to some other date (e.g., the date when they completed some test). This is pretty easy to do in Excel.

Calculating age in years
The simplest way to do this is using the following formula

=yearfrac(start_date,end_date,1)

where start_date is the cell containing the person's date of birth.

Using the above formula for someone with a D.O.B. of 20/3/1990 who was tested on 19/9/2016 will return the value 26.5017238, which may be reduced to fewer decimal points if so desired.

Calculating age in years and months
To calculate age in years and months, rather than using a decimal point, use the following formula

=concatenate(datedif(start_date,end_date,"Y"," years, ",datedif(start_date,end_date,"YM")," months")

Using this formula will return the value 26 years, 5 months. This formula can be modified to return other commonly used formats such as 26;5.


11 June 2015

How to set up Tweetbot iCloud sync across iOS and OS X

Tapbots recently released their much anticipated v.2 update for their Mac OS X Yosemite version of their Twitter client, Tweetbot. One of the most touted features is the ability to sync timeline position across devices using iCloud. However, a quick Google search reveals that many people are experiencing issues with getting iCloud sync to work. Some of the more detailed guides I came across are:

How To Get Tweetbot to Sync to iCloud on iPhone (Fix) via Apptactics

Tweetbot and that f*cking iCloud sync via Coupaman's New Digs

Unfortunately, neither of the above guides solved my iCloud timeline sync issues. In the end, the thing that fixed the problem was signing out of iCloud on my iPhone and then signing back in.

Steps:

1. In iOS, tap Settings, then iCloud.

2. Scroll down to the bottom and tap Sign Out, and then confirm when prompted.

3. Sign back in to iCloud.

That's what did it for me. I hope that this is helpful for those who are experiencing similar issues.

09 December 2014

How to fix the no sound issue on a MacBook

I have been experiencing some sound output issues on my MacBook Air recently, and a quick Google search revealed that many people have been experiencing the same problem. Here is a short description of the the problem and my solution.

What's the problem?
I like to use ear phones with my MacBook. The sound works fine when I first boot up, however, if I am away from the computer and it goes to sleep (e.g., during lunch), the volume icon is greyed out when I wake the computer. The sound does not work and I cannot adjust the volume. Very annoying.

Troubleshooting
Sound is affected on a system-wide level. This is not restricted to a single app. Rebooting the computer resolves the issue, but this is not something I want to be doing all the time. Other users recommend flushing PRAM and doing all sorts of weird things in the Terminal that I don't want to be part of my regular workflow. Ideally, I'd like to do something once that fixes the problem for good.

The solution
When the volume icon is greyed out, click System Preferences | Sound | Output and select Headphone port as your device for sound output. That's it.

And there you have it. A simple solution to a persistent and complex problem.