2

I want to use some predictors (for example, $x_1$ and $x_2$ below) to simulate the multinomial outcome (for example, with 3 levels).

Below are the codes I found in another question regarding simulating binary outcome.

> set.seed(666)
> x1 = rnorm(1000)           # some continuous variables 
> x2 = rnorm(1000)
> z = 1 + 2*x1 + 3*x2        # linear combination with a bias
> pr = 1/(1+exp(-z))         # pass through an inv-logit function
> y = rbinom(1000,1,pr)      # bernoulli response variable

By doing this, I got the binary outcome y.

I have two questions:

  1. How can I extend this to simulate the multinomial outcome (more than 2 levels).
  2. How can I control the proportion of each level (for example, 3 levels, 0.5:0.3:0.2).

Thanks much!!!

Stephan Kolassa
  • 123,354

0 Answers0