get_likelihood_category: Get likelihood category for a p-value

View source: R/likelihood.R

get_likelihood_categoryR Documentation

Get likelihood category for a p-value

Description

Given a probabiliy p it returns the term used to describe the category this probability belongs to. It ensures the levels of the output are ordered appropietly.

Usage

get_likelihood_category(p, scale = c("statsnz", "ipcc"),
  term_type = c("worsening-improving", "improving-worsening",
  "increasing-decreasing", "decreasing-increasing", "likely-unlikely"),
  p_is = c("probability", "percentage"))

Arguments

p

the probability (or percentage) used to caclulate the category

scale

whether to base the categories using the Statistics New Zealand likelihood scale ("statsnz") or the IPCC scale ("ipcc")

term_type

when scale = "statsnz" it allows to modify the terms depending on what the probability p indicates. term_type = "worsening-improving" indicates that a large p corresponds to a worsening trend; this is the default. term_type = "improving-worsening" indicates that a large p corresponds to an improving trend. term_type = "increasing-decreasing" indicates that the output should range from "Very likely increasing" to "Very likely decreasing". term_type = "likely-unlikely" indicates that the output should range from "Very likely" to "Very unlikely".

p_is

whether p is a probability (from 0 to 1) or a percentage (from 0 to 100)

Details

This function uses the data contained in the statsnz_likelihood_scale and ipcc_likelihood_scale tables to determine the category of a given probability (usually a p-value). It uses order_likelihood_levels to ensure that levels of the output are ordered correctly.

Value

a character

See Also

Other likelihood functions: order_likelihood_levels, simplify_likelihood_levels

Examples

p <- seq(0, 1, length.out = 11)

# In most water quality metrics an increasing trend (large p) corresponds to
# a worsening trend
get_likelihood_category(p, term_type = "worsening-improving") %>%
  order_likelihood_levels()

# In climate metrics we usually prefer an increasing-decreasing scale
get_likelihood_category(p, term_type = "increasing-decreasing") %>%
  order_likelihood_levels()

# Also works when p is a percentages
get_likelihood_category(p*100, p_is = "percentage") %>%
  order_likelihood_levels()

# We can also get terms used by ipcc if desired
get_likelihood_category(p, scale = "ipcc") %>%
  order_likelihood_levels()

StatisticsNZ/er.helpers documentation built on Oct. 2, 2023, 7:24 a.m.