Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.Rproj.user
.Rhistory
.RData
.Ruserdata
inst/doc
wrappedtools.Rproj
.Rproj.user
.Rhistory
.RData
.Ruserdata
inst/doc
wrappedtools.Rproj
.DS_Store
5 changes: 5 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ Authors@R: c(
family = "Asser",
role = c("aut"),
email = "billyasser@hotmail.co.uk",
comment = ""),
person(given = "Franziska",
family = "Eidloth",
role = c("aut"),
email = "franziska.eidloth@gmail.com",
comment = ""))
Maintainer: Andreas Busjahn <andreas@busjahn.net>
License: GPL-3
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export(logrange_12357)
export(logrange_15)
export(logrange_5)
export(markSign)
export(mean_cl_boot)
export(meansd)
export(meanse)
export(median_cl_boot)
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#wrappedtools 0.9.7
- function identical_cols to find and remove duplicated columns
- function compare2numvars can now additionally calculate confidence intervals
- function compare2numvars now has the additional option for a singleline or stacked display
- new function mean_cl_boot which calculates the mean and confidence intervals
- function median_cl_boot now has an additional round option

#wrappedtools 0.9.6
- function ksnormal now uses Lilliefors test by default
Expand Down
63 changes: 57 additions & 6 deletions R/descriptives.R
Original file line number Diff line number Diff line change
Expand Up @@ -255,25 +255,35 @@ se_median <- function(x) {
#' @param conf confidence interval with default 95%.
#' @param type type for function boot.ci.
#' @param nrepl number of bootstrap replications, defaults to 1000.
#' @param round logical, applies [roundR] function to results. Output is character.
#' @param roundDig number of relevant digits for function [roundR].
#'
#' @return A tibble with one row and three columns: Median, CIlow, CIhigh.
#'
#' @examples
#' # basic usage of median_cl_boot
#' median_cl_boot(x = mtcars$wt)
#' @export
median_cl_boot <- function(x, conf = 0.95, type = "basic", nrepl = 10^3) {
median_cl_boot <- function(x, conf = 0.95, type = "basic", nrepl = 10^3, round = FALSE, roundDig = 2) {
x <- na.omit(x)
lconf <- (1 - conf) / 2
uconf <- 1 - lconf
bmedian <- function(x, ind) median(x[ind], na.rm = TRUE)
bt <- boot::boot(x, bmedian, nrepl)
bb <- boot::boot.ci(bt, type = type)
tibble(
Median = median(x, na.rm = TRUE),
CIlow = quantile(bt$t, lconf),
CIhigh = quantile(bt$t, uconf)
)
if (round) {
return(tibble(
Median = roundR(median(x, na.rm = TRUE), level = roundDig),
CIlow = roundR(quantile(bt$t, lconf), level = roundDig),
CIhigh = roundR(quantile(bt$t, uconf), level = roundDig)
))
} else {
return(tibble(
Median = median(x, na.rm = TRUE),
CIlow = quantile(bt$t, lconf),
CIhigh = quantile(bt$t, uconf)
))
}
}
#' Rename output from \link{median_cl_boot} for use in ggplot.
#'
Expand All @@ -296,6 +306,47 @@ median_cl_boot_gg <- function(x){
rename(y="Median",ymin="CIlow",ymax="CIhigh")
return(out)
}

#' Compute confidence interval of mean by bootstrapping.
#'
#' \code{mean_cl_boot} computes lower and upper confidence limits for the
#' estimated mean, based on bootstrapping.
#'
#' @param x Data for computation.
#' @param conf confidence interval with default 95%.
#' @param type type for function boot.ci.
#' @param nrepl number of bootstrap replications, defaults to 1000.
#' @param round logical, applies [roundR] function to results. Output is character.
#' @param roundDig Number of relevant digits for functio [roundR].
#'
#' @return A tibble with one row and three columns: Mean, CIlow, CIhigh.
#'
#' @examples
#' # basic usage of mean_cl_boot
#' mean_cl_boot(x = mtcars$wt)
#' @export
mean_cl_boot <- function(x, conf = 0.95, type = "basic", nrepl = 10^3,
round = FALSE, roundDig = 2) ##
{
x <- na.omit(x)
lconf <- (1 - conf)/2
uconf <- 1 - lconf
bmean <- function(x, ind) mean(x[ind], na.rm = TRUE)
bt <- boot::boot(x, bmean, nrepl)
bb <- boot::boot.ci(bt, type = type)

if(round){
tibble(Mean = roundR(mean(x, na.rm = TRUE), level = roundDig),
CIlow = roundR(quantile(bt$t, lconf), level = roundDig),
CIhigh = roundR(quantile(bt$t, uconf), level = roundDig)
)
} else{
tibble(Mean = mean(x, na.rm = TRUE),
CIlow = quantile(bt$t, lconf),
CIhigh = quantile(bt$t, uconf)
)
}
}
#' Compute absolute and relative frequencies.
#'
#' \code{cat_desc_stats} computes absolute and relative frequencies for
Expand Down
2 changes: 1 addition & 1 deletion R/pkgstart.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ NULL
#' @importFrom rlist list.append
NULL

#' @importFrom forcats fct_lump_n fct_drop
#' @importFrom forcats fct_lump_n fct_drop fct_inorder
NULL

#' @importFrom grDevices boxplot.stats
Expand Down
Loading
Loading