Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debug diagnostic in sim_core signals error when model uses index variables #370

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions R/map-quap-class.r
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@ function( object , n=10000 , clean=TRUE , ... ) {
} else {
mu <- xcoef(object)
}
result <- as.data.frame( mvrnorm( n=n , mu=mu , Sigma=vcov(object) ) )
if ( n==1 ) {
result <- as.data.frame( t( mvrnorm( n=n , mu=mu , Sigma=vcov(object) ) ) )
} else {
result <- as.data.frame( mvrnorm( n=n , mu=mu , Sigma=vcov(object) ) )
}
if ( clean==TRUE ) {
# convert (Intercept) to Intercept
for ( i in 1:ncol(result) ) {
Expand All @@ -112,7 +116,11 @@ setMethod("extract.samples", "map",
function(object,n=1e4,...){
# require(MASS) # import now, so no need to require?
mu <- object@coef
result <- as.data.frame( mvrnorm( n=n , mu=mu , Sigma=vcov(object) ) )
if ( n==1 ) {
result <- as.data.frame( t( mvrnorm( n=n , mu=mu , Sigma=vcov(object) ) ) )
} else {
result <- as.data.frame( mvrnorm( n=n , mu=mu , Sigma=vcov(object) ) )
}
# convert vector parameters to vectors in list
veclist <- attr(object,"veclist")
name_head <- function(aname) strsplit( aname , "[" , fixed=TRUE )[[1]][1]
Expand Down
2 changes: 1 addition & 1 deletion R/sim.r
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ sim_core <- function( fit , data , post , vars , n , refresh=0 , replace=list()
f <- fit@formula[[1]]
for ( i in 1:length(fit@formula) ) {
f <- fit@formula[[i]]
left <- as.character( f[[2]] )
left <- deparse( f[[2]] )
if ( left==var ) {
if ( debug==TRUE ) print(f)
break
Expand Down