1

I want to simulate survey data- think of a survey where people respond on a scale from 1(strongly disagree) to 7(strongly agree).

I want to be able to specify the mean of the simulated sample, as well. For example, I want to simulate 100 numbers between 1 and 7 with a mean of 4 and an SD of 1.

Then I would like to simulate 100 more numbers between 1 and 7 with a mean of 3 and an SD of 1.

This way, I can compute an effect size of d = 1.00. I will use this data for a classroom demonstration.

rnorm() allows me to specify a mean, but not the bounds.

runif() allows me to specify the bounds but not the mean.

sample() allows me to specify the bounds but not the mean.

Applying round() to rnorm() gives me whole numbers, but will sometimes generate 0s or 8s (eg numbers outside of the 1-7 range). Yes, I can recode them but this adjusts my effect size:

round(rnorm(200, 2, 1))

Is there not a way to generate either whole numbers between 1 and 7 with a specified mean OR two samples with a specified mean difference and range?

1 Answers1

1

What about rounding the result of truncnorm::truncnorm()?

library(truncnorm)
set.seed(1234)
u <- round(rtruncnorm(10000, a=1, b=7, mean=3, sd=1))
summary(u)

Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
  1.000   2.000   3.000   3.054   4.000   7.000 
s__
  • 9,270
  • 3
  • 27
  • 45
  • 1
    Ah, that works pretty well! I have never come across that function or package before. This is a very simple solution to a problem that so many people have. Thanks! – socialresearcher Aug 03 '21 at 12:11