Package 'nlist'

Title: Lists of Numeric Atomic Objects
Description: Create and manipulate numeric list ('nlist') objects. An 'nlist' is an S3 list of uniquely named numeric objects. An numeric object is an integer or double vector, matrix or array. An 'nlists' object is a S3 class list of 'nlist' objects with the same names, dimensionalities and typeofs. Numeric list objects are of interest because they are the raw data inputs for analytic engines such as 'JAGS', 'STAN' and 'TMB'. Numeric lists objects, which are useful for storing multiple realizations of of simulated data sets, can be converted to coda::mcmc and coda::mcmc.list objects.
Authors: Joe Thorley [aut, cre] , Kirill Müller [ctb] , Nadine Hussein [ctb] , Ayla Pearson [ctb] , Poisson Consulting [cph, fnd]
Maintainer: Joe Thorley <[email protected]>
License: MIT + file LICENSE
Version: 0.3.3.9000
Built: 2024-11-01 16:19:37 UTC
Source: https://github.com/poissonconsulting/nlist

Help Index


Aggregate nlist

Description

Aggregates an nlist_object() into a named list of numeric scalars.

Usage

## S3 method for class 'nlist'
aggregate(x, fun = mean, ...)

Arguments

x

An nlist object.

fun

A function that given a numeric vector returns a numeric scalar.

...

Additional arguments passed to fun.

Value

An named list of numeric scalars

See Also

Other aggregate: aggregate.nlists()

Examples

aggregate(nlist(x = 1:9))
aggregate(nlist(y = 3:5, zz = matrix(1:9, 3)), fun = function(x) x[1])

Aggregate nlists

Description

Aggregates an nlists_object() into a nlist_object() or by_chain = TRUE an nlists_object() with nchains nlist_object()s.

Usage

## S3 method for class 'nlists'
aggregate(x, fun = mean, ..., by_chain = FALSE)

Arguments

x

An object.

fun

A function that given a numeric vector returns a numeric scalar.

...

Unused.

by_chain

A flag specifying whether to aggregate by chains.

Value

An nlist object if by_chain = FALSE otherwise an nlists object.

See Also

Other aggregate: aggregate.nlist()

Examples

aggregate(nlists(nlist(x = 1:3), nlist(x = 2:4)))

Coerce to mcmc Object

Description

Coerce an R object to an mcmc object.

Usage

as_mcmc(x, ...)

## S3 method for class 'mcmc.list'
as_mcmc(x, ...)

## S3 method for class 'nlist'
as_mcmc(x, ...)

## S3 method for class 'nlists'
as_mcmc(x, ...)

Arguments

x

An object.

...

Unused.

Value

An mcmc object.

Methods (by class)

  • as_mcmc(mcmc.list): Coerce an mcmc.list object to an mcmc object.

  • as_mcmc(nlist): Coerce an nlist object to an mcmc object.

  • as_mcmc(nlists): Coerce an nlists object to an mcmc object.

See Also

coda::as.mcmc()

Other mcmc: as_mcmc_list()

Examples

as_mcmc(as_mcmc_list(nlists(nlist(x = 2), nlist(x = 3))))
as_mcmc(nlist(x = matrix(1:6, 2)))
as_mcmc(nlists(
  nlist(x = matrix(1:6, 2)),
  nlist(x = matrix(3:8, 2))
))

Coerce to an mcmc.list Object

Description

Coerce an R object to an mcmc.list object.

Usage

as_mcmc_list(x, ...)

## S3 method for class 'mcmc'
as_mcmc_list(x, ...)

## S3 method for class 'nlist'
as_mcmc_list(x, ...)

## S3 method for class 'nlists'
as_mcmc_list(x, ...)

Arguments

x

An object.

...

Unused.

Value

An mcmc.list object.

Methods (by class)

  • as_mcmc_list(mcmc): Coerce an mcmc object to an mcmc.list object.

  • as_mcmc_list(nlist): Coerce an nlist object to an mcmc.list object.

  • as_mcmc_list(nlists): Coerce an nlists object to an mcmc.list object.

See Also

Other mcmc: as_mcmc()

Examples

as_mcmc_list(nlist(x = matrix(1:6, 2)))
as_mcmc_list(nlists(
  nlist(x = matrix(1:6, 2)),
  nlist(x = matrix(3:8, 2))
))

Coerce to nlist

Description

Coerce an R object to an nlist_object().

Usage

as_nlist(x, ...)

as.nlist(x, ...)

## S3 method for class 'numeric'
as_nlist(x, ...)

## S3 method for class 'list'
as_nlist(x, ...)

## S3 method for class 'data.frame'
as_nlist(x, ...)

## S3 method for class 'mcmc'
as_nlist(x, ...)

## S3 method for class 'mcmc.list'
as_nlist(x, ...)

as.nlists(x, ...)

Arguments

x

An object.

...

Unused.

Value

An nlist object.

