|
9 | 9 | #' @param group A vector of group names as character or factor. Used to aggregate and group points on plots |
10 | 10 | #' @param data_type A string identifying the type of data used for in the plot, the adjustment used and the reference point. One of: "SR" forindirectly standardised ratios, such SHMI, "PR" for proportions, or "RC" for ratios of counts. Default is "SR". |
11 | 11 | #' @param title Plot title |
12 | | -#' @param label_outliers Add group labels to outliers on plot. Accepted values are: 95 or 99 corresponding to 95\% or 99.8\% quantiles of the distribution. Default=99 |
| 12 | +#' @param label_outliers Add group labels to outliers on plot. Accepted values are: 95 or 99 corresponding to 95\% or 99.8\% quantiles of the distribution. Default=99,and applies to OD limits if both OD and Poisson are used. |
13 | 13 | #' @param Poisson_limits Draw exact Poisson limits, without overdispersion adjustment. (default=FALSE) |
14 | 14 | #' @param OD_adjust Draw overdispersed limits using hierarchical model, assuming at group level, as described in Spiegelhalter (2012) <doi:https://doi.org/10.1111/j.1467-985X.2011.01010.x>. |
15 | 15 | #' It calculates a second variance component ' for the 'between' standard deviation (Tau2), that is added to the 'within' standard deviation (sigma) (default=TRUE) |
|
18 | 18 | #' SHMI, instead, uses log-transformation and doesn't Winsorise, but truncates the distribution before assessing overdisperison. |
19 | 19 | #' Both methods then calculate a dispersion ratio (phi) on this altered dataset. This ratio is then used to scale the full dataset, |
20 | 20 | #' and the plot is drawn for the full dataset. |
21 | | -#' @param winsorise_by Proportion of the distribution for winsorisation/truncation. Default is 10 \% (0.1). Note, this is applied in a two-sided |
| 21 | +#' @param trim_by Proportion of the distribution for winsorisation/truncation. Default is 10 \% (0.1). Note, this is applied in a two-sided |
22 | 22 | #' fashion, e.g. 10\% refers to 10\% at each end of the distribution (20\% winsorised/truncated) |
23 | 23 | #' @param multiplier Scale relative risk and funnel by this factor. Default to 1, but 100 sometime used, e.g. in some hospital mortality ratios. |
24 | 24 | #' @param x_label Title for the funnel plot x-axis. Usually expected deaths, readmissions, incidents etc. |
|
71 | 71 |
|
72 | 72 |
|
73 | 73 | funnel_plot <- function(numerator, denominator, group, data_type = "SR", label_outliers = 99, |
74 | | - Poisson_limits = FALSE, OD_adjust = TRUE, sr_method = "SHMI", winsorise_by = 0.1, |
| 74 | + Poisson_limits = FALSE, OD_adjust = TRUE, sr_method = "SHMI", trim_by = 0.1, |
75 | 75 | title="Untitled Funnel Plot", multiplier = 1, x_label = "Expected", |
76 | 76 | y_label ,xrange = "auto", yrange = "auto", |
77 | 77 | return_elements=c("plot", "data", "limits"), theme = funnel_clean()){ |
@@ -131,7 +131,11 @@ funnel_plot <- function(numerator, denominator, group, data_type = "SR", label_o |
131 | 131 | mod_plot_agg <- transformed_zscore(mod_plot_agg=mod_plot_agg, data_type = data_type, sr_method = sr_method) |
132 | 132 |
|
133 | 133 | # Winsorise or truncate depending on method |
134 | | - mod_plot_agg <- winsorisation(mod_plot_agg = mod_plot_agg, data_type=data_type, sr_method = sr_method, winsorise_by=winsorise_by) |
| 134 | + if(data_type=="SR" & sr_method=="SHMI"){ |
| 135 | + mod_plot_agg <- truncation(mod_plot_agg = mod_plot_agg, trim_by=trim_by) |
| 136 | + } else { |
| 137 | + mod_plot_agg <- winsorisation(mod_plot_agg = mod_plot_agg, trim_by=trim_by) |
| 138 | + } |
135 | 139 |
|
136 | 140 | n <- as.numeric(sum(!is.na(mod_plot_agg$Wuzscore))) |
137 | 141 | # Calculate Phi (the overdispersion factor) |
|
0 commit comments