Generate 90-items survey data structure


#1

Hi, I was wondering if the package would come with a solution to produce more than dozen of columns at one go rather than ‘Q1, Q2, Q3, Q4…Q100’. I have a 90-items surveys and it would be very nice to use the package to explore the data structure before the data collection.

`survey_data <- fabricate(

N = 100,
Q1 = draw_likert(x = rnorm(N), type = 7),
Q2 = draw_likert(x = rnorm(N), type = 5),
Q3 = draw_likert(x = rnorm(N), type = 4),
Q4 = draw_likert(x = rnorm(N), breaks = c(-Inf, -0.8, 0, 1, 2, Inf))
)`


#2

You can do this using a rlang !! notation, but I think it’s easier to just write a for loop. For example,

types <- sample(c(4,5,7), 100, replace=TRUE)

df <- fabricate(N=100)

for(i in 1:100) {
  df <- fabricate(df, z=draw_likert(rnorm(N), type=types[i]))
  names(df)[i+1] <- paste0("Q", i)
}

This approach requires a list of all the various arguments you want to use (types[i]), so it isn’t really much easier than using copy/paste to make the 100 lines for fabricate.

Also if you think that the latent variables may be correlated, you can generate them directly and apply the likert transformation:

latent_X <- MASS::mvrnorm(n=100, mu=rep(0,100), Sigma = diag(100))

likert_X <- mapply(draw_likert, as.data.frame(latent_X), type=types)