Hello,
Below is the code for generating dichotomous data based on IRT 2PL model. I want to generate dichotomous data using IRT 3PL model, how should I incorporate the c parameter in the code. thanks!

Hi! The 3PL IRT model is usually defined as shown here.

First, I we can define a function, irt_prob that calculates the probability of a correct response, with or without c parameters. Then we pass that function to one more apply() function. The full code is below:

Thanks much for the help!
I have two more questions need your help.

If I want my c parameter average value is ~.25, that is, the items are 4 options multiple choice items, how should I modify the beta distribution?

2.using the code you helped, I then want to do parameter estimation using the following code, but there is warning message as below, what should I do to improve the code so that to achieve stable estimation?

The Beta distribution has a mean of shape1 / (shape1 + shape2). So, for example, beta(10, 30) would give you a mean around .25. There are obviously many combinations of shape1 and shape2 that will give you a mean around .25 (e.g., beta(1,3), beta(50,150), etc.). The magnitude of shape1 and shape2 relate to the variance. The full formula can be seen here, but in general, the bigger the numbers, the more narrow the distribution. See, for example, beta(10,30) compared to beta(100,300). Both give an expected value around .25, but have very different ranges of plausible values they draw from.

It's hard to know for sure, as I'm not familiar with the tpm() function. I generally use the mirt package or brms/rstan. My guess is that your sample is a little small. As a rule of thumb, I usually aim for 500-1000 respondents for a 3PL model. Another problem I've run into before is an item with 0 variance (e.g., all of the simulated responses are 0). If everyone gets an item wrong, then it may look "infinitely difficult". So I would add a check to your function to make sure after generating the item responses, no item is either all correct or all incorrect. If any of those items exist, then re-generate the responses.