[R] Path Analysis

John Fox jfox at mcmaster.ca
Sat Nov 2 19:48:38 CET 2013

Dear Sarah,

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().

In addition:

(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,

John Fox
McMaster University
Hamilton, Ontario, Canada
On Sat, 2 Nov 2013 11:02:31 +0100
 Sarah Rogers <rogerssarah65 at gmail.com> wrote:
>  Hello,
> 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:
> cov_matrix<-var(xdata)
> library(sem)
> model.xdata<-specifyModel()
> 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!
> Sarah
> 	[[alternative HTML version deleted]]
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> 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 mailing list