Skip to content

Commit

Permalink
1
Browse files Browse the repository at this point in the history
  • Loading branch information
unknown committed Apr 12, 2024
1 parent 963dd82 commit 13bfffa
Show file tree
Hide file tree
Showing 15 changed files with 886 additions and 10 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: kim
Title: A Toolkit for Behavioral Scientists
Version: 0.5.424
Version: 0.5.425
Authors@R:
person(given = "Jin",
family = "Kim",
Expand Down
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export(check_modes)
export(check_req_pkg)
export(chi_squared_test)
export(chi_squared_test_pairwise)
export(ci_of_mean)
export(clean_data_from_qualtrics)
export(coefficent_of_variation)
export(cohen_d)
Expand Down Expand Up @@ -39,6 +40,7 @@ export(detach_user_installed_pkgs)
export(duplicated_values)
export(excel_formula_convert)
export(exit_from_parent_function)
export(factorial_anova_2_way)
export(find_duplicates)
export(fisher_z_transform)
export(floodlight_2_by_continuous)
Expand Down Expand Up @@ -74,6 +76,7 @@ export(mean_center)
export(mediation_analysis)
export(merge_data_table_list)
export(merge_data_tables)
export(mixed_anova_2_way)
export(modes_of_objects)
export(multiple_regression)
export(noncentrality_parameter)
Expand Down
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# kim 0.5.425
* Added the following function(s): factorial_anova_2_way,
mixed_anova_2_way, ci_of_mean
* Updated the following function(s) (and other functions that use them):
two_way_anova, se_of_mean

# kim 0.5.423
* Updated the following function(s) (and other functions that use them):
floodlight_2_by_continuous, scatterplot, install_all_dependencies
Expand Down
44 changes: 44 additions & 0 deletions R/ci_of_mean.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#' Confidence Interval of the Mean of a Vector
#'
#' Returns the confidence interval of the mean of a numeric vector.
#'
#' @param x a numeric vector
#' @param confidence_level What is the desired confidence level
#' expressed as a decimal? (default = 0.95)
#' @return the output will be a named numeric vector with the
#' lower and upper limit of the confidence interval.
#' @examples
#' ci_of_mean(x = 1:100, confidence_level = 0.95)
#' ci_of_mean(mtcars$mpg)
#' @export
ci_of_mean <- function(
x = NULL,
confidence_level = 0.95,
notify_na_count = NULL) {
# deal with NA values
x_no_na <- x[!is.na(x)]
na_count <- length(x) - length(x_no_na)
# by default, notify only if NA values are present
if (is.null(notify_na_count)) {
notify_na_count <- ifelse(na_count > 0, TRUE, FALSE)
}
if (notify_na_count == TRUE) {
message(paste0(
"\n", na_count,
" observation(s) were removed due to missing values.\n"
))
}
ci_ll <- tryCatch(
as.numeric(stats::t.test(
x_no_na, conf.level = confidence_level)[["conf.int"]][1]),
warning = function(w) NA_real_, error = function(e) NA_real_)
ci_ul <- tryCatch(
as.numeric(stats::t.test(
x_no_na, conf.level = confidence_level)[["conf.int"]][2]),
warning = function(w) NA_real_, error = function(e) NA_real_)
output <- c(ci_ll, ci_ul)
names(output) <- c(
paste0("ci_", confidence_level * 100, "_ll"),
paste0("ci_", confidence_level * 100, "_ul"))
return(output)
}
Loading

0 comments on commit 13bfffa

Please sign in to comment.