sim {psych} | R Documentation |
A number of functions in the psych package will generate simulated data. These functions include
link{sim}
(for a factor simplex), and sim.simplex
( for a data simplex) sim.circ
for a circumplex structure, sim.congeneric
(for a one factor factor congeneric model), sim.dichot
(to simulate dichotomous items), sim.hierarchical
(a hierarchical factor model), sim.item
(general item simulations),
sim.minor
(to simulate major and minor factors)
sim.structural
(general simulation of structural models), sim.anova
for ANOVA and lm simulatins, and sim.VSS
. These functions are separately documented and are listed here for ease of the help function. See each function for more detailed help.
sim(fx=NULL,Phi=NULL,fy=NULL,n=0,mu=NULL,raw=TRUE) sim.simplex(nvar =12, r=.8,mu=NULL, n=0) sim.minor(nvar=12,nfact=3,n=0,fbig=NULL,fsmall = NULL)
fx |
The measurement model for x. If NULL, a 4 factor model is generated |
Phi |
The structure matrix of the latent variables |
fy |
The measurement model for y |
mu |
The means structure for the fx factors |
n |
Number of cases to simulate. If n=0 or NULL, the population matrix is returned. |
raw |
if raw=TRUE, raw data are returned as well. |
nvar |
Number of variables for a simplex structure |
nfact |
Number of large factors to simulate in sim.minor |
r |
the base correlation for a simplex |
fbig |
Factor loadings for the main factors. Default is a simple structure with loadings sampled from (.8,.6) for nvar/nfact variables and 0 for the remaining. If fbig is specified, then it will be used. |
fsmall |
nvar/2 small factors are generated with loadings sampled from (-.2,0,.2) |
Simulation of data structures is a very useful tool in psychometric research and teaching. By knowing ``truth" it is possible to see how well various algorithms can capture it.
The default values for sim.structure
is to generate a 4 factor, 12 variable data set with a simplex structure between the factors.
Two data structures that are particular challenges to exploratory factor analysis are the simplex structure and the presence of minor factors. Simplex structures sim.simplex
will typically occur in developmental or learning contexts and have a correlation structure of r between adjacent variables and r^n for variables n apart. Although just one latent variable (r) needs to be estimated, the structure will have nvar-1 factors.
Many simulations of factor structures assume that except for the major factors, all residuals are normally distributed around 0. An alternative, and perhaps more realistic situation, is that the there are a few major (big) factors and many minor (small) factors. The challenge is thus to identify the major factors. sim.minor
generates such structures.
Other simulation functions in psych are:
sim.structure
A function to combine a measurement and structural model into one data matrix. Useful for understanding structural equation models. Combined with structure.diagram
to see the proposed structure.
sim.congeneric
A function to create congeneric items/tests for demonstrating classical test theory. This is just a special case of sim.structure.
sim.hierarchical
A function to create data with a hierarchical (bifactor) structure.
sim.item
A function to create items that either have a simple structure or a circumplex structure.
sim.circ
Create data with a circumplex structure.
sim.dichot
Create dichotomous item data with a simple or circumplex structure.
sim.minor
Create a factor structure for nvar variables defined by nfact major factors and nvar/2 ``minor" factors.
sim.anova
Simulate a 3 way balanced ANOVA or linear model, with or without repeated measures.
William Revelle
Revelle, W. (in preparation) An Introduction to Psychometric Theory with applications in R. Springer. at http://personality-project.org/r/book/
See above
simplex <- sim.simplex() #create the default structure round(simplex,2) #the correlation matrix congeneric <- sim.congeneric() round(congeneric,2) R <- sim.hierarchical() R fx <- matrix(c(.9,.8,.7,rep(0,6),c(.8,.7,.6)),ncol=2) fy <- c(.6,.5,.4) Phi <- matrix(c(1,0,.5,0,1,.4,0,0,0),ncol=3) R <- sim.structure(fx,Phi,fy) cor.plot(R$model) #show it graphically simp <- sim.simplex() #show the simplex structure using cor.plot cor.plot(simp,colors=TRUE)