diff --git a/DESCRIPTION b/DESCRIPTION index 9a873f1..3d9a714 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: SimDesign Title: Structure for Organizing Monte Carlo Simulation Designs -Version: 2.18.3 +Version: 2.18.4 Authors@R: c(person("Phil", "Chalmers", email = "rphilip.chalmers@gmail.com", role = c("aut", "cre"), comment = c(ORCID="0000-0001-5332-2810")), person("Matthew", "Sigal", role = c("ctb")), diff --git a/NEWS.md b/NEWS.md index 8ed07ab..cae08b2 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,10 @@ # NEWS file for SimDesign +## Changes in SimDesign 2.19 + +- Multiple parameter `bias()` returned incorrect behavior/errors + for `relative` and `abs_relative` types (see #60) + ## Changes in SimDesign 2.18 - Objects built by `createDesign()` gain `[]` and `rbind()` S3 functions for diff --git a/R/summary_functions.R b/R/summary_functions.R index 96ed743..738f6bf 100644 --- a/R/summary_functions.R +++ b/R/summary_functions.R @@ -80,6 +80,8 @@ #' # different parameter associated with each column #' mat <- cbind(M1=rnorm(1000, 2, sd = 0.25), M2 = rnorm(1000, 3, sd = .25)) #' bias(mat, parameter = c(2,3)) +#' bias(mat, parameter = c(2,3), type='relative') +#' bias(mat, parameter = c(2,3), type='standardized') #' #' # same, but with data.frame #' df <- data.frame(M1=rnorm(100, 2, sd = 0.5), M2 = rnorm(100, 2, sd = 1)) @@ -128,8 +130,8 @@ bias <- function(estimate, parameter = NULL, type = 'bias', abs = FALSE, if(!equal_len) stopifnot(ncol(estimate) == length(parameter)) diff <- t(t(estimate) - parameter) - ret <- if(type == 'relative') colMeans(diff / parameter) - else if(type == 'abs_relative') colMeans(diff / abs(parameter)) + ret <- if(type == 'relative') rowMeans(t(diff) / parameter) + else if(type == 'abs_relative') rowMeans(t(diff) / abs(parameter)) else if(type == 'standardized') colMeans(diff) / colSDs(estimate) else colMeans(diff) if(abs) ret <- abs(ret) diff --git a/SimDesign.Rproj b/SimDesign.Rproj index 081c716..11f8443 100644 --- a/SimDesign.Rproj +++ b/SimDesign.Rproj @@ -1,4 +1,5 @@ Version: 1.0 +ProjectId: fe769c1e-d77f-4cb0-8cc9-a5d4a1fc8243 RestoreWorkspace: No SaveWorkspace: No diff --git a/man/SimFunctions.Rd b/man/SimFunctions.Rd index b663b63..a277860 100644 --- a/man/SimFunctions.Rd +++ b/man/SimFunctions.Rd @@ -28,10 +28,10 @@ is generally the recommended approach when beginning to write a Monte Carlo simu \item{save_structure}{character indicating the number of files to break the simulation code into when \code{filename} is included (default is 'single' for one file). When \code{save_structure = 'double'} the output is saved to two separate files containing the functions and design definitions, -and when \code{save_structure = 'all'} the generate, analyse, summarise, and execution code area all saved into -separate files. The purpose for this structure is because multiple structured files -often makes organization and debugging slightly easier larger Monte Carlo simulations, though in principle -all files could be stored into a single R script} +and when \code{save_structure = 'all'} the generate, analyse, summarise, and execution code are all saved into +separate files. The purpose of this structure is because multiple structured files +often makes organization and debugging slightly easier for larger Monte Carlo simulations, though, in principle, +all files could be stored in a single R script} \item{extra_file}{logical; should an extra file be saved containing user-defined functions or objects? Default is \code{FALSE}} diff --git a/man/bias.Rd b/man/bias.Rd index bf03ca0..7749ab4 100644 --- a/man/bias.Rd +++ b/man/bias.Rd @@ -79,6 +79,8 @@ bias(mat, parameter = 2, type = 'standardized') # different parameter associated with each column mat <- cbind(M1=rnorm(1000, 2, sd = 0.25), M2 = rnorm(1000, 3, sd = .25)) bias(mat, parameter = c(2,3)) +bias(mat, parameter = c(2,3), type='relative') +bias(mat, parameter = c(2,3), type='standardized') # same, but with data.frame df <- data.frame(M1=rnorm(100, 2, sd = 0.5), M2 = rnorm(100, 2, sd = 1))