Package 'funnelR'

Title: Funnel Plots for Proportion Data
Description: A set of simplified functions for creating funnel plots for proportion data. This package supports user defined benchmarks, confidence limits and estimation methods (i.e. exact or approximate) based on Spiegelhalter (2005) <doi:10.1002/sim.1970>. Additional routines for returning scored unit level data according to a set of specifications is also implemented for convenience. Specifically, both a categorical and a continuous score variable is returned to the sample data frame, which identifies which observations are deemed extreme or in control. Typically, such variables are useful as stratifications or covariates in further exploratory analyses. Lastly, the plotting routine returns a base funnel plot ('ggplot2'), which can also be tailored.
Authors: Matthew Kumar <[email protected]>
Maintainer: Matthew Kumar <[email protected]>
License: GPL-3
Version: 0.1.0
Built: 2024-11-12 03:10:11 UTC
Source: https://github.com/cran/funnelR

Help Index


Compute Control Limits for Proportion Data

Description

This function will return a single data frame consisting of two sets of control limits, which can then be overlaid in a funnel plot. The incoming data frame (input) should have one observation per row. It must have a column labeled 'n' which represents the number of events (numerator) and a column labeled 'd' which represents the total (denominator). Other by variables are permitted (e.g. sex, or age).

Usage

fundata(input, benchmark, alpha = 0.95, alpha2 = 0.998,
  method = "approximate", step = 0.5)

Arguments

input

A data frame of your sample data, in the format outlined above.

benchmark

A number between 0 and 1 representing the benchmark (e.g. null) estimate for which confidence limits are calculated for. If not specified, the overall proportion of events is used.

alpha

A number between 0 and 1 representing the desired confidence limit (e.g. 0.95)

alpha2

A number between 0 and 1 representing the desired confidence limit (e.g. 0.998)

method

Choose between approximate or exact binomial control limits.

step

Minor ticks between 1 and the maximum denominator size of the raw data for which the control limits are calculated for. Must be integer for method=exact.

Examples

#My sample data
my_data  <- data.frame(id=c('A','B','C','D','E'), n=c(2,5,10,15,18), d=c(20,20,20,20,20))

#Compute approximate control limits
my_fpdata <- fundata(my_data, alpha=0.95, alpha2=0.998, method='approximate', step=0.5)

Create a funnel plot

Description

This function will return a ggplot2 object. It requires two data frames: the sample data frame and the control limit data frame. An optional sub-group variable can be present in the sample data frame for coloring the funnel plot.

Usage

funplot(input, fundata, byvar)

Arguments

input

A data frame of the raw data with a denominator (total) as d, and numerator (events) as n

fundata

A data frame from the fundata function which holds the control limits to be overlayed.

byvar

A subgroup variable to color the plots by (Optional). Variable name must be wrapped in quotes.

Examples

#My sample data
my_data  <- data.frame(id=c('A','B','C','D','E'), n=c(2,5,10,15,18), d=c(20,20,20,20,20))

#Process sample data through fundata
my_fpdata <- fundata(my_data, alpha=0.95, alpha2=0.998, method='approximate', step=0.5)

#Use sample data and fundata to make the plot.
my_plot <- funplot(my_data, my_fpdata)

#View plot
my_plot

Score Proportion Data

Description

This function will return a single data frame consisting of (1) the original sample data and (2) two categorical variables which record whether each sample data point is In Control or Extreme, relative to the two sets of alphas specified. These two categorical variables might be useful for additional analyses or coloring the funnel plot.

Usage

funscore(input, benchmark, alpha = 0.95, alpha2 = 0.998,
  method = "approximate")

Arguments

input

A data frame of your sample data, in the format outlined above.

benchmark

A number between 0 and 1 representing the benchmark (e.g. null) estimate for which confidence limits are calculated for. If not specified, the overall proportion of events is used.

alpha

A number between 0 and 1 representing the desired confidence limit (e.g. 0.95)

alpha2

A number between 0 and 1 representing the desired confidence limit (e.g. 0.998)

method

Choose between approximate or exact binomial control limits.

Examples

#My sample data
my_data  <- data.frame(id=c('A','B','C','D','E'), n=c(2,5,10,15,18), d=c(20,20,20,20,20))

#Score sample data
my_scoredata <- funscore(my_data, alpha=0.95, alpha2=0.998, method='approximate')

#View scored data
head(my_scoredata)