sp.name <- "cb" # *** CHANGE HERE degfree <- 10 # *** CHANGE HERE Nreps <- 399 # *** CHANGE HERE options(echo=F) # # INSTRUCTIONS FOR BATCH PROCESS: # # This file is called bootstrap.in. It is *not* an Splus function, # but is a file kept in the working directory of Splus. # Note: designed for Splus v3.4 for UNIX: I don't know whether (or how) # this works on other systems. # # RUNNING THE JOB: # 1) Edit in this file the name of the species data frame (sp.name), # the degrees of freedom (degfree), and the number of # bootstrap replicates required (Nreps): # these three lines are marked with the note # *** CHANGE HERE. # It is best to choose Nreps to be (say) 499, 399, 299, 199, etc # for later calculation of confidence intervals. # 2) The output file will be called sp.bootind.Nreps.df, # where "sp" is replaced by the species code (e.g. cb), # "Nreps" is replaced by the number of replicates (e.g. 399), # and "df" is replaced by the degrees of freedom for the fit # (e.g. 10). # 3) *Outside* of Splus, type the batch command: # Splus BATCH bootstrap.in sp.bootind.Nreps.df # where sp, Nreps, and df have been changed accordingly. # (e.g. Splus BATCH bootstrap.in cb.bootind.399.10). # Monitor progress via the output file sp.bootind.Nreps.df; # the whole computation could take several hours. # 4) When the program has finished, start Splus and view the # resulting matrix of bootstrapped indices, which has name # sp.bootind.Nreps.df in Splus (sp, Nreps, df as appropriate). # 5) No harm in starting Splus sessions or anything else while # the BATCH program is running, but note that running this # BATCH program will automatically obliterate any previous Splus # objects called sp.bootind.Nreps.df or tmp.index.matrix. # (Also see the last line of this file, in the rm(...) statement, # to see the names of all other objects that will be # obliterated.) # So *be very careful* that sp.name, or degfree, or Nreps, has # been edited at the top before this function is next applied, # otherwise all results from the previous application will be # obliterated. Killing the batch process at any time during its # execution will prevent this from happening, but once the batch # process is finished, the previous objects are lost. # # NOTE: # # If the bootstrap crashes or has to be terminated, all of the results # up to the point of termination are preserved in the output file # sp.bootind.Nreps.df, (i.e. cb.bootind.399.10 or whatever). # # To salvage the results from this file in the event of early termination: # 1) edit out everything up to and including the line marked "EDIT # OUT EVERYTHING UP TO HERE"; # 2) at the Splus command line, type (e.g.) # sp.bootind.crash <- as.matrix(read.table("sp.bootind.Nreps.df",header=T)) # where sp, Nreps, and df are replaced as appropriate. # 3) edit out everything beyond the line at bottom of file marked # "EDIT OUT EVERYTHING BEYOND HERE" # 4) the results so far are probably also in Splus object # tmp.index.matrix, but check them against the output file and # be cautious because this object is overwritten every time # the batch process is started. # # sps <- eval(parse(text=sp.name)) if(length(sps$count[is.na(sps$count)]) > 0) stop( "no missing data allowed") # start bootstrap loop: assign("sps", sps, frame = 1) assign("degfree", degfree, frame = 1) cat("\n\nEDIT OUT EVERYTHING UP TO HERE \n\n") cat("rep", paste("yr", 1:length(unique(sps$year)), sep=""), "\n") replicate.func <- function(i) { rep.indices <- bootstrap.func(sps, defree = degfree) cat(paste("rep", i, sep=""), format(rep.indices, digits=8), "\n") rep.indices } tmp.index.matrix <- vector("list", Nreps) # # tmp.index.matrix will store the results but be removed as soon as the # full set is transferred to an object with the correct name. For(i = 1:Nreps, tmp.index.matrix = replicate.func(i)) cat("\n\nEDIT OUT EVERYTHING BEYOND HERE \n\n") resmat.name <- paste(sp.name, "bootind", Nreps, degfree, sep=".") tmp.index.matrix <- matrix(unlist(tmp.index.matrix), byrow = T, nrow = Nreps) assign(resmat.name, tmp.index.matrix) cat("Bootstrapping complete : now start Splus session to find matrix of results: \n",resmat.name, ".\n") rm(tmp.index.matrix, sps, replicate.func, i, resmat.name, degfree, sp.name, Nreps)