Methods (by class)

  • as_nlist(numeric): Coerce named numeric vector to nlist

  • as_nlist(list): Coerce list to nlist

  • as_nlist(data.frame): Coerce data.frame to nlist

  • as_nlist(mcmc): Coerce mcmc (with one iteration) to nlist

  • as_nlist(mcmc.list): Coerce mcmc.list (with one iteration) to nlist

See Also

Other coerce: as_nlists()

Examples

as_nlist(list(x = 1:4))
as_nlist(c(`a[2]` = 3, `a[1]` = 2))

Coerce to nlists

Description

Coerce an R object to an nlists_object().

Usage

as_nlists(x, ...)

## S3 method for class 'list'
as_nlists(x, ...)

## S3 method for class 'mcmc'
as_nlists(x, ...)

## S3 method for class 'mcmc.list'
as_nlists(x, ...)

## S3 method for class 'nlist'
as_nlists(x, ...)

Arguments

x

An object.

...

Unused.

Value

An nlists object.

Methods (by class)

  • as_nlists(list): Coerce list to nlists

  • as_nlists(mcmc): Coerce mcmc to nlists

  • as_nlists(mcmc.list): Coerce mcmc.list to nlists

  • as_nlists(nlist): Coerce nlist to nlists

See Also

Other coerce: as_nlist()

Examples

as_nlists(list(nlist(x = c(1, 5)), nlist(x = c(2, 3)), nlist(x = c(3, 2))))

Coerce to a Term Frame

Description

A term frame is a tibble with the first column a term vector called and a numeric column called value and in the case of an nlists object an integer vector called samples. It includes the original nlist or nlists object.

Usage

as_term_frame(x, ...)

Arguments

x

An object.

...

Unused.

Value

An term_frame object.

See Also

Other coerce term: as_term.mcmc(), as_term.nlist(), as_term.nlists(), as_term_frame.nlist(), as_term_frame.nlists()


Coerce nlist Object to Data Frame

Description

Coerces an nlist object to a data.frame with an term column and a value column.

Usage

## S3 method for class 'nlist'
as_term_frame(x, ...)

Arguments

x

An nlist object.

...

Unused.

Value

A data.frame.

See Also

Other coerce term: as_term.mcmc(), as_term.nlist(), as_term.nlists(), as_term_frame(), as_term_frame.nlists()

Examples

as_term_frame(nlist(x = 1, y = 4:6))

Coerce nlists Object to Data Frame

Description

Coerces an nlists object to a data.frame with a term, sample and value column.

Usage

## S3 method for class 'nlists'
as_term_frame(x, ...)

Arguments

x

An nlists object.

...

Unused.

Value

A data.frame.

See Also

Other coerce term: as_term.mcmc(), as_term.nlist(), as_term.nlists(), as_term_frame(), as_term_frame.nlist()

Examples

as_term_frame(nlists(
  nlist(x = 1, y = 4:6),
  nlist(x = 3, y = 1:3)
))

Coerce to a Term Vector

Description

Coerce to a Term Vector

Usage

## S3 method for class 'mcmc'
as_term(x, ...)

Arguments

x

An object.

...

Unused.

See Also

Other coerce term: as_term.nlist(), as_term.nlists(), as_term_frame(), as_term_frame.nlist(), as_term_frame.nlists()

Examples

as_term(as_mcmc(nlist(x = matrix(1:4, ncol = 2))))

Coerce to a Term Vector

Description

Coerce to a Term Vector

Usage

## S3 method for class 'nlist'
as_term(x, ...)

Arguments

x

An object.

...

Unused.

See Also

Other coerce term: as_term.mcmc(), as_term.nlists(), as_term_frame(), as_term_frame.nlist(), as_term_frame.nlists()

Examples

as_term(nlist(x = matrix(1:4, ncol = 2)))

Coerce to a Term Vector

Description

Coerce to a Term Vector

Usage

## S3 method for class 'nlists'
as_term(x, ...)

Arguments

x

An object.

...

Unused.

See Also

Other coerce term: as_term.mcmc(), as_term.nlist(), as_term_frame(), as_term_frame.nlist(), as_term_frame.nlists()

Examples

as_term(nlists(nlist(x = matrix(1:4, ncol = 2))))

Bind Iterations

Description

Combines two MCMC objects (with the same parameters and chains) by iterations.

Usage

## S3 method for class 'mcmc'
bind_iterations(x, x2, ...)

Arguments

x

An object.

x2

A second object.

...

Other arguments passed to methods.

Value

The combined object.

See Also

Other MCMC manipulations: bind_chains(), collapse_chains(), estimates(), split_chains()

Examples

bind_iterations(as_mcmc(nlist(x = 1)), as_mcmc(nlist(x = 3)))

Bind Iterations

Description

Combines two MCMC objects (with the same parameters and chains) by iterations.

Usage

## S3 method for class 'mcmc.list'
bind_iterations(x, x2, ...)

Arguments

x

An object.

x2

A second object.

...

Other arguments passed to methods.

Value

The combined object.

See Also

Other MCMC manipulations: bind_chains(), collapse_chains(), estimates(), split_chains()

Examples

bind_iterations(as_mcmc_list(nlist(x = 1)), as_mcmc_list(nlist(x = 3)))

