"cta" <- function(n=3,t=5000, cues = NULL, act=NULL, inhibit=NULL, consume = NULL,ten = NULL, type="both",fast=2 ,compare=FALSE) { #simulation of the CTA reparamaterization of the dynamics of action if(n > 4){ colours <- rainbow(n)} else {colours <- c("black","blue", "red", "green") } step <- .05 ten.start <- ten act.start <- act if(is.null(cues)) {cues <- 2^(n-1:n)} if(is.null(inhibit)) {inhibit <- matrix(1,ncol=n,nrow=n) diag(inhibit) <- .05} if(n>1) {colnames(inhibit) <- rownames(inhibit) <- paste("A",1:n,sep="")} if(is.null(consume) ) {consume <- diag(.05,ncol=n,nrow=n) } excite <- diag(step,n) #first run for time= t to find the maximum values to make nice plots as well as to get the summary stats if (is.null(ten.start)) {ten <- rep(0,n)} else {ten <- ten.start} if(is.null(act.start) ) {act <- cues} else {act <- act.start} maxact <- minact <- minten <- maxten <- 0 counts <- rep(0,n) transitions <- matrix(0,ncol=n,nrow=n) frequency <- matrix(0,ncol=n,nrow=n) colnames(frequency) <- paste("T",1:n,sep="") rownames(frequency) <- paste("F",1:n,sep="") old.act <- which.max(act) for (i in 1:t) { ten <- cues %*% excite + ten - act %*% excite %*% consume act <- ten %*% excite + act - act %*% excite %*% inhibit act[act<0] <- 0 maxact <- max(maxact,act) minact <- min(minact,act) maxten <- max(maxten,ten) minten <- min(minten,ten) which.act <- which.max(act) counts[which.act] <- counts[which.act]+1 transitions[old.act,which.act] <- transitions[old.act,which.act] + 1 if(old.act!=which.act) { frequency[old.act,which.act] <- frequency[old.act,which.act] + 1 frequency[which.act,which.act] <- frequency[which.act,which.act] +1} old.act <- which.act } #now do various types of plots, depending upon the type of plot desired plots <- 1 action <- FALSE #state diagrams plot two tendencies agaist each other over time if (type!="none") {if (type=="state") { op <- par(mfrow=c(1,1)) if (is.null(ten.start)) {ten <- rep(0,n)} else {ten <- ten.start} if(is.null(act.start) ) {act <- cues} else {act <- act.start} plot(ten[1],ten[2],xlim=c(minten,maxten),ylim=c(minten,maxten),col="black", main="State diagram",xlab="Tendency 1", ylab="Tendency 2") for (i in 1:t) { ten <- cues %*% excite + ten - act %*% excite %*% consume act <- ten %*% excite + act - act %*% excite %*% inhibit act[act<0] <- 0 if(!(i %% fast)) points(ten[1],ten[2],col="black",pch=20,cex=.2) } } else { #the basic default is to plot action tendencies and actions in a two up graph if(type=="both") {if(compare) {op <- par(mfrow=c(2,2))} else {op <- par(mfrow=c(2,1))} plots <- 2 } else {op <- par(mfrow=c(1,1))} if (type=="action") {action <- TRUE} else {if(type=="tend" ) action <- FALSE} for (k in 1:plots) { if (is.null(ten.start)) {ten <- rep(0,n)} else {ten <- ten.start} if(is.null(act.start) ) {act <- cues} else {act <- act.start} if(action ) plot(rep(1,n),act,xlim=c(0,t),ylim=c(minact,maxact),xlab="time",ylab="action", main="Actions over time") else plot(rep(1,n),ten,xlim=c(0,t),ylim=c(minten,maxten),xlab="time",ylab="action tendency",main="Action Tendencies over time") for (i in 1:t) { ten <- cues %*% excite + ten - act %*% excite %*% consume act <- ten %*% excite + act - act %*% excite %*% inhibit act[act<0] <- 0 if(!(i %% fast) ) {if( action) points(rep(i,n),act,col=colours,cex=.2) else points(rep(i,n),ten,col=colours,cex=.2) }} action <- TRUE} } } results <- list(cues=cues,inihibition=inhibit,time = counts,frequency=frequency, ten=ten, act=act) return(results) }