ff_estimates_ci: Matrix of estimates and confidence intervals

View source: R/analysis.R

ff_estimates_ciR Documentation

Matrix of estimates and confidence intervals

Description

This function returns a square symetrical matrix of all differences between all combinations of rows, along with the 95 percent confidence interval of the difference. For binomial (categorical) datasets, the difference is the percentile difference.

Usage

ff_estimates_ci(
  data_frame,
  estimate,
  se,
  format,
  success = NULL,
  trials = NULL,
  rate_per_unit = 1,
  var_names = NULL,
  pretty_print = FALSE,
  table_name = NULL
)

Arguments

data_frame

A dataframe containing estimates and either standard errors for continuous data or successes and trials for binomial data.

estimate

An integer or float containing the number to compare differences. Required for continuous format.

se

Standard error of the estimate. Required for continuous format.

format

Type of data; either 'continuous' or 'binomial'. If continuous, the 'estimate' columns is used to generate differences. If binomial, the 'success' and 'trials' columns are used. Default is continuous.

success

The number of successful trials. Required for binomial format.

trials

The total number of trials. Required for binomial format.

rate_per_unit

Integer used to calculate the rate per x number of people. For example, the crime rate is the number of crimes per 100,000 people, so 100,000 would be entered. Defaults to 1, which is no adjustment. Only used if format equals 'binomial'.

var_names

A character vector of variables that can be combined to create distinct names for each row and column.

pretty_print

Boolean (TRUE / FALSE) indicating whether to return the table as a Kable HTML table that bolds statistically significant finding and creates other stylistic changes. Default is FALSE.

table_name

Character string to use as the name of the Kable table. Only used if 'pretty_print' is TRUE.

Value

A square, symmetrical, with a length and width equal the number of rows in the data frame. Each cell in the matrix contains the difference in the estimate of the column minus the row. It also contains the 95 percent confidence interval of the difference.

Examples

df <- data.frame(year = c(2016, 2016, 2017, 2017),
                 geo_description = c('Forsyth County, NC', 'Guilford County, NC',
                                     'Forsyth County, NC', 'Guilford County, NC'),
                estimate = c(.66, .63, .88, .48),
                se = c(.1, .15, .06, .09),
                success = c(10, 12, 15, 19),
                trials = c(15, 19, 17, 39))

# binomial data
ff_estimates_ci(df, 'estimate', format = 'binomial',
                success = 'success', trials = 'trials', var_names = c('year', 'geo_description'))

forsythfuture/FFtools documentation built on April 5, 2022, 10:02 p.m.