#functions for Parallel Simulations Research Profile comb <- function(...) { mapply('cbind', ..., SIMPLIFY=FALSE) } rwalk <- function(n.org, time, stepsize = 0, prob = 0.5, plot = TRUE, title = "name", radius = 300){ require(ggplot2) whereto <- matrix(ncol = 2) #creates matrix to store data in for(x in 1:n.org){ walker <- matrix(c(0,0), nrow = time + 1, ncol = 2, byrow = T) #creates matrix of x,y coordinants for(i in 1:time){ #calculating it in polar cordinants # Stepsize step <- stepsize # Movement direction <- runif(1, 0, 360) #conversion constant #pi = 180 degrees conversion = pi/180 #random radian angle radian <- direction * conversion #Conversion from polar coordinants to cartesian plane xspot <- step* cos(radian) yspot <- step* sin(radian) #adding those coordinants to our last ones walker[i+1, 1] <- walker[i,1] + xspot walker[i+1, 2] <- walker[i,2] + yspot } whereto <- rbind(whereto, walker) } id <- rep(1:n.org, each = time +1) colnames(whereto) <- c("x" , "y") whereto <- as.data.frame(whereto) whereto <- cbind(whereto[2:nrow(whereto),], org = factor(id)) #binds the two matricies together if(plot){ require(ggplot2) p <- ggplot(whereto, aes(x = x, y = y, colour = org)) p <- p + geom_path() + ggtitle(title) + theme(legend.position="none") + annotate("path", #specifies the path of the vemco circle x=0+radius*cos(seq(0,2*pi,length.out=100)), #x positions y=0+radius*sin(seq(0,2*pi,length.out=100))) + #y positions annotate("text", x = radius, y = radius, label = "Vemco Detection Radius") print(p) } return(whereto) } dfresults <- function(listname, listnum, IDcol =ID) { l<-eval(parse(text = paste(listname, "[", listnum, "]", sep = ""))) #pulls the list d <- data.frame(l) #turns it into dataframe rd <- NULL rd$x <- stack(d[str_detect(names(d), "x")])$values rd$y <- stack(d[str_detect(names(d), "y")])$values rd$org <- as.factor(IDcol) rd <- data.frame(rd) return(rd) }