in Beginner, Guide, Matlab, psychoPy, Python, R

A heat map is a graphical representation of data where the individual values contained in a matrix are represented as colors. –Wikipedia

 Concept

Here is my approach to deal with it. All that is need is a frequency of a value being repeated in case of one dimension and then creating a color  map for high to low and plotting them on a graph.

Problem statement

For eye tracking data, we are dealing with a 2d data of x and y points. In the experiement there are squares of size 3.4cm. They are arranged in 10 colomns and 6 rows. We want to see in which of those squares are hit more frequently and produce a heatmap.

Experiment data

For the hits, we have the data from the participant eye tracking. After some manipulations from the eye tracker raw data, we get points x and y. Here we are not using time series analysis so time stamps are not required.

The experiment uses a specific eye tracker but the data is saved using python and the format of the data looks like the following

Timestamp\tTrigger\tLeftValidity\tRightValidity\tLeftX\tLeftY\RigthX\tRightY

Data from userXX trialXXX

[wpdm_file id=3]

Solution code

positions <- read.table("http://blog.southpaw.in/?wpdmact=process&did=My5ob3RsaW5r")
br.x <- seq(-23.5, 23.5, length.out=10)
br.y <- seq(-16.1, 16.1, length.out=6)
int.x <- findInterval(positions[,1], br.x)
int.y <- findInterval(positions[,2], br.y)
#See footnote
int.x <- factor(int.x, levels=10)
int.y <- factor(int.y, levels=6)
tb <- table(int.x, int.y)
image(br.x, br.y, tb, xlab="X", ylab="Y", las=1, main="Heat map")

Conclusion

The image generated can be interpreted as red with low frequecy or almost no hits and the white is with the largest number of hits in this give data set.

Footnote: The two factor calls are necessary because table will otherwise ignore intervals where no data point is present. Converting to a factor effectively forces table to output values even in those slots that have no values in it.

References

 

 

 

 

Write a Comment

Comment

 

This site uses Akismet to reduce spam. Learn how your comment data is processed.