(This routine is an unconstrained mathematical model time series generator. In the Curve Shape Testing Routine most of the code below is used to generate time series that can be tested in the Curve Shape Testing Routine. In a fully developed Mathematical Model Generator Routine, the generator should be coupled to the Characterization Routine in order to characterize and eliminate unsuitable equation coefficients. Most of the documentation of this code is contained in the Readme for the Curve Shape Testing Routine. Therefore only broad divisions are repeated here, along with a few comments about parts of the code that need refinement.) (The following part is a function or subroutine for calcuating the value of a time series from a proposed set of coupled modeling equations embedded in the code below. ) # 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; np<-0 nn<-0 y[1]<- a; z[1]<- f; m[1] <- 0; (essentially all the above just defines variables that are used below and gives them some initial values. The code may be clumsy, since it introduces variables by filling them with arbitrary values (1 to 100) in order to get the computer to recognize them. Their values are later replaced in the code below. There may be simpler and more elegant ways of defining values.) (below is the recursive calculations of the values produced by the coupled equations. The equations can be altered - these are pretty arbitrary guesses at how to simulate a client and therapist interacting.) 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]; }; (the following just gets ready to print to console (number outputs) and *.pdf (graphical output) the coefficients of each set of equations and the results from it.) 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) } (the following variation routine recalculates the values of the functions in the equations, with methodical variation of the coefficients of the terms in the coupled equations.) #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) } } } # } (below the device is turned off so that you can immediately look at the *.pdf file. If it doesn't work, let R complete generating its data, save the console output, and then close the R program. Look for the output *.pdf file in your disk, and click on it to open the *.pdf file.) dev.off()