rstochvec: Random Generation of Stochastic (Probability) Vectors

View source: R/randmat.R

rstochvecR Documentation

Random Generation of Stochastic (Probability) Vectors

Description

Randomly generate probability vectors, that is, non-negative vectors whose elements sum to unity.

Usage

rstochvec(n, labels)

Arguments

n

the length of the vector. If n is not specified, it is inferred from the lenth of ‘⁠labels⁠’.

labels

a vector of labels for the elements of the vector. If ‘⁠labels⁠’ is not specified, n must be specified and the value as.character(1:n) is assumed.

Details

Stochastic (or probability) vectors are non-negative vectors that sum to unity. This function uniformly generates samples from the set of probability vector sof length n.

At least one of the arguments must be specified. The missing argument is infered from the other.

Value

A probability vector of length n with elements named according to ‘⁠labels⁠’.

Author(s)

Andrew Hart and Servet Martínez

Examples

rstochvec(4)
rstochvec(3, c("a", "b", "c"))
rstochvec(labels=c("r", "R"))

spgs documentation built on Oct. 3, 2023, 5:07 p.m.