rdatagen {sgr} | R Documentation |
Simulate discrete data.
Description
Simulate discrete data from either a correlation matrix or thresholds or probabilities.
Usage
rdatagen(n = 100, R = diag(1,2), Q = NULL, th = NULL, probs = NULL)
Arguments
n |
Number of observations. |
R |
Correlation matrix. |
Q |
Number of discrete values in the
random variables. It is a single value or a vector. If |
th |
List of thresholds; each element contains |
probs |
List of probabilities; each elements contains |
Value
Returns a list with four elements:
data |
The simulated data matrix. |
R |
Correlation matrix. |
thresholds |
The list of thresholds. |
probs |
The list of probabilities. |
Note
Defaults work like in the mvrnorm
function of the MASS
package.
Author(s)
Massimiliano Pastore, Luigi Lombardi & Marco Bressan
References
Lombardi, L., Pastore, M. (2014). sgr: A Package for Simulating Conditional Fake Ordinal Data. The R Journal, 6, 164-177.
Pastore, M., Lombardi, L. (2014). The impact of faking on Cronbach's Alpha for dichotomous and ordered rating scores. Quality & Quantity, 48, 1191-1211.
Examples
require(MASS)
## only default
rdatagen()
## set correlations only
R <- matrix(c(1,.4,.4,1),2,2)
Dx <- rdatagen(n=10000,R=R)$data
par(mfrow=c(1,2))
for (j in 1:ncol(Dx)) hist(Dx[,j])
## set correlations and Q
Dx <- rdatagen(n=10000,R=R,Q=2)$data
par(mfrow=c(1,2))
for (j in 1:ncol(Dx)) barplot(table(Dx[,j])/nrow(Dx))
## set correlations and thresholds
th <- list(c(-Inf,qchisq(pbinom(0:3,4,.5),1),Inf),
c(-Inf,qnorm(pbinom(0:2,3,.5)),Inf))
Dx <- rdatagen(n=10000,R=R,th=th)$data
par(mfrow=c(1,2))
for (j in 1:ncol(Dx)) barplot(table(Dx[,j])/nrow(Dx))
## set correlations and probabilities [1]
probs <- list(c(.125,.375,.375,.125),c(.125,.375,.375,.125))
Dx <- rdatagen(n=10000,R=R,probs=probs)$data
par(mfrow=c(1,2))
for (j in 1:ncol(Dx)) barplot(table(Dx[,j])/nrow(Dx))
## set correlations and probabilities [2]
probs <- c(.125,.375,.375,.125)
Dx <- rdatagen(n=10000,R=R,probs=probs)$data
par(mfrow=c(1,2))
for (j in 1:ncol(Dx)) barplot(table(Dx[,j])/nrow(Dx))
## set different values for Q
Dx <- rdatagen(n=1000,Q=c(2,4),R=R)$data
par(mfrow=c(1,2))
for (j in 1:ncol(Dx)) barplot(table(Dx[,j])/nrow(Dx))