# NOT RUN {
library(OpenMx)
# make a unit-weighted 10-row data set of values 1 thru 10
myData = mxData(data.frame(weight=1.0, value=1:10), "raw", weight = "weight")
sum(1:10)
# Model sums data$value (sum(1:10)= 55), subtracts "A", squares the result,
# and tries to minimize this (achieved by setting A=55)
testModel = mxModel(model = "testModel1", myData,
mxMatrix(name = "A", "Full", nrow = 1, ncol = 1, values = 1, free=TRUE),
# nb: filteredDataRow is an auto-generated matrix of
# non-missing data from the present row.
# This is placed into the "rowResults" matrix (also auto-generated)
mxAlgebra(name = "rowAlg", data.weight * filteredDataRow),
# Algebra to turn the rowResults into a single number
mxAlgebra(name = "reduceAlg", (sum(rowResults) - A)^2),
mxFitFunctionRow(
rowAlgebra = "rowAlg",
reduceAlgebra = "reduceAlg",
dimnames = "value"
)
# no need for an MxExpectation object when using mxFitFunctionRow
)
testModel = mxRun(testModel) # A is estimated at 55, with SE= 1
testBoot = mxBootstrap(testModel)
summary(testBoot) # A is estimated at 55, with SE= 0
# Let's compute A^2 (55^2 = 3025)
mxBootstrapEval(A^2, testBoot)
# SE 25.0% 75.0%
# [1,] 0 3025 3025
# }
Run the code above in your browser using DataLab