Posts

Showing posts with the label statistics

Jittering in R (ggplot2)

Image
Jittering is the act of adding random noise to data in order to prevent overplotting in statistical graphs. Overplotting can occur when a continuous measurement is rounded to a convenient unit. This has the effect of making a continuous variable appear like a discrete ordinal variable.  For example, age is measured in years and body weight is measured in pounds or kilograms.  A scatter plot of weight versus age, which includes a sufficiently large sample of people will involve considerable overlap. Many individuals may be recorded as, 29 years old and weighing 70 kg, and there will be many markers plotted at the point (29, 70). The same is often true when plotting other individual difference metrics throughout psychology (e.g. personality) (Figure 1). Figure 1: Before Jittering - a significant positive correlation between x & y [r = .37]. To alleviate overplotting, it is possible to add a small amount of random noise to the data...

Arranging Multiple Plots in R

Image
Arranging several plots in R as part of a grid isn't always straightforward. Imagine you had three plots and wanted one to stretch along the bottom row and place the other two above (i.e. Figure 1). Figure 1: Sketch of intended placement Using grid.arrange , it is possible to plot several outputs, but the function will automatically place them into a default grid structure (Figure 2). grid.arrange(p1, p2, p3, p4, p5, p6, p7, p8, p9) Figure 2: Using grid.arrange This may be perfectly adequate if they are to be of equal size. However, this isn't always ideal. For example, when aligning the plots below, the result becomes cluttered (Figure 3). grid.arrange(p3, p4, p5) Figure 3: Work in progress As per my original sketch, I want the top plot (with no legend) to run along the bottom row and the other two plots to be positioned side by side above. The following example shows how this can be accomplished. First, a new layout is created, here a...

How predictable is English Football? Using linear regression to forecast future league positions

Image
Sport produces a lot of data that pundits generally ignore. Somehow, they manage to spend hours debating how a season of football was hampered or improved by the actions of a few individuals. Usually referees. My gut feeling has always been that success for any English Premier League football team is highly dependant on financial management. This varies considerably between clubs. Curiosity got the better of me on this one. In statistics, linear regression is an approach to modelling the relationship between a scalar dependent variable y and one or more explanatory variables denoted X. It was the first type of regression to be studied seriously and the first to be used extensively in practical applications. In this instance, my dependant variable is league points awarded this season, and my predictors are turnover, profit/loss before tax, net debt, interest owed on any debt and the club's wage bill. These predictors were all taken from the previous season.* Multiple r...

Why are we still paying for statistical software?

' What programme should I use to analyse this data? ' About ten  years ago there was little choice and expensive software would have arrived in a box containing a CD-ROM! I still have SPSS and MATLAB in my applications folder. They don't come on CDs anymore, but from a central university server. Like CDs however, these programmes are on the verge of becoming a redundant medium.  Given the choice of free tools available today, how are commercial alternatives going to survive?  IBM acquired SPSS a few years back  for $1.2 billion, which I am not convinced was a particularly smart move.  Psychologists typically want to test  predictions,  visualise data and produce models. That said, additional functionality can often be required quickly and unexpectedly as a research project or idea develops. An open-source community allows for flexibility that paid alternatives do not offer (yet). The ba...

At the pub with a time series

Image
When following the variation of some quantity over time, it is termed a time series.  For example , when plotting the number of births per month in New York city from 1946-1960, there is a peak each summer (seasonability). There is also long-term growth in the number of births each year (a trend). The pilot data below comes from an accelerometer showing the amount of movement produced by an individual over time. This sensor is worn around the neck and produces a data point every second. To keep things interesting, I should mention that the individual wearing this sensor was at the pub for around 2 hours and while there consumed 2 units of alcohol. The rapid spike at the start shows them walking down the stairs to the bar (conveniently located below the School of Psychology). Due to the large number of data points and variation within the data, it is almost impossible to get an idea of what is going on as the evening progresses (if anything!). Although w...

Kernel Density Plots: Has the histogram had its day?

Image
Simple statistical concepts include the mean, median, standard deviation, and percentiles. These are useful for summarising data. Except these summary statistics are only useful under certain circumstances. When basic assumptions are not met, then any conclusions based on simple summary statistics are likely to be inaccurate. Unable to give a hint as to what is wrong, the numbers can often look perfectly reasonable. Lets consider a sample of 64 reaction time observations (in milliseconds): Mean = 387ms Median = 340ms These look ok, until you view the distribution, which is not unimodal.  Despite being a staple in data visualisation, histograms can often be a poor method for determining the shape of a given distribution because they are strongly affected by the number of bins used. For example, visualising the same data with only four bins can make the same observations appear normally distributed. Similarly, a box-plot can also hide data irregulari...

Network analysis: Where are you in my social network?

Image
Michael Slater-Townshend  talks extensively about the merits of understanding your own and other online communities in this in this months Royal Statistical Society magazine. After following his advice, I have discovered that it is surprisingly easy to download your own Facebook data and see which of your friends form connected groups. Several apps allow you to download 'raw' Facebook data in a format that suits almost any statistical package. I used NameGenWeb . The resulting file can then be imported into a variety of statistical packages. I chose to use Gelphi  for this example. My unprocessed Facebook network looks like this... Each dot (or node) is a friend and the lines show friendship connections between each individual.  In order to make things manageable, I ran a cluster analysis to look for groups of people who are more connected to each other. This quickly produced three distinct groups. The larger ...

Squash and Statistics - Together at Last!

Image
Wimbledon, Euro 2012, The Olympics. The Great British summer of sport has already arrived, but I am sad to say that my sport of choice will not be represented in any of these events. I can't do anything about that, but what I can do is attempt to see where my own game could use some improvement. I regularly play games against my friend Josh (@bain_josh) and most of the time, these games are pretty close. My own gut feeling is that when I win a match, I am overreliant on gaining points when serving. When Josh wins, this doesn't seem to happen. I should add at this stage that you  do not  need to hold serve to score a point in squash. Points are awarded based on who wins a rally. The winner of that rally then goes onto start the next and so on. Basically, I think amongst the many things we could both improve on, one of those is our return of serve. After filming two games - I set out to try and answer how important this ...

Being honest with statistics

Image
Daniel Bor's latest blog entry  discusses problems with weak statistics in neuroimaging papers, but the issues raised are relevant to any area of research that relies on inferential statistics. For example, as behavioural scientists move towards collecting larger data sets, the risk of finding false-positives increases accordingly. Statistics also play an important role in any psychology degree. Gaps in statistical knowledge quickly become apparent when students are asked to critically review other's work or carry out their own research. One wonders if these early misconceptions could contribute to poor research practices further down the line.  In my somewhat limited experience, psychology students generally know what numbers they need to report, but often fail to understand what goes into making those numbers a reality. This common misunderstanding can be split into three distinctive areas where undergraduates may benefit from additional ...