# summary(MxModel) object

4 posts / 0 new
Offline
Joined: 10/19/2009 - 15:38
summary(MxModel) object

trying to put OpenMxGUI into a package, i ran into a problem with the object from summary(MxModel). for some reason, the object is of class "summary.mxmodel" when all of OpenMxGUI is input using source(). in the package, however, the object is of class "table."

this is what i get when i read in the code using "source" and run the model:
> head(summary(thisOMxModel)$parameters) name matrix row col Estimate Std.Error 1 sqrtStdE 1 1 1.9426018 0.05663194 2 sqrtStdE 2 2 2.1226024 0.08699889 3 sqrtStdE 3 3 1.8922519 0.06716601 4 sqrtStdE 4 4 2.1911936 0.05992282 5 sqrtStdE 5 5 1.9405663 0.05366479 6 RE 1 2 0.4240149 0.05843882 > test <- summary(thisOMxModel) > class(test) [1] "summary.mxmodel" > getClass("summary.mxmodel") Error in getClass("summary.mxmodel") : "summary.mxmodel" is not a defined class this is what i get when the following code is executed in a package: CODE: x <- summary(thisOMxModel)$parameters
testProj <<- summary(thisOMxModel)
classTestProj <<- class(testProj)
RESULTS:
Error in summary(thisOMxModel)$parameters :$ operator is invalid for atomic vectors
> classTestProj
[1] "table"
> testProj
Length Class Mode
1 MxModel S4
>

in the NAMESPACE file for OpenMx, "summary.mxmodel" is treated as an S3 method. the package seems to be treating it as S4. anything funky here?

greg

Offline
Joined: 07/31/2009 - 15:24
summary() on MxModel returns

summary() on MxModel returns an S3 object with class "summary.mxmodel". I'm not sure why it is yielding an S4 object in your query. You could try explicitly giving the object the S3 class "summary.mxmodel" with the statement class(x) <- "summary.mxmodel".

Offline
Joined: 10/19/2009 - 15:38
thanks, mike i am unsure

thanks, mike
i am unsure whether i followed your suggestion correctly. here is the function giving the problem (non-indented code used here for illustration):

# --- omxGUIgetParms: create a data.frame from the parameters
omxGUIgetParms <- function() {
x <- summary(thisOMxModel)
outx1 <<- x
class(x) <- "summary.mxmodel"
outx2 <<- x
num <- which(names(x) == "parameters")
parms <- as.data.frame(x[num])
colnames(parms) <- gsub("parameters.", "", colnames(parms))
outparms <<- parms
return(parms)
}

> class(outx1)
[1] "summary.mxmodel"
> outx1
data:
$MZ.data$MZ.data$cov English1 Math1 SocSci1 NatSci1 Vocab1 English2 Math2 English1 22.5236 16.0187 14.8236 15.5180 15.6883 17.0398 14.5703 Math1 16.0187 39.0364 19.0094 23.9329 16.8449 14.5703 29.0442 SocSci1 14.8236 19.0094 23.8313 18.6608 18.4180 13.6112 17.5001 NatSci1 15.5180 23.9329 18.6608 33.5830 16.1748 14.8395 21.9457 Vocab1 15.6883 16.8449 18.4180 16.1748 24.1408 14.1761 15.6345 ETC. > class(outx2) [1] "summary.mxmodel" > outx2 data:$MZ.data
$MZ.data$cov
English1 Math1 SocSci1 NatSci1 Vocab1 English2 Math2
English1 22.5236 16.0187 14.8236 15.5180 15.6883 17.0398 14.5703
Math1 16.0187 39.0364 19.0094 23.9329 16.8449 14.5703 29.0442
SocSci1 14.8236 19.0094 23.8313 18.6608 18.4180 13.6112 17.5001
NatSci1 15.5180 23.9329 18.6608 33.5830 16.1748 14.8395 21.9457
Vocab1 15.6883 16.8449 18.4180 16.1748 24.1408 14.1761 15.6345
ETC.
> class(outparms)
[1] "data.frame"
name matrix row col Estimate Std.Error
1 VA 1 1 7.116811 1.523642
2 VA 1 2 8.819272 1.684875
3 VA 2 2 20.328838 3.189467
4 VA 1 3 7.075928 1.266004
5 VA 2 3 9.636136 1.809873
6 VA 3 3 11.228362 1.734959
SEE attached figure Parms1.tiff

WHEN EXECUTED AFTER: R CMD INSTALL OpenMxGUI
> class(outx1)
[1] "table"
> outx1
Length Class Mode
1 MxModel S4
> class(outx2)
[1] "summary.mxmodel"
> outx2
Error in x$dataSummary :$ operator is invalid for atomic vectors
> class(outparms)
[1] "data.frame"
> outparms
[1] x[num]
<0 rows> (or 0-length row.names)
>
SEE attached figure Parms2.tiff

R CMD INSTALL --help gives no solace. can't find any specific switches for S3 classes.

its weird that the packaged version still gives the correct gradient (see figures).

greg

Offline
Joined: 10/19/2009 - 15:38
think i've got it

(1) swore that i had posted a reply earlier today from work, but do not see it now.
(2) anyway, adding "import(OpenMx)" to the NAMESPACE file rectified the problem on both my work computer and my home one.
(3) suggest that in any documentation about folks writing R packages that will use/extend OpenMx, you include a statement that the user may have to add an explicit statement "import(OpenMx)" to the NAMESPACE and not rely solely on the "depends" conventions for interfacing with OpenMx.
hope this helps,
greg