# rcat.factor: Random Sample for a Categorical Factor In osofr/simcausal: Simulating Longitudinal Data with Causal Inference Applications

## Description

Matrix version of the categorical distribution. The argument `probs` can be a matrix of n rows, specifying individual (varying in sample) categorical probabilities. The number of categories generated is equal to `ncol(probs)+1`, the levels labeled as: `1,...,ncol(probs)+1`.

## Usage

 ```1 2 3``` ```rcat.factor(n, probs) rcategor(n, probs) ```

## Arguments

 `n` Sample size. `probs` Either a vector or a matrix of success probabilities. When `probs` is a vector, `n` identically distributed random categorical variables are generated with categories: 1, 2, ..., length(probs)+1. When `probs` is a matrix, the categorical probabilities of the `k`th sample are determined by the `k`th row of `probs` matrix, i.e., `probs[k,]`.

## Value

A factor of length `n` with levels: `1,2, ...,ncol(probs)+1`.

## Functions

• `rcategor`: (Deperecated) Random Sample of a Categorical Factor

`rcat.b1`, `rcat.b0`
 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19``` ```#--------------------------------------------------------------------------------------- # Specifying and simulating from a DAG with one categorical node with constant # probabilities #--------------------------------------------------------------------------------------- D <- DAG.empty() D <- D + node("race",t=0,distr="rcat.factor",probs=c(0.2,0.1,0.4,0.15,0.05,0.1)) Dset <- set.DAG(D) simdat <- sim(Dset, n=200, rndseed=1) #--------------------------------------------------------------------------------------- # Specifying and simulating from a DAG with a categorical node with varying # probabilities (probabilities are determined by values sampled for nodes L0 and L1) #--------------------------------------------------------------------------------------- D <- DAG.empty() D <- D + node("L0", distr="rnorm", mean=10, sd=5) D <- D + node("L1", distr="rnorm", mean=10, sd=5) D <- D + node("L2", distr="rcat.factor", probs=c(abs(1/L0), abs(1/L1))) Dset <- set.DAG(D) simdat <- sim(Dset, n=200, rndseed=1) ```