Sorry for posting this again.

I am trying to adapt the sample script on FIML estimation for missing data. In the script below (from OpenMx documentation) how do I change the component of the "firstHalfCalc" expression of the likelihood function (log2pi %*% 2) to represent the number of variables that has nonmissing data for that observation? Will the sample code work for all situations without modification?

Sorry if this is a silly question. I am quite new to OpenMx.

#simulate data

require(MASS)

set.seed(200)

rs
xy

#create a data frame

testData
testVars
names(testData)
summary(testData)

cov(testData)

#model specification

bivCorModel
mxData(

observed=testData,

type="raw",

),

mxMatrix(

type="Full",

nrow=1,

ncol=2,

free=TRUE,

values=c(0,0),

name="expMean"

),

mxMatrix(

type="Lower",

nrow=2,

ncol=2,

free=TRUE,

values=.2,

name="Chol"

),

mxAlgebra(

expression=Chol %*% t(Chol),

name="expCov",

)

)

#filtering

bivCorModel
mxAlgebra(

expression=omxSelectRowsAndCols(expCov, existenceVector),

name="filteredExpCov",

),

mxAlgebra(

expression=omxSelectCols(expMean, existenceVector),

name="filteredExpMean",

)

)

#row objective specification

bivCorModel
mxMatrix("Full", 1, 1, values = log(2*pi), name = "log2pi"),

mxAlgebra(

expression=log2pi %*% 2 + log(det(filteredExpCov)),

name ="firstHalfCalc",

),

mxAlgebra(

expression=(filteredDataRow - filteredExpMean) %&% solve(filteredExpCov) ,

name = "secondHalfCalc",

),

mxAlgebra(

expression=(firstHalfCalc + secondHalfCalc),

name="rowAlgebra",

),

mxAlgebra(

expression=sum(rowResults),

name = "reduceAlgebra",

),

mxRowObjective(

rowAlgebra='rowAlgebra',

reduceAlgebra='reduceAlgebra',

dimnames=c('X','Y'),

)

)

#model fitting

bivCorFit

There is an updated script in the repository which uses the sum of the existenceVector so that the number of variables is correctly used for the likelihood.

http://openmx.psyc.virginia.edu/repoview/1/trunk/demo/RowObjectiveFIMLBivariateSaturated.R

However, I would point out that multivariate normal FIML - for continuous, ordinal or binary variables, or any combination thereof, is much more easily accomplished using, e.g.,

mxFIMLObjective(covariance="myModelCovs", means="myMeanMatrix", dimnames = myVarNames, thresholds="myThresholdMatrix")

Sorry for delay in response!