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-12-01 07:42:35 UTC |
Source: | https://github.com/poissonconsulting/nlist |
Aggregates an nlist_object()
into a named list of numeric scalars.
## S3 method for class 'nlist' aggregate(x, fun = mean, ...)
## S3 method for class 'nlist' aggregate(x, fun = mean, ...)
x |
An nlist object. |
fun |
A function that given a numeric vector returns a numeric scalar. |
... |
Additional arguments passed to fun. |
An named list of numeric scalars
Other aggregate:
aggregate.nlists()
aggregate(nlist(x = 1:9)) aggregate(nlist(y = 3:5, zz = matrix(1:9, 3)), fun = function(x) x[1])
aggregate(nlist(x = 1:9)) aggregate(nlist(y = 3:5, zz = matrix(1:9, 3)), fun = function(x) x[1])
Aggregates an nlists_object()
into a nlist_object()
or by_chain = TRUE an nlists_object()
with nchains
nlist_object()
s.
## S3 method for class 'nlists' aggregate(x, fun = mean, ..., by_chain = FALSE)
## S3 method for class 'nlists' aggregate(x, fun = mean, ..., by_chain = FALSE)
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. |
An nlist object if by_chain = FALSE
otherwise an nlists object.
Other aggregate:
aggregate.nlist()
aggregate(nlists(nlist(x = 1:3), nlist(x = 2:4)))
aggregate(nlists(nlist(x = 1:3), nlist(x = 2:4)))
Coerce an R object to an mcmc object.
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, ...)
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, ...)
x |
An object. |
... |
Unused. |
An mcmc object.
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.
Other mcmc:
as_mcmc_list()
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)) ))
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 an R object to an mcmc.list object.
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, ...)
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, ...)
x |
An object. |
... |
Unused. |
An mcmc.list object.
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.
Other mcmc:
as_mcmc()
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)) ))
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 an R object to an nlist_object()
.
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, ...)
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, ...)
x |
An object. |
... |
Unused. |
An nlist object.
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
Other coerce:
as_nlists()
as_nlist(list(x = 1:4)) as_nlist(c(`a[2]` = 3, `a[1]` = 2))
as_nlist(list(x = 1:4)) as_nlist(c(`a[2]` = 3, `a[1]` = 2))
Coerce an R object to an nlists_object()
.
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, ...)
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, ...)
x |
An object. |
... |
Unused. |
An nlists object.
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
Other coerce:
as_nlist()
as_nlists(list(nlist(x = c(1, 5)), nlist(x = c(2, 3)), nlist(x = c(3, 2))))
as_nlists(list(nlist(x = c(1, 5)), nlist(x = c(2, 3)), nlist(x = c(3, 2))))
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.
as_term_frame(x, ...)
as_term_frame(x, ...)
x |
An object. |
... |
Unused. |
An term_frame object.
Other coerce term:
as_term.mcmc()
,
as_term.nlist()
,
as_term.nlists()
,
as_term_frame.nlist()
,
as_term_frame.nlists()
Coerces an nlist object to a data.frame with an term column and a value column.
## S3 method for class 'nlist' as_term_frame(x, ...)
## S3 method for class 'nlist' as_term_frame(x, ...)
x |
An nlist object. |
... |
Unused. |
A data.frame.
Other coerce term:
as_term.mcmc()
,
as_term.nlist()
,
as_term.nlists()
,
as_term_frame()
,
as_term_frame.nlists()
as_term_frame(nlist(x = 1, y = 4:6))
as_term_frame(nlist(x = 1, y = 4:6))
Coerces an nlists object to a data.frame with a term, sample and value column.
## S3 method for class 'nlists' as_term_frame(x, ...)
## S3 method for class 'nlists' as_term_frame(x, ...)
x |
An nlists object. |
... |
Unused. |
A data.frame.
Other coerce term:
as_term.mcmc()
,
as_term.nlist()
,
as_term.nlists()
,
as_term_frame()
,
as_term_frame.nlist()
as_term_frame(nlists( nlist(x = 1, y = 4:6), nlist(x = 3, y = 1:3) ))
as_term_frame(nlists( nlist(x = 1, y = 4:6), nlist(x = 3, y = 1:3) ))
Coerce to a Term Vector
## S3 method for class 'mcmc' as_term(x, ...)
## S3 method for class 'mcmc' as_term(x, ...)
x |
An object. |
... |
Unused. |
Other coerce term:
as_term.nlist()
,
as_term.nlists()
,
as_term_frame()
,
as_term_frame.nlist()
,
as_term_frame.nlists()
as_term(as_mcmc(nlist(x = matrix(1:4, ncol = 2))))
as_term(as_mcmc(nlist(x = matrix(1:4, ncol = 2))))
Coerce to a Term Vector
## S3 method for class 'nlist' as_term(x, ...)
## S3 method for class 'nlist' as_term(x, ...)
x |
An object. |
... |
Unused. |
Other coerce term:
as_term.mcmc()
,
as_term.nlists()
,
as_term_frame()
,
as_term_frame.nlist()
,
as_term_frame.nlists()
as_term(nlist(x = matrix(1:4, ncol = 2)))
as_term(nlist(x = matrix(1:4, ncol = 2)))
Coerce to a Term Vector
## S3 method for class 'nlists' as_term(x, ...)
## S3 method for class 'nlists' as_term(x, ...)
x |
An object. |
... |
Unused. |
Other coerce term:
as_term.mcmc()
,
as_term.nlist()
,
as_term_frame()
,
as_term_frame.nlist()
,
as_term_frame.nlists()
as_term(nlists(nlist(x = matrix(1:4, ncol = 2))))
as_term(nlists(nlist(x = matrix(1:4, ncol = 2))))
Combines two MCMC objects (with the same parameters and chains) by iterations.
## S3 method for class 'mcmc' bind_iterations(x, x2, ...)
## S3 method for class 'mcmc' bind_iterations(x, x2, ...)
x |
An object. |
x2 |
A second object. |
... |
Other arguments passed to methods. |
The combined object.
Other MCMC manipulations:
bind_chains()
,
collapse_chains()
,
estimates()
,
split_chains()
bind_iterations(as_mcmc(nlist(x = 1)), as_mcmc(nlist(x = 3)))
bind_iterations(as_mcmc(nlist(x = 1)), as_mcmc(nlist(x = 3)))
Combines two MCMC objects (with the same parameters and chains) by iterations.
## S3 method for class 'mcmc.list' bind_iterations(x, x2, ...)
## S3 method for class 'mcmc.list' bind_iterations(x, x2, ...)
x |
An object. |
x2 |
A second object. |
... |
Other arguments passed to methods. |
The combined object.
Other MCMC manipulations:
bind_chains()
,
collapse_chains()
,
estimates()
,
split_chains()
bind_iterations(as_mcmc_list(nlist(x = 1)), as_mcmc_list(nlist(x = 3)))
bind_iterations(as_mcmc_list(nlist(x = 1)), as_mcmc_list(nlist(x = 3)))
chk_nlist
checks if an nlist-object()
.
chk_nlist(x, x_name = NULL) chk_nlists(x, x_name = NULL)
chk_nlist(x, x_name = NULL) chk_nlists(x, x_name = NULL)
x |
The object to check. |
x_name |
A string of the name of object x or NULL. |
NULL
, invisibly. Called for the side effect of throwing an error
if the condition is not met.
chk_nlists()
: Check nlists Object
chk_nlists
checks if an nlists-object()
.
# chk_nlist chk_nlist(nlist(x = 1)) try(chk_nlist(list(x = 1))) # chk_nlists chk_nlists(nlists(nlist(x = 1)))
# chk_nlist chk_nlist(nlist(x = 1)) try(chk_nlist(list(x = 1))) # chk_nlists chk_nlists(nlists(nlist(x = 1)))
Collapses an MCMC object's chains into a single chain.
## S3 method for class 'mcmc' collapse_chains(x, ...)
## S3 method for class 'mcmc' collapse_chains(x, ...)
x |
An object. |
... |
Other arguments passed to methods. |
As mcmc objects can only have 1 chain the object is unchanged.
The modified object with one chain.
Other collapse:
collapse_chains.nlist()
,
collapse_chains.nlists()
collapse_chains(as_mcmc(nlist(x = 2)))
collapse_chains(as_mcmc(nlist(x = 2)))
Collapses an MCMC object's chains into a single chain.
## S3 method for class 'mcmc.list' collapse_chains(x, ...)
## S3 method for class 'mcmc.list' collapse_chains(x, ...)
x |
An object. |
... |
Other arguments passed to methods. |
The modified object with one chain.
Other MCMC manipulations:
bind_chains()
,
bind_iterations()
,
estimates()
,
split_chains()
Collapses an MCMC object's chains into a single chain.
## S3 method for class 'nlist' collapse_chains(x, ...)
## S3 method for class 'nlist' collapse_chains(x, ...)
x |
An object. |
... |
Other arguments passed to methods. |
As nlist objects can only have 1 chain the object is unchanged.
The modified object with one chain.
Other collapse:
collapse_chains.mcmc()
,
collapse_chains.nlists()
collapse_chains(nlist(x = 2))
collapse_chains(nlist(x = 2))
Collapses an MCMC object's chains into a single chain.
## S3 method for class 'nlists' collapse_chains(x, ...)
## S3 method for class 'nlists' collapse_chains(x, ...)
x |
An object. |
... |
Other arguments passed to methods. |
The modified object with one chain.
Other collapse:
collapse_chains.mcmc()
,
collapse_chains.nlist()
collapse_chains(nlist(x = 2))
collapse_chains(nlist(x = 2))
Adds any absent elements to an mcmc object.
## S3 method for class 'mcmc' complete_terms(x, silent = FALSE, ...)
## S3 method for class 'mcmc' complete_terms(x, silent = FALSE, ...)
x |
An mcmc object. |
silent |
A flag specifying whether to suppress warning messages. |
... |
Unused. |
The terms are repaired before being completed. Missing or invalid or inconsistent terms are dropped with a warning.
The repaired and complete mcmc object.
mcmc <- as_mcmc(nlist(beta = matrix(1:4, nrow = 2))) mcmc <- mcmc[, -4, drop = FALSE] complete_terms(mcmc)
mcmc <- as_mcmc(nlist(beta = matrix(1:4, nrow = 2))) mcmc <- mcmc[, -4, drop = FALSE] complete_terms(mcmc)
Calculates the estimates for an MCMC object.
## S3 method for class 'nlist' estimates(x, fun = median, ...)
## S3 method for class 'nlist' estimates(x, fun = median, ...)
x |
An object. |
fun |
A function that given a numeric vector returns a numeric scalar. |
... |
Additional arguments passed to fun. |
A list of uniquely named numeric objects.
Other MCMC manipulations:
bind_chains()
,
bind_iterations()
,
collapse_chains()
,
split_chains()
estimates(nlist(x = 1:9)) estimates(nlist(y = 3:5, zz = matrix(1:9, 3)))
estimates(nlist(x = 1:9)) estimates(nlist(y = 3:5, zz = matrix(1:9, 3)))
Calculates the estimates for an MCMC object.
## S3 method for class 'nlists' estimates(x, fun = median, ...)
## S3 method for class 'nlists' estimates(x, fun = median, ...)
x |
An object. |
fun |
A function that given a numeric vector returns a numeric scalar. |
... |
Additional arguments passed to fun. |
A list of uniquely named numeric objects.
Other MCMC manipulations:
bind_chains()
,
bind_iterations()
,
collapse_chains()
,
split_chains()
estimates(nlists(nlist(x = 1:3), nlist(x = 2:4)), fun = mean)
estimates(nlists(nlist(x = 1:3), nlist(x = 2:4)), fun = mean)
Fills all of an object's (missing and non-missing) values while preserving the object's dimensionality and class.
## S3 method for class 'nlist' fill_all(x, value = 0L, nas = TRUE, ...)
## S3 method for class 'nlist' fill_all(x, value = 0L, nas = TRUE, ...)
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. |
It should only be defined for objects with values of consistent class ie not standard data.frames.
The modified object.
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
Other fill:
fill_na()
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(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)
Fills all of an object's (missing and non-missing) values while preserving the object's dimensionality and class.
## S3 method for class 'nlists' fill_all(x, value = 0L, nas = TRUE, ...)
## S3 method for class 'nlists' fill_all(x, value = 0L, nas = TRUE, ...)
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. |
It should only be defined for objects with values of consistent class ie not standard data.frames.
The modified object.
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
Other fill:
fill_na()
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_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)
Fills all of an object's missing values while preserving the object's dimensionality and class.
## S3 method for class 'nlist' fill_na(x, value = 0L, ...)
## S3 method for class 'nlist' fill_na(x, value = 0L, ...)
x |
An object. |
value |
A scalar of the value to replace values with. |
... |
Other arguments passed to methods. |
It should only be defined for objects with values of consistent class ie not standard data.frames.
The modified object.
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
Other fill:
fill_all()
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_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))))
Fills all of an object's missing values while preserving the object's dimensionality and class.
## S3 method for class 'nlists' fill_na(x, value = 0L, ...)
## S3 method for class 'nlists' fill_na(x, value = 0L, ...)
x |
An object. |
value |
A scalar of the value to replace values with. |
... |
Other arguments passed to methods. |
It should only be defined for objects with values of consistent class ie not standard data.frames.
The modified object.
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
Other fill:
fill_all()
fill_na(nlist(x = c(2, NA), y = matrix(c(1:3, NA), nrow = 2)))
fill_na(nlist(x = c(2, NA), y = matrix(c(1:3, NA), nrow = 2)))
Ask whether x is a numeric object,
nlist_object()
or nlists_object()
.
is_numeric(x) is_nlist(x) is_nlists(x)
is_numeric(x) is_nlist(x) is_nlists(x)
x |
An object. |
A flag indicating whether x is a numeric object or inherits from S3 class nlist or nlists.
is_nlist()
: Is nlist
is_nlists()
: Is nlists
# 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)))
# 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)))
Gets the number of chains of an MCMC object.
## S3 method for class 'mcmc' nchains(x, ...)
## S3 method for class 'mcmc' nchains(x, ...)
x |
An object. |
... |
Other arguments passed to methods. |
An integer scalar of the number of chains.
Other MCMC dimensions:
niters()
,
npars()
,
nsams()
,
nsims()
,
nterms()
Gets the number of chains of an MCMC object.
## S3 method for class 'mcmc.list' nchains(x, ...)
## S3 method for class 'mcmc.list' nchains(x, ...)
x |
An object. |
... |
Other arguments passed to methods. |
An integer scalar of the number of chains.
Other MCMC dimensions:
niters()
,
npars()
,
nsams()
,
nsims()
,
nterms()
Gets the number of terms of an MCMC object.
## S3 method for class 'nlist' nchains(x, ...)
## S3 method for class 'nlist' nchains(x, ...)
x |
An object. |
... |
Other arguments passed to methods. |
Always 1L.
A integer scalar of the number of terms.
Other MCMC dimensions:
nchains()
,
niters()
,
npars()
,
nsams()
,
nsims()
nchains(nlist(x = 1:2))
nchains(nlist(x = 1:2))
Gets the number of terms of an MCMC object.
## S3 method for class 'nlists' nchains(x, ...)
## S3 method for class 'nlists' nchains(x, ...)
x |
An object. |
... |
Other arguments passed to methods. |
A integer scalar of the number of terms.
Other MCMC dimensions:
nchains()
,
niters()
,
npars()
,
nsams()
,
nsims()
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)))))
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)))))
Gets the number of iterations (in a chain) of an MCMC object.
## S3 method for class 'mcmc' niters(x, ...)
## S3 method for class 'mcmc' niters(x, ...)
x |
An object. |
... |
Other arguments passed to methods. |
An integer scalar of the number of iterations.
Other MCMC dimensions:
nchains()
,
npars()
,
nsams()
,
nsims()
,
nterms()
Gets the number of iterations (in a chain) of an MCMC object.
## S3 method for class 'mcmc.list' niters(x, ...)
## S3 method for class 'mcmc.list' niters(x, ...)
x |
An object. |
... |
Other arguments passed to methods. |
An integer scalar of the number of iterations.
Other MCMC dimensions:
nchains()
,
npars()
,
nsams()
,
nsims()
,
nterms()
Gets the number of iterations (in a chain) of an MCMC object.
## S3 method for class 'nlist' niters(x, ...)
## S3 method for class 'nlist' niters(x, ...)
x |
An object. |
... |
Other arguments passed to methods. |
Always 1.
An integer scalar of the number of iterations.
Other MCMC dimensions:
nchains()
,
npars()
,
nsams()
,
nsims()
,
nterms()
niters(nlist(x = 1:2))
niters(nlist(x = 1:2))
Gets the number of iterations (in a chain) of an MCMC object.
## S3 method for class 'nlists' niters(x, ...)
## S3 method for class 'nlists' niters(x, ...)
x |
An object. |
... |
Other arguments passed to methods. |
An integer scalar of the number of iterations.
Other MCMC dimensions:
nchains()
,
npars()
,
nsams()
,
nsims()
,
nterms()
niters(nlists(nlist(x = c(2, 9)), nlist(x = c(1, 7))))
niters(nlists(nlist(x = c(2, 9)), nlist(x = c(1, 7))))
Creates a nlist_object()
from one of more uniquely named numeric arguments.
nlist(...)
nlist(...)
... |
Uniquely named numeric objects. |
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.
An nlist object.
nlist() nlist(x = 1) nlist(y = 1:4, zz = matrix(1:9, 3))
nlist() nlist(x = 1) nlist(y = 1:4, zz = matrix(1:9, 3))
Creates an nlists_object()
from one of more nlist_object()
s.
nlists(...)
nlists(...)
... |
nlist objects. |
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.
An nlists object.
nlists() nlists(nlist()) nlists(nlist(x = 1)) nlists(nlist(x = 1), nlist(x = -3))
nlists() nlists(nlist()) nlists(nlist(x = 1)) nlists(nlist(x = 1), nlist(x = -3))
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.
## S3 method for class 'mcmc.list' npdims(x, ...)
## S3 method for class 'mcmc.list' npdims(x, ...)
x |
An object. |
... |
Other arguments passed to methods. |
A named integer vector of the number of dimensions of each parameter.
Other dimensions:
dims()
,
ndims()
,
pdims()
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.
## S3 method for class 'nlist' npdims(x, ...)
## S3 method for class 'nlist' npdims(x, ...)
x |
An object. |
... |
Other arguments passed to methods. |
A named integer vector of the number of dimensions of each parameter.
Other dimensions:
dims()
,
ndims()
,
pdims()
npdims(nlist(x = 1:3)) npdims(nlist(y = 3, zz = matrix(2:5, 2)))
npdims(nlist(x = 1:3)) npdims(nlist(y = 3, zz = matrix(2:5, 2)))
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.
## S3 method for class 'nlists' npdims(x, ...)
## S3 method for class 'nlists' npdims(x, ...)
x |
An object. |
... |
Other arguments passed to methods. |
A named integer vector of the number of dimensions of each parameter.
Other dimensions:
dims()
,
ndims()
,
pdims()
npdims(nlists(nlist(x = 1:3))) npdims(nlists( nlist(y = 3, zz = matrix(2:5, 2)), nlist(y = 5, zz = matrix(1:4, 2)) ))
npdims(nlists(nlist(x = 1:3))) npdims(nlists( nlist(y = 3, zz = matrix(2:5, 2)), nlist(y = 5, zz = matrix(1:4, 2)) ))
Gets the number of simulations (iterations * chains) of an MCMC object.
The default methods returns the product of nchains()
and niters()
.
## S3 method for class 'nlist' nsims(x, ...)
## S3 method for class 'nlist' nsims(x, ...)
x |
An object. |
... |
Other arguments passed to methods. |
Always 1L.
An integer scalar of the number of simulations.
Other MCMC dimensions:
nchains()
,
niters()
,
npars()
,
nsams()
,
nterms()
nsims(nlist(x = 1:2))
nsims(nlist(x = 1:2))
Gets the number of simulations (iterations * chains) of an MCMC object.
The default methods returns the product of nchains()
and niters()
.
## S3 method for class 'nlists' nsims(x, ...)
## S3 method for class 'nlists' nsims(x, ...)
x |
An object. |
... |
Other arguments passed to methods. |
An integer scalar of the number of simulations.
Other MCMC dimensions:
nchains()
,
niters()
,
npars()
,
nsams()
,
nterms()
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)))))
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)))))
Gets the number of terms of an MCMC object.
## S3 method for class 'mcmc' nterms(x, ...)
## S3 method for class 'mcmc' nterms(x, ...)
x |
An object. |
... |
Other arguments passed to methods. |
A integer scalar of the number of terms.
Other MCMC dimensions:
nchains()
,
niters()
,
npars()
,
nsams()
,
nsims()
Gets the number of terms of an MCMC object.
## S3 method for class 'mcmc.list' nterms(x, ...)
## S3 method for class 'mcmc.list' nterms(x, ...)
x |
An object. |
... |
Other arguments passed to methods. |
A integer scalar of the number of terms.
Other MCMC dimensions:
nchains()
,
niters()
,
npars()
,
nsams()
,
nsims()
Gets the number of terms of an MCMC object.
## S3 method for class 'nlist' nterms(x, ...)
## S3 method for class 'nlist' nterms(x, ...)
x |
An object. |
... |
Other arguments passed to methods. |
A integer scalar of the number of terms.
Other MCMC dimensions:
nchains()
,
niters()
,
npars()
,
nsams()
,
nsims()
nterms(nlist(x = 2)) nterms(nlist(x = NA_real_)) nterms(nlist(x = 3, zz = matrix(2:5, 2)))
nterms(nlist(x = 2)) nterms(nlist(x = NA_real_)) nterms(nlist(x = 3, zz = matrix(2:5, 2)))
Gets the number of terms of an MCMC object.
## S3 method for class 'nlists' nterms(x, ...)
## S3 method for class 'nlists' nterms(x, ...)
x |
An object. |
... |
Other arguments passed to methods. |
A integer scalar of the number of terms.
Other MCMC dimensions:
nchains()
,
niters()
,
npars()
,
nsams()
,
nsims()
nterms(nlists(nlist(x = 1:3))) nterms(nlists( nlist(y = 3, zz = matrix(2:5, 2)), nlist(y = 5, zz = matrix(1:4, 2)) ))
nterms(nlists(nlist(x = 1:3))) nterms(nlists( nlist(y = 3, zz = matrix(2:5, 2)), nlist(y = 5, zz = matrix(1:4, 2)) ))
Gets the parameter names.
## S3 method for class 'mcmc' pars(x, scalar = NULL, terms = FALSE, ...)
## S3 method for class 'mcmc' pars(x, scalar = NULL, terms = FALSE, ...)
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. |
A character vector of the names of the parameters.
Other parameters:
npars()
,
set_pars()
Gets the parameter names.
## S3 method for class 'mcmc.list' pars(x, scalar = NULL, terms = FALSE, ...)
## S3 method for class 'mcmc.list' pars(x, scalar = NULL, terms = FALSE, ...)
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. |
A character vector of the names of the parameters.
Other parameters:
npars()
,
set_pars()
Gets the parameter names.
## S3 method for class 'nlist' pars(x, scalar = NULL, terms = FALSE, ...)
## S3 method for class 'nlist' pars(x, scalar = NULL, terms = FALSE, ...)
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. |
A character vector of the names of the parameters.
Other parameters:
npars()
,
set_pars()
pars(nlist(zz = 1, y = 3:6))
pars(nlist(zz = 1, y = 3:6))
Gets the parameter names.
## S3 method for class 'nlists' pars(x, scalar = NULL, terms = FALSE, ...)
## S3 method for class 'nlists' pars(x, scalar = NULL, terms = FALSE, ...)
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. |
A character vector of the names of the parameters.
Other parameters:
npars()
,
set_pars()
pars(nlists(nlist(zz = 1, y = 3:6), nlist(zz = 4, y = 13:16)))
pars(nlists(nlist(zz = 1, y = 3:6), nlist(zz = 4, y = 13:16)))
Gets the dimensions of each parameter of an object.
## S3 method for class 'mcmc' pdims(x, ...)
## S3 method for class 'mcmc' pdims(x, ...)
x |
An object. |
... |
Other arguments passed to methods. |
A named list of integer vectors of the dimensions of each parameter.
Other dimensions:
dims()
,
ndims()
,
npdims()
Gets the dimensions of each parameter of an object.
## S3 method for class 'mcmc.list' pdims(x, ...)
## S3 method for class 'mcmc.list' pdims(x, ...)
x |
An object. |
... |
Other arguments passed to methods. |
A named list of integer vectors of the dimensions of each parameter.
Other dimensions:
dims()
,
ndims()
,
npdims()
Gets the dimensions of each parameter of an object.
## S3 method for class 'nlist' pdims(x, ...)
## S3 method for class 'nlist' pdims(x, ...)
x |
An object. |
... |
Other arguments passed to methods. |
A named list of integer vectors of the dimensions of each parameter.
Other dimensions:
dims()
,
ndims()
,
npdims()
pdims(nlist(x = 1:3)) pdims(nlist(y = 3, zz = matrix(2:5, 2)))
pdims(nlist(x = 1:3)) pdims(nlist(y = 3, zz = matrix(2:5, 2)))
Gets the dimensions of each parameter of an object.
## S3 method for class 'nlists' pdims(x, ...)
## S3 method for class 'nlists' pdims(x, ...)
x |
An object. |
... |
Other arguments passed to methods. |
A named list of integer vectors of the dimensions of each parameter.
Other dimensions:
dims()
,
ndims()
,
npdims()
pdims(nlists(nlist(x = 1:3))) pdims(nlists( nlist(y = 3, zz = matrix(2:5, 2)), nlist(y = 5, zz = matrix(1:4, 2)) ))
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 nlist object that has been unlisted to a named numeric vector. Ensures absent terms are included and preserves integer class.
relist_nlist(flesh, skeleton)
relist_nlist(flesh, skeleton)
flesh |
An atomic vector |
skeleton |
An nlist object. |
A numeric vector of the values in x.
as_nlist.numeric()
and unlist_nlist()
relist_nlist(c(`a[2]` = 5), nlist(a = 1:3))
relist_nlist(c(`a[2]` = 5), nlist(a = 1:3))
Sets an object's parameter names.
The assignment version pars<-()
forwards to set_pars()
.
## S3 method for class 'mcmc' set_pars(x, value, ...)
## S3 method for class 'mcmc' set_pars(x, value, ...)
x |
An object. |
value |
A character vector of the new parameter names. |
... |
Other arguments passed to methods. |
value
must be a unique character vector of the same length as the
object's parameters.
The modified object.
Other parameters:
npars()
,
pars()
Sets an object's parameter names.
The assignment version pars<-()
forwards to set_pars()
.
## S3 method for class 'mcmc.list' set_pars(x, value, ...)
## S3 method for class 'mcmc.list' set_pars(x, value, ...)
x |
An object. |
value |
A character vector of the new parameter names. |
... |
Other arguments passed to methods. |
value
must be a unique character vector of the same length as the
object's parameters.
The modified object.
Other parameters:
npars()
,
pars()
Sets an object's parameter names.
The assignment version pars<-()
forwards to set_pars()
.
## S3 method for class 'nlist' set_pars(x, value, ...)
## S3 method for class 'nlist' set_pars(x, value, ...)
x |
An object. |
value |
A character vector of the new parameter names. |
... |
Other arguments passed to methods. |
value
must be a unique character vector of the same length as the
object's parameters.
The modified object.
Other parameters:
npars()
,
pars()
nlist <- nlist(x = 1, y = 3:4) pars(nlist) <- c("a", "b") nlist set_pars(nlist, c("z", "c1"))
nlist <- nlist(x = 1, y = 3:4) pars(nlist) <- c("a", "b") nlist set_pars(nlist, c("z", "c1"))
Sets an object's parameter names.
The assignment version pars<-()
forwards to set_pars()
.
## S3 method for class 'nlists' set_pars(x, value, ...)
## S3 method for class 'nlists' set_pars(x, value, ...)
x |
An object. |
value |
A character vector of the new parameter names. |
... |
Other arguments passed to methods. |
value
must be a unique character vector of the same length as the
object's parameters.
The modified object.
Other parameters:
npars()
,
pars()
nlists <- nlists(nlist(x = 2), nlist(x = 3)) pars(nlists) <- "a" nlists set_pars(nlists, "zz")
nlists <- nlists(nlist(x = 2), nlist(x = 3)) pars(nlists) <- "a" nlists set_pars(nlists, "zz")
Splits each of an MCMC object's chains in half to double the number of chains and halve the number of iterations.
## S3 method for class 'nlists' split_chains(x, ...)
## S3 method for class 'nlists' split_chains(x, ...)
x |
An object. |
... |
Other arguments passed to methods. |
The modified object.
Other MCMC manipulations:
bind_chains()
,
bind_iterations()
,
collapse_chains()
,
estimates()
nlists <- nlists(nlist(x = c(2, 9)), nlist(x = c(1, 7))) nchains(nlists) nchains(split_chains(nlists))
nlists <- nlists(nlist(x = c(2, 9)), nlist(x = c(1, 7))) nchains(nlists) nchains(split_chains(nlists))
Subsets an mcmc object by its parameters and/or iterations.
## S3 method for class 'mcmc' subset(x, iters = NULL, pars = NULL, iterations = NULL, parameters = NULL, ...)
## S3 method for class 'mcmc' subset(x, iters = NULL, pars = NULL, iterations = NULL, parameters = NULL, ...)
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. |
Future versions should allow it to be reordered by its parameters.
An mcmc object.
mcmc <- as_mcmc(nlist(beta = 1:2, theta = 1)) subset(mcmc, pars = "beta") subset(mcmc, iters = c(1L,1L))
mcmc <- as_mcmc(nlist(beta = 1:2, theta = 1)) subset(mcmc, pars = "beta") subset(mcmc, iters = c(1L,1L))
Subsets an mcmc.list object by its chains, parameters and/or iterations.
## S3 method for class 'mcmc.list' subset( x, chains = NULL, iters = NULL, pars = NULL, iterations = NULL, parameters = NULL, ... )
## S3 method for class 'mcmc.list' subset( x, chains = NULL, iters = NULL, pars = NULL, iterations = NULL, parameters = NULL, ... )
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. |
Future versions should allow it to be reordered by its parameters.
An mcmc.list object.
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))
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))
Subsets an nlist object by its parameters.
## S3 method for class 'nlist' subset(x, pars = NULL, ...)
## S3 method for class 'nlist' subset(x, pars = NULL, ...)
x |
An nlist object. |
pars |
A character vector of parameter names. |
... |
Unused. |
It can also be used to reorder the parameters.
An nlist object.
nlist <- nlist(a = 1, y = 3, x = 1:4) subset(nlist) subset(nlist, "a") subset(nlist, c("x", "a"))
nlist <- nlist(a = 1, y = 3, x = 1:4) subset(nlist) subset(nlist, "a") subset(nlist, c("x", "a"))
Subsets an nlists object by its parameters, chains and iterations.
## S3 method for class 'nlists' subset(x, chains = NULL, iters = NULL, pars = NULL, ...)
## S3 method for class 'nlists' subset(x, chains = NULL, iters = NULL, pars = NULL, ...)
x |
An nlists object. |
chains |
An integer vector of chains. |
iters |
An integer vector of iterations. |
pars |
A character vector of parameter names. |
... |
Unused. |
It can also be used to reorder the parameters as well as duplicate chains and iterations.
An nlists object.
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))
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))
Thins an MCMC object's iterations.
## Default S3 method: thin(x, nthin = 1L, ...)
## Default S3 method: thin(x, nthin = 1L, ...)
x |
An object. |
nthin |
A positive integer of the thinning rate. |
... |
Unused. |
The thinned MCMC object.
thin(nlists(nlist(x = 1), nlist(x = 2), nlist(x = 3), nlist(x = 4)), nthin = 2)
thin(nlists(nlist(x = 1), nlist(x = 2), nlist(x = 3), nlist(x = 4)), nthin = 2)
Turn an object into a tidy tibble
## S3 method for class 'mcmc' tidy(x, simplify = FALSE, ...)
## S3 method for class 'mcmc' tidy(x, simplify = FALSE, ...)
x |
An object. |
simplify |
A flag specifying whether to drop sd and zscore columns. |
... |
Unused. |
A tibble::tibble()
with information about model components.
No methods found in currently loaded packages.
Turn an object into a tidy tibble
## S3 method for class 'mcmc.list' tidy(x, simplify = FALSE, ...)
## S3 method for class 'mcmc.list' tidy(x, simplify = FALSE, ...)
x |
An object. |
simplify |
A flag specifying whether to drop sd and zscore columns. |
... |
Unused. |
A tibble::tibble()
with information about model components.
No methods found in currently loaded packages.
Turn an object into a tidy tibble
## S3 method for class 'nlists' tidy(x, simplify = FALSE, ...)
## S3 method for class 'nlists' tidy(x, simplify = FALSE, ...)
x |
An object. |
simplify |
A flag specifying whether to drop sd and zscore columns. |
... |
Unused. |
A tibble::tibble()
with information about model components.
No methods found in currently loaded packages.
tidy(nlists( nlist(x = 1, y = 4:6), nlist(x = 3, y = 7:9) ), simplify = TRUE)
tidy(nlists( nlist(x = 1, y = 4:6), nlist(x = 3, y = 7:9) ), simplify = TRUE)
Simplifies an nlist object to an named numeric vector where the names are the terms.
unlist_nlist(x)
unlist_nlist(x)
x |
An nlist object. |
A named numeric vector of the values in x.
as_nlist.numeric()
and relist_nlist()
unlist_nlist(nlist(y = 2, x = matrix(4:7, ncol = 2)))
unlist_nlist(nlist(y = 2, x = matrix(4:7, ncol = 2)))
Flatten nlist Object
## S3 method for class 'nlist' unlist(x, recursive = TRUE, use.names = TRUE)
## S3 method for class 'nlist' unlist(x, recursive = TRUE, use.names = TRUE)
x |
An nlist object. |
recursive |
Ignored. |
use.names |
A flag specifying whether to preserve names. |
A named numeric vector of the values in x.
unlist(nlist(y = 2, x = matrix(4:7, ncol = 2)))
unlist(nlist(y = 2, x = matrix(4:7, ncol = 2)))
Validate nlist Object or nlists Object
vld_nlist(x) vld_nlists(x)
vld_nlist(x) vld_nlists(x)
x |
The object to check. |
A flag indicating whether the object was validated.
vld_nlists()
: Validate nlists Object
# vld_nlist vld_nlist(nlist(x = 1)) try(vld_nlist(list(x = 1))) # vld_nlists vld_nlists(nlists(nlist(x = 1))) vld_nlists(1)
# vld_nlist vld_nlist(nlist(x = 1)) try(vld_nlist(list(x = 1))) # vld_nlists vld_nlists(nlists(nlist(x = 1))) vld_nlists(1)