Check nlist Object or nlists Object

Description

chk_nlist checks if an nlist-object().

Usage

chk_nlist(x, x_name = NULL)

chk_nlists(x, x_name = NULL)

Arguments

x

The object to check.

x_name

A string of the name of object x or NULL.

Value

NULL, invisibly. Called for the side effect of throwing an error if the condition is not met.

Functions

  • chk_nlists(): Check nlists Object

    chk_nlists checks if an nlists-object().

Examples

# chk_nlist
chk_nlist(nlist(x = 1))
try(chk_nlist(list(x = 1)))

# chk_nlists
chk_nlists(nlists(nlist(x = 1)))

Collapse Chains

Description

Collapses an MCMC object's chains into a single chain.

Usage

## S3 method for class 'mcmc'
collapse_chains(x, ...)

Arguments

x

An object.

...

Other arguments passed to methods.

Details

As mcmc objects can only have 1 chain the object is unchanged.

Value

The modified object with one chain.

See Also

Other collapse: collapse_chains.nlist(), collapse_chains.nlists()

Examples

collapse_chains(as_mcmc(nlist(x = 2)))

Collapse Chains

Description

Collapses an MCMC object's chains into a single chain.

Usage

## S3 method for class 'mcmc.list'
collapse_chains(x, ...)

Arguments

x

An object.

...

Other arguments passed to methods.

Value

The modified object with one chain.

See Also

Other MCMC manipulations: bind_chains(), bind_iterations(), estimates(), split_chains()


Collapse Chains

Description

Collapses an MCMC object's chains into a single chain.

Usage

## S3 method for class 'nlist'
collapse_chains(x, ...)

Arguments

x

An object.

...

Other arguments passed to methods.

Details

As nlist objects can only have 1 chain the object is unchanged.

Value

The modified object with one chain.

See Also

Other collapse: collapse_chains.mcmc(), collapse_chains.nlists()

Examples

collapse_chains(nlist(x = 2))

Collapse Chains

Description

Collapses an MCMC object's chains into a single chain.

Usage

## S3 method for class 'nlists'
collapse_chains(x, ...)

Arguments

x

An object.

...

Other arguments passed to methods.

Value

The modified object with one chain.

See Also

Other collapse: collapse_chains.mcmc(), collapse_chains.nlist()

Examples

collapse_chains(nlist(x = 2))

Complete Terms

Description

Adds any absent elements to an mcmc object.

Usage

## S3 method for class 'mcmc'
complete_terms(x, silent = FALSE, ...)

Arguments

x

An mcmc object.

silent

A flag specifying whether to suppress warning messages.

...

Unused.

Details

The terms are repaired before being completed. Missing or invalid or inconsistent terms are dropped with a warning.

Value

The repaired and complete mcmc object.

Examples

mcmc <- as_mcmc(nlist(beta = matrix(1:4, nrow = 2)))
mcmc <- mcmc[, -4, drop = FALSE]
complete_terms(mcmc)

Estimates

Description

Calculates the estimates for an MCMC object.

Usage

## S3 method for class 'nlist'
estimates(x, fun = median, ...)

Arguments

x

An object.

fun

A function that given a numeric vector returns a numeric scalar.

...

Additional arguments passed to fun.

Value

A list of uniquely named numeric objects.

See Also

Other MCMC manipulations: bind_chains(), bind_iterations(), collapse_chains(), split_chains()

Examples

estimates(nlist(x = 1:9))
estimates(nlist(y = 3:5, zz = matrix(1:9, 3)))

Estimates

Description

Calculates the estimates for an MCMC object.

Usage

## S3 method for class 'nlists'
estimates(x, fun = median, ...)

Arguments

x

An object.

fun

A function that given a numeric vector returns a numeric scalar.

...

Additional arguments passed to fun.

Value

A list of uniquely named numeric objects.

See Also

Other MCMC manipulations: bind_chains(), bind_iterations(), collapse_chains(), split_chains()

Examples

estimates(nlists(nlist(x = 1:3), nlist(x = 2:4)), fun = mean)

Fill All Values

Description

Fills all of an object's (missing and non-missing) values while preserving the object's dimensionality and class.

Usage

## S3 method for class 'nlist'
fill_all(x, value = 0L, nas = TRUE, ...)

Arguments

x

An object.

value

A scalar of the value to replace values with.

nas

A flag specifying whether to also fill missing values.

...

Other arguments passed to methods.

Details

It should only be defined for objects with values of consistent class ie not standard data.frames.

Value

The modified object.

Methods (by class)

  • fill_all(logical): Fill All for logical Objects

  • fill_all(integer): Fill All for integer Objects

  • fill_all(numeric): Fill All for numeric Objects

  • fill_all(character): Fill All for character Objects

See Also

Other fill: fill_na()

Examples

fill_all(nlist(x = c(2, NA), y = matrix(c(1:3, NA), nrow = 2)))
fill_all(nlist(x = c(2, NA), y = matrix(c(1:3, NA), nrow = 2)), nas = FALSE)

