From 2c4dba42745763b65a2838706c4d525023babb31 Mon Sep 17 00:00:00 2001 From: Ronald Garcia Date: Thu, 8 Dec 2022 10:04:50 +1300 Subject: [PATCH 1/4] replace as.character with deparse, as per pull request #285 Related pull request fix for issue with link not adding intercept for linear models #285 I'm having trouble using sim with models that have index variables. Some debug code is crashing, and I think this may fix it. --- R/sim.r | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/sim.r b/R/sim.r index 7948665..3739d40 100644 --- a/R/sim.r +++ b/R/sim.r @@ -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 From 3cd570d3e78cd33a4ad8fc94ed8fe5f7c8376e69 Mon Sep 17 00:00:00 2001 From: Ronald Garcia Date: Fri, 9 Dec 2022 10:01:51 +1300 Subject: [PATCH 2/4] produce appropriate data frame for n = 1 --- R/map-quap-class.r | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/R/map-quap-class.r b/R/map-quap-class.r index f05525a..0c2b787 100644 --- a/R/map-quap-class.r +++ b/R/map-quap-class.r @@ -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( matrix( mvrnorm( n=n , mu=mu , Sigma=vcov(object) ), ncol=length(mu) ) ) + } 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) ) { From e270793eae63c010fce0e7228b78bd406618cf9a Mon Sep 17 00:00:00 2001 From: Ronald Garcia Date: Fri, 9 Dec 2022 10:07:44 +1300 Subject: [PATCH 3/4] produce appropriate data frame for n=1 --- R/map-quap-class.r | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/R/map-quap-class.r b/R/map-quap-class.r index 0c2b787..63b10b6 100644 --- a/R/map-quap-class.r +++ b/R/map-quap-class.r @@ -116,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( matrix( mvrnorm( n=n , mu=mu , Sigma=vcov(object) ), ncol=length(mu) ) ) + } 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] From 7874b77f3a89b8a84914a18f93cc185e10412ddb Mon Sep 17 00:00:00 2001 From: Ronald Garcia Date: Fri, 9 Dec 2022 10:59:08 +1300 Subject: [PATCH 4/4] Use t to transpose --- R/map-quap-class.r | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/map-quap-class.r b/R/map-quap-class.r index 63b10b6..3b0b1de 100644 --- a/R/map-quap-class.r +++ b/R/map-quap-class.r @@ -96,7 +96,7 @@ function( object , n=10000 , clean=TRUE , ... ) { mu <- xcoef(object) } if ( n==1 ) { - result <- as.data.frame( matrix( mvrnorm( n=n , mu=mu , Sigma=vcov(object) ), ncol=length(mu) ) ) + 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) ) ) } @@ -117,7 +117,7 @@ function(object,n=1e4,...){ # require(MASS) # import now, so no need to require? mu <- object@coef if ( n==1 ) { - result <- as.data.frame( matrix( mvrnorm( n=n , mu=mu , Sigma=vcov(object) ), ncol=length(mu) ) ) + 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) ) ) }