[R] easy way to fit saturated model in sem package?

Joshua Wiley jwiley.psych at gmail.com
Thu Jul 12 08:52:38 CEST 2012


Hi,

I am wondering if anyone knows of an easy way to fit a saturated model
using the sem package on raw data?  Say the data were:

mtcars[, c("mpg", "hp", "wt")]

The model would estimate the three means (intercepts) of c("mpg",
"hp", "wt").  The variances of c("mpg", "hp", "wt").  The covariance
of mpg with hp and wt and the covariance of hp with wt.

I am interested in this because I want to obtain the MLE mean vector
and covariance matrix when there is missing data (i.e., the sum of the
case wise likelihoods or so-called full information maximum
likelihood).  Here is exemplary missing data:

dat <- as.matrix(mtcars[, c("mpg", "hp", "wt")])
dat[sample(length(dat), length(dat) * .25)] <- NA
dat <- as.data.frame(dat)

It is not too difficult to write a wrapper that does this in the
OpenMx package because you can easily define paths using vectors and
get all pairwise combinations using:

combn(c("mpg", "hp", "wt"), 2)

but I would prefer to use the sem package, because OpenMx does not
work on 64 bit versions of R for Windows x64 and is not available from
CRAN presently.  Obviously it is not difficult to write out the model,
but I am hoping to bundle this in a function that for some arbitrary
data, will return the FIML estimated covariance (and correlation
matrix).  Alternately, if there are any functions/packages that just
return FIML estimates of a covariance matrix from raw data, that would
be great (but googling and using findFn() from the sos package did not
turn up good results).

Thanks!

Josh


-- 
Joshua Wiley
Ph.D. Student, Health Psychology
Programmer Analyst II, Statistical Consulting Group
University of California, Los Angeles
https://joshuawiley.com/



More information about the R-help mailing list