Fill All Values

Description

Fills all of an object's (missing and non-missing) values while preserving the object's dimensionality and class.

Usage

## S3 method for class 'nlists'
fill_all(x, value = 0L, nas = TRUE, ...)

Arguments

x

An object.

value

A scalar of the value to replace values with.

nas

A flag specifying whether to also fill missing values.

...

Other arguments passed to methods.

Details

It should only be defined for objects with values of consistent class ie not standard data.frames.

Value

The modified object.

Methods (by class)

  • fill_all(logical): Fill All for logical Objects

  • fill_all(integer): Fill All for integer Objects

  • fill_all(numeric): Fill All for numeric Objects

  • fill_all(character): Fill All for character Objects

See Also

Other fill: fill_na()

Examples

fill_all(nlists(nlist(x = c(2, NA)), nlist(x = c(NA_real_, NA))))
fill_all(nlists(nlist(x = c(2, NA)), nlist(x = c(NA_real_, NA))), nas = FALSE)

Fill Missing Values

Description

Fills all of an object's missing values while preserving the object's dimensionality and class.

Usage

## S3 method for class 'nlist'
fill_na(x, value = 0L, ...)

Arguments

x

An object.

value

A scalar of the value to replace values with.

...

Other arguments passed to methods.

Details

It should only be defined for objects with values of consistent class ie not standard data.frames.

Value

The modified object.

Methods (by class)

  • fill_na(logical): Fill Missing Values for logical Objects

  • fill_na(integer): Fill Missing Values for integer Objects

  • fill_na(numeric): Fill Missing Values for numeric Objects

  • fill_na(character): Fill Missing Values for character Objects

See Also

Other fill: fill_all()

Examples

fill_na(nlist(x = c(2, NA), y = matrix(c(1:3, NA), nrow = 2)))
fill_na(nlists(nlist(x = c(2, NA)), nlist(x = c(NA_real_, NA))))

Fill Missing Values

Description

Fills all of an object's missing values while preserving the object's dimensionality and class.

Usage

## S3 method for class 'nlists'
fill_na(x, value = 0L, ...)

Arguments

x

An object.

value

A scalar of the value to replace values with.

...

Other arguments passed to methods.

Details

It should only be defined for objects with values of consistent class ie not standard data.frames.

Value

The modified object.

Methods (by class)

  • fill_na(logical): Fill Missing Values for logical Objects

  • fill_na(integer): Fill Missing Values for integer Objects

  • fill_na(numeric): Fill Missing Values for numeric Objects

  • fill_na(character): Fill Missing Values for character Objects

See Also

Other fill: fill_all()

Examples

fill_na(nlist(x = c(2, NA), y = matrix(c(1:3, NA), nrow = 2)))

Is numeric, nlist or nlists

Description

Ask whether x is a numeric object, nlist_object() or nlists_object().

Usage

is_numeric(x)

is_nlist(x)

is_nlists(x)

Arguments

x

An object.

Value

A flag indicating whether x is a numeric object or inherits from S3 class nlist or nlists.

Functions

  • is_nlist(): Is nlist

  • is_nlists(): Is nlists

Examples

# is_numeric
is_numeric(list(x = 1))
is_numeric(1)

# is_nlist
is_nlist(1)
is_nlist(list(x = 1))
is_nlist(nlist(x = 1))

# is_nlists
is_nlists(nlist(x = 1))
is_nlists(nlists(nlist(x = 2), nlist(x = 3.5)))

Number of Chains

Description

Gets the number of chains of an MCMC object.

Usage

## S3 method for class 'mcmc'
nchains(x, ...)

Arguments

x

An object.

...

Other arguments passed to methods.

Value

An integer scalar of the number of chains.

See Also

Other MCMC dimensions: niters(), npars(), nsams(), nsims(), nterms()


Number of Chains

Description

Gets the number of chains of an MCMC object.

Usage

## S3 method for class 'mcmc.list'
nchains(x, ...)

Arguments

x

An object.

...

Other arguments passed to methods.

Value

An integer scalar of the number of chains.

See Also

Other MCMC dimensions: niters(), npars(), nsams(), nsims(), nterms()


Number of Terms

Description

Gets the number of terms of an MCMC object.

Usage

## S3 method for class 'nlist'
nchains(x, ...)

Arguments

x

An object.

...

Other arguments passed to methods.

Details

Always 1L.

Value

A integer scalar of the number of terms.

See Also

Other MCMC dimensions: nchains(), niters(), npars(), nsams(), nsims()

Examples

nchains(nlist(x = 1:2))

Number of Terms

Description

Gets the number of terms of an MCMC object.

Usage

## S3 method for class 'nlists'
nchains(x, ...)

Arguments

x

An object.

...

Other arguments passed to methods.

Value

A integer scalar of the number of terms.

See Also

Other MCMC dimensions: nchains(), niters(), npars(), nsams(), nsims()

Examples

nchains(nlists(nlist(x = c(2, 9)), nlist(x = c(1, 7))))
nchains(split_chains(nlists(nlist(x = c(2, 9)), nlist(x = c(1, 7)))))

