# What would be the best way to simulate a variable that takes integer values ranging from 0 to 40 (in R)? A stats newbie

I am sorry if this question is confusing, but I am stats newbie!! I am trying to simulate a composite variable which takes values ranging from 0 to 40. The composite variable is made of the sum of 8 questions which could take values between 0 and 5. I am aware that I cannot use rnorm, since it will also give me negative values, and the original data is right skewed. I have the probabilities for each score (o to 5) occurring for each of the compositor variables, so I have considered generating each of them separately using the sample function, and then summing them to create my sum variable. However, I am afraid that they probably would be correlated, and I haven't been able to find a way to simulate them simultaneously while also accounting for correlation. Essentially, to make it easier to imagine, the paper contrasts the use of 2 languages in different scenarios, so those same questions are asked twice to each participant for each language. Therefore, the variables might also be correlated between conditions. Is there a way to deal with that, or would it be best to simulate the total score variable directly? From what I understand, although I am not sure if I am correct, I could use the rpois function to do this? Or another solution I could thin of is simulate the data using rnorm, and then square it to make a right skew? Any opinion would be very useful!!! Thank you in advance!!

I have tried using rpois and simulating each compositor variable separately.

• I think this is more of a Cross-validated question. In that forum, you should say what you know about the joint distribution of the 8 items, and they should be able to tell you statistical distributions that match your needs. Dec 5, 2022 at 19:19
• What is the purpose of the simulation and what quantitative facts do you know or assume about the correlations among the questions?
– whuber
Dec 5, 2022 at 21:55
• Hi, thanks for replying and sorry if my question was confusing. Essentially, there are two within-subject language categories (English and French) and the 8 item questionnaire was filled out for each of the languages separately. The questions were about amount of exposure to each language in different contexts. This is why I presume that the questions would be correlated within and between languages (language exposure in certain contexts might increase or decrease likelihood of exposure in other contexts; additionally greater exposure to eg English might result in lesser exposure to French) Dec 5, 2022 at 23:20
• The purpose is to simulate this and other variables, which I will then use to run a GLMM and then a power analysis. I have the dataset used in the original analysis, so I have created correlation matrices for each language separately, so I have calculated their correlations, but am unaware if it would be possible to include them when simulating the data. I also do not know how to create a correlation matrix that displays the item correlations for both languages together (if that makes any sense at all). Again, sorry if this is very confusing, I am really bad at explaining Dec 5, 2022 at 23:29

Easy enough with the the base R sample function using the probability parameter. Example:
# first generate dummy probabilities