Hello,
I'm trying to fit a pretty simple confirmatory factor analysis using
the sem package. There's a CFA example in the examples, which is helpful,
but the output for my (failing) model is hard to understand. I'd be
interested in any other ways to do a CFA in R, if this proves troublesome.
The CFA is replicating a 5 uncorrelated-factor structure (for those
interested, it is a structure of word usage patterns in weblogs) in a
special population. The model looks like model.txt (attached as many people
hate long emails); the correlation matrix cors.txt as well.
I'm setting no overlap between factors, no correlation between
factors, and estimating a separate variance for each observed variable
(which should be everything on the right-hand side of the -> arrows), but
setting the factor variances equal to 1...pretty standard. I've ensured that
everything is typed correctly to the best I am able.
The problem:
library(sem)
model.kr <- specify.model(file="model.txt") # printing it checks out ok
correl <- read.csv("cors.csv", header=TRUE) # printing it checks out ok
kr.sem <- sem(ram=model.kr,S=correl,N=3034)
...about 10 seconds pass...
Warning message:
In sem.default(ram = ram, S = S, N = N, param.names = pars, var.names = vars, :
Could not compute QR decomposition of Hessian.
Optimization probably did not converge.
(running qr on correl works fine; randomly-generated correl matrices fail in
the same way; I do not know how to further troubleshoot this)
...and then the model itself (which is produced, as the above was just a
warning):
summary(kr.sem)
Error in data.frame(object$coeff, se, z, 2 * (1 - pnorm(abs(z))), par.code) :
arguments imply differing number of rows: 47, 0
...both of these error messages are beyond my ability to troubleshoot. Any
help would be greatly appreciated. Because I am unsure what exactly the
problem with this analysis is, I can't create a simpler example for testing
purposes...but I think my model and correlation matrix are fairly simple.
unlist(R.Version())
platform arch
"x86_64-unknown-linux-gnu" "x86_64"
os system
"linux-gnu" "x86_64, linux-gnu"
status major
"" "2"
minor year
"7.2" "2008"
month day
"08" "25"
svn rev language
"46428" "R"
version.string
"R version 2.7.2 (2008-08-25)"
...sem installed via install.packages("sem") which I assume is current.
Cordially,
Adam Kramer
-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
On
Behalf Of Adam D. I. Kramer
Sent: September-18-08 1:02 PM
To: r-help at r-project.org
Subject: [R] Difficulty understanding sem errors / failed confirmatory
factor
analysis
Hello,
I'm trying to fit a pretty simple confirmatory factor analysis using
the sem package. There's a CFA example in the examples, which is helpful,
but the output for my (failing) model is hard to understand. I'd be
interested in any other ways to do a CFA in R, if this proves troublesome.
The CFA is replicating a 5 uncorrelated-factor structure (for those
interested, it is a structure of word usage patterns in weblogs) in a
special population. The model looks like model.txt (attached as many
people
hate long emails); the correlation matrix cors.txt as well.
As far as I can see, the attachments aren't there. If you like, you can send
them to me privately. Without the input covariance matrix and your model,
it's very hard to tell what the source of the problem is, but one guess
(assuming that you've specified the model correctly) is that the assumption
of uncorrelated factors is too far off. Also see below.
I'm setting no overlap between factors, no correlation between
factors, and estimating a separate variance for each observed variable
(which should be everything on the right-hand side of the -> arrows), but
setting the factor variances equal to 1...pretty standard. I've ensured
that
everything is typed correctly to the best I am able.
The problem:
library(sem)
model.kr <- specify.model(file="model.txt") # printing it checks out ok
correl <- read.csv("cors.csv", header=TRUE) # printing it checks out ok
kr.sem <- sem(ram=model.kr,S=correl,N=3034)
...about 10 seconds pass...
Warning message:
In sem.default(ram = ram, S = S, N = N, param.names = pars, var.names =
vars,
:
Could not compute QR decomposition of Hessian.
Optimization probably did not converge.
(running qr on correl works fine; randomly-generated correl matrices fail
in
the same way; I do not know how to further troubleshoot this)
Doing a QR decomposition on the correlation matrix of the data is
essentially irrelevant. The issue is the Hessian. (The scaled inverse
Hessian is the covariance matrix of the parameter estimates, not of the
data.) That you observe similar problems for randomly generated covariance
matrices may or may not be troublesome, depending upon how you generated
them.
...and then the model itself (which is produced, as the above was just a
warning):
summary(kr.sem)
Error in data.frame(object$coeff, se, z, 2 * (1 - pnorm(abs(z))),
par.code) :
arguments imply differing number of rows: 47, 0
If the Hessian isn't positive-definite, it won't be possible to get
estimated coefficient standard errors. I suspect that this is the source of
this error message. If so, it would be better for summary.sem() to provide a
more informative error message.
Regards,
John
...both of these error messages are beyond my ability to troubleshoot. Any
help would be greatly appreciated. Because I am unsure what exactly the
problem with this analysis is, I can't create a simpler example for
testing
purposes...but I think my model and correlation matrix are fairly simple.
unlist(R.Version())
platform arch
"x86_64-unknown-linux-gnu" "x86_64"
os system
"linux-gnu" "x86_64, linux-gnu"
status major
"" "2"
minor year
"7.2" "2008"
month day
"08" "25"
svn rev language
"46428" "R"
version.string
"R version 2.7.2 (2008-08-25)"
...sem installed via install.packages("sem") which I assume is current.
Cordially,
Adam Kramer
No new info, but the model and correlation table are pasted at the end of
this message.
--Adam
On Thu, 18 Sep 2008, Adam D. I. Kramer wrote:
Hello,
I'm trying to fit a pretty simple confirmatory factor analysis using
the sem package. There's a CFA example in the examples, which is helpful,
but the output for my (failing) model is hard to understand. I'd be
interested in any other ways to do a CFA in R, if this proves troublesome.
The CFA is replicating a 5 uncorrelated-factor structure (for those
interested, it is a structure of word usage patterns in weblogs) in a
special population. The model looks like model.txt (attached as many people
hate long emails); the correlation matrix cors.txt as well.
I'm setting no overlap between factors, no correlation between
factors, and estimating a separate variance for each observed variable
(which should be everything on the right-hand side of the -> arrows), but
setting the factor variances equal to 1...pretty standard. I've ensured that
everything is typed correctly to the best I am able.
The problem:
library(sem)
model.kr <- specify.model(file="model.txt") # printing it checks out ok
correl <- read.csv("cors.csv", header=TRUE) # printing it checks out ok
kr.sem <- sem(ram=model.kr,S=correl,N=3034)
...about 10 seconds pass...
Warning message:
In sem.default(ram = ram, S = S, N = N, param.names = pars, var.names = vars,
:
Could not compute QR decomposition of Hessian.
Optimization probably did not converge.
(running qr on correl works fine; randomly-generated correl matrices fail in
the same way; I do not know how to further troubleshoot this)
...and then the model itself (which is produced, as the above was just a
warning):
summary(kr.sem)
Error in data.frame(object$coeff, se, z, 2 * (1 - pnorm(abs(z))), par.code) :
arguments imply differing number of rows: 47, 0
...both of these error messages are beyond my ability to troubleshoot. Any
help would be greatly appreciated. Because I am unsure what exactly the
problem with this analysis is, I can't create a simpler example for testing
purposes...but I think my model and correlation matrix are fairly simple.
unlist(R.Version())
platform arch
"x86_64-unknown-linux-gnu" "x86_64"
os system
"linux-gnu" "x86_64, linux-gnu"
status major
"" "2"
minor year
"7.2" "2008"
month day
"08" "25"
svn rev language
"46428" "R"
version.string "R version 2.7.2 (2008-08-25)"
...sem installed via install.packages("sem") which I assume is current.
Cordially,
Adam Kramer
Dear Adam,
(1) Note that your input correlation matrix appears to be numerically
singular:
solve(R)
Error in solve.default(R) :
system is computationally singular: reciprocal condition number =
2.38183e-17
det(R)
[1] -1.753523e-25
qr(R)$rank
[1] 23
(2) In addition, you have specified what are essentially redundant
constraints on the model, fixing *both* the loading for a "reference"
indicator for each factor to 1 *and* fixing the factor variances to 1. One
would normally do one or the other.
I think that (1) rather than (2) is the essential source of the problem, and
fixing (2) doesn't make the problem go away.
Because sem() can't compute the covariance matrix of the estimated
parameters, this component is missing from the returned object, causing the
cryptic error message in summary.sem(). I'll provide a more informative
error or warning.
I hope this helps,
John
------------------------------
John Fox, Professor
Department of Sociology
McMaster University
Hamilton, Ontario, Canada
web: socserv.mcmaster.ca/jfox
-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
On
Behalf Of Adam D. I. Kramer
Sent: September-18-08 1:37 PM
To: r-help at r-project.org
Subject: Re: [R] Difficulty understanding sem errors / failed confirmatory
factor analysis
No new info, but the model and correlation table are pasted at the end of
this message.
--Adam
On Thu, 18 Sep 2008, Adam D. I. Kramer wrote:
Hello,
I'm trying to fit a pretty simple confirmatory factor analysis using
the sem package. There's a CFA example in the examples, which is
helpful,
but the output for my (failing) model is hard to understand. I'd be
interested in any other ways to do a CFA in R, if this proves
troublesome.
The CFA is replicating a 5 uncorrelated-factor structure (for those
interested, it is a structure of word usage patterns in weblogs) in a
special population. The model looks like model.txt (attached as many
people
hate long emails); the correlation matrix cors.txt as well.
I'm setting no overlap between factors, no correlation between
factors, and estimating a separate variance for each observed variable
(which should be everything on the right-hand side of the -> arrows),
but
setting the factor variances equal to 1...pretty standard. I've ensured
that
everything is typed correctly to the best I am able.
The problem:
library(sem)
model.kr <- specify.model(file="model.txt") # printing it checks out ok
correl <- read.csv("cors.csv", header=TRUE) # printing it checks out ok
kr.sem <- sem(ram=model.kr,S=correl,N=3034)
...about 10 seconds pass...
Warning message:
In sem.default(ram = ram, S = S, N = N, param.names = pars, var.names =
vars,
:
Could not compute QR decomposition of Hessian.
Optimization probably did not converge.
(running qr on correl works fine; randomly-generated correl matrices
fail
in
the same way; I do not know how to further troubleshoot this)
...and then the model itself (which is produced, as the above was just a
warning):
summary(kr.sem)
Error in data.frame(object$coeff, se, z, 2 * (1 - pnorm(abs(z))),
par.code)
:
arguments imply differing number of rows: 47, 0
...both of these error messages are beyond my ability to troubleshoot.
Any
help would be greatly appreciated. Because I am unsure what exactly the
problem with this analysis is, I can't create a simpler example for
testing
purposes...but I think my model and correlation matrix are fairly
simple.
unlist(R.Version())
platform arch
"x86_64-unknown-linux-gnu" "x86_64"
os system
"linux-gnu" "x86_64, linux-gnu"
status major
"" "2"
minor year
"7.2" "2008"
month day
"08" "25"
svn rev language
"46428" "R"
version.string "R version 2.7.2 (2008-08-25)"
...sem installed via install.packages("sem") which I assume is current.
Cordially,
Adam Kramer
model.kr <- specify.model()
Melancholy -> Affect, mel.aff, NA
Melancholy -> Negemo, mel.neg, NA
Melancholy -> Sad, mel.sad, NA
Melancholy -> Physcal, mel.phys, NA
Melancholy -> Body, mel.phys, NA
Melancholy -> Eating, mel.eat, NA
Melancholy -> Groom, NA, 1
Social -> numlines, soc.nrow, NA
Social -> Leisure, soc.leis, NA
Social -> Home, soc.home, NA
Social -> Sports, soc.sports, NA
Social -> TV, soc.tv, NA
Social -> Music, soc.mus, NA
Social -> Money, NA, 1
Rant -> Swear, rant.swear, NA
Rant -> Sexual, rant.sex, NA
Rant -> Anger, rant.anger, NA
Rant -> I, NA, 1
Metaphysical -> Metaph, met.met, NA
Metaphysical -> Relig, met.relig, NA
Metaphysical -> Death, NA, 1
Work -> Occup, work.occ, NA
Work -> School, work.school, NA
Work -> Job, NA, 1
Affect <-> Affect,Affect.var,NA
Negemo <-> Negemo,Negemo.var,NA
Sad <-> Sad,Sad.var,NA
Physcal <-> Physcal,Physcal.var,NA
Body <-> Body,Body.var,NA
Eating <-> Eating,Eating.var,NA
Groom <-> Groom,Groom.var,NA
numlines <-> numlines,numlines.var,NA
Leisure <-> Leisure,Leisure.var,NA
Home <-> Home,Home.var,NA
Sports <-> Sports,Sports.var,NA
TV <-> TV,TV.var,NA
Music <-> Music,Music.var,NA
Money <-> Money,Money.var,NA
Swear <-> Swear,Swear.var,NA
Sexual <-> Sexual,Sexual.var,NA
Anger <-> Anger,Anger.var,NA
I <-> I,I.var,NA
Metaph <-> Metaph,Metaph.var,NA
Relig <-> Relig,Relig.var,NA
Death <-> Death,Death.var,NA
Occup <-> Occup,Occup.var,NA
School <-> School,School.var,NA
Job <-> Job,Job.var,NA
Melancholy <-> Melancholy, NA, 1
Social <-> Social, NA, 1
Rant <-> Rant, NA, 1
Work <-> Work, NA, 1
Metaphysical <-> Metaphysical, NA, 1
correl <- matrix(0,nrow=24,ncol=24)
correl[lower.tri(correl,diag=TRUE)] <- c(1, 0.940530496413442,
0.765560263936915, 0.705665939921134,
0.659038546655712, 0.282665099938120, 0.234892888297051,
I'm trying to fit a pretty simple confirmatory factor analysis using
the sem package. There's a CFA example in the examples, which is helpful,
but the output for my (failing) model is hard to understand. I'd be
interested in any other ways to do a CFA in R, if this proves
troublesome.
The CFA is replicating a 5 uncorrelated-factor structure (for those
interested, it is a structure of word usage patterns in weblogs) in a
special population. The model looks like model.txt (attached as many
people hate long emails); the correlation matrix cors.txt as well.
As far as I can see, the attachments aren't there. If you like, you can
send them to me privately. Without the input covariance matrix and your
model, it's very hard to tell what the source of the problem is, but one
guess (assuming that you've specified the model correctly) is that the
assumption of uncorrelated factors is too far off. Also see below.
I have pasted the matrix into another email; apologies for failing to attach
them acceptably before.
I also augmented the model to allow the factors to correlate, by adding
these lines to the model:
Melancholy <-> Social, Soc.Mel, NA
Melancholy <-> Rant, Rant.Mel, NA
Melancholy <-> Work, Work.Mel, NA
Melancholy <-> Metaphysical, Meta.Mel, NA
Social <-> Rant, Soc.Rant, NA
Social <-> Work, Soc.Work, NA
Social <-> Metaphysical, Soc.Meta, NA
Rant <-> Work, Rant.Work, NA
Rant <-> Metaphysical, Rant.Meta, NA
Work <-> Metaphysical, Work.Meta, NA
...and obtain the same errors.
I'm setting no overlap between factors, no correlation between
factors, and estimating a separate variance for each observed variable
(which should be everything on the right-hand side of the -> arrows), but
setting the factor variances equal to 1...pretty standard. I've ensured
that
everything is typed correctly to the best I am able.
The problem:
library(sem)
model.kr <- specify.model(file="model.txt") # printing it checks out ok
correl <- read.csv("cors.csv", header=TRUE) # printing it checks out ok
kr.sem <- sem(ram=model.kr,S=correl,N=3034)
...about 10 seconds pass...
Warning message:
In sem.default(ram = ram, S = S, N = N, param.names = pars, var.names =
vars,
:
Could not compute QR decomposition of Hessian.
Optimization probably did not converge.
(running qr on correl works fine; randomly-generated correl matrices fail
in
the same way; I do not know how to further troubleshoot this)
Doing a QR decomposition on the correlation matrix of the data is
essentially irrelevant. The issue is the Hessian. (The scaled inverse
Hessian is the covariance matrix of the parameter estimates, not of the
data.) That you observe similar problems for randomly generated covariance
matrices may or may not be troublesome, depending upon how you generated
them.
df <- as.data.frame(matrix(rnorm(3034*24),nrow=3034,ncol=24))
df.cor <- cor(df)
rownames(df.cor) <- colnames(df.cor) <- colnames(correl)
sem.df <- sem(model.kr, df.cor, 3034)
...which now does not throw errors with the new model, even though that syntax
was copied from my .Rhistory. I think I may have gotten unlucky with random
data the first time.
Thanks for the info on what the error message means, though--I was largely
in the dark on that.
...and then the model itself (which is produced, as the above was just a
warning):
summary(kr.sem)
Error in data.frame(object$coeff, se, z, 2 * (1 - pnorm(abs(z))),
par.code) :
arguments imply differing number of rows: 47, 0
If the Hessian isn't positive-definite, it won't be possible to get
estimated coefficient standard errors. I suspect that this is the source
of this error message. If so, it would be better for summary.sem() to
provide a more informative error message.
This makes sense. It may also be useful for the sem() function to throw an
error rather than a warning if the Hessian matrix cannot be decomposed,
perhaps? How often is an SEM model without estimated coefficient standard
errors desirable?
Thanks again for the assistance. I think the trouble may now be in my
correlation matrix; I will play around with my model and see whether
something else is more reasonable.
--Adam
Dear Adam,
I'm afraid that our emails have crossed. Please see my previous message.
John
------------------------------
John Fox, Professor
Department of Sociology
McMaster University
Hamilton, Ontario, Canada
web: socserv.mcmaster.ca/jfox
-----Original Message-----
From: Adam D. I. Kramer [mailto:adik at ilovebacon.org]
Sent: September-18-08 2:12 PM
To: John Fox
Cc: r-help at r-project.org
Subject: Re: [R] Difficulty understanding sem errors / failed confirmatory
factor analysis
Dear John,
On Thu, 18 Sep 2008, John Fox wrote:
I'm trying to fit a pretty simple confirmatory factor analysis using
the sem package. There's a CFA example in the examples, which is
helpful,
but the output for my (failing) model is hard to understand. I'd be
interested in any other ways to do a CFA in R, if this proves
troublesome.
The CFA is replicating a 5 uncorrelated-factor structure (for those
interested, it is a structure of word usage patterns in weblogs) in a
special population. The model looks like model.txt (attached as many
people hate long emails); the correlation matrix cors.txt as well.
As far as I can see, the attachments aren't there. If you like, you can
send them to me privately. Without the input covariance matrix and your
model, it's very hard to tell what the source of the problem is, but one
guess (assuming that you've specified the model correctly) is that the
assumption of uncorrelated factors is too far off. Also see below.
I have pasted the matrix into another email; apologies for failing to
attach
them acceptably before.
I also augmented the model to allow the factors to correlate, by adding
these lines to the model:
Melancholy <-> Social, Soc.Mel, NA
Melancholy <-> Rant, Rant.Mel, NA
Melancholy <-> Work, Work.Mel, NA
Melancholy <-> Metaphysical, Meta.Mel, NA
Social <-> Rant, Soc.Rant, NA
Social <-> Work, Soc.Work, NA
Social <-> Metaphysical, Soc.Meta, NA
Rant <-> Work, Rant.Work, NA
Rant <-> Metaphysical, Rant.Meta, NA
Work <-> Metaphysical, Work.Meta, NA
...and obtain the same errors.
I'm setting no overlap between factors, no correlation between
factors, and estimating a separate variance for each observed variable
(which should be everything on the right-hand side of the -> arrows),
but
setting the factor variances equal to 1...pretty standard. I've ensured
that
everything is typed correctly to the best I am able.
The problem:
library(sem)
model.kr <- specify.model(file="model.txt") # printing it checks out ok
correl <- read.csv("cors.csv", header=TRUE) # printing it checks out ok
kr.sem <- sem(ram=model.kr,S=correl,N=3034)
...about 10 seconds pass...
Warning message:
In sem.default(ram = ram, S = S, N = N, param.names = pars, var.names =
vars,
:
Could not compute QR decomposition of Hessian.
Optimization probably did not converge.
(running qr on correl works fine; randomly-generated correl matrices
fail
in
the same way; I do not know how to further troubleshoot this)
Doing a QR decomposition on the correlation matrix of the data is
essentially irrelevant. The issue is the Hessian. (The scaled inverse
Hessian is the covariance matrix of the parameter estimates, not of the
data.) That you observe similar problems for randomly generated
covariance
matrices may or may not be troublesome, depending upon how you generated
them.
df <- as.data.frame(matrix(rnorm(3034*24),nrow=3034,ncol=24))
df.cor <- cor(df)
rownames(df.cor) <- colnames(df.cor) <- colnames(correl)
sem.df <- sem(model.kr, df.cor, 3034)
...which now does not throw errors with the new model, even though that
syntax
was copied from my .Rhistory. I think I may have gotten unlucky with
random
data the first time.
Thanks for the info on what the error message means, though--I was largely
in the dark on that.
...and then the model itself (which is produced, as the above was just
a
warning):
summary(kr.sem)
Error in data.frame(object$coeff, se, z, 2 * (1 - pnorm(abs(z))),
par.code) :
arguments imply differing number of rows: 47, 0
If the Hessian isn't positive-definite, it won't be possible to get
estimated coefficient standard errors. I suspect that this is the source
of this error message. If so, it would be better for summary.sem() to
provide a more informative error message.
This makes sense. It may also be useful for the sem() function to throw an
error rather than a warning if the Hessian matrix cannot be decomposed,
perhaps? How often is an SEM model without estimated coefficient standard
errors desirable?
Thanks again for the assistance. I think the trouble may now be in my
correlation matrix; I will play around with my model and see whether
something else is more reasonable.
--Adam
Hi John,
Thanks very much for your response. It does appear now that my
correlation matrix and not your software is the problem. I apologize for
wasting your time! I do think that a more informative error message may have
prompted me to consider this possibility more fully.
--Adam
On Thu, 18 Sep 2008, John Fox wrote:
Dear Adam,
(1) Note that your input correlation matrix appears to be numerically
singular:
solve(R)
Error in solve.default(R) :
system is computationally singular: reciprocal condition number =
2.38183e-17
det(R)
[1] -1.753523e-25
qr(R)$rank
[1] 23
(2) In addition, you have specified what are essentially redundant
constraints on the model, fixing *both* the loading for a "reference"
indicator for each factor to 1 *and* fixing the factor variances to 1. One
would normally do one or the other.
I think that (1) rather than (2) is the essential source of the problem, and
fixing (2) doesn't make the problem go away.
Because sem() can't compute the covariance matrix of the estimated
parameters, this component is missing from the returned object, causing the
cryptic error message in summary.sem(). I'll provide a more informative
error or warning.
I hope this helps,
John
------------------------------
John Fox, Professor
Department of Sociology
McMaster University
Hamilton, Ontario, Canada
web: socserv.mcmaster.ca/jfox
-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
On
Behalf Of Adam D. I. Kramer
Sent: September-18-08 1:37 PM
To: r-help at r-project.org
Subject: Re: [R] Difficulty understanding sem errors / failed confirmatory
factor analysis
No new info, but the model and correlation table are pasted at the end of
this message.
--Adam
On Thu, 18 Sep 2008, Adam D. I. Kramer wrote:
Hello,
I'm trying to fit a pretty simple confirmatory factor analysis using
the sem package. There's a CFA example in the examples, which is
helpful,
but the output for my (failing) model is hard to understand. I'd be
interested in any other ways to do a CFA in R, if this proves
troublesome.
The CFA is replicating a 5 uncorrelated-factor structure (for those
interested, it is a structure of word usage patterns in weblogs) in a
special population. The model looks like model.txt (attached as many
people
hate long emails); the correlation matrix cors.txt as well.
I'm setting no overlap between factors, no correlation between
factors, and estimating a separate variance for each observed variable
(which should be everything on the right-hand side of the -> arrows),
but
setting the factor variances equal to 1...pretty standard. I've ensured
that
everything is typed correctly to the best I am able.
The problem:
library(sem)
model.kr <- specify.model(file="model.txt") # printing it checks out ok
correl <- read.csv("cors.csv", header=TRUE) # printing it checks out ok
kr.sem <- sem(ram=model.kr,S=correl,N=3034)
...about 10 seconds pass...
Warning message:
In sem.default(ram = ram, S = S, N = N, param.names = pars, var.names =
vars,
:
Could not compute QR decomposition of Hessian.
Optimization probably did not converge.
(running qr on correl works fine; randomly-generated correl matrices
fail
in
the same way; I do not know how to further troubleshoot this)
...and then the model itself (which is produced, as the above was just a
warning):
summary(kr.sem)
Error in data.frame(object$coeff, se, z, 2 * (1 - pnorm(abs(z))),
par.code)
:
arguments imply differing number of rows: 47, 0
...both of these error messages are beyond my ability to troubleshoot.
Any
help would be greatly appreciated. Because I am unsure what exactly the
problem with this analysis is, I can't create a simpler example for
testing
purposes...but I think my model and correlation matrix are fairly
simple.
unlist(R.Version())
platform arch
"x86_64-unknown-linux-gnu" "x86_64"
os system
"linux-gnu" "x86_64, linux-gnu"
status major
"" "2"
minor year
"7.2" "2008"
month day
"08" "25"
svn rev language
"46428" "R"
version.string "R version 2.7.2 (2008-08-25)"
...sem installed via install.packages("sem") which I assume is current.
Cordially,
Adam Kramer
model.kr <- specify.model()
Melancholy -> Affect, mel.aff, NA
Melancholy -> Negemo, mel.neg, NA
Melancholy -> Sad, mel.sad, NA
Melancholy -> Physcal, mel.phys, NA
Melancholy -> Body, mel.phys, NA
Melancholy -> Eating, mel.eat, NA
Melancholy -> Groom, NA, 1
Social -> numlines, soc.nrow, NA
Social -> Leisure, soc.leis, NA
Social -> Home, soc.home, NA
Social -> Sports, soc.sports, NA
Social -> TV, soc.tv, NA
Social -> Music, soc.mus, NA
Social -> Money, NA, 1
Rant -> Swear, rant.swear, NA
Rant -> Sexual, rant.sex, NA
Rant -> Anger, rant.anger, NA
Rant -> I, NA, 1
Metaphysical -> Metaph, met.met, NA
Metaphysical -> Relig, met.relig, NA
Metaphysical -> Death, NA, 1
Work -> Occup, work.occ, NA
Work -> School, work.school, NA
Work -> Job, NA, 1
Affect <-> Affect,Affect.var,NA
Negemo <-> Negemo,Negemo.var,NA
Sad <-> Sad,Sad.var,NA
Physcal <-> Physcal,Physcal.var,NA
Body <-> Body,Body.var,NA
Eating <-> Eating,Eating.var,NA
Groom <-> Groom,Groom.var,NA
numlines <-> numlines,numlines.var,NA
Leisure <-> Leisure,Leisure.var,NA
Home <-> Home,Home.var,NA
Sports <-> Sports,Sports.var,NA
TV <-> TV,TV.var,NA
Music <-> Music,Music.var,NA
Money <-> Money,Money.var,NA
Swear <-> Swear,Swear.var,NA
Sexual <-> Sexual,Sexual.var,NA
Anger <-> Anger,Anger.var,NA
I <-> I,I.var,NA
Metaph <-> Metaph,Metaph.var,NA
Relig <-> Relig,Relig.var,NA
Death <-> Death,Death.var,NA
Occup <-> Occup,Occup.var,NA
School <-> School,School.var,NA
Job <-> Job,Job.var,NA
Melancholy <-> Melancholy, NA, 1
Social <-> Social, NA, 1
Rant <-> Rant, NA, 1
Work <-> Work, NA, 1
Metaphysical <-> Metaphysical, NA, 1
correl <- matrix(0,nrow=24,ncol=24)
correl[lower.tri(correl,diag=TRUE)] <- c(1, 0.940530496413442,
0.765560263936915, 0.705665939921134,
0.659038546655712, 0.282665099938120, 0.234892888297051,
-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
On
Behalf Of Adam D. I. Kramer
Sent: September-18-08 2:33 PM
To: John Fox
Cc: r-help at r-project.org
Subject: Re: [R] Difficulty understanding sem errors / failed confirmatory
factor analysis
Hi John,
Thanks very much for your response. It does appear now that my
correlation matrix and not your software is the problem. I apologize for
wasting your time! I do think that a more informative error message may
have
prompted me to consider this possibility more fully.
Agreed. I've put a more informative error message into summary.sem() in the
development version of the package on R-Forge. I think that I'll also add a
check for singularity of the input covariance matrix.
Regards,
John
--Adam
On Thu, 18 Sep 2008, John Fox wrote:
Dear Adam,
(1) Note that your input correlation matrix appears to be numerically
singular:
solve(R)
Error in solve.default(R) :
system is computationally singular: reciprocal condition number =
2.38183e-17
det(R)
[1] -1.753523e-25
qr(R)$rank
[1] 23
(2) In addition, you have specified what are essentially redundant
constraints on the model, fixing *both* the loading for a "reference"
indicator for each factor to 1 *and* fixing the factor variances to 1.
One
would normally do one or the other.
I think that (1) rather than (2) is the essential source of the problem,
and
fixing (2) doesn't make the problem go away.
Because sem() can't compute the covariance matrix of the estimated
parameters, this component is missing from the returned object, causing
the
cryptic error message in summary.sem(). I'll provide a more informative
error or warning.
I hope this helps,
John
------------------------------
John Fox, Professor
Department of Sociology
McMaster University
Hamilton, Ontario, Canada
web: socserv.mcmaster.ca/jfox
-----Original Message-----
From: r-help-bounces at r-project.org
[mailto:r-help-bounces at r-project.org]
On
Behalf Of Adam D. I. Kramer
Sent: September-18-08 1:37 PM
To: r-help at r-project.org
Subject: Re: [R] Difficulty understanding sem errors / failed
confirmatory
factor analysis
No new info, but the model and correlation table are pasted at the end
of
this message.
--Adam
On Thu, 18 Sep 2008, Adam D. I. Kramer wrote:
Hello,
I'm trying to fit a pretty simple confirmatory factor analysis using
the sem package. There's a CFA example in the examples, which is
helpful,
but the output for my (failing) model is hard to understand. I'd be
interested in any other ways to do a CFA in R, if this proves
troublesome.
The CFA is replicating a 5 uncorrelated-factor structure (for those
interested, it is a structure of word usage patterns in weblogs) in a
special population. The model looks like model.txt (attached as many
people
hate long emails); the correlation matrix cors.txt as well.
I'm setting no overlap between factors, no correlation between
factors, and estimating a separate variance for each observed variable
(which should be everything on the right-hand side of the -> arrows),
but
setting the factor variances equal to 1...pretty standard. I've
ensured
that
everything is typed correctly to the best I am able.
The problem:
library(sem)
model.kr <- specify.model(file="model.txt") # printing it checks out
ok
correl <- read.csv("cors.csv", header=TRUE) # printing it checks out
ok
kr.sem <- sem(ram=model.kr,S=correl,N=3034)
...about 10 seconds pass...
Warning message:
In sem.default(ram = ram, S = S, N = N, param.names = pars, var.names
=
vars,
:
Could not compute QR decomposition of Hessian.
Optimization probably did not converge.
(running qr on correl works fine; randomly-generated correl matrices
fail
in
the same way; I do not know how to further troubleshoot this)
...and then the model itself (which is produced, as the above was just
a
warning):
summary(kr.sem)
Error in data.frame(object$coeff, se, z, 2 * (1 - pnorm(abs(z))),
par.code)
:
arguments imply differing number of rows: 47, 0
...both of these error messages are beyond my ability to troubleshoot.
Any
help would be greatly appreciated. Because I am unsure what exactly
the
problem with this analysis is, I can't create a simpler example for
testing
purposes...but I think my model and correlation matrix are fairly
simple.
unlist(R.Version())
platform arch
"x86_64-unknown-linux-gnu" "x86_64"
os system
"linux-gnu" "x86_64, linux-gnu"
status major
"" "2"
minor year
"7.2" "2008"
month day
"08" "25"
svn rev language
"46428" "R"
version.string "R version 2.7.2 (2008-08-25)"
...sem installed via install.packages("sem") which I assume is
current.
Cordially,
Adam Kramer
model.kr <- specify.model()
Melancholy -> Affect, mel.aff, NA
Melancholy -> Negemo, mel.neg, NA
Melancholy -> Sad, mel.sad, NA
Melancholy -> Physcal, mel.phys, NA
Melancholy -> Body, mel.phys, NA
Melancholy -> Eating, mel.eat, NA
Melancholy -> Groom, NA, 1
Social -> numlines, soc.nrow, NA
Social -> Leisure, soc.leis, NA
Social -> Home, soc.home, NA
Social -> Sports, soc.sports, NA
Social -> TV, soc.tv, NA
Social -> Music, soc.mus, NA
Social -> Money, NA, 1
Rant -> Swear, rant.swear, NA
Rant -> Sexual, rant.sex, NA
Rant -> Anger, rant.anger, NA
Rant -> I, NA, 1
Metaphysical -> Metaph, met.met, NA
Metaphysical -> Relig, met.relig, NA
Metaphysical -> Death, NA, 1
Work -> Occup, work.occ, NA
Work -> School, work.school, NA
Work -> Job, NA, 1
Affect <-> Affect,Affect.var,NA
Negemo <-> Negemo,Negemo.var,NA
Sad <-> Sad,Sad.var,NA
Physcal <-> Physcal,Physcal.var,NA
Body <-> Body,Body.var,NA
Eating <-> Eating,Eating.var,NA
Groom <-> Groom,Groom.var,NA
numlines <-> numlines,numlines.var,NA
Leisure <-> Leisure,Leisure.var,NA
Home <-> Home,Home.var,NA
Sports <-> Sports,Sports.var,NA
TV <-> TV,TV.var,NA
Music <-> Music,Music.var,NA
Money <-> Money,Money.var,NA
Swear <-> Swear,Swear.var,NA
Sexual <-> Sexual,Sexual.var,NA
Anger <-> Anger,Anger.var,NA
I <-> I,I.var,NA
Metaph <-> Metaph,Metaph.var,NA
Relig <-> Relig,Relig.var,NA
Death <-> Death,Death.var,NA
Occup <-> Occup,Occup.var,NA
School <-> School,School.var,NA
Job <-> Job,Job.var,NA
Melancholy <-> Melancholy, NA, 1
Social <-> Social, NA, 1
Rant <-> Rant, NA, 1
Work <-> Work, NA, 1
Metaphysical <-> Metaphysical, NA, 1
correl <- matrix(0,nrow=24,ncol=24)
correl[lower.tri(correl,diag=TRUE)] <- c(1, 0.940530496413442,
0.765560263936915, 0.705665939921134,
0.659038546655712, 0.282665099938120, 0.234892888297051,