[R] Path Analysis
jfox at mcmaster.ca
Sat Nov 2 19:48:38 CET 2013
It's generally a good idea to include a reproducible example if you want to get help with a problem, but in this case it's a safe bet that the problem is that the model you specified has no variance or covariance parameters for the variables x1 and x2, which, I assume, you mean to be exogenous. The easiest way to include these variances and covariance in the model is to specify the argument fixed.x=c("x1", "x2") in the call to sem().
(1) Your model is fully recursive (guessing that all the x's and y's are observed variables), and so it amounts to four OLS regressions. You could just use lm() to fit the model.
(2) It's generally easier in the sem package to use specifyEquations() than specifyModel() for model specification.
(3) If you have the original data set, as you do, it's generally preferable to use the data argument to sem() than to pass it the covariance matrix for the observed variables.
I hope that this helps,
Hamilton, Ontario, Canada
On Sat, 2 Nov 2013 11:02:31 +0100
Sarah Rogers <rogerssarah65 at gmail.com> wrote:
> I have just started to work on a path analysis (see attached image for the
> diagram), but I have encountered an error message.
> This is the code I have used:
> x1 -> y2, xy12, NA
> x2 -> y1, xy21, NA
> y1 -> y2, yy12, NA
> y2 -> y3, yy23, NA
> y2 -> y4, yy24, NA
> y3 -> y4, yy34, NA
> y2 <-> y2, y2error, NA
> y1 <-> y1, y1error, NA
> y3 <-> y3, y3error, NA
> y4 <-> y4, y4error, NA
> model.xdata.sem <- sem(model.xdata, cov_matrix, nrow(xdata))
> and the error message is:
> Error in csem(model = model.description, start, opt.flag = 1, typsize =
> typsize, :
> The matrix is non-invertable.
> I fear to have a problem in the data.
> I would be very grateful if you could help me to solve this problem and
> proceed with my analyses.
> thank you in advance for your help!
> [[alternative HTML version deleted]]
> R-help at r-project.org mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help