# function for calculating coupled equations session <- function(a,b,c,d,e,f,g,h,p,cnt){ xlim1 <- c(0,100) ylim1 <- c(-4,4) ylim2 <- c(-4,4) ylim3 <- c(0,10) v<-rnorm(100,0,1); w<-rnorm(100,0,0.5); i<-1:100; x<-1:100; z<-1:100; m<-1:100; y<-1:100; y[1]<- a; z[1]<- f; m[1] <- 0; for(i in 2:100){ y[i]=y[1]-b*sin(i/32)-c*sin(i/4)-d*(z[i-1])+e*v[i]; if (y[i] < 0.0) m[i] <- y[i]^2 else m[i]=0; z[i]=z[1]+g*sin(i/32)+h*m[i]+p*w[i]; }; main1<-paste("#",cnt+1," Generated TS - Client Self-Directed Affect - ") # print(y) # print(z) par(mfrow=c(4,1)); cnt<-cnt+1 q <- c(a,b,c,d,e,f,g,h,p) plot (x,v, type="l", col="darkred", xlab="time", ylab="random - client", cex.lab=1.2, xlim=xlim1, ylim=ylim1, main="Generated Time Series - Client Random Factor", col.main= "darkblue", cex.main=3); plot (x,w, type="l", col="darkred", xlab="time", ylab="random - therapist", cex.lab=1.2, xlim=xlim1, ylim=ylim1, main="Generated Time Series - Therapist Random Factor", col.main= "darkblue", cex.main=3); plot (x,y, type="l", col="darkred", xlab="time", ylab="client measure", cex.lab=1.2, xlim=xlim1, ylim=ylim2, main=main1, col.main= "darkblue", cex.main=3); plot (x,z, type="l", col="darkred", xlab="time", ylab="therapist measure", cex.lab=1.2, xlim=xlim1, ylim=ylim3, main="Generated Time Series - Therapist Attention to Client", col.main= "darkblue", cex.main=3); print(cnt) print(q) print(y[1]) print(y[100]) return(cnt) } #routine for varying the parameters cnt <- 0 # a <- 2 # b <- 2 # c <- 1.5 d <- 0.3 e <- 0.8 f <- 3 g <- 2.5 h <- 0.1 p <- 2 setwd("F:/York University/York University Courses/Fall-Winter 2011-12/4th Yr Thesis/Thesis - Dr. John Eastwood/R/Programs/Mathematical Model Generator Routine/pdf outputs") pdf(file="GeneratedFromEquations-1.pdf",width= 12, height= 12, family = "Helvetica", title = "MBF Data",bg="white") for (a in -4:4){ for (b in -5:5){ for (c1 in 0:5){ # for (d1 in 2:4){ c <- c1/2 # d <- d1/10 cnt<-session(a,b,c,d,e,f,g,h,p,cnt) } } } # } dev.off()