library(simplFeedbackPerformance)
library(ggplot2)
library(magrittr)
df <- df %>%
dplyr::filter(traineePGY < 6,
date >= "2018-07-01",
date < "2019-07-01")To make it even clearer, we can take a look at the data in a table:
table(df$performance)
#>
#> CD UP IP PR EP
#> 38 4346 14986 8554 817
table(df$supervision)
#>
#> ST AH PH SO
#> 3166 13914 10074 4753
df %>%
dplyr::group_by(supervision, traineePGY) %>%
dplyr::filter(!is.na(supervision)) %>%
dplyr::summarise(n = dplyr::n()) %>%
dplyr::mutate(rate = n/sum(n)) %>%
ggplot() +
geom_bar(aes(x = supervision, y = rate, fill = traineePGY), stat = "identity", position = "dodge")
#> `summarise()` regrouping output by 'supervision' (override with `.groups` argument)
df %>%
dplyr::group_by(performance, traineePGY) %>%
dplyr::filter(!is.na(performance)) %>%
dplyr::summarise(n = dplyr::n()) %>%
dplyr::mutate(rate = n/sum(n)) %>%
ggplot() +
geom_bar(aes(x = performance, y = rate, fill = traineePGY), stat = "identity", position = "dodge")
#> `summarise()` regrouping output by 'performance' (override with `.groups` argument)df %>%
dplyr::filter(traineeType == "CATEGORICAL",
subjectRole == "Trainee",
raterRole == "Attending",
paired) %>%
dplyr::group_by(subjectID) %>%
dplyr::summarise(count = dplyr::n()) %>%
ggplot() +
geom_histogram(aes(x = count), bins = 75)
#> `summarise()` ungrouping output (override with `.groups` argument)getquant <- function(x) {
ifelse(x < 5, 1,
ifelse(x < 10, 2,
ifelse(x < 20, 3, 4)))
}
df %>%
dplyr::filter(traineeType == "CATEGORICAL",
subjectRole == "Trainee",
raterRole == "Attending",
paired,
!is.na(performance)) %>%
dplyr::group_by(subjectID, performance) %>%
dplyr::summarise(count = dplyr::n()) %>%
dplyr::mutate(totalcount = sum(count),
rate = count/sum(count),
quant = getquant(totalcount)) %>%
ggplot(aes(x = quant, y = rate, group = quant)) +
geom_boxplot() +
facet_wrap(~performance)
#> `summarise()` regrouping output by 'subjectID' (override with `.groups` argument)
df %>%
dplyr::filter(traineeType == "CATEGORICAL",
subjectRole == "Trainee",
raterRole == "Attending",
paired,
!is.na(supervision)) %>%
dplyr::group_by(subjectID, supervision) %>%
dplyr::summarise(count = dplyr::n()) %>%
dplyr::mutate(totalcount = sum(count),
rate = count/sum(count),
quant = getquant(totalcount)) %>%
ggplot(aes(x = quant, y = rate, group = quant)) +
geom_boxplot() +
facet_wrap(~supervision)
#> `summarise()` regrouping output by 'subjectID' (override with `.groups` argument)getquant <- function(x) {
ifelse(x < 5, 1,
ifelse(x < 10, 2,
ifelse(x < 20, 3, 4)))
}
getRatio <- function(count, performance) {
if(length(performance) == 2) {
count[performance == "Independent"]/count[performance =="Not independent"]
} else 0
}
df %>%
dplyr::filter(traineeType == "CATEGORICAL",
subjectRole == "Trainee",
raterRole == "Attending",
paired,
!is.na(performance)) %>%
dplyr::mutate(performance =
forcats::fct_collapse(performance, Independent = c("PR","EP"), `Not independent` = c("CD", "UP", "IP"))) %>%
dplyr::group_by(subjectID, performance) %>%
dplyr::summarise(count = dplyr::n()) %>%
dplyr::mutate(ratio = getRatio(count, performance),
totalcount = sum(count),
quant = factor(getquant(totalcount), levels = c(1,2,3,4), ordered = TRUE)) %>%
dplyr::filter(ratio != 0) %>%
ggplot(aes(x = quant, y = ratio)) +
geom_boxplot()
#> `summarise()` regrouping output by 'subjectID' (override with `.groups` argument)getquant <- function(x) {
ifelse(x < 30, 1, 2)
}
df %>%
dplyr::filter(traineeType == "CATEGORICAL",
subjectRole == "Trainee",
raterRole == "Attending",
paired,
!is.na(performance)) %>%
dplyr::mutate(performance =
forcats::fct_collapse(performance, Independent = c("PR","EP"), `Not independent` = c("CD", "UP", "IP"))) %>%
dplyr::group_by(subjectID, performance) %>%
dplyr::summarise(count = dplyr::n()) %>%
dplyr::mutate(ratio = getRatio(count, performance),
totalcount = sum(count),
quant = factor(getquant(totalcount), levels = c(1,2), ordered = TRUE)) %>%
dplyr::filter(ratio != 0) %>%
ggplot(aes(x = quant, y = ratio)) +
geom_boxplot()
#> `summarise()` regrouping output by 'subjectID' (override with `.groups` argument)getquant <- function(x) {
ifelse(x < 5, 1,
ifelse(x < 10, 2,
ifelse(x < 20, 3, 4)))
}
getRatio <- function(count, supervision) {
if(length(supervision) == 2) {
count[supervision == "Independent"]/count[supervision =="Not independent"]
} else 0
}
df %>%
dplyr::filter(traineeType == "CATEGORICAL",
subjectRole == "Trainee",
raterRole == "Attending",
paired,
!is.na(supervision)) %>%
dplyr::mutate(supervision =
forcats::fct_collapse(supervision, Independent = c("SO","PH"), `Not independent` = c("ST", "AH"))) %>%
dplyr::group_by(subjectID, supervision) %>%
dplyr::summarise(count = dplyr::n()) %>%
dplyr::mutate(ratio = getRatio(count, supervision),
totalcount = sum(count),
quant = factor(getquant(totalcount), levels = c(1,2,3,4), ordered = TRUE)) %>%
dplyr::filter(ratio != 0) %>%
ggplot(aes(x = quant, y = ratio)) +
geom_boxplot()
#> `summarise()` regrouping output by 'subjectID' (override with `.groups` argument)