You are here

FIML estimation using Row Objective Specification

2 posts / 0 new
Last post
AN's picture
AN
Offline
Joined: 12/03/2011 - 13:51
FIML estimation using Row Objective Specification

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 <- .5
xy <- mvrnorm (1000, c(0,0), matrix(c(1, rs, rs, 1), nrow=2, ncol=2))

create a data frame

testData <- as.data.frame(xy)
testVars <- c('X','Y')
names(testData) <- testVars
summary(testData)
cov(testData)

model specification

bivCorModel <- mxModel(name="FIML BivCor",
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 <- mxModel(model=bivCorModel,
mxAlgebra(
expression=omxSelectRowsAndCols(expCov, existenceVector),
name="filteredExpCov",
),
mxAlgebra(
expression=omxSelectCols(expMean, existenceVector),
name="filteredExpMean",
)
)

row objective specification

bivCorModel <- mxModel(model=bivCorModel,
mxMatrix("Full", 1, 1, values = log(2pi), 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 <- mxRun(bivCorModel)

neale's picture
Offline
Joined: 07/31/2009 - 15:14
Correct, this script doesn't handle missing data

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!