0
$\begingroup$

I have created code to simulate normally distributed data based on loadings from a bifactor model (Caspi et al., 2014). I need to add a skew of 2.0 to each variable in the data set to simulate the typical distribution of psychopathological symptoms in the community. In another paper (Greene et al., 2019), using R, the authors added the skew of 2.0 to their Monte Carlo developed data sets (which they developed through MPlus). I would like to use their code to apply the same skew to my data set, however, I am unsure of what the numeric values in their code represent. I assume that the values (e.g., 54, 3, etc.) are specific to their data. What values would I need from my data to input into the code to develop the 2.0 skew? I would also like to maintain the correlations between variables, and the means if possible.

Here is my code to develop the bifactor simulation data:

library(lavaan)
library(Rcmdr)

#creating a dataset for p + externasling(f1) and internalsing (f2), all orthogonal

n  <- 1000

p  <- rnorm(n)

ext <- rnorm(n)

int <- rnorm(n)


Alc <- .626 * ext + .397 * p + rnorm(n,0,sqrt(1 - (.626*.397)^2))

Cann <- .811 * ext + .455*p + rnorm(n,0,sqrt(1 - (.811*.455)^2))

HD <- .709 * ext + .452 * p + rnorm(n,0,sqrt(1 - (.709*.452)^2))

Tobacco <- .420 * ext + .504 * p + rnorm(n,0,sqrt(1 - (.420*.504)^2))

CD <- .691 * ext + .557 * p + rnorm(n,0,sqrt(1 - (.691*.557)^2))

Depression <- .340 * int + .835 * p + rnorm(n,0,sqrt(1 - (.340*.835)^2))

GAD <- .497 * int + .812 * p + rnorm(n,0,sqrt(1 - (.497*.812)^2))

Fears <- .441 * int + .623 * p + rnorm(n,0,sqrt(1 - (.441*.623)^2))

OCD <- .725 * p + rnorm(n,0,sqrt(1 - (.725)^2))

Mania <- .973 * p + rnorm(n,0,sqrt(1 - (.973)^2))

Schiz <- .819 * p + rnorm(n,0,sqrt(1 - (.819)^2))

bifac <- data.frame(Alc,Cann,HD,Tobacco,CD,Depression,GAD,Fears,OCD,Mania,Schiz)
rm(n,ext,int,p,Alc,Cann,HD,Tobacco,CD,Depression,GAD,Fears,OCD,Mania,Schiz)
summary(bifac)
nrow(bifac)

#Saving created data set

library("rio")
export(bifac,"Bifactor_Sim_data.csv")

Here is Greene et al. (2019)'s code used to skew their data:

Skewness transformation in R: For continuous models, R was used to perform the skewness transformation. Below is the annotated R syntax using the MplusAutomation package (Hallquist & Wiley, 2018).

###load the library to run Mplus for continuous data simulation 

library(MplusAutomation) 

###Parameter settings for the data transformation to create skew 

cc <- -(54*sqrt(2)+81)^(1/3)

xx <- -(3+cc+9/cc)/3 

a <- exp(sqrt(log(xx))) 


###Run Mplus models 

runModels() 

###Transform all the simulated data into skewed data 

for(k in 1:500)
{   
d <- read.table(paste('data000rep',k,'.DAT',sep=''))
}
   
write.table(a^d,paste('data000rep',k,'.DAT',sep=''),col.names = F,row.names = F)}
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.