This page has some wonderful resources for recurrence analysis. One particularly useful resource on this site is the listing of software options for conducting recurrence analysis. After a fair amount of searching, I couldn't find an R package that computed the metrics from a recurrence quantification analysis. The tseriesChaos package provides a function for producing recurrence plots; but, I didn't see anything for quantifying these plots.
After digging through the different software options listed on this site, I tried out and really like the Commandline Recurrence Plots script offered by Norbert Marwan himself.
The script was very easy to setup on my Mac and, by using Rscript it was easy to combine with R code to (a) draw specific chunks of data for different individuals in my dataset; (b) compute and output the recurrence quantification metrics; (c) output the recurrence plot dataset for creating the actual plot; and, (d) producing the plot and creating a dataset of metrics.
I'll clean up, comment, and post the code that I used as soon as I can come up for air.
Showing posts with label graphing. Show all posts
Showing posts with label graphing. Show all posts
Monday, May 20, 2013
Monday, April 15, 2013
R Graphics Parameters -- Rows and Columns
For some reason I always forget the code for setting R's graphics parameters. And, I always need this same line. So, now I shan't forget it.
quartz(type="pdf",file="figure_NUM.pdf")
par(mfrow=c(3,2), cex=1, mar=c(2,2,2,2))
dev.off()
Thursday, November 15, 2012
Using color in R graphics
I'm sticking this here because I always forget the simple ways to specify and manipulate color in R graphics:
Earl Glynn put together a very useful presentation, which covers a range of topics on using color in R graphics.
Earl Glynn put together a very useful presentation, which covers a range of topics on using color in R graphics.
Sunday, September 23, 2012
Create a filled line graph with R
I used the code below to create a presentation-quality graph of data on how individual's activation level (measured as electrodermal activity) changes over time during a group-based task. (Click on the image to enlarge.)
quartz(width=16,height=8,type="pdf",file="indiv_eda_z.pdf",dpi=600)
par(xpd=TRUE)
par(family="Tahoma", bg="white", mar=c(3,3,3,3), mgp=c(1,1,1))
ylim <- c(-1.5, 1.5)
xlim <- c(-540, 2700)
x <- aggsub$task_time
y <- aggsub$eda_z
ylo <- rep(min(y), length(y))
plot(x,y, type="n", ylim=ylim, axes=FALSE, ylab="Electrodermal Activity", xlab="Time (in minutes)", xlim=xlim, col="dark green")
xpos <- seq(-540, 2700, 180)
lab <- seq(-9, 45, 3)
axis(1, at=xpos, labels=lab, cex =1.5, lwd=.5, lty=3, tck=1, col="dark gray", pos=-1.5, col.axis="dark gray")
ypos <- seq(-1.5, 1.5, .5)
axis(2, at=ypos , labels=ypos, cex =1.5, las=2, tck=1, lwd=.5, lty=3, col="dark gray", pos=-540, col.axis="dark gray")
zerox <- -540:2700
zeroy <- rep(0, length(zerox))
lines(zerox, zeroy, lty=1, lwd=2, col="red")
lines(x,y, lwd=2.5,col="dark green")
xx <- c(x, rev(x))
yy <- c(ylo, rev(y))
polygon(xx, yy, col="light green", border=FALSE)
sessionstart <- min(x)
taskstart <- 0
taskend <- 1800
recordend <- 1920
sessionend <- max(x)
polygon(c(sessionstart, sessionstart, taskstart, taskstart), c(1.5, min(y), min(y), 1.5), col="#0015FF25", border=FALSE)
text(-270, 1.25, "Pre-Task Survey", col="dark blue")
#polygon(c(taskstart, taskstart, taskend, taskend), c(1.5, min(y), min(y), 1.5), col="#EAFF0025", border=FALSE)
text(900, 1.25, "Group Members Work to Develop Recruitment Video", col="dark green")
polygon(c(taskend, taskend, recordend, recordend), c(1.5, min(y), min(y), 1.5), col="#FA050535", border=FALSE)
text(recordend-(recordend-taskend)/2, 1.25, "Record\nVideo", col="red")
polygon(c(recordend, recordend, sessionend, sessionend), c(1.5, min(y), min(y), 1.5), col="#0015FF25", border=FALSE)
text(sessionend-(sessionend-recordend)/2, 1.25, "Post-Task Survey", col="dark blue")
dev.off()
Create animated graphs with R
I collected some longitudinal data on how group members' electrodermal activity changes over the course of a group task. Displaying the data in motion was helpful for emphasizing a few points, which I won't re-hash here. The size of the bubbles in the graph below correspond to the average amount of variation within groups in the sample.Click on the GIF file below to see the result, which uses the animation package in R to create a moving graph.
# Record this as a movie
ymin <- -1.5
ymax <- 1.5
xmin <- -7
xmax <- 45
aggsub <- agg[agg$min1 >= (xmin+2) & agg$min1 <=xmax,]
sessionstart <- xmin
taskstart <- 0
taskend <- 30
recordend <- 32
sessionend <- xmax
saveMovie({
for (i in (xmin+2):xmax) {
x <- aggsub[aggsub$min1 >= xmin & aggsub$min1 <=i, c("min1")]
y <- aggsub[aggsub$min1 >= xmin & aggsub$min1 <=i, c("eda_z")]
r <- aggsub[aggsub$min1 >= xmin & aggsub$min1 <=i, c("eda_z_sd")]
plot(x,y,ylim = c(-1.5,1.5), xlim=c(xmin,xmax),ylab="Electrodermal Activity", xlab="Time", axes=FALSE, type="n")
xpos <- seq(xmin, xmax, 3)
lab <- seq(xmin, xmax, 3)
axis(1, at=xpos, labels=lab, cex =1.5, lwd=.5, lty=3, tck=1, col="dark gray", pos=ymin, col.axis="dark gray")
ypos <- seq(ymin, ymax, .5)
axis(2, at=ypos , labels=ypos, cex =1.5, las=2, tck=1, lwd=.5, lty=3, col="dark gray", pos=xmin, col.axis="dark gray")
zerox <- xmin:xmax
zeroy <- rep(0, length(zerox))
lines(zerox, zeroy, lty=1, lwd=2, col="red")
polygon(c(sessionstart, sessionstart, taskstart, taskstart), c(ymax, ymin, ymin, ymax), col="#0015FF25", border=FALSE)
text(taskstart-(taskstart-xmin)/2, 1.35, "Pre-Task Survey", col="dark blue")
if(i >= taskstart) {
#polygon(c(taskstart, taskstart, taskend, taskend), c(1.5, min(y), min(y), 1.5), col="#EAFF0025", border=FALSE)
text(taskend-(taskend-taskstart)/2, 1.35, "Group Members Work to Develop Recruitment Video", col="dark green")
}
if(i >=taskend) {
polygon(c(taskend, taskend, recordend, recordend), c(ymax, ymin, ymin, ymax), col="#FA050535", border=FALSE)
text(recordend-(recordend-taskend)/2, 1.35, "Record\nVideo", col="red")
}
if(i >=recordend) {
polygon(c(recordend, recordend, sessionend, sessionend), c(ymax, ymin, ymin, ymax), col="#0015FF25", border=FALSE)
text(sessionend-(sessionend-recordend)/2, 1.35, "Post-Task Survey", col="dark blue")
}
symbols(x, y, circles=r, inches=.5, fg="white", bg="dark blue", add=TRUE)
lines(x,y, lwd=1,col="light gray", lty=3)
}
}, interval=.25, moviename="eda_z_team_full.gif", loop=1, filename="eda_z_team_full", fileext="png", outdir=getwd(), width=1600, height=800)
Subscribe to:
Posts (Atom)

