Skip to content

Commit

Permalink
fix #96 (#97)
Browse files Browse the repository at this point in the history
* fix #96

* c
  • Loading branch information
chainsawriot authored Oct 22, 2024
1 parent e336c03 commit ff0561d
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 15 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: oolong
Title: Create Validation Tests for Automated Content Analysis
Version: 0.6.1
Version: 0.6.2
Authors@R:
c(person(given = "Chung-hong", family = "Chan", role = c("aut", "cre"), email = "[email protected]", comment = c(ORCID = "0000-0002-6232-7530")),
person(given = "Marius", family = "Sältzer", role = c("aut"), email = "[email protected]", comment = c(ORCID = "0000-0002-8604-4666")))
Expand All @@ -19,7 +19,7 @@ Imports:
digest,
R6,
quanteda (>= 3.0.0),
irr,
icr,
ggplot2,
cowplot,
cli,
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# oolong 0.6.2 (development)

* Add content for MH
* Use `icr` for the calculation of Krippendorff's Alpha

# oolong 0.6.1

Expand Down
16 changes: 8 additions & 8 deletions R/oolong_summary.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#' These functions print or plot a useful summary of the results from \code{\link{summarize_oolong}}. For details, please see the overview vignette: \code{vignette("overview", package = "oolong")}
#'
#' @section Summary:
#'
#'
#' Print function displays the following information:
#' \describe{
#' \item{Mean model precision}{(wi, wsi) Higher value indicates better topic interpretability}
Expand All @@ -18,17 +18,17 @@
#' \item{Correlation (average answer)}{(gs) Pearson's correlation between average answer and target value}
#' \item{Corrlation (content length)}{(gs) Pearson's correlation between content length and target value}
#' }
#'
#'
#' @section Diagnostic plot:
#'
#'
#' Plot function displays a diagnostic plot with the following subplots (gs only).
#' \describe{
#' \item{Top left}{Correlation between answer from coders and target value to check for correlation between two values. Both axes are minmax transformed.}
#' \item{Top right}{Bland-altman plot of answer from coders and target value to check for agreement between two values.}
#' \item{Bottom left}{Correlation between target value and content length to check for the influence of content length.}
#' \item{Bottom right}{Cook's distance to check for influential observations.}
#' }
#'
#'
#' @param x an oolong_summary
#' @param ... other parameters
#' @method print oolong_summary
Expand All @@ -53,7 +53,7 @@ plot.oolong_summary <- function(x, ...) {
} else {
.cstop(TRUE, "Don't know how to plot this oolong_summary.")
}

}

.print_oolong_summary_tm <- function(oolong_summary) {
Expand Down Expand Up @@ -85,15 +85,15 @@ plot.oolong_summary <- function(x, ...) {

.print_oolong_summary_gs <- function(oolong_summary) {
cli::cli_h1("Summary (gold standard generation):")
.cp(oolong_summary$n_models > 1, "Krippendorff's Alpha: ", round(oolong_summary$kripp_alpha$value, 3))
.cp(oolong_summary$n_models > 1, "Krippendorff's Alpha: ", round(oolong_summary$kripp_alpha$alpha, 3))
.cp(!is.null(oolong_summary$cor), "Correlation: ", round(oolong_summary$cor$estimate, 3), " (p = ", round(oolong_summary$cor$p.value, 4), ")")
.cp(!is.null(oolong_summary$cor_length), "Effect of content length: ", round(oolong_summary$cor_length$estimate, 3), " (p = ", round(oolong_summary$cor_length$p.value, 4), ")")
}

#' Summarize oolong objects
#'
#' This function summarizes one or more oolong objects. All oolong objects must be locked.
#'
#'
#' @param ... (tm/gs) one or more oolong objects to be summarized
#' @param target_value (gs) a vector of numeric values, the value you want to validate against the human-coded gold standard. One example of this target value is sentiment score extracted automatically from text
#' @param n_iter (ti) number of iterations to calculate the median test
Expand Down Expand Up @@ -127,7 +127,7 @@ plot.oolong_summary <- function(x, ...) {
#' @author Chung-hong Chan
#' @references
#' Chang, J., Gerrish, S., Wang, C., Boyd-Graber, J. L., & Blei, D. M. (2009). Reading tea leaves: How humans interpret topic models. In Advances in neural information processing systems (pp. 288-296).
#'
#'
#' Song et al. (2020) In validations we trust? The impact of imperfect human annotations as a gold standard on the quality of validation of automated content analysis. Political Communication.
#'
#' Ying, L., Montgomery, J. M., & Stewart, B. M. (2021). Topics, Concepts, and Measurement: A Crowdsourced Procedure for Validating Topics as Measures. Political Analysis.
Expand Down
4 changes: 2 additions & 2 deletions R/oolong_summary_gs.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.minmax <- function(x) {
(x - min(x)) / (max(x) - min(x))
(x - min(x)) / (max(x) - min(x))
}

.corr_plot <- function(answers, target_value) {
Expand Down Expand Up @@ -37,7 +37,7 @@
avg_answer <- apply(answers, 1, mean)
answers$avg_answer <- avg_answer
if (length(obj_list) > 1) {
kripp <- irr::kripp.alpha(t(as.matrix(answers[,grepl("^answer", colnames(answers))])), method = "ordinal")
kripp <- icr::krippalpha(t(as.matrix(answers[,grepl("^answer", colnames(answers))])), metric = "ordinal")
} else {
kripp <- NA
}
Expand Down
4 changes: 2 additions & 2 deletions R/oolong_summary_tm.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
res$multiple_test <- NA
res$rater_precision_p_value <- NA
} else {
res$kripp_alpha <- irr::kripp.alpha(t(ifelse(correction_matrix, 2, 1)))$value
res$kripp_alpha <- icr::krippalpha(t(ifelse(correction_matrix, 2, 1)))$alpha
res$multiple_test <- purrr::map(n_correct, ~binom.test(., n = nrow(correction_matrix), p = 1/n_choices, alternative = "greater"))
res$rater_precision_p_value <- .combine_p_fisher(purrr::map_dbl(res$multiple_test, "p.value"))
}
Expand Down Expand Up @@ -90,7 +90,7 @@
if (length(obj_list) == 1) {
res$kripp_alpha_wsi <- NA
} else {
res$kripp_alpha_wsi <- irr::kripp.alpha(t(ifelse(correction_matrix, 2, 1)))$value
res$kripp_alpha_wsi <- icr::krippalpha(t(ifelse(correction_matrix, 2, 1)))$alpha
}
}
return(res)
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/printing.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
i Mean model precision: 0.833333333333333
i K Precision:
0.3, 0.7, 0.7, 0.7, 1, 1, 1, 1, 1, 1
i Krippendorff's alpha: 0.056
i Krippendorff's alpha: 0.072

---

Expand Down

0 comments on commit ff0561d

Please sign in to comment.