Number of Iterations

Description

Gets the number of iterations (in a chain) of an MCMC object.

Usage

## S3 method for class 'mcmc'
niters(x, ...)

Arguments

x

An object.

...

Other arguments passed to methods.

Value

An integer scalar of the number of iterations.

See Also

Other MCMC dimensions: nchains(), npars(), nsams(), nsims(), nterms()


Number of Iterations

Description

Gets the number of iterations (in a chain) of an MCMC object.

Usage

## S3 method for class 'mcmc.list'
niters(x, ...)

Arguments

x

An object.

...

Other arguments passed to methods.

Value

An integer scalar of the number of iterations.

See Also

Other MCMC dimensions: nchains(), npars(), nsams(), nsims(), nterms()


Number of Iterations

Description

Gets the number of iterations (in a chain) of an MCMC object.

Usage

## S3 method for class 'nlist'
niters(x, ...)

Arguments

x

An object.

...

Other arguments passed to methods.

Details

Always 1.

Value

An integer scalar of the number of iterations.

See Also

Other MCMC dimensions: nchains(), npars(), nsams(), nsims(), nterms()

Examples

niters(nlist(x = 1:2))

Number of Iterations

Description

Gets the number of iterations (in a chain) of an MCMC object.

Usage

## S3 method for class 'nlists'
niters(x, ...)

Arguments

x

An object.

...

Other arguments passed to methods.

Value

An integer scalar of the number of iterations.

See Also

Other MCMC dimensions: nchains(), npars(), nsams(), nsims(), nterms()

Examples

niters(nlists(nlist(x = c(2, 9)), nlist(x = c(1, 7))))

Create nlist Object

Description

Creates a nlist_object() from one of more uniquely named numeric arguments.

Usage

nlist(...)

Arguments

...

Uniquely named numeric objects.

Details

An nlist object is an S3 class list of uniquely named numeric elements.

nlist objects are the raw data inputs for analytic engines such as JAGS, STAN and TMB.

Value

An nlist object.

See Also

nlists()

Examples

nlist()
nlist(x = 1)
nlist(y = 1:4, zz = matrix(1:9, 3))

Create nlists Object

Description

Creates an nlists_object() from one of more nlist_object()s.

Usage

nlists(...)

Arguments

...

nlist objects.

Details

An nlists object is a S3 class list of nlist_object() elements with the same names, dimensionalities and typeofs.

nlists objects are useful for storing individual realizations of a simulated data set.

Value

An nlists object.

See Also

nlist()

Examples

nlists()
nlists(nlist())
nlists(nlist(x = 1))
nlists(nlist(x = 1), nlist(x = -3))

Number of Parameter Dimensions

Description

Gets the number of the dimensions of each parameter of an object.

The default methods returns the length of each element of pdims() as an integer vector.

Usage

## S3 method for class 'mcmc.list'
npdims(x, ...)

Arguments

x

An object.

...

Other arguments passed to methods.

Value

A named integer vector of the number of dimensions of each parameter.

See Also

Other dimensions: dims(), ndims(), pdims()


Number of Parameter Dimensions

Description

Gets the number of the dimensions of each parameter of an object.

The default methods returns the length of each element of pdims() as an integer vector.

Usage

## S3 method for class 'nlist'
npdims(x, ...)

Arguments

x

An object.

...

Other arguments passed to methods.

Value

A named integer vector of the number of dimensions of each parameter.

See Also

Other dimensions: dims(), ndims(), pdims()

Examples

npdims(nlist(x = 1:3))
npdims(nlist(y = 3, zz = matrix(2:5, 2)))

Number of Parameter Dimensions

Description

Gets the number of the dimensions of each parameter of an object.

The default methods returns the length of each element of pdims() as an integer vector.

Usage

## S3 method for class 'nlists'
npdims(x, ...)

Arguments

x

An object.

...

Other arguments passed to methods.

Value

A named integer vector of the number of dimensions of each parameter.

See Also

Other dimensions: dims(), ndims(), pdims()

Examples

npdims(nlists(nlist(x = 1:3)))
npdims(nlists(
  nlist(y = 3, zz = matrix(2:5, 2)),
  nlist(y = 5, zz = matrix(1:4, 2))
))

Number of Simulations

Description

Gets the number of simulations (iterations * chains) of an MCMC object.

The default methods returns the product of nchains() and niters().

Usage

## S3 method for class 'nlist'
nsims(x, ...)

Arguments

x

An object.

...

Other arguments passed to methods.

Details

Always 1L.

Value

An integer scalar of the number of simulations.

See Also

Other MCMC dimensions: nchains(), niters(), npars(), nsams(), nterms()

Examples

nsims(nlist(x = 1:2))

Number of Simulations

Description

Gets the number of simulations (iterations * chains) of an MCMC object.

The default methods returns the product of nchains() and niters().

Usage

## S3 method for class 'nlists'
nsims(x, ...)

Arguments

x

An object.

...

Other arguments passed to methods.

Value

