This time, let’s try some entropy of DIFFERENCES. We want to know how stable a person’s typing is. I’ll cover some quick examples with typing.

To begin, let’s load up example subjects, as before:

subject1 = read.table('1.csv',header=T)
subject2 = read.table('2.csv',header=T)
plot(subject1$RT)

plot(subject2$RT)

Let’s create a new time series of differences from keystroke to keystroke. In other words, how much does the reaction time change from key to key – is this person a really stable typist, with a consistent keystroke from key to key? Or is this person more variable, showing fits and starts as they type? A way to check this is to use the “diff” function, which creates a new time series by subtracting the prior keystroke from the next keystroke. This can be called a differenced time series.

differenced_time_series = diff(subject1$RT)
plot(differenced_time_series)

differenced_time_series = diff(subject2$RT)
plot(differenced_time_series) # notice we reused the differenced_time_series by "writing" over it!

Notice how the new times series is “jumping” above and below zero. If the differenced value (in the new times series) is positive, that means their NEXT keystroke was SLOWER than the prior keystroke; if it shows a negative (below zero) value, that means they sped up – the NEXT keystroke was FASTER. Now we have a representation of the keystroke to keystroke typing speed… in a sense, this gives us a “window” onto the stability of the mental process itself.

Let’s take the entropy of this, as we did in the prior exercise.

library(entropy)
entropy(discretize(differenced_time_series,numBins=10)) # entropy of differenced time series
## [1] 0.7707383

Note that we just have to substitute the variable that we created (the new time series) into the entropy calculation from the prior exercise.

Simple exercise

Go back to your script that you created, and carry out this differencing process on a few of them that you found interesting… identify subjects that seem to be really variable in their typing. Calculate entropy for each in the way I show you here.

Advanced exercise for fun: STOCKS!

Let’s take a totally different data set, simply to show you that these ideas apply across a any dynamic domain. We can even step outside cognitive science, and into finance. Click here to download a set of 3 stock prices for major companies: Microsoft, Apple, and Facebook.

Use your skills now to load in the data table for each. Answer the following questions.

  1. What are the variables (the columns) of these data sets?

  2. Plot the stocks – do you notice anything strange about them?

  3. Which stock shows the highest entropy in its Close price?

Advanced, optional:

  1. Which stock shows the highest differenced entropy in the Close price – which is more irregular in its up and down changes, over time?

If you get through this, you’ve made a major advanced in your RStudio skills – you can load a new dataset, interpret and understand that dataset, plot and quantify it using basic techniques, including learning a bit about an advanced topic like entropy. Alright!