rconst: Constant (Degenerate) Distribution (Returns its Own Argument...

Description Usage Arguments Value Examples

View source: R/distributions.R

Description

Wrapper for constant value (degenerate) distribution.

Usage

1
rconst(n, const)

Arguments

n

Sample size.

const

Either a vector with one constant value (replicated n times) or a vector of length n or a matrix with n rows (for a multivariate node).

Value

A vector of constants of length n.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
#---------------------------------------------------------------------------------------
# Specifying and simulating from a DAG with 1 Bernoulli and 2 constant nodes
#---------------------------------------------------------------------------------------
D <- DAG.empty()
D <- D + node("W1", distr = "rbern", prob = 0.45)
D <- D + node("W2", distr = "rconst", const = 1)
D <- D + node("W3", distr = "rconst", const = ifelse(W1 == 1, 5, 10))

# TWO equivalent ways of creating a multivariate node (just repeating W1 and W2):
create_mat <- function(W1, W2) cbind(W1, W2)
vecfun.add("create_mat")

D <- D + node(c("W1.copy1", "W2.copy1"), distr = "rconst", const = c(W1, W2))
D <- D + node(c("W1.copy2", "W2.copy2"), distr = "rconst", const = create_mat(W1, W2))
Dset <- set.DAG(D)
sim(Dset, n=10, rndseed=1)

simcausal documentation built on Oct. 9, 2017, 1:03 a.m.