diff --git a/R/ctModel.R b/R/ctModel.R index eb911cd..c201790 100644 --- a/R/ctModel.R +++ b/R/ctModel.R @@ -141,6 +141,8 @@ #' covariances are generated by ctFit. #' Better starting values may improve model fit speed and the chance of an appropriate model fit. #' +#' @param silent Suppress all output to console. +#' #' @examples #' ### Frequentist example: #' ### impulse and level change time dependent predictor @@ -176,7 +178,7 @@ #' @export ctModel<-function(LAMBDA, type='omx',n.manifest = 'auto', n.latent='auto', Tpoints=NULL, - manifestNames='auto', latentNames='auto', id='id',time='time', + manifestNames='auto', latentNames='auto', id='id',time='time', silent=FALSE, T0VAR="auto", T0MEANS="auto", MANIFESTMEANS="auto", MANIFESTVAR="auto", DRIFT="auto", CINT="auto", DIFFUSION="auto", n.TDpred='auto', TDpredNames='auto', @@ -194,12 +196,12 @@ ctModel<-function(LAMBDA, type='omx',n.manifest = 'auto', n.latent='auto', Tpoin #get dimensions if(is.null(n.manifest) || is.null(n.latent) || all(n.manifest %in% 'auto') || all(n.latent %in% 'auto')){ if(is.matrix(LAMBDA)){ - message('System dimensions inferred from LAMBDA') + if(!silent) message('System dimensions inferred from LAMBDA') n.manifest <- nrow(LAMBDA) n.latent <- ncol(LAMBDA) } else { if(!all(manifestNames %in% 'auto') && !all(latentNames %in% 'auto')){ - message('System dimensions inferred from manifestNames and latentNames') + if(!silent) message('System dimensions inferred from manifestNames and latentNames') n.manifest <- length(manifestNames) n.latent <- length(latentNames) } else stop('LAMBDA must either a matrix, n.manifest and n.latent must be specified, or manifestNames and latentNames must be specified!') @@ -208,11 +210,11 @@ ctModel<-function(LAMBDA, type='omx',n.manifest = 'auto', n.latent='auto', Tpoin if(is.null(n.TDpred) || all(n.TDpred %in% 'auto')){ if(is.matrix(TDPREDEFFECT)){ - message('n.TDpred inferred from TDPREDEFFECT') + if(!silent) message('n.TDpred inferred from TDPREDEFFECT') n.TDpred <- ncol(TDPREDEFFECT) } else { if(!all(TDpredNames %in% 'auto')){ - message('n.TDpred inferred inferred from TDpredNames') + if(!silent) message('n.TDpred inferred inferred from TDpredNames') n.TDpred <- length(TDpredNames) } else n.TDpred <- 0 } @@ -220,7 +222,7 @@ ctModel<-function(LAMBDA, type='omx',n.manifest = 'auto', n.latent='auto', Tpoin if(is.null(n.TIpred) || all(n.TIpred %in% 'auto')){ if(!all(TIpredNames %in% 'auto')){ - message('n.TIpred inferred inferred from TIpredNames') + if(!silent) message('n.TIpred inferred inferred from TIpredNames') n.TIpred <- length(TIpredNames) } else n.TIpred <- 0 } @@ -288,9 +290,9 @@ ctModel<-function(LAMBDA, type='omx',n.manifest = 'auto', n.latent='auto', Tpoin counter <- 0 #then start filling with vector if(length(val) != length(mat) && length(val) !=1) stop(paste0(m,' needs ',length(mat),' values for ',nrow(mat),' * ',ncol(mat),' matrix, but has ',length(val))) if(length(val)==1 && length(mat) > 1) { - message(m,' specified via single value -- filling ',nrow(mat),' * ',ncol(mat),' matrix:') + if(!silent) message(m,' specified via single value -- filling ',nrow(mat),' * ',ncol(mat),' matrix:') val <- rep(val,length(mat)) - } else message(paste0(m,' vector spec input rowwise into ',nrow(mat),' * ',ncol(mat),' matrix:')) + } else if(!silent) message(paste0(m,' vector spec input rowwise into ',nrow(mat),' * ',ncol(mat),' matrix:')) for(ri in 1:nrow(mat)){ for(ci in 1:ncol(mat)){ counter <- counter + 1 @@ -298,7 +300,7 @@ ctModel<-function(LAMBDA, type='omx',n.manifest = 'auto', n.latent='auto', Tpoin } } - print(mat,right=TRUE) + if(!silent) print(mat,right=TRUE) assign(m, mat) } } diff --git a/man/ctModel.Rd b/man/ctModel.Rd index 01c5e7f..330079f 100644 --- a/man/ctModel.Rd +++ b/man/ctModel.Rd @@ -14,6 +14,7 @@ ctModel( latentNames = "auto", id = "id", time = "time", + silent = FALSE, T0VAR = "auto", T0MEANS = "auto", MANIFESTMEANS = "auto", @@ -73,6 +74,8 @@ id data may be of any form, though will be coerced internally to an integer sequ \item{time}{character string denoting column name containing timing data. Timing data must be numeric.} +\item{silent}{Suppress all output to console.} + \item{T0VAR}{lower triangular n.latent*n.latent cholesky matrix of latent process initial variance / covariance. "auto" freely estimates all parameters.} diff --git a/tests/testthat/test-tdeffectvariation_covtest.R b/tests/testthat/test-tdeffectvariation_covtest.R index 4b33873..5df3afb 100644 --- a/tests/testthat/test-tdeffectvariation_covtest.R +++ b/tests/testthat/test-tdeffectvariation_covtest.R @@ -15,7 +15,7 @@ if(identical(Sys.getenv("NOT_CRAN"), "true")& .Machine$sizeof.pointer != 4){ effect <- rnorm(nsubjects, 5-baseline/3, 0.5) for(i in 1:nsubjects){ - gm <- suppressMessages(ctModel(Tpoints=ntimes, + gm <- suppressMessages(ctModel(silent=TRUE,Tpoints=ntimes, LAMBDA=matrix(c(1,0),1,2), DRIFT= c(-1,1, 0,-.5), @@ -33,7 +33,7 @@ if(identical(Sys.getenv("NOT_CRAN"), "true")& .Machine$sizeof.pointer != 4){ } #regular bw effect approach - m <- ctModel(type='stanct', + m <- ctModel(silent=TRUE,type='stanct', LAMBDA=matrix(c(1,0),1,2), DRIFT= c('drift',1, 0,-0.5), @@ -43,7 +43,7 @@ if(identical(Sys.getenv("NOT_CRAN"), "true")& .Machine$sizeof.pointer != 4){ TDPREDEFFECT = matrix(c(0,'tdpredeffect|param|TRUE'))) #manual bw effects - m2 <- ctModel(type='omx',Tpoints=3, + m2 <- ctModel(silent=TRUE,type='omx',Tpoints=3, LAMBDA=matrix(c(1,0,0,0),1,4), DRIFT= c('drift',1,0,0, 0,-0.5,0,0, @@ -143,7 +143,7 @@ if(identical(Sys.getenv("NOT_CRAN"), "true")& .Machine$sizeof.pointer != 4){ effect <- rnorm(nsubjects, 5-baseline/3, 0.5) for(i in 1:nsubjects){ - gm <- suppressMessages(ctModel(Tpoints=ntimes, + gm <- suppressMessages(ctModel(silent=TRUE,Tpoints=ntimes, LAMBDA=matrix(c(1,effect[i]),1,2), DRIFT= c(-1,0, 0,-.5), @@ -161,7 +161,7 @@ if(identical(Sys.getenv("NOT_CRAN"), "true")& .Machine$sizeof.pointer != 4){ } #regular bw effect approach - m <- ctModel(type='stanct', + m <- ctModel(silent=TRUE,type='stanct', LAMBDA=matrix(c(1,'tdpredeffect|param|TRUE'),1,2), DRIFT= c('drift',0, 0,-0.5), @@ -171,7 +171,7 @@ if(identical(Sys.getenv("NOT_CRAN"), "true")& .Machine$sizeof.pointer != 4){ TDPREDEFFECT = matrix(c(0,1))) #manual bw effects - m2 <- ctModel(type='omx',Tpoints=3, + m2 <- ctModel(silent=TRUE,type='omx',Tpoints=3, LAMBDA=matrix(c(1,'state[4]',0,0),1,4), DRIFT= c('drift',0,0,0, 0,-0.5,0,0, @@ -268,7 +268,7 @@ if(identical(Sys.getenv("NOT_CRAN"), "true")& .Machine$sizeof.pointer != 4){ effect <- -log1p(exp(-raweffect)) for(i in 1:nsubjects){ - gm <- suppressMessages(ctModel(Tpoints=ntimes, + gm <- suppressMessages(ctModel(silent=TRUE,Tpoints=ntimes, LAMBDA=matrix(1), DRIFT= c(effect[i]), T0MEANS = c(t0m[i]), @@ -283,12 +283,12 @@ if(identical(Sys.getenv("NOT_CRAN"), "true")& .Machine$sizeof.pointer != 4){ } #regular bw effect approach - m <- ctModel(type='stanct', + m <- ctModel(silent=TRUE,type='stanct', CINT='cint',MANIFESTMEANS=0, LAMBDA=matrix(1),DRIFT='drift|-log1p_exp(-param)|TRUE') #manual bw effects - m2 <- ctModel(type='omx',Tpoints=3, + m2 <- ctModel(silent=TRUE,type='omx',Tpoints=3, LAMBDA=matrix(c(1,0,0),ncol=3), DRIFT= c('-log1p_exp(-state[2])',0,0, 0,-1e-6,0, @@ -388,7 +388,7 @@ if(identical(Sys.getenv("NOT_CRAN"), "true")& .Machine$sizeof.pointer != 4){ effect <- log1p(exp(raweffect)) for(i in 1:nsubjects){ - gm <- suppressMessages(ctModel(Tpoints=ntimes, + gm <- suppressMessages(ctModel(silent=TRUE,Tpoints=ntimes, LAMBDA=matrix(1), DRIFT= -1, T0MEANS = c(t0m[i]), @@ -404,14 +404,14 @@ if(identical(Sys.getenv("NOT_CRAN"), "true")& .Machine$sizeof.pointer != 4){ } #regular bw effect approach - m <- ctModel(type='stanct', + m <- ctModel(silent=TRUE,type='stanct', T0MEANS='t0m|param', MANIFESTVAR=.5, MANIFESTMEANS=0,CINT='cint|param', LAMBDA=matrix(1),DIFFUSION='diffusion|log1p_exp(param)|TRUE') #manual bw effects - m2 <- ctModel(type='omx',Tpoints=3, + m2 <- ctModel(silent=TRUE,type='omx',Tpoints=3, LAMBDA=matrix(c(1,0,0),ncol=3), DRIFT= c('drift',0,0, 0,-1e-12,0, @@ -521,7 +521,7 @@ if(identical(Sys.getenv("NOT_CRAN"), "true")& .Machine$sizeof.pointer != 4){ effect <- log1p(exp(raweffect)) for(i in 1:nsubjects){ - gm <- suppressMessages(ctModel(Tpoints=ntimes, + gm <- suppressMessages(ctModel(silent=TRUE,Tpoints=ntimes, LAMBDA=matrix(1), DRIFT= -1, T0MEANS = c(t0m[i]), @@ -537,14 +537,14 @@ if(identical(Sys.getenv("NOT_CRAN"), "true")& .Machine$sizeof.pointer != 4){ } #regular bw effect approach - m <- ctModel(type='stanct', + m <- ctModel(silent=TRUE,type='stanct', T0MEANS='t0m|param', DIFFUSION=.5, MANIFESTMEANS=0,CINT='cint|param', LAMBDA=matrix(1),MANIFESTVAR='errsd|log1p_exp(param)|TRUE') #manual bw effects - m2 <- ctModel(type='omx',Tpoints=3, + m2 <- ctModel(silent=TRUE,type='omx',Tpoints=3, LAMBDA=matrix(c(1,0,0),ncol=3), DRIFT= c('drift',0,0, 0,-1e-12,0,