Skip to contents

Computes the (relative) bias of a sample estimate from the parameter value. Accepts estimate and parameter values, as well as estimate values which are in deviation form. If relative bias is requested the estimate and parameter inputs are both required.

Usage

bias(
  estimate,
  parameter = NULL,
  type = "bias",
  abs = FALSE,
  percent = FALSE,
  unname = FALSE
)

Arguments

estimate

a numeric vector, matrix/data.frame, or list of parameter estimates. If a vector, the length is equal to the number of replications. If a matrix/data.frame, the number of rows must equal the number of replications. list objects will be looped over using the same rules after above after first translating the information into one-dimensional vectors and re-creating the structure upon return

parameter

a numeric scalar/vector indicating the fixed parameters. If a single value is supplied and estimate is a matrix/data.frame then the value will be recycled for each column; otherwise, each element will be associated with each respective column in the estimate input. If NULL then it will be assumed that the estimate input is in a deviation form (therefore mean(estimate)) will be returned)

type

type of bias statistic to return. Default ('bias') computes the standard bias (average difference between sample and population), 'relative' computes the relative bias statistic (i.e., divide the bias by the value in parameter; note that multiplying this by 100 gives the "percent bias" measure, or if Type I error rates (\(\alpha\)) are supplied will result in the "percentage error"), 'abs_relative' computes the relative bias but the absolute values of the parameters are used in the denominator rather than the (potentially) signed input values, and 'standardized' computes the standardized bias estimate (standard bias divided by the standard deviation of the sample estimates)

abs

logical; find the absolute bias between the parameters and estimates? This effectively just applies the abs transformation to the returned result. Default is FALSE

percent

logical; change returned result to percentage by multiplying by 100? Default is FALSE

unname

logical; apply unname to the results to remove any variable names?

Value

returns a numeric vector indicating the overall (relative/standardized) bias in the estimates

References

Chalmers, R. P., & Adkins, M. C. (2020). Writing Effective and Reliable Monte Carlo Simulations with the SimDesign Package. The Quantitative Methods for Psychology, 16(4), 248-280. doi:10.20982/tqmp.16.4.p248

Sigal, M. J., & Chalmers, R. P. (2016). Play it again: Teaching statistics with Monte Carlo simulation. Journal of Statistics Education, 24(3), 136-156. doi:10.1080/10691898.2016.1246953

See also

Author

Phil Chalmers rphilip.chalmers@gmail.com

Examples


pop <- 2
samp <- rnorm(100, 2, sd = 0.5)
bias(samp, pop)
#> [1] 0.0398212
bias(samp, pop, type = 'relative')
#> [1] 0.0199106
bias(samp, pop, type = 'standardized')
#> [1] 0.0800926

dev <- samp - pop
bias(dev)
#> [1] 0.0398212

# equivalent here
bias(mean(samp), pop)
#> [1] 0.0398212

# matrix input
mat <- cbind(M1=rnorm(100, 2, sd = 0.5), M2 = rnorm(100, 2, sd = 1))
bias(mat, parameter = 2)
#>          M1          M2 
#> -0.01850358  0.07757825 
bias(mat, parameter = 2, type = 'relative')
#>          M1          M2 
#> -0.00925179  0.03878912 
bias(mat, parameter = 2, type = 'standardized')
#>          M1          M2 
#> -0.03281049  0.08895343 

# 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))
#>           M1           M2 
#> -0.005719856 -0.003655121 

# same, but with data.frame
df <- data.frame(M1=rnorm(100, 2, sd = 0.5), M2 = rnorm(100, 2, sd = 1))
bias(df, parameter = c(2,2))
#>         M1         M2 
#> 0.04919156 0.07691533 

# parameters of the same size
parameters <- 1:10
estimates <- parameters + rnorm(10)
bias(estimates, parameters)
#> [1] -0.03489829

# relative difference dividing by the magnitude of parameters
bias(estimates, parameters, type = 'abs_relative')
#> [1] -0.1708617

# relative bias as a percentage
bias(estimates, parameters, type = 'abs_relative', percent = TRUE)
#> [1] -17.08617

# percentage error (PE) statistic given alpha (Type I error) and EDR() result
# edr <- EDR(results, alpha = .05)
edr <- c(.04, .05, .06, .08)
bias(matrix(edr, 1L), .05, type = 'relative', percent = TRUE)
#> [1] -20   0  20  60