Package 'greta.distributions'

Title: Extends Distributions Available in the 'greta' Package
Description: Provides extra distributions for use with the 'greta' package. These will include distributions such as zero inflated negative binomial, zero inflated poisson, interval censored lognormal, and more.
Authors: Nick Golding [aut] , Nicholas Tierney [aut, cre]
Maintainer: Nicholas Tierney <[email protected]>
License: Apache License 2.0
Version: 0.0.0.9000
Built: 2024-12-19 05:21:57 UTC
Source: https://github.com/greta-dev/greta.distributions

Help Index


Create a template greta distribution

Description

This code creates the text of a basic greta distribution. To write the text to file, see write_new_distribution().

Usage

greta_distribution_template(dist_name, dist_arg_list)

Arguments

dist_name

character length 1, name of the distribution

dist_arg_list

character vector, arguments to the distribution

Value

text of a basic greta distribution

Examples

greta_distribution_template(
  dist_name = "lognormal", 
  dist_arg_list = c("meanlog", "sdlog")
  )

Create a test template for a distribution

Description

When you add a new distribution, you want to add a test to make sure it is behaving as expected. This function generates a test template. It only creates the text, it does not write to file. See write_distribution_test() to write the test to file automatically.

Usage

greta_distribution_template_test(dist_name)

Arguments

dist_name

character. A distribution name. E.g., "lognormal"

Value

text containing test template code

Examples

gumbel <- greta_distribution_template_test("gumbel")

Create a test template for a distribution

Description

When you add a new distribution, you want to add a test to make sure it is behaving as expected. This function generates a test template. See also greta_distribution_template_test() to see the text generated if you want to save it somewhere else.

Usage

write_distribution_test(dist_name, overwrite = FALSE)

Arguments

dist_name

character, name of distribution.

overwrite

logical. Default is FALSE. Whether to overwrite the test file if it already exists.

Value

test file written out to tests/testthat/test-{dist_name}.

Examples

## Not run: 
write_distribution_test("gumbel")

## End(Not run)

Write a new greta distribution template file

Description

This generates a starting place for writing a new greta distribution. By default this will save the output to "R/dist_name.R". To save to somewhere else, see greta_distribution_template(), which will generate the R code as plain text, and you can then save somewhere else as you wish.

Usage

write_new_distribution(
  dist_name = NULL,
  dist_arg_list = NULL,
  overwrite = FALSE
)

Arguments

dist_name

name of distribution.

dist_arg_list

arguments for distribution.

overwrite

logical. default FALSE. Whether to overwrite the test file if it already exists.

Value

writes to file a new distribution name.

Examples

## Not run: 
write_new_distribution(
  dist_name = "lognormal", 
  dist_arg_list = c("meanlog", "sdlog")
  )

## End(Not run)

Zero Inflated Negative Binomial

Description

A Zero Inflated Negative Binomial distribution

Usage

zero_inflated_negative_binomial(size, prob, pi, dim = NULL)

Arguments

size

positive integer parameter

prob

probability parameter (⁠0 < prob < 1⁠),

pi

proportion of zeros

dim

a scalar giving the number of rows in the resulting greta array

Examples

## Not run: 
zinb <- zero_inflated_negative_binomial(size = 2, prob= 0.2, pi = 0.10)
calculate(zinb, nsim = 10)
m <- model(zinb)
mcmc(m)

## End(Not run)

Zero Inflated Poisson distribution

Description

A zero inflated poisson distribution.

Usage

zero_inflated_poisson(lambda, pi, dim = NULL)

Arguments

lambda

rate parameter

pi

proportion of zeros

dim

a scalar giving the number of rows in the resulting greta array

Examples

## Not run: 
zip <- zero_inflated_poisson(lambda = 2, pi = 0.2)
calculate(zip, nsim = 10)
mcmc(m)

## End(Not run)