An integer scalar of the number of simulations.

See Also

Other MCMC dimensions: nchains(), niters(), npars(), nsams(), nterms()

Examples

nsims(nlists(nlist(x = c(2, 9)), nlist(x = c(1, 7))))
nsims(split_chains(nlists(nlist(x = c(2, 9)), nlist(x = c(1, 7)))))

Number of Terms

Description

Gets the number of terms of an MCMC object.

Usage

## S3 method for class 'mcmc'
nterms(x, ...)

Arguments

x

An object.

...

Other arguments passed to methods.

Value

A integer scalar of the number of terms.

See Also

Other MCMC dimensions: nchains(), niters(), npars(), nsams(), nsims()


Number of Terms

Description

Gets the number of terms of an MCMC object.

Usage

## S3 method for class 'mcmc.list'
nterms(x, ...)

Arguments

x

An object.

...

Other arguments passed to methods.

Value

A integer scalar of the number of terms.

See Also

Other MCMC dimensions: nchains(), niters(), npars(), nsams(), nsims()


Number of Terms

Description

Gets the number of terms of an MCMC object.

Usage

## S3 method for class 'nlist'
nterms(x, ...)

Arguments

x

An object.

...

Other arguments passed to methods.

Value

A integer scalar of the number of terms.

See Also

Other MCMC dimensions: nchains(), niters(), npars(), nsams(), nsims()

Examples

nterms(nlist(x = 2))
nterms(nlist(x = NA_real_))
nterms(nlist(x = 3, zz = matrix(2:5, 2)))

Number of Terms

Description

Gets the number of terms of an MCMC object.

Usage

## S3 method for class 'nlists'
nterms(x, ...)

Arguments

x

An object.

...

Other arguments passed to methods.

Value

A integer scalar of the number of terms.

See Also

Other MCMC dimensions: nchains(), niters(), npars(), nsams(), nsims()

Examples

nterms(nlists(nlist(x = 1:3)))
nterms(nlists(
  nlist(y = 3, zz = matrix(2:5, 2)),
  nlist(y = 5, zz = matrix(1:4, 2))
))

Parameter Names

Description

Gets the parameter names.

Usage

## S3 method for class 'mcmc'
pars(x, scalar = NULL, terms = FALSE, ...)

Arguments

x

An object.

scalar

A logical scalar specifying whether to include all parameters (NULL), only scalars (TRUE) or all parameters except scalars (FALSE).

terms

A flag specifying whether to return the parameter name for each term element.

...

Other arguments passed to methods.

Value

A character vector of the names of the parameters.

See Also

Other parameters: npars(), set_pars()


Parameter Names

Description

Gets the parameter names.

Usage

## S3 method for class 'mcmc.list'
pars(x, scalar = NULL, terms = FALSE, ...)

Arguments

x

An object.

scalar

A logical scalar specifying whether to include all parameters (NULL), only scalars (TRUE) or all parameters except scalars (FALSE).

terms

A flag specifying whether to return the parameter name for each term element.

...

Other arguments passed to methods.

Value

A character vector of the names of the parameters.

See Also

Other parameters: npars(), set_pars()


Parameter Names

Description

Gets the parameter names.

Usage

## S3 method for class 'nlist'
pars(x, scalar = NULL, terms = FALSE, ...)

Arguments

x

An object.

scalar

A logical scalar specifying whether to include all parameters (NULL), only scalars (TRUE) or all parameters except scalars (FALSE).

terms

A flag specifying whether to return the parameter name for each term element.

...

Other arguments passed to methods.

Value

A character vector of the names of the parameters.

See Also

Other parameters: npars(), set_pars()

Examples

pars(nlist(zz = 1, y = 3:6))

Parameter Names

Description

Gets the parameter names.

Usage

## S3 method for class 'nlists'
pars(x, scalar = NULL, terms = FALSE, ...)

Arguments

x

An object.

scalar

A logical scalar specifying whether to include all parameters (NULL), only scalars (TRUE) or all parameters except scalars (FALSE).

terms

A flag specifying whether to return the parameter name for each term element.

...

Other arguments passed to methods.

Value

A character vector of the names of the parameters.

See Also

Other parameters: npars(), set_pars()

Examples

pars(nlists(nlist(zz = 1, y = 3:6), nlist(zz = 4, y = 13:16)))

Parameter Dimensions

Description

Gets the dimensions of each parameter of an object.

Usage

## S3 method for class 'mcmc'
pdims(x, ...)

Arguments

x

An object.

...

Other arguments passed to methods.

Value

A named list of integer vectors of the dimensions of each parameter.

See Also

Other dimensions: dims(), ndims(), npdims()


Parameter Dimensions

Description

Gets the dimensions of each parameter of an object.

Usage

## S3 method for class 'mcmc.list'
pdims(x, ...)

Arguments

x

An object.

...

Other arguments passed to methods.

Value

A named list of integer vectors of the dimensions of each parameter.

See Also

Other dimensions: dims(), ndims(), npdims()


Parameter Dimensions

Description

Gets the dimensions of each parameter of an object.

Usage

## S3 method for class 'nlist'
pdims(x, ...)

Arguments

x

An object.

...

Other arguments passed to methods.

Value

A named list of integer vectors of the dimensions of each parameter.

See Also

Other dimensions: dims(), ndims(), npdims()

Examples

pdims(nlist(x = 1:3))
pdims(nlist(y = 3, zz = matrix(2:5, 2)))

Parameter Dimensions

Description

Gets the dimensions of each parameter of an object.

Usage

## S3 method for class 'nlists'
pdims(x, ...)

Arguments

x

An object.

...

Other arguments passed to methods.

Value

A named list of integer vectors of the dimensions of each parameter.

See Also

Other dimensions: dims(), ndims(), npdims()

Examples

pdims(nlists(nlist(x = 1:3)))
pdims(nlists(
  nlist(y = 3, zz = matrix(2:5, 2)),
  nlist(y = 5, zz = matrix(1:4, 2))
))

Relists an unlist nlist Object

Description

Relists an nlist object that has been unlisted to a named numeric vector. Ensures absent terms are included and preserves integer class.

Usage

relist_nlist(flesh, skeleton)

Arguments

flesh

An atomic vector

skeleton

An nlist object.

Value

A numeric vector of the values in x.

See Also

as_nlist.numeric() and unlist_nlist()

Examples

relist_nlist(c(`a[2]` = 5), nlist(a = 1:3))

Set Parameters

Description

Sets an object's parameter names.

The assignment version ⁠pars<-()⁠ forwards to set_pars().

Usage

## S3 method for class 'mcmc'
set_pars(x, value, ...)

Arguments

x

An object.

value

A character vector of the new parameter names.

...

Other arguments passed to methods.

Details

value must be a unique character vector of the same length as the object's parameters.

Value

The modified object.

See Also

Other parameters: npars(), pars()


Set Parameters

Description

Sets an object's parameter names.

The assignment version ⁠pars<-()⁠ forwards to set_pars().

Usage

## S3 method for class 'mcmc.list'
set_pars(x, value, ...)

Arguments

x

An object.

value

A character vector of the new parameter names.

...

Other arguments passed to methods.

Details

value must be a unique character vector of the same length as the object's parameters.

Value

The modified object.

See Also

Other parameters: npars(), pars()


Set Parameter Names

Description

Sets an object's parameter names.

The assignment version ⁠pars<-()⁠ forwards to set_pars().

Usage

## S3 method for class 'nlist'
set_pars(x, value, ...)

Arguments

x

An object.

value

A character vector of the new parameter names.

...

Other arguments passed to methods.

Details

value must be a unique character vector of the same length as the object's parameters.

Value

The modified object.

See Also

Other parameters: npars(), pars()

Examples

nlist <-  nlist(x = 1, y = 3:4)
pars(nlist) <- c("a", "b")
nlist
set_pars(nlist, c("z", "c1"))

Set Parameter Names

Description

Sets an object's parameter names.

The assignment version ⁠pars<-()⁠ forwards to set_pars().

Usage

## S3 method for class 'nlists'
set_pars(x, value, ...)

Arguments

x

An object.

value

A character vector of the new parameter names.

...

Other arguments passed to methods.

Details

value must be a unique character vector of the same length as the object's parameters.

Value

The modified object.

See Also

Other parameters: npars(), pars()

Examples

nlists <- nlists(nlist(x = 2), nlist(x = 3))
pars(nlists) <- "a"
nlists
set_pars(nlists, "zz")

Split Chains

Description

Splits each of an MCMC object's chains in half to double the number of chains and halve the number of iterations.

Usage

## S3 method for class 'nlists'
split_chains(x, ...)

Arguments

x

An object.

...

Other arguments passed to methods.

Value

The modified object.

See Also

Other MCMC manipulations: bind_chains(), bind_iterations(), collapse_chains(), estimates()

Examples

nlists <- nlists(nlist(x = c(2, 9)), nlist(x = c(1, 7)))
nchains(nlists)
nchains(split_chains(nlists))

Subset mcmc Object

Description

Subsets an mcmc object by its parameters and/or iterations.

Usage

## S3 method for class 'mcmc'
subset(x, iters = NULL, pars = NULL, iterations = NULL, parameters = NULL, ...)

Arguments

x

An mcmc object.

iters

An integer vector of iterations.

pars

A character vector of parameter names.

iterations

An integer vector (or NULL) of the iterations to subset by.

parameters

A character vector (or NULL) of the parameters to subset by.

...

Unused.

Details

Future versions should allow it to be reordered by its parameters.

Value

An mcmc object.

Examples

mcmc <- as_mcmc(nlist(beta = 1:2, theta = 1))
subset(mcmc, pars = "beta")
subset(mcmc, iters = c(1L,1L))

Subset mcmc.list Object

Description

Subsets an mcmc.list object by its chains, parameters and/or iterations.

Usage

## S3 method for class 'mcmc.list'
subset(
  x,
  chains = NULL,
  iters = NULL,
  pars = NULL,
  iterations = NULL,
  parameters = NULL,
  ...
)

Arguments

x

An mcmc.list object.

chains

An integer vector of chains.

iters

An integer vector of iterations.

pars

A character vector of parameter names.

iterations

An integer vector (or NULL) of the iterations to subset by.

parameters

A character vector (or NULL) of the parameters to subset by.

...

Unused.

Details

Future versions should allow it to be reordered by its parameters.

Value

An mcmc.list object.

Examples

mcmc.list <- as_mcmc_list(nlists(nlist(beta = 1:2, theta = 1), 
                                 nlist(beta = 3:4, theta = -1)))
subset(mcmc.list, pars = "beta")
subset(mcmc.list, iters = c(1L,1L))

Subset nlist Object

Description

Subsets an nlist object by its parameters.

Usage

## S3 method for class 'nlist'
subset(x, pars = NULL, ...)

Arguments

x

An nlist object.

pars

A character vector of parameter names.

...

Unused.

Details

It can also be used to reorder the parameters.

Value

An nlist object.

Examples

nlist <- nlist(a = 1, y = 3, x = 1:4)
subset(nlist)
subset(nlist, "a")
subset(nlist, c("x", "a"))

Subset nlists Object

Description

Subsets an nlists object by its parameters, chains and iterations.

Usage

## S3 method for class 'nlists'
subset(x, chains = NULL, iters = NULL, pars = NULL, ...)

Arguments

x

An nlists object.

chains

An integer vector of chains.

iters

An integer vector of iterations.

pars

A character vector of parameter names.

...

Unused.

Details

It can also be used to reorder the parameters as well as duplicate chains and iterations.

Value

An nlists object.

Examples

nlists <- nlists(
  nlist(a = 1, y = 3, x = 1:4),
  nlist(a = 2, y = 4, x = 4:1),
  nlist(a = 3, y = 6, x = 5:2)
)
subset(nlists)
subset(nlists, pars = "a")
subset(nlists, pars = c("x", "a"))
subset(nlists, iters = 1L)
subset(nlists, iters = c(2L, 2L))

Thin MCMC Object

Description

Thins an MCMC object's iterations.

Usage

## Default S3 method:
thin(x, nthin = 1L, ...)

Arguments

x

An object.

nthin

A positive integer of the thinning rate.

...

Unused.

Value

The thinned MCMC object.

Examples

thin(nlists(nlist(x = 1), nlist(x = 2), nlist(x = 3), nlist(x = 4)), nthin = 2)

Turn an object into a tidy tibble

Description

Turn an object into a tidy tibble

Usage

## S3 method for class 'mcmc'
tidy(x, simplify = FALSE, ...)

Arguments

x

An object.

simplify

A flag specifying whether to drop sd and zscore columns.

...

Unused.

Value

A tibble::tibble() with information about model components.

Methods

No methods found in currently loaded packages.


Turn an object into a tidy tibble

Description

Turn an object into a tidy tibble

Usage

## S3 method for class 'mcmc.list'
tidy(x, simplify = FALSE, ...)

Arguments

x

An object.

simplify

A flag specifying whether to drop sd and zscore columns.

...

Unused.

Value

A tibble::tibble() with information about model components.

Methods

No methods found in currently loaded packages.


Turn an object into a tidy tibble

Description

Turn an object into a tidy tibble

Usage

## S3 method for class 'nlists'
tidy(x, simplify = FALSE, ...)

Arguments

x

An object.

simplify

A flag specifying whether to drop sd and zscore columns.

...

Unused.

Value

A tibble::tibble() with information about model components.

Methods

No methods found in currently loaded packages.

Examples

tidy(nlists(
  nlist(x = 1, y = 4:6),
  nlist(x = 3, y = 7:9)
), simplify = TRUE)

Flatten nlist Object

Description

Simplifies an nlist object to an named numeric vector where the names are the terms.

Usage

unlist_nlist(x)

Arguments

x

An nlist object.

Value

A named numeric vector of the values in x.

See Also

as_nlist.numeric() and relist_nlist()

Examples

unlist_nlist(nlist(y = 2, x = matrix(4:7, ncol = 2)))

Flatten nlist Object

Description

Flatten nlist Object

Usage

## S3 method for class 'nlist'
unlist(x, recursive = TRUE, use.names = TRUE)

Arguments

x

An nlist object.

recursive

Ignored.

use.names

A flag specifying whether to preserve names.

Value

A named numeric vector of the values in x.

See Also

unlist_nlist()

Examples

unlist(nlist(y = 2, x = matrix(4:7, ncol = 2)))

Validate nlist Object or nlists Object

Description

Validate nlist Object or nlists Object

Usage

vld_nlist(x)

vld_nlists(x)

Arguments

x

The object to check.

Value

A flag indicating whether the object was validated.

Functions

  • vld_nlists(): Validate nlists Object

Examples

# vld_nlist
vld_nlist(nlist(x = 1))
try(vld_nlist(list(x = 1)))

# vld_nlists
vld_nlists(nlists(nlist(x = 1)))
vld_nlists(1)