Title: | Create, Manipulate and Query Parameter Terms |
---|---|
Description: | Creates, manipulates, queries and repairs vectors of parameter terms. Parameter terms are the labels used to reference values in vectors, matrices and arrays. They represent the names in coefficient tables and the column names in 'mcmc' and 'mcmc.list' objects. |
Authors: | Joe Thorley [aut, cre] , Kirill Müller [aut] , Ayla Pearson [ctb] , Evan Amies-Galonski [ctb] , Poisson Consulting [cph, fnd] |
Maintainer: | Joe Thorley <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.3.5.9000 |
Built: | 2024-11-01 16:19:18 UTC |
Source: | https://github.com/poissonconsulting/term |
Coerces an R object to a term-vector()
.
as_term(x, ...) as.term(x, ...) ## S3 method for class 'character' as_term(x, repair = FALSE, normalize = repair, ...) ## S3 method for class 'numeric' as_term(x, name = "par", ...)
as_term(x, ...) as.term(x, ...) ## S3 method for class 'character' as_term(x, repair = FALSE, normalize = repair, ...) ## S3 method for class 'numeric' as_term(x, name = "par", ...)
x |
The object. |
... |
Unused. |
repair |
A flag specifying whether to repair terms. |
normalize |
A flag specifying whether to normalize terms. |
name |
A string specifying the name of the parameter. |
as_term(character)
: Coerce character vector to term vector
as_term(numeric)
: Coerce numeric object to term vector
term-vector()
and repair_terms()
as_term(matrix(1:4, 2)) as_term(c("parm3[10]", "parm3[2]", "parm[2,2]", "parm[1,1]"))
as_term(matrix(1:4, 2)) as_term(c("parm3[10]", "parm3[2]", "parm[2,2]", "parm[1,1]"))
Coerces an R object to a term_rcrd
.
as_term_rcrd(x, ...) ## S3 method for class 'character' as_term_rcrd(x, repair = FALSE, ...) ## S3 method for class 'numeric' as_term_rcrd(x, name = "par", ...) ## S3 method for class 'term' as_term_rcrd(x, repair = FALSE, ...)
as_term_rcrd(x, ...) ## S3 method for class 'character' as_term_rcrd(x, repair = FALSE, ...) ## S3 method for class 'numeric' as_term_rcrd(x, name = "par", ...) ## S3 method for class 'term' as_term_rcrd(x, repair = FALSE, ...)
x |
The object. |
... |
Unused. |
repair |
A flag specifying whether to repair terms. |
name |
A string specifying the name of the parameter. |
as_term_rcrd(character)
: Coerce character vector to term_rcrd
as_term_rcrd(numeric)
: Coerce numeric vector to term_rcrd
as_term_rcrd(term)
: Coerce term vector to term_rcrd
as_term(matrix(1:4, 2)) as_term(c("parm3[10]", "parm3[2]", "parm[2,2]", "parm[1,1]"))
as_term(matrix(1:4, 2)) as_term(c("parm3[10]", "parm3[2]", "parm[2,2]", "parm[1,1]"))
Checks if term using vld_term()
or vld_term_rcrd()
.
chk_term(x, validate = "complete", x_name = NULL) chk_term_rcrd(x, validate = "complete", x_name = NULL)
chk_term(x, validate = "complete", x_name = NULL) chk_term_rcrd(x, validate = "complete", x_name = NULL)
x |
The object. |
validate |
A string specifying the level of the validation. The possible values in order of increasing strictness are 'class', 'valid', 'consistent' and 'complete'. |
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_term_rcrd()
: Check Term Record
# chk_term x <- term("x[2]", "x[1]") chk_term(x) x <- c("x[2]", "x[1]") try(chk_term(x, validate = "sorted")) # chk_term_rcrd x <- term_rcrd("x[2]", "x[1]") chk_term_rcrd(x) x <- c("x[2]", "x[1]") try(chk_term_rcrd(x, validate = "sorted"))
# chk_term x <- term("x[2]", "x[1]") chk_term(x) x <- c("x[2]", "x[1]") try(chk_term(x, validate = "sorted")) # chk_term_rcrd x <- term_rcrd("x[2]", "x[1]") chk_term_rcrd(x) x <- c("x[2]", "x[1]") try(chk_term_rcrd(x, validate = "sorted"))
Completes an object's terms.
complete_terms(x, ...) ## S3 method for class 'term' complete_terms(x, ...) ## S3 method for class 'term_rcrd' complete_terms(x, ...)
complete_terms(x, ...) ## S3 method for class 'term' complete_terms(x, ...) ## S3 method for class 'term_rcrd' complete_terms(x, ...)
x |
The object. |
... |
Unused. |
It must not have any invalid or missing (NA) values.
complete_terms(term)
: Complete Terms for a term Vector
complete_terms(term_rcrd)
: Complete Terms for a term_rcrd vector
term-vector()
, repair_terms()
and is_incomplete_terms()
.
complete_terms(term("b[3]", "b[1]", "b[2]")) complete_terms(term("z[2,2]", "z[1,1]")) ## Not run: complete_terms(term_rcrd("b[3]", "b[1]", "b[2]")) complete_terms(term_rcrd("z[2,2]", "z[1,1]")) ## End(Not run)
complete_terms(term("b[3]", "b[1]", "b[2]")) complete_terms(term("z[2,2]", "z[1,1]")) ## Not run: complete_terms(term_rcrd("b[3]", "b[1]", "b[2]")) complete_terms(term_rcrd("z[2,2]", "z[1,1]")) ## End(Not run)
Test whether the number of dimensions of terms in the same parameter are consistent.
consistent_term(x)
consistent_term(x)
x |
The object. |
A logical vector indicating whether the number of dimensions is consistent.
consistent_term(term("alpha[1]", "alpha[3]", "beta[1,1]", "beta[2,1]")) consistent_term(term("alpha[1]", NA_term_, "beta[1,1]", "beta[2]"))
consistent_term(term("alpha[1]", "alpha[3]", "beta[1,1]", "beta[2,1]")) consistent_term(term("alpha[1]", NA_term_, "beta[1,1]", "beta[2]"))
Gets the dimensions of an object.
## S3 method for class 'term' dims(x, ...)
## S3 method for class 'term' dims(x, ...)
x |
An object. |
... |
Other arguments passed to methods. |
Unlike base::dim()
, dims returns the length of an atomic vector.
An integer vector of the dimensions.
Other dimensions:
ndims()
,
npdims()
,
pdims()
dims(term("beta[1,1]")) dims(term("beta[1,1]", "beta[1,2]"))
dims(term("beta[1,1]")) dims(term("beta[1,1]", "beta[1,2]"))
Gets the dimensions of an object.
## S3 method for class 'term_rcrd' dims(x, ...)
## S3 method for class 'term_rcrd' dims(x, ...)
x |
An object. |
... |
Other arguments passed to methods. |
Unlike base::dim()
, dims returns the length of an atomic vector.
An integer vector of the dimensions.
Other dimensions:
ndims()
,
npdims()
,
pdims()
dims(term_rcrd("beta[1,1]")) dims(term_rcrd("beta[1,1]", "beta[1,2]"))
dims(term_rcrd("beta[1,1]")) dims(term_rcrd("beta[1,1]", "beta[1,2]"))
Tests whether a term vector has absent elements. The vector should not require repairing.
is_incomplete_terms(x, ...)
is_incomplete_terms(x, ...)
x |
The object. |
... |
Unused. |
A logical scalar indicating whether the object's terms are incomplete.
term-vector()
and complete_terms()
is_incomplete_terms(term("b[2]")) is_incomplete_terms(term("b[2]", "b[1]")) is_incomplete_terms(term("b[2]", "b[1]", "b[1]"))
is_incomplete_terms(term("b[2]")) is_incomplete_terms(term("b[2]", "b[1]")) is_incomplete_terms(term("b[2]", "b[1]", "b[1]"))
Tests whether a term vector has inconsistent elements. Returns TRUE if includes missing or invalid terms.
is_inconsistent_terms(x, ...)
is_inconsistent_terms(x, ...)
x |
The object. |
... |
Unused. |
A logical scalar indicating whether the object's terms are inconsistent.
term-vector()
and consistent_term()
is_inconsistent_terms(term("b[2]")) is_inconsistent_terms(term("b[2]", "b[1]")) is_inconsistent_terms(term("b[2]", "b[1,1]"))
is_inconsistent_terms(term("b[2]")) is_inconsistent_terms(term("b[2]", "b[1]")) is_inconsistent_terms(term("b[2]", "b[1,1]"))
Tests whether an R object inherits from S3 class term
.
is_term(x)
is_term(x)
x |
The object. |
It does not test the validity of consistency of the term elements.
A flag indicating whether the test was positive.
term-vector()
, vld_term()
, valid_term()
and consistent_term()
is_term(c("parameter[2]", "parameter[10]")) is_term(term("parameter[2]", "parameter[10]"))
is_term(c("parameter[2]", "parameter[10]")) is_term(term("parameter[2]", "parameter[10]"))
Tests whether an R object inherits from S3 class term_rcrd
.
is_term_rcrd(x)
is_term_rcrd(x)
x |
The object. |
It does not test the validity of consistency of the term elements.
A flag indicating whether the test was positive.
valid_term()
and consistent_term()
is_term_rcrd(new_term_rcrd())
is_term_rcrd(new_term_rcrd())
A missing term element.
NA_term_
NA_term_
An object of class term
(inherits from vctrs_vctr
) of length 1.
is_term(NA_term_) is.na(NA_term_)
is_term(NA_term_) is.na(NA_term_)
A missing term element of term_rcrd
type.
NA_term_rcrd_
NA_term_rcrd_
An object of class term_rcrd
(inherits from vctrs_rcrd
, vctrs_vctr
) of length 1.
is_term_rcrd(NA_term_) is.na(NA_term_)
is_term_rcrd(NA_term_) is.na(NA_term_)
Use this function to quickly construct a term object
from a character vector, without checking the input.
Use term()
to repair the input.
new_term(x = character())
new_term(x = character())
x |
A character vector. |
new_term() new_term(c("a", "b[1]", "b[2]")) # Terms are not checked for validity: new_term("r[") repair_terms(new_term("r["))
new_term() new_term(c("a", "b[1]", "b[2]")) # Terms are not checked for validity: new_term("r[") repair_terms(new_term("r["))
Use this function to quickly construct a term_rcrd object.
new_term_rcrd( x = data.frame(par = character(), dim = I(list()), stringsAsFactors = FALSE) )
new_term_rcrd( x = data.frame(par = character(), dim = I(list()), stringsAsFactors = FALSE) )
x |
A data frame with columns par and dim. |
new_term_rcrd() ## Not run: new_term_rcrd(data.frame( par = c("x", "x", "y"), dim = I(list(1, 2, c(2,2))), stringsAsFactors = FALSE )) ## End(Not run)
new_term_rcrd() ## Not run: new_term_rcrd(data.frame( par = c("x", "x", "y"), dim = I(list(1, 2, c(2,2))), stringsAsFactors = FALSE )) ## End(Not run)
Normalizes a term vector.
normalize_terms(x)
normalize_terms(x)
x |
The object. |
If a parameter such as b
is a scalar then b[1]
is replaced by b
but if higher indices are included such as b[2]
then b
is replaced by b[1]
.
The normalized term vector.
term-vector()
and repair_terms()
normalize_terms(new_term(c("b", "b[3]"))) normalize_terms(new_term(c("b[1]", "a[3]")))
normalize_terms(new_term(c("b", "b[3]"))) normalize_terms(new_term(c("b[1]", "a[3]")))
Gets the number of parameters of an object.
The default methods returns the length of pars()
if none are
NA
, otherwise it returns NA
.
## S3 method for class 'term' npars(x, scalar = NULL, ...)
## S3 method for class 'term' npars(x, scalar = NULL, ...)
x |
An object. |
scalar |
A flag specifying whether to by default return all parameters (NULL), or only scalar parameters (TRUE) or only non-scalar parameters (FALSE). |
... |
Other arguments passed to methods. |
An integer scalar of the number of parameters.
Other MCMC dimensions:
nchains()
,
niters()
,
nsams()
,
nsims()
,
nterms()
Other parameters:
pars()
,
set_pars()
npars(term("sigma", "alpha[1]", "alpha[2]", "beta[1,1]", "beta[2,1]"))
npars(term("sigma", "alpha[1]", "alpha[2]", "beta[1,1]", "beta[2,1]"))
## S3 method for class 'term' npdims(x, terms = FALSE, ...)
## S3 method for class 'term' npdims(x, terms = FALSE, ...)
x |
An object. |
terms |
A flag specifying whether to get the number of dimensions for each term element. |
... |
Other arguments passed to methods. |
A named integer vector of the number of dimensions of each parameter.
Other dimensions:
dims()
,
ndims()
,
pdims()
npdims(term("alpha[1]", "alpha[3]", "beta[1,1]", "beta[2,1]"))
npdims(term("alpha[1]", "alpha[3]", "beta[1,1]", "beta[2,1]"))
Gets the number of terms of an object.
## Default S3 method: nterms(x, ...)
## Default S3 method: 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(term("alpha[1]", "alpha[2]", "beta[1,1]", "beta[2,1]")) nterms(term("alpha[1]", "alpha[1]", "beta[1,1]", "beta[1,1]"))
nterms(term("alpha[1]", "alpha[2]", "beta[1,1]", "beta[2,1]")) nterms(term("alpha[1]", "alpha[1]", "beta[1,1]", "beta[1,1]"))
Gets the number of terms of an MCMC object.
## S3 method for class 'term' nterms(x, ...)
## S3 method for class 'term' 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(term("alpha[1]", "alpha[2]", "beta[1,1]", "beta[2,1]")) nterms(term("alpha[1]", "alpha[1]", "beta[1,1]", "beta[1,1]"))
nterms(term("alpha[1]", "alpha[2]", "beta[1,1]", "beta[2,1]")) nterms(term("alpha[1]", "alpha[1]", "beta[1,1]", "beta[1,1]"))
Gets the number of terms of an MCMC object.
## S3 method for class 'term_rcrd' nterms(x, ...)
## S3 method for class 'term_rcrd' 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(as_term_rcrd(term("alpha[1]", "alpha[2]", "beta[1,1]", "beta[2,1]"))) nterms(as_term_rcrd(term("alpha[1]", "alpha[1]", "beta[1,1]", "beta[1,1]")))
nterms(as_term_rcrd(term("alpha[1]", "alpha[2]", "beta[1,1]", "beta[2,1]"))) nterms(as_term_rcrd(term("alpha[1]", "alpha[1]", "beta[1,1]", "beta[1,1]")))
Gets the name of each parameter for each term.
pars_terms(x, scalar = NULL, ...)
pars_terms(x, scalar = NULL, ...)
x |
A term vector. |
scalar |
A flag specifying whether to by default return all parameters (NULL), or only scalar parameters (TRUE) or only non-scalar parameters (FALSE). |
... |
Unused. |
A character vector of the term parameter names.
Other parameters:
pars.character()
,
pars.default()
,
pars.term()
,
pars.term_rcrd()
term <- term( "alpha[1]", "alpha[2]", "beta[1,1]", "beta[2,1]", "beta[1,2]", "beta[2,2]", "sigma", NA ) pars_terms(term)
term <- term( "alpha[1]", "alpha[2]", "beta[1,1]", "beta[2,1]", "beta[1,2]", "beta[2,2]", "sigma", NA ) pars_terms(term)
Gets the parameter names.
## S3 method for class 'character' pars(x, scalar = NULL, ...)
## S3 method for class 'character' pars(x, scalar = NULL, ...)
x |
An object. |
scalar |
A flag specifying whether to by default return all parameters (NULL), or only scalar parameters (TRUE) or only non-scalar parameters (FALSE). |
... |
Other arguments passed to methods. |
A character vector of the names of the parameters.
Other parameters:
pars.default()
,
pars.term()
,
pars.term_rcrd()
,
pars_terms()
pars(c("a", "b[1]", "a[3]"))
pars(c("a", "b[1]", "a[3]"))
Gets the parameter names.
## Default S3 method: pars(x, scalar = NULL, ...)
## Default S3 method: pars(x, scalar = NULL, ...)
x |
An object. |
scalar |
A flag specifying whether to by default return all parameters (NULL), or only scalar parameters (TRUE) or only non-scalar parameters (FALSE). |
... |
Other arguments passed to methods. |
A character vector of the names of the parameters.
Other parameters:
pars.character()
,
pars.term()
,
pars.term_rcrd()
,
pars_terms()
pars(matrix(1:4, nrow = 2))
pars(matrix(1:4, nrow = 2))
Gets the parameter names.
## S3 method for class 'term' pars(x, scalar = NULL, terms = FALSE, ...)
## S3 method for class 'term' pars(x, scalar = NULL, terms = FALSE, ...)
x |
An object. |
scalar |
A flag specifying whether to by default return all parameters (NULL), or only scalar parameters (TRUE) or only non-scalar parameters (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:
pars.character()
,
pars.default()
,
pars.term_rcrd()
,
pars_terms()
term <- term( "alpha[1]", "alpha[2]", "beta[1,1]", "beta[2,1]", "beta[1,2]", "beta[2,2]", "sigma", NA ) pars(term) pars(term, scalar = TRUE) pars(term, scalar = FALSE)
term <- term( "alpha[1]", "alpha[2]", "beta[1,1]", "beta[2,1]", "beta[1,2]", "beta[2,2]", "sigma", NA ) pars(term) pars(term, scalar = TRUE) pars(term, scalar = FALSE)
Gets the parameter names.
## S3 method for class 'term_rcrd' pars(x, scalar = NULL, ...)
## S3 method for class 'term_rcrd' pars(x, scalar = NULL, ...)
x |
An object. |
scalar |
A flag specifying whether to by default return all parameters (NULL), or only scalar parameters (TRUE) or only non-scalar parameters (FALSE). |
... |
Other arguments passed to methods. |
A character vector of the names of the parameters.
Other parameters:
pars.character()
,
pars.default()
,
pars.term()
,
pars_terms()
term <- term( "alpha[1]", "alpha[2]", "beta[1,1]", "beta[2,1]", "beta[1,2]", "beta[2,2]", "sigma", NA ) pars(term) pars(term, scalar = TRUE) pars(term, scalar = FALSE)
term <- term( "alpha[1]", "alpha[2]", "beta[1,1]", "beta[2,1]", "beta[1,2]", "beta[2,2]", "sigma", NA ) pars(term) pars(term, scalar = TRUE) pars(term, scalar = FALSE)
Gets the dimensions of each parameter of an object.
## S3 method for class 'term' pdims(x, ...)
## S3 method for class 'term' pdims(x, ...)
x |
An object. |
... |
Other arguments passed to methods. |
Errors if the parameter dimensions are invalid or inconsistent.
A named list of the dimensions of each parameter can be converted
into the equivalent term-vector()
using term()
.
A named list of integer vectors of the dimensions of each parameter.
Other dimensions:
dims()
,
ndims()
,
npdims()
pdims(term("alpha[1]", "alpha[3]", "beta[1,1]", "beta[2,1]"))
pdims(term("alpha[1]", "alpha[3]", "beta[1,1]", "beta[2,1]"))
Gets the dimensions of each parameter of an object.
## S3 method for class 'term_rcrd' pdims(x, ...)
## S3 method for class 'term_rcrd' pdims(x, ...)
x |
An object. |
... |
Other arguments passed to methods. |
Errors if the parameter dimensions are inconsistent.
A named list of integer vectors of the dimensions of each parameter.
Other dimensions:
dims()
,
ndims()
,
npdims()
pdims(as_term_rcrd(term("alpha[1]", "alpha[3]", "beta[1,1]", "beta[2,1]")))
pdims(as_term_rcrd(term("alpha[1]", "alpha[3]", "beta[1,1]", "beta[2,1]")))
Repairs a terms vector.
repair_terms(x, normalize = TRUE)
repair_terms(x, normalize = TRUE)
x |
The object. |
normalize |
A flag specifying whether to normalize terms. |
Invalid elements are replaced by missing values and spaces removed.
The repaired term vector.
term-vector()
, valid_term()
and normalize_terms()
repair_terms(new_term(c("b[3]", "b"))) repair_terms(new_term(c("a[3]", "b[1]"))) repair_terms(new_term(c("a [3]", " b [ 1 ] "))) repair_terms(new_term(c("a", NA)))
repair_terms(new_term(c("b[3]", "b"))) repair_terms(new_term(c("a[3]", "b[1]"))) repair_terms(new_term(c("a [3]", " b [ 1 ] "))) repair_terms(new_term(c("a", NA)))
Test whether each term is a scalar.
scalar_term(x)
scalar_term(x)
x |
The object. |
A logical vector indicating whether the term is a scalar.
scalar_term(term("alpha[1]", "alpha[3]", "beta[1]", "sigma[3]")) scalar_term(term("alpha[1]", NA_term_, "beta[1]", "beta[3]"))
scalar_term(term("alpha[1]", "alpha[3]", "beta[1]", "sigma[3]")) scalar_term(term("alpha[1]", NA_term_, "beta[1]", "beta[3]"))
Sets an object's parameter names.
The assignment version pars<-()
forwards to set_pars()
.
## S3 method for class 'term' set_pars(x, value, ...)
## S3 method for class 'term' 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()
term <- as_term(c("b[2]", "a[1]", "b[3,3]")) set_pars(term, c("x", "y"))
term <- as_term(c("b[2]", "a[1]", "b[3,3]")) set_pars(term, c("x", "y"))
Subsets a term vector.
## S3 method for class 'term' subset(x, pars = NULL, select = NULL, ...)
## S3 method for class 'term' subset(x, pars = NULL, select = NULL, ...)
x |
The object. |
pars |
A character vector of parameter names. |
select |
A character vector of the names of the parameters to include in the subsetted object. |
... |
Unused. |
The modified term vector.
term <- term( "alpha[1]", "alpha[2]", "beta[1,1]", "beta[2,1]", "beta[1,2]", "beta[2,2]", "sigma" ) subset(term, "beta") subset(term, c("alpha", "sigma"))
term <- term( "alpha[1]", "alpha[2]", "beta[1,1]", "beta[2,1]", "beta[1,2]", "beta[2,2]", "sigma" ) subset(term, "beta") subset(term, c("alpha", "sigma"))
Subsets a term_rcrd.
## S3 method for class 'term_rcrd' subset(x, pars = NULL, ...)
## S3 method for class 'term_rcrd' subset(x, pars = NULL, ...)
x |
The object. |
pars |
A character vector of parameter names. |
... |
Unused. |
The modified term vector.
term_rcrd <- term_rcrd( "alpha[1]", "alpha[2]", "beta[1,1]", "beta[2,1]", "beta[1,2]", "beta[2,2]", "sigma" ) ## Not run: subset(term_rcrd, "beta") subset(term_rcrd, c("alpha", "sigma")) ## End(Not run)
term_rcrd <- term_rcrd( "alpha[1]", "alpha[2]", "beta[1,1]", "beta[2,1]", "beta[1,2]", "beta[2,2]", "sigma" ) ## Not run: subset(term_rcrd, "beta") subset(term_rcrd, c("alpha", "sigma")) ## End(Not run)
Creates a term vector from values.
A term
vector is an S3 vector of parameter terms
of the form p
, q[#]
or r[#,#]
where #
are
positive integers.
This function checks that all terms are valid
but does not require stronger levels of consistency,
see chk_valid()
for details.
term(...)
term(...)
... |
Unnamed values are term values, named values describe the parameter in the name and the dimensionality in the value. |
A term vector.
dims()
, ndims()
, npdims()
and pdims()
Other term:
term_rcrd()
,
tindex()
term() term("p", "q[1]", "q[2]", "q[3]") term("q[1]", "q[2]", "q[3]") combined <- term(par = 2:4, "alpha") pdims(combined) term(!!!pdims(combined)) # Invalid terms are rejected: try(term("r[")) # Valid terms are repaired term("r [ 1 ,2 ]")
term() term("p", "q[1]", "q[2]", "q[3]") term("q[1]", "q[2]", "q[3]") combined <- term(par = 2:4, "alpha") pdims(combined) term(!!!pdims(combined)) # Invalid terms are rejected: try(term("r[")) # Valid terms are repaired term("r [ 1 ,2 ]")
Creates a term_rcrd from values.
This function checks that all terms are valid
but does not require stronger levels of consistency,
see chk_valid()
for details.
term_rcrd(...)
term_rcrd(...)
... |
Unnamed values are term values, named values describe the parameter in the name and the dimensionality in the value. |
A term_rcrd vector.
dims()
, ndims()
, npdims()
and pdims()
term_rcrd() ## Not run: term_rcrd("p", "q[1]", "q[2]", "q[3]") term_rcrd("q[1]", "q[2]", "q[3]") ## End(Not run)
term_rcrd() ## Not run: term_rcrd("p", "q[1]", "q[2]", "q[3]") term_rcrd("q[1]", "q[2]", "q[3]") ## End(Not run)
Gets the index for each term of an term or term_rcrd object.
tindex(x)
tindex(x)
x |
The object. |
For example the index of beta[2,1]
is c(2L, 1L)
while the index for sigma
is 1L
.
It is useful for extracting the values of individual terms.
A named list of integer vectors of the index for each term.
dims()
, ndims()
, npdims()
and pdims()
Other term:
term()
,
term_rcrd()
tindex(term("alpha", "alpha[2]", "beta[1,1]", "beta[2 ,1 ]"))
tindex(term("alpha", "alpha[2]", "beta[1,1]", "beta[2 ,1 ]"))
Test whether each element in a term or term_rcrd object is valid.
valid_term(x)
valid_term(x)
x |
The object. |
Repairing a term vector replaces invalid terms with missing values.
A logical vector indicating whether each term is valid.
term-vector()
and repair_terms()
Other valid:
vld_term()
# valid term elements valid_term(term("a", "a [3]", " b [ 1 ] ", "c[1,300,10]")) # invalid term elements valid_term(new_term(c("a b", "a[1]b", "a[0]", "b[1,]", "c[]", "d[1][2]")))
# valid term elements valid_term(term("a", "a [3]", " b [ 1 ] ", "c[1,300,10]")) # invalid term elements valid_term(new_term(c("a b", "a[1]b", "a[0]", "b[1,]", "c[]", "d[1][2]")))
Validates the elements of a term or term_rcrd vector.
Use chk_s3_class()
to check if an object is a term or term_rcrd.
vld_term(x, validate = "complete") vld_term_rcrd(x, validate = "complete")
vld_term(x, validate = "complete") vld_term_rcrd(x, validate = "complete")
x |
The object. |
validate |
A string specifying the level of the validation. The possible values in order of increasing strictness are 'class', 'valid', 'consistent' and 'complete'. |
Internal validity of a term can be checked on three levels:
"valid"
checks that all terms are of the form
x
, x[#]
, x[#,#]
etc. where x
is an identifier
and #
are positive integers.
"consistent"
checks that all terms are addressed
with the same dimensionality; the terms x[1]
and x[2,3]
are inconsistent.
"complete"
checks that the values span all possible values
across all dimensions; if x[3,4]
exist, the vector must
contain at least 11 more terms to be consistent
(x[1,1]
to x[1,4]
, x[2,1]
to x[2,4]
and
x[3,1]
to x[3,3]
).
Missing values are ignored as are duplicates and order.
A flag indicating whether the condition was met.
vld_term_rcrd()
: Validate Term Record
Other valid:
valid_term()
Other valid:
valid_term()
# vld_term vld_term(c("x[2]", "x[1]")) vld_term(term("x[2]", "x[1]")) # vld_term_rcrd vld_term_rcrd(c("x[2]", "x[1]")) vld_term_rcrd(term_rcrd("x[2]", "x[1]"))
# vld_term vld_term(c("x[2]", "x[1]")) vld_term(term("x[2]", "x[1]")) # vld_term_rcrd vld_term_rcrd(c("x[2]", "x[1]")) vld_term_rcrd(term_rcrd("x[2]", "x[1]"))