diff --git a/R-libraries/Casal2_22.03.tar.gz b/R-libraries/Casal2_22.03.tar.gz index 426722aa2..a48cbbf95 100644 Binary files a/R-libraries/Casal2_22.03.tar.gz and b/R-libraries/Casal2_22.03.tar.gz differ diff --git a/R-libraries/casal2/DESCRIPTION b/R-libraries/casal2/DESCRIPTION index b607d8c01..cf10f6a00 100644 --- a/R-libraries/casal2/DESCRIPTION +++ b/R-libraries/casal2/DESCRIPTION @@ -1,7 +1,7 @@ Package: Casal2 Title: Casal2 extract package Version: 22.03 -Date: 2022-03-02 +Date: 2022-03-15 Author: Casal2 Development Team Description: A set of R functions for extracting and plotting from Casal2 configuration input files, reports, and other associated files. Maintainer: Casal2 Development Team diff --git a/R-libraries/casal2/R/ShortHandFunctions.R b/R-libraries/casal2/R/ShortHandFunctions.R new file mode 100644 index 000000000..5137d7ad3 --- /dev/null +++ b/R-libraries/casal2/R/ShortHandFunctions.R @@ -0,0 +1,197 @@ + +#' @title expand_category_block +#' +#' @description +#' A utility function for expanding short hand syntax in @category blocks in casal2 config files +#' +#' @author Craig Marsh +#' @param categories string of categories +#' @return a vector of strings +#' @keywords internal +#' @examples +#' \dontrun{ +#' expand_category_block("stock") +#' expand_category_block("stock.male,female") +#' expand_category_block("stock.male,female.untagged,1990") +#' } +expand_category_block <- function(categories) { + expanded_labels = vector(); + groups = strsplit(categories, split = ".", fixed = TRUE)[[1]] + category_list = list() + for(i in 1:length(groups)) { + if(grepl(groups[i], pattern = ",")) { + sub_groups = strsplit(groups[i], split = ",", fixed = TRUE)[[1]] + category_list[[i]] = sub_groups + } else { + category_list[[i]] = groups[i] + } + } + ## now permutate them + all_perms <- expand.grid(category_list, stringsAsFactors = FALSE) + new_perms = NULL + ## need to re-order based on first factor + i = 1 + for(j in 1:length(category_list[[i]])) { + ndx = all_perms$Var1 == category_list[[i]][j] + new_perms = rbind(new_perms, all_perms[ndx,]) + } + for(i in 1:nrow(new_perms)) { + expanded_labels = c(expanded_labels, paste0(new_perms[i,], collapse = ".")) + } + return(expanded_labels) +} + +#' @title expand_category_shorthand +#' +#' @description +#' A utility function for expanding short hand syntax of categories used in subcommands throught casal2 config files +#' +#' @author Craig Marsh +#' @param shorthand_categories shorthand values to expand +#' @param reference_categories string of categories expanded from the @category block of a config. derived from expand_category_block +#' @param category_format the format defined in the @categories block +#' @return a vector of strings +#' @keywords internal +#' @examples +#' \dontrun{ +#' expand_category_shorthand(shorthand_categories ="format=*.EN.*", reference_categories = c("BOP.EN.male")) +#' expand_category_shorthand(shorthand_categories ="format=*.EN.*", reference_categories = c("BOP.EN.male", "BOP.EN.female")) +#' expand_category_shorthand(shorthand_categories ="format=*.EN.*", reference_categories = c("BOP.EN.male", "BOP.EN.female", "HAGU.EN.male", "HAGU.EN.female")) +#' expand_category_shorthand(shorthand_categories ="format = *.EN.+", reference_categories = c("BOP.EN.male", "BOP.EN.female")) +#' expand_category_shorthand(shorthand_categories ="format = *.EN.+", reference_categories = c("BOP.EN.male", "BOP.EN.female", "HAGU.EN.male", "HAGU.EN.female")) +#' expand_category_shorthand(shorthand_categories ="*", reference_categories = c("BOP.EN.male", "BOP.EN.female", "HAGU.EN.male", "HAGU.EN.female")) +#' expand_category_shorthand(shorthand_categories ="stock=BOP", reference_categories = c("BOP.EN.male", "BOP.EN.female", "HAGU.EN.male", "HAGU.EN.female"), category_format = "stock.area.sex") +#' } +expand_category_shorthand <- function(shorthand_categories, reference_categories, category_format = NULL) { + expanded_categories = vector(); + formats = NULL + if(!is.null(category_format)) { + formats = strsplit(category_format, ".", fixed = T)[[1]] + } + broken_ref_vals = Reduce(rbind, strsplit(reference_categories, ".", fixed = T)) + if(is.null(dim(broken_ref_vals))) { + broken_ref_vals = matrix(broken_ref_vals, nrow =1) + } + # strip whitespace + shorthand_categories_no_space = gsub(" ", "", shorthand_categories, fixed = TRUE) + expanded_categories = shorthand_categories_no_space + # if format strip that out + format_found = grepl(shorthand_categories_no_space, pattern = "format=", fixed = TRUE) + if(format_found) { + shorthand_categories_no_space = gsub("format=", "", shorthand_categories_no_space, fixed = TRUE) + } + # if other shorthand + format_found = grepl(shorthand_categories_no_space, pattern = "=", fixed = TRUE) + if(format_found) { + expanded_categories = NULL + temp_formats = strsplit(shorthand_categories_no_space, "=", fixed = T)[[1]] + cat_ndx = which(formats == temp_formats[1]) + ref_ndx = broken_ref_vals[,cat_ndx] == temp_formats[2] + these_categories = broken_ref_vals[ref_ndx, ] + for(i in 1:nrow(these_categories)) { + expanded_categories = c(expanded_categories, paste0(these_categories[i,], collapse = ".")) + } + } + + + ## now should be only category labels, periods ('.'), astrix, or + + rep_syntax = grepl(shorthand_categories_no_space, pattern = "*", fixed = TRUE) + category_list = list(); + if(rep_syntax) { + if(shorthand_categories_no_space == "*") { + # return all categories + expanded_categories = reference_categories + } else { + ## need to repeat some category levels + broken_vals = strsplit(shorthand_categories_no_space, ".", fixed = T)[[1]] + for(i in 1:length(broken_vals)) { + if(broken_vals[i] == "*") { + category_list[[i]] = unique(broken_ref_vals[,i]) + } else { + category_list[[i]] = broken_vals[i] + } + } + ## now permutate them + all_perms <- expand.grid(category_list, stringsAsFactors = FALSE) + for(i in 1:nrow(all_perms)) { + expanded_categories = c(expanded_categories, paste0(all_perms[i,], collapse = ".")) + } + } + } + return(expanded_categories) +} + +#' @title expand_shorthand_syntax +#' +#' @description +#' A utility function for expanding short hand syntax for based on - format=*.EN.*, label*5, and + syntax +#' +#' @author Craig Marsh +#' @param syntax string of the syntax to expand +#' @return a vector of strings +#' @keywords internal +#' @examples +#' \dontrun{ +#' # currently can handle these shorthand +#' expand_shorthand_syntax(syntax = "age_length") +#' expand_shorthand_syntax(syntax = "age_length * 8") +#' expand_shorthand_syntax(syntax ="age_length*8") +#' expand_shorthand_syntax(syntax ="age_length_BP*4 age_length_EN*4") +#' expand_shorthand_syntax(syntax = "1990:2000") +#' expand_shorthand_syntax(syntax ="age_length_BP*4,age_length_EN*4") +#' expand_shorthand_syntax(syntax ="0.75*3") +#' expand_shorthand_syntax(syntax ="0.75 * 3 ") +#' # cant deal with +#' expand_shorthand_syntax(syntax ="0.75*3 0.75*3") +#' } +expand_shorthand_syntax <- function(syntax) { + syntax = paste(syntax, collapse = "") + ## strip whitespace out of syntax to make it easier + syntax_no_space = gsub(" ", "", syntax, fixed = TRUE) + # we wont deal with ',' so strip them out to + syntax_no_space = gsub(",", "", syntax_no_space, fixed = TRUE) + + rep_syntax = grepl(syntax_no_space, pattern = "*", fixed = TRUE) + colon_syntax = grepl(syntax_no_space, pattern = ":", fixed = TRUE) + + ## deal with repeat labels + repeated_values = vector(); + if(rep_syntax) { + ## simple expansion + rep_components = strsplit(syntax_no_space, split = "*", fixed = TRUE)[[1]] + convert_vals = suppressWarnings(as.numeric(rep_components)) + if(all(!is.na(convert_vals))) { + ## all numbers so must be 0.45 * 2 + # pairs = length(rep_components) / 2 + if(length(rep_components) != 2) + stop("unknown syntax") + repeated_values = rep(convert_vals[1], convert_vals[2]) + } else { + # Numbers and words + for(i in 1:length(rep_components)) { + # no numbers + if(gsub("[^\\d]+", "", rep_components[i], perl=TRUE) == "") { + ## simple case "label" + value = rep_components[i] + } else if(gsub("[^\\d]+", "", rep_components[i], perl=TRUE) != "" & (nchar(gsub("[^\\d]+", "", rep_components[i], perl=TRUE)) != nchar(rep_components[i]))) { + ## has numbers and words... + ## get number + rep_num = as.numeric(gsub("[^\\d]+", "", rep_components[i], perl=TRUE)) + repeated_values = c(repeated_values, rep(value, rep_num)) + ## get the other word + value = gsub('[[:digit:]]+', '', rep_components[i]) + } else { + ## just number repeat value by this number + repeated_values = c(repeated_values, rep(value, as.numeric(gsub("[^\\d]+", "", rep_components[i], perl=TRUE)))) + } + } + } + } else if(colon_syntax) { + ## assumes only numbers lowerval:upperval + seq_components = strsplit(syntax_no_space, split = ":", fixed = TRUE)[[1]] + repeated_values = as.numeric(seq_components[1]):as.numeric(seq_components[2]) + } else { + repeated_values = syntax + } + return(repeated_values) +} diff --git a/R-libraries/casal2/R/extract.csl2.file.R b/R-libraries/casal2/R/extract.csl2.file.R index 943c10efe..cb2f702ee 100644 --- a/R-libraries/casal2/R/extract.csl2.file.R +++ b/R-libraries/casal2/R/extract.csl2.file.R @@ -63,7 +63,6 @@ ## this will be the default label if no user defined label is specified for (i in 1:length(file)) { temp <- string.to.vector.of.words(file[i]) - check_inputs <- check_short_hand(temp) ## expand numeric shorthand #if (any(check_inputs$numeric) && (substr(Command, 1, 3) != "est") | (substr(Command, 1, 3) != "par")) { #vals <- eval(parse(text = temp[check_inputs$numeric])) @@ -101,8 +100,24 @@ } ## Check if it is a valid type/subcommand if (type == "vector") { - ## deal with a vector subcommand - ans[[Command]][[temp[1]]] <- list("value" = temp[-1]) + new_string = temp[1] + ## if category or parameter subcommand skip expand short hand for * and : + if(grepl(temp[1], pattern = "categor", fixed = TRUE) | grepl(temp[1], pattern = "parameter", fixed = TRUE)) { + new_string = temp + } else { + ## check white space hasn't split it up already + second_values = NULL + if(any(temp[2:length(temp)] == "*")) { + second_values = paste(temp[2:length(temp)], collapse = "") + } else { + second_values = temp[2:length(temp)] + } + ## deal with : shorthand + for (j in 1:length(second_values)) { + new_string <- c(new_string, expand_shorthand_syntax(second_values[j])) + } + } + ans[[Command]][[new_string[1]]] <- list("value" = new_string[-1]) } else if ((type == "table_label") || in_table) { ## deal with a table input. the biggest pain in ithe ass in_table <- TRUE diff --git a/R-libraries/casal2/R/generate.starting.pars.R b/R-libraries/casal2/R/generate.starting.pars.R index 16d4f1dda..0cd2dcecb 100644 --- a/R-libraries/casal2/R/generate.starting.pars.R +++ b/R-libraries/casal2/R/generate.starting.pars.R @@ -3,18 +3,20 @@ #' This function reads a Casal2 estimation configuration file and returns a par file. Where each parameter is drawn from the prior defined in an @estimate block. #' #' @author Craig Marsh -#' @param Estimation_csl2_file the name of the configuration file containing the @estimate blocks. +#' @param estimation_csl2_file the name of the configuration file containing the @estimate blocks. #' @param path Optionally, the path to the file -#' @param N the number of random samples you want. +#' @param n_sim the number of random samples you want. #' @param par_file_name = the filename of the file created #' @param all_uniform = logical if TRUE draw from a uniform between bounds regardless of prior distribution +#' @param quiet Optional, supresses printing statements #' @param fileEncoding Optional, allows the R-library to read in files that have been encoded in alternative UTF formats, see the manual for the error message that would indicate when to use this switch. + #' @return a file named 'parms.out' in the path directory #' @export #' -'generate.starting.pars' = function(path = "", Estimation_csl2_file = "Estimation.csl2", N = 10, par_file_name = "starting_pars.out", all_uniform = FALSE, fileEncoding = "") { - estimate_config = extract.csl2.file(file = Estimation_csl2_file, path = path, fileEncoding = fileEncoding); +generate.starting.pars <- function(path = "", estimation_csl2_file = "Estimation.csl2", n_sim = 10, par_file_name = "starting_pars.out", all_uniform = FALSE, fileEncoding = "", quiet = T) { + estimate_config = extract.csl2.file(file = estimation_csl2_file, path = path, fileEncoding = fileEncoding, quiet = quiet); ## pull out the estimates only, they are the only components interested in at the moment estimate_ndx = grepl(pattern = "estimate\\[", x = names(estimate_config)) estimate_block_labels = names(estimate_config)[estimate_ndx] @@ -37,67 +39,7 @@ if (!this_estimate$type %in% allowed_types) { stop(paste0("Sorry, we haven't coded a random number generator for the distribution of type ", this_estimate$type, " we currently only have the following types ", paste(allowed_types, collapse = ", "))) } - ######################################### - ## Check priors don't related to EstimateTransformations? - ## these will need to be taken care of - deal_with_transformations = FALSE; - skip_parameter = FALSE - ## this gets tricky we need to iterate over the estimate_transfomration blocks so we can see if there is another parameter involved? - if (!is.null(this_estimate$prior_applies_to_transform) && (this_estimate$prior_applies_to_transform$value == "TRUE" || this_estimate$prior_applies_to_transform$value == "t" || this_estimate$prior_applies_to_transform$value == "true")) { - ## Check to see if we haven't already found this parameter in a previous transformation - if (length(names(conditional_parameters)) > 0) { - for (previous_trans in names(conditional_parameters)) { - previous_transformation = get(previous_trans, conditional_parameters) - if (previous_transformation$other_label == Label) { - ## this parameter has been associated with a previous transformatin block. - skip_parameter = TRUE; - } - } - } - if (!skip_parameter) { - estimate_transformation_ndx = grepl(pattern = "estimate_transformation", x = names(estimate_config)) - if (any(estimate_transformation_ndx)) { - for (trans in 1:sum(estimate_transformation_ndx)) { - this_trans = get(names(estimate_config)[estimate_transformation_ndx][trans], estimate_config) - if (this_trans$type$value == "average_difference") { - if (this_trans$estimate_label$value == Label) { - conditional_parameters[[Label]]$other_label = this_trans$difference_estimate$value - conditional_parameters[[Label]]$type = "average_difference" - conditional_parameters[[Label]]$first_estimate = "true" - } else if (this_trans$difference_estimate$value == Label) { - conditional_parameters[[Label]]$other_label = this_trans$estimate_label$value - conditional_parameters[[Label]]$type = "average_difference" - conditional_parameters[[Label]]$first_estimate = "false" - } - } else if (this_trans$type$value == "log_sum") { - if (this_trans$estimate_label$value == Label) { - conditional_parameters[[Label]]$other_label = this_trans$second_estimate$value - conditional_parameters[[Label]]$type = "log_sum" - conditional_parameters[[Label]]$first_estimate = "true" - } else if (this_trans$second_estimate$value == Label) { - conditional_parameters[[Label]]$other_label = this_trans$estimate_label$value - conditional_parameters[[Label]]$type = "log_sum" - conditional_parameters[[Label]]$first_estimate = "false" - } - } else if (this_trans$type$value == "orthogonal") { - if (this_trans$estimate_label$value == Label) { - conditional_parameters[[Label]]$other_label = this_trans$second_estimate$value - conditional_parameters[[Label]]$first_estimate = "true" - conditional_parameters[[Label]]$type = "orthogonal" - } else if (this_trans$second_estimate$value == Label) { - conditional_parameters[[Label]]$other_label = this_trans$estimate_label$value - conditional_parameters[[Label]]$type = "orthogonal" - conditional_parameters[[Label]]$first_estimate = "false" - } - } else if (this_trans$type$value == "simplex") { - if (this_trans$estimate_label$value == Label) { - stop("This code cannot deal with the simplex transformation?") - } - } - } - } - } - } + ## check if this parameter needs to be split out into multiple parameters start_nd = as.numeric(regexpr(pattern = "\\{", text = this_estimate$parameter$value)) end_nd = as.numeric(regexpr(pattern = "\\}", text = this_estimate$parameter$value)) @@ -123,19 +65,19 @@ param_labels = c(param_labels, this_estimate$parameter$value) ## Now simulate data. values = NULL; - if (this_estimate$type == "uniform" || all_uniform) { - values = runif(n = N, min = as.numeric(this_estimate$lower_bound$value), max = as.numeric(this_estimate$upper_bound$value)) - } else if (this_estimate$type == "uniform_log") { - values = exp(runif(n = N, min = log(as.numeric(this_estimate$lower_bound$value)), max = log(as.numeric(this_estimate$upper_bound$value)))) - } else if (this_estimate$type == "normal") { + if (this_estimate$type$value == "uniform" || all_uniform) { + values = runif(n = n_sim, min = as.numeric(this_estimate$lower_bound$value), max = as.numeric(this_estimate$upper_bound$value)) + } else if (this_estimate$type$value == "uniform_log") { + values = exp(runif(n = n_sim, min = log(as.numeric(this_estimate$lower_bound$value)), max = log(as.numeric(this_estimate$upper_bound$value)))) + } else if (this_estimate$type$value == "normal") { std_dev = as.numeric(this_estimate$mu$value) * as.numeric(this_estimate$cv$value) - values = rnorm(n = N, mean = as.numeric(this_estimate$mu$value), sd = std_dev) + values = rnorm(n = n_sim, mean = as.numeric(this_estimate$mu$value), sd = std_dev) } else if (this_estimate$type == "lognormal") { - values = Rlnorm(n = N, mu = as.numeric(this_estimate$mu$value), cv = as.numeric(this_estimate$cv$value)) + values = Rlnorm(n = n_sim, mu = as.numeric(this_estimate$mu$value), cv = as.numeric(this_estimate$cv$value)) } else if (this_estimate$type == "normal_by_stdev") { - values = rnorm(n = N, mean = as.numeric(this_estimate$mu$value), sd = as.numeric(this_estimate$sigma$value)) + values = rnorm(n = n_sim, mean = as.numeric(this_estimate$mu$value), sd = as.numeric(this_estimate$sigma$value)) } else if (this_estimate$type == "normal_log") { - values = exp(rnorm(n = N, mean = as.numeric(this_estimate$mu$value), sd = as.numeric(this_estimate$sigma$value))) + values = exp(rnorm(n = n_sim, mean = as.numeric(this_estimate$mu$value), sd = as.numeric(this_estimate$sigma$value))) } ## set to bounds if generated past them values[values < as.numeric(this_estimate$lower_bound$value)] = as.numeric(this_estimate$lower_bound$value) @@ -164,7 +106,7 @@ ## Now simulate data for each param if (this_estimate$type == "uniform" || all_uniform) { for (param in 1:n_params) { - values = runif(n = N, min = as.numeric(this_estimate$lower_bound$value[param]), max = as.numeric(this_estimate$upper_bound$value[param])) + values = runif(n_sim = n_sim, min = as.numeric(this_estimate$lower_bound$value[param]), max = as.numeric(this_estimate$upper_bound$value[param])) ## check within bounds values[values < as.numeric(this_estimate$lower_bound$value[param])] = as.numeric(this_estimate$lower_bound$value[param]) values[values > as.numeric(this_estimate$upper_bound$value[param])] = as.numeric(this_estimate$upper_bound$value[param]) @@ -172,7 +114,7 @@ } } else if (this_estimate$type == "uniform_log") { for (param in 1:n_params) { - values = exp(runif(n = N, min = log(as.numeric(this_estimate$lower_bound$value[param])), max = log(as.numeric(this_estimate$upper_bound$value[param])))) + values = exp(runif(n_sim = n_sim, min = log(as.numeric(this_estimate$lower_bound$value[param])), max = log(as.numeric(this_estimate$upper_bound$value[param])))) ## check within bounds values[values < as.numeric(this_estimate$lower_bound$value[param])] = as.numeric(this_estimate$lower_bound$value[param]) values[values > as.numeric(this_estimate$upper_bound$value[param])] = as.numeric(this_estimate$upper_bound$value[param]) @@ -192,7 +134,7 @@ std_dev = as.numeric(this_estimate$mu$value) * as.numeric(this_estimate$cv$value) for (param in 1:n_params) { - values = rnorm(n = N, mean = as.numeric(this_estimate$mu$value[param]), sd = std_dev[param]) + values = rnorm(n_sim = n_sim, mean = as.numeric(this_estimate$mu$value[param]), sd = std_dev[param]) ## check within bounds values[values < as.numeric(this_estimate$lower_bound$value[param])] = as.numeric(this_estimate$lower_bound$value[param]) values[values > as.numeric(this_estimate$upper_bound$value[param])] = as.numeric(this_estimate$upper_bound$value[param]) @@ -210,7 +152,7 @@ this_estimate$cv$value = rep(left_value, n_params) } for (param in 1:n_params) { - values = Rlnorm(n = N, mu = as.numeric(this_estimate$mu$value[param]), cv = as.numeric(this_estimate$cv$value[param])) + values = Rlnorm(n = n_sim, mu = as.numeric(this_estimate$mu$value[param]), cv = as.numeric(this_estimate$cv$value[param])) ## check within bounds values[values < as.numeric(this_estimate$lower_bound$value[param])] = as.numeric(this_estimate$lower_bound$value[param]) values[values > as.numeric(this_estimate$upper_bound$value[param])] = as.numeric(this_estimate$upper_bound$value[param]) @@ -228,7 +170,7 @@ this_estimate$sigma$value = rep(left_value, n_params) } for (param in 1:n_params) { - values = rnorm(n = N, mean = as.numeric(this_estimate$mu$value[param]), sd = as.numeric(this_estimate$sigma$value[param])) + values = rnorm(n_sim = n_sim, mean = as.numeric(this_estimate$mu$value[param]), sd = as.numeric(this_estimate$sigma$value[param])) ## check within bounds values[values < as.numeric(this_estimate$lower_bound$value[param])] = as.numeric(this_estimate$lower_bound$value[param]) values[values > as.numeric(this_estimate$upper_bound$value[param])] = as.numeric(this_estimate$upper_bound$value[param]) @@ -246,7 +188,7 @@ this_estimate$sigma$value = rep(left_value, n_params) } for (param in 1:n_params) { - values = exp(rnorm(n = N, mean = as.numeric(this_estimate$mu$value), sd = as.numeric(this_estimate$sigma$value))) + values = exp(rnorm(n_sim = n_sim, mean = as.numeric(this_estimate$mu$value), sd = as.numeric(this_estimate$sigma$value))) ## check within bounds values[values < as.numeric(this_estimate$lower_bound$value[param])] = as.numeric(this_estimate$lower_bound$value[param]) values[values > as.numeric(this_estimate$upper_bound$value[param])] = as.numeric(this_estimate$upper_bound$value[param]) @@ -257,45 +199,12 @@ } } colnames(param_values) = value_labels; - ## Deal with transformations if any of the priors are described for the transformed space. - if (length(names(conditional_parameters)) > 0) { - for (previous_trans in names(conditional_parameters)) { - previous_transformation = get(previous_trans, conditional_parameters) - if (previous_transformation$type == "average_difference") { - ## get the correct columns from the values matrix to transform - X2 = param_values[, previous_transformation$other_label] - X1 = param_values[, previous_trans] - param1 = X1 + (X2 / 2) - param2 = X1 - (X2 / 2) - ## override values - param_values[, previous_transformation$other_label] = param2 - param_values[, previous_trans] = param1 - } else if (previous_transformation$type == "log_sum") { - ## get the correct columns from the values matrix to transform - X2 = param_values[, previous_transformation$other_label] - X1 = param_values[, previous_trans] - total = exp(X1); - param1 = total * X2 - param2 = total * (1 - X2) - param_values[, previous_transformation$other_label] = param2 - param_values[, previous_trans] = param1 - } else if (previous_transformation$type == "orthogonal") { - ## get the correct columns from the values matrix to transform - X2 = param_values[, previous_transformation$other_label] - X1 = param_values[, previous_trans] - param1 = sqrt(X1 * X2); - param2 = sqrt(X1 / X2); - param_values[, previous_transformation$other_label] = param2 - param_values[, previous_trans] = param1 - } - } - } ## write the file. filename = make.filename(path = path, file = par_file_name) cat(param_labels, file = filename, sep = " ", fill = F, labels = NULL, append = F) cat("\n", file = filename, sep = " ", fill = F, labels = NULL, append = T) - for (i in 1:N) { + for (i in 1:n_sim) { cat(param_values[i,], file = filename, sep = " ", fill = F, labels = NULL, append = T) cat("\n", file = filename, sep = " ", fill = F, labels = NULL, append = T) } -} \ No newline at end of file +} diff --git a/R-libraries/casal2/man/expand_category_block.Rd b/R-libraries/casal2/man/expand_category_block.Rd new file mode 100644 index 000000000..06ec72e30 --- /dev/null +++ b/R-libraries/casal2/man/expand_category_block.Rd @@ -0,0 +1,28 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/ShortHandFunctions.R +\name{expand_category_block} +\alias{expand_category_block} +\title{expand_category_block} +\usage{ +expand_category_block(categories) +} +\arguments{ +\item{categories}{string of categories} +} +\value{ +a vector of strings +} +\description{ +A utility function for expanding short hand syntax in @category blocks in casal2 config files +} +\examples{ +\dontrun{ +expand_category_block("stock") +expand_category_block("stock.male,female") +expand_category_block("stock.male,female.untagged,1990") +} +} +\author{ +Craig Marsh +} +\keyword{internal} diff --git a/R-libraries/casal2/man/expand_category_shorthand.Rd b/R-libraries/casal2/man/expand_category_shorthand.Rd new file mode 100644 index 000000000..a454ab45d --- /dev/null +++ b/R-libraries/casal2/man/expand_category_shorthand.Rd @@ -0,0 +1,40 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/ShortHandFunctions.R +\name{expand_category_shorthand} +\alias{expand_category_shorthand} +\title{expand_category_shorthand} +\usage{ +expand_category_shorthand( + shorthand_categories, + reference_categories, + category_format = NULL +) +} +\arguments{ +\item{shorthand_categories}{shorthand values to expand} + +\item{reference_categories}{string of categories expanded from the @category block of a config. derived from expand_category_block} + +\item{category_format}{the format defined in the @categories block} +} +\value{ +a vector of strings +} +\description{ +A utility function for expanding short hand syntax of categories used in subcommands throught casal2 config files +} +\examples{ +\dontrun{ +expand_category_shorthand(shorthand_categories ="format=*.EN.*", reference_categories = c("BOP.EN.male")) +expand_category_shorthand(shorthand_categories ="format=*.EN.*", reference_categories = c("BOP.EN.male", "BOP.EN.female")) +expand_category_shorthand(shorthand_categories ="format=*.EN.*", reference_categories = c("BOP.EN.male", "BOP.EN.female", "HAGU.EN.male", "HAGU.EN.female")) +expand_category_shorthand(shorthand_categories ="format = *.EN.+", reference_categories = c("BOP.EN.male", "BOP.EN.female")) +expand_category_shorthand(shorthand_categories ="format = *.EN.+", reference_categories = c("BOP.EN.male", "BOP.EN.female", "HAGU.EN.male", "HAGU.EN.female")) +expand_category_shorthand(shorthand_categories ="*", reference_categories = c("BOP.EN.male", "BOP.EN.female", "HAGU.EN.male", "HAGU.EN.female")) +expand_category_shorthand(shorthand_categories ="stock=BOP", reference_categories = c("BOP.EN.male", "BOP.EN.female", "HAGU.EN.male", "HAGU.EN.female"), category_format = "stock.area.sex") +} +} +\author{ +Craig Marsh +} +\keyword{internal} diff --git a/R-libraries/casal2/man/expand_shorthand_syntax.Rd b/R-libraries/casal2/man/expand_shorthand_syntax.Rd new file mode 100644 index 000000000..c79711684 --- /dev/null +++ b/R-libraries/casal2/man/expand_shorthand_syntax.Rd @@ -0,0 +1,36 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/ShortHandFunctions.R +\name{expand_shorthand_syntax} +\alias{expand_shorthand_syntax} +\title{expand_shorthand_syntax} +\usage{ +expand_shorthand_syntax(syntax) +} +\arguments{ +\item{syntax}{string of the syntax to expand} +} +\value{ +a vector of strings +} +\description{ +A utility function for expanding short hand syntax for based on - format=*.EN.*, label*5, and + syntax +} +\examples{ +\dontrun{ +# currently can handle these shorthand +expand_shorthand_syntax(syntax = "age_length") +expand_shorthand_syntax(syntax = "age_length * 8") +expand_shorthand_syntax(syntax ="age_length*8") +expand_shorthand_syntax(syntax ="age_length_BP*4 age_length_EN*4") +expand_shorthand_syntax(syntax = "1990:2000") +expand_shorthand_syntax(syntax ="age_length_BP*4,age_length_EN*4") +expand_shorthand_syntax(syntax ="0.75*3") +expand_shorthand_syntax(syntax ="0.75 * 3 ") +# cant deal with +expand_shorthand_syntax(syntax ="0.75*3 0.75*3") +} +} +\author{ +Craig Marsh +} +\keyword{internal} diff --git a/R-libraries/casal2/man/generate.starting.pars.Rd b/R-libraries/casal2/man/generate.starting.pars.Rd index a2aee3cbd..243e369c5 100644 --- a/R-libraries/casal2/man/generate.starting.pars.Rd +++ b/R-libraries/casal2/man/generate.starting.pars.Rd @@ -6,25 +6,28 @@ \usage{ generate.starting.pars( path = "", - Estimation_csl2_file = "Estimation.csl2", - N = 10, + estimation_csl2_file = "Estimation.csl2", + n_sim = 10, par_file_name = "starting_pars.out", all_uniform = FALSE, - fileEncoding = "" + fileEncoding = "", + quiet = T ) } \arguments{ \item{path}{Optionally, the path to the file} -\item{Estimation_csl2_file}{the name of the configuration file containing the @estimate blocks.} +\item{estimation_csl2_file}{the name of the configuration file containing the @estimate blocks.} -\item{N}{the number of random samples you want.} +\item{n_sim}{the number of random samples you want.} \item{par_file_name}{= the filename of the file created} \item{all_uniform}{= logical if TRUE draw from a uniform between bounds regardless of prior distribution} \item{fileEncoding}{Optional, allows the R-library to read in files that have been encoded in alternative UTF formats, see the manual for the error message that would indicate when to use this switch.} + +\item{quiet}{Optional, supresses printing statements} } \value{ a file named 'parms.out' in the path directory