cfa {lazy.fa} | R Documentation |
Sigma = Lambda %*% Phi %*% t(Lambda) + Psi
Simple Iterative Solution of Confirmatory Factor Analysis
Sigma = Lambda %*% Phi %*% t(Lambda) + Psi
with Prescribed Zeros in Lambda.
cfa( S, ndim = 3, n = 1, Lambda0 = NULL, psi0 = NULL, Phi0 = NULL, Lambda = NULL, psi = NULL, Phi = NULL, estLambda = 1, estpsi = 1, estPhi = 0, nodiag = 1, maxiter = 1000, epsd = 1e-07, minpsi = 0.01, maxPhi = 0.9, derivN = 1, SQUAREM = 3, nSQUAREM = 1, minalpha = -99, maxalpha = 1, always = 1, reset1 = 1, reset2 = 2, print = 1 )
S |
Input dispersion matrix |
ndim |
# of dimensions |
n |
# of observations |
Lambda0 |
Lambda matrix to specify the fixed elements. |
psi0 |
psi vector to specify the fixed elements. |
Phi0 |
Phi matrix to specify the fixed elements. |
Lambda |
Initial value of Lambda. (cannot have NAs.) |
psi |
Initial value of c(Psi). (cannot have NAs.) |
Phi |
Initial value of Phi. (cannot have NAs.) |
estLambda |
= 0 to skip the estimation of Lambda. |
estpsi |
= 0 to skip the estimatio of Psi. |
estPhi |
= 1 to estimate the off diagonal elements of Phi. |
nodiag |
= 0 to estimate the diagonal elements of Phi. (Always use nodiag=1.) |
maxiter |
Maximum # of iterations |
epsd |
The convergence criterion for the difference of param values. |
minpsi |
The minimum value of psi. |
maxPhi |
The maximum value of off diag elements of Phi. |
derivN |
= 0 to skip the calculation of the final derivative numerically. |
SQUAREM |
= 3 : See the help of iSQUAREM in lazy.accel package. |
nSQUAREM |
>= 1 # of iterations a which SQUAREM begins. |
minalpha |
= -999 : See the help of iSQUAREM in lazy.accel package. |
maxalpha |
= -1 : See the help of iSQUAREM in lazy.accel package. |
always |
= 1 : See the help of iSQUAREM in lazy.accel package. |
reset1 |
= 0 : See the help of iSQUAREM in lazy.accel package. |
reset2 |
= 1 : See the help of iSQUAREM in lazy.accel package. |
print |
= 1 to print the result. |
This function minimizes -2/n times the log likelihood ratio criterion:
crit = tr(S%*%invSigma)+log(det(Sigma)) - log(det(S)) - nvar
where S is the observed dispersion matrix, Sigma is the model dispersion
matrix, invSigma is the inverse of Sigma, nvar is the # of variables,
and n is the # of observations.
Note that n is not used during the course of estimation.
The EM algorithm is used to minimize crit with some restrictions
on the elements of the paramters.
When estLambda=1, either Lambda or Lambda0 must contain a valid initial.
The same goes with psi and Phi.
In this version, Phi is scaled so that diag(Phi)=I.
A list of
Lambda Factor Loadings
Psi Scalar error variance
Phi Factor correlation matrix
crit The value of criterion function.
nparam, aic # of parameters and aic
dcritN and dcritA The derivatives of the criterion.
dcritA and dcritN analutic and numeric derivative of the criterion function.
Rubin, D.B., Thayer, T.T.(1982) EM algorithms for ML factor analysis.
Psychometrika 47, 69-76.
# Orthogonal Independent Cluster seed=1701 set.seed(seed) nvar=20 ndim0=2 ps=0.2 df=500 phi=0 A=gendatafa_A( nvar, ndim0, large=0.8,small=0.01, pc=0, sd=0.01 )$loadings Phi=(1-phi)*diag(ndim0)+phi*matrix(1,ndim0,ndim0) Sigma=A%*%Phi%*%t(A)+ps*diag(nvar) dS=sqrt(diag(Sigma)) Sigma=diag(1/dS)%*%Sigma%*%diag(1/dS) # Print(Sigma) S=rWishart( 1, df, Sigma ) S=S[,,1]/df dS=sqrt(diag(S)) S=diag(1/dS)%*%S%*%diag(1/dS) ndim=2 Lambda0=gendatafa_A( nvar, ndim, large=1,small=0, pc=0, sd=0 )$loadings Lambda0[Lambda0==1]=NA res2=cfa( S, ndim=ndim, Lambda0=Lambda0, print=1 ) res2=cfa( S, ndim=ndim, Lambda0=Lambda0, print=1, estPhi=1 ) # Oblique Independent Cluster seed=1701 set.seed(seed) nvar=20 ndim0=4 ps=0.2 df=500 phi=0.3 A=gendatafa_A( nvar, ndim0, large=0.8,small=0.01, pc=0, sd=0.01 )$loadings Phi=(1-phi)*diag(ndim0)+phi*matrix(1,ndim0,ndim0) Sigma=A%*%Phi%*%t(A)+ps*diag(nvar) dS=sqrt(diag(Sigma)) Sigma=diag(1/dS)%*%Sigma%*%diag(1/dS) # Print(Sigma) S=rWishart( 1, df, Sigma ) S=S[,,1]/df dS=sqrt(diag(S)) S=diag(1/dS)%*%S%*%diag(1/dS) ndim=3 Lambda0=gendatafa_A( nvar, ndim, large=1,small=0, pc=0, sd=0 )$loadings Lambda0[Lambda0==1]=NA res2=cfa( S, ndim=ndim, n=df, Lambda0=Lambda0, print=1 ) res2=cfa( S, ndim=ndim, n=df, Lambda0=Lambda0, print=1, estPhi=1 ) # Bifactor Model seed=1701 set.seed(seed) nvar=20 ndim0=3 ps=0.2 df=500 phi=0 A=gendatafa_A( nvar, ndim0-1, large=0.8,small=0.01, pc=0, sd=0.01 )$loadings A=cbind(0.9,A) Phi=(1-phi)*diag(ndim0)+phi*matrix(1,ndim0,ndim0) Sigma=A%*%Phi%*%t(A)+ps*diag(nvar) dS=sqrt(diag(Sigma)) Sigma=diag(1/dS)%*%Sigma%*%diag(1/dS) # Print(Sigma) S=rWishart( 1, df, Sigma ) S=S[,,1]/df dS=sqrt(diag(S)) S=diag(1/dS)%*%S%*%diag(1/dS) ndim=3 Lambda0=gendatafa_A( nvar, ndim-1, large=1,small=0, pc=0, sd=0 )$loadings Lambda0=cbind(1,Lambda0) Lambda0[Lambda0==1]=NA Phi0=diag(ndim) Phi0[3,2]=NA; Phi0[2,3]=NA Phi1=diag(ndim) Phi1[2:ndim,1]=NA; Phi1[1,2:ndim]=NA Phi2=diag(ndim) Phi2[3,2]=0.4; Phi2[2,3]=0.4 # crit = 0.2926539 res1=cfa( S, ndim=ndim, Lambda0=Lambda0, print=1, estPhi=0 ) # crit = 0.288043 res11=cfa( S, ndim=ndim, Lambda0=Lambda0, print=1, estPhi=0, Phi0=Phi2 ) # crit = 0.2891818 res2=cfa( S, ndim=ndim, Lambda0=Lambda0, print=1, estPhi=1 ) # crit = 0.3323131 res3=cfa( S, ndim=ndim, Lambda0=Lambda0, print=1, estPhi=1, Phi0=Phi0 ) # crit = 0.2873195 res4=cfa( S, ndim=ndim, Lambda0=Lambda0, print=1, estPhi=1 , Phi0=Phi0, Phi=res11$Phi, Lambda=res11$Lambda, psi=res11$psi ) # crit = 0.28719 res5=cfa( S, ndim=ndim, Lambda0=Lambda0, print=1, estPhi=1, Phi0=NULL , Phi=res11$Phi, Lambda=res11$Lambda, psi=res11$psi, maxiter=4000 )