Skip to content

Commit

Permalink
Add vcov S3 method
Browse files Browse the repository at this point in the history
  • Loading branch information
jpritikin committed Sep 18, 2017
1 parent bd80b4c commit 7a12549
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ S3method(summary, MxModel)
S3method(anova, MxModel)
S3method(simulate, MxModel)
S3method(confint, MxModel)
S3method(vcov, MxModel)

# Export S3 .DollarNames functions
S3method(.DollarNames, MxModel) # MxModel has a unique .DollarNames function
Expand Down
17 changes: 17 additions & 0 deletions R/MxModel.R
Original file line number Diff line number Diff line change
Expand Up @@ -659,3 +659,20 @@ setMethod("imxVerifyModel", "MxModel",
return(TRUE)
}
)

vcov.MxModel <- function(model) {
fu <- model$output$fitUnits
if (fu == "-2lnL") {
if (!is.null(model$output[['ihessian']])) {
2 * model$output[['ihessian']]
} else if (!is.null(model$output[['hessian']])) {
2 * solve(model$output$hessian)
} else {
stop(paste("Parameter variance covariance matrix is not available.",
"Did you estimate the Hessian?"))
}
} else {
stop(paste("Don't know how to extract vcov from model",
omxQuotes(model$name), "fit in", omxQuotes(fu), "units"))
}
}

0 comments on commit 7a12549

Please sign in to comment.