cdriveraus / ctsem Goto Github PK
View Code? Open in Web Editor NEWHierarchical continuous time state space modelling
Hierarchical continuous time state space modelling
Hello,
I get this error, I am not sure what could be causing it.
> stan_checkdivergences(tabi_res$fit)
Error in [email protected]$stan_fit_instance$unconstrain_pars(pars) :
mismatch in number dimensions declared and found in context; processing stage=initialization; variable name=non_sparse_sigma; dims declared=(1); dims found=()
Hello,
The in-text citations of the manual on CRAN seem to be broken or at the very least, they're certainly going out of bounds.
Hello,
It seems like page 7 of your Hierarchical Manual https://cran.r-project.org/web/packages/ctsem/vignettes/hierarchicalmanual.pdf has its equations going past the margins.
Cheers,
Michael
Hi Charlie. I noticed when I try to plot a ctStanFit
object i get an error when attempting to plot the posterior densities:
Plotting posterior density estimates using stan_dens; Error in .mode_check(object) : is.stanfit(object) is not TRUE
Running rstan::stan_dens(object$stanfit)
returns the same error message. However, running rstan::stan_dens(object$stanfit$stanfit)
is successful. Perhaps a typo on lines 97 and 100 of plot.ctStanFit.R
, because i see the second level stanfit
object is called for the trace plots.
I'm running ctsem 3.5.3, rstan 2.21.2 and StanHeaders 2.21.0-7 on:
R version 4.0.3 (2020-10-10)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.04.5 LTS
R 3.4.4
OS Ubuntu 16.04.4 64 bits
I tried to update ctsem from 2.5.0 to 2.6.4 and got these errors
* installing *source* package ‘ctsem’ ...
** package ‘ctsem’ successfully unpacked and MD5 sums checked
** libs
"/usr/lib/R/bin/Rscript" -e "source(file.path('..', 'tools', 'make_cc.R')); make_cc(commandArgs(TRUE))" stan_files/ctsm.stan
Error in file(filename, "r", encoding = encoding) :
cannot open the connection
Calls: source -> file
In addition: Warning message:
In file(filename, "r", encoding = encoding) :
cannot open file '../tools/make_cc.R': No such file or directory
Execution halted
Makevars:17: recipe for target 'stan_files/ctsm.cc' failed
make: *** [stan_files/ctsm.cc] Error 1
ERROR: compilation failed for package ‘ctsem’
* removing ‘/usr/lib/R/library/ctsem’
* restoring previous ‘/usr/lib/R/library/ctsem’
The downloaded source packages are in
‘/tmp/RtmpmAN7Mp/downloaded_packages’
Updating HTML index of packages in '.Library'
Making 'packages.html' ... done
Warning message:
In install.packages(update[instlib == l, "Package"], l, contriburl = contriburl, :
installation of package ‘ctsem’ had non-zero exit status
Please advise
Thanks.
I am running ctStanFit to receive a Bayesian estimation via Stan’s NUTS sampler. An error message is infinite loop printing while doing so. This doesn’t seem to be interfering with the underlying computation as the function appears to run to completion (albeit probably slower). The error is
sh: findstr: command not found
From a quick search of the codebase, there doesn't appear to be many instances of the findstr
function. Just here and here.
As brought up by Jonah here, the below code does NOT produce the same error pattern
library(rstan)
code <- "
parameters {
real x;
}
model {
x ~ normal(0, 1);
}
"
fit <- stan(model_code = code)
Any help is appreciated. Thanks in advance!
data("ctExample1TIpred")
tipredmodel <- ctModel(n.manifest = 2, n.latent = 2, n.TIpred = 1,
manifestNames = c("LeisureTime", "Happiness"),
latentNames = c("LeisureTime", "Happiness"),
TIpredNames = "NumFriends", Tpoints = 6, LAMBDA = diag(2),
TRAITVAR = "auto")
tipredfit <- ctFit(dat = ctExample1TIpred, ctmodelobj = tipredmodel)
summary(tipredfit, verbose = TRUE)["addedTIPREDVAR"]
How can I see the p value in the output?
I'm trying to plot specific subjects DRIFT matrix, however when specifying any integer in the subjects
argument, this error is produced:
Error in if ("all" %in% subjects || dim(e[[matname]])[2] == 1) { :
missing value where TRUE / FALSE is required
I've noticed that the corresponding conditional part of the script is made to change the names of the object e
from "DRIFT" to "pop_DRIFT" and so on:
for (matname in c("DRIFT", "DIFFUSIONcov", "asymDIFFUSION")) {
if ("all" %in% subjects || dim(e[[matname]])[2] == 1) {
ctpars[[matname]] <- e[[paste0("pop_", matname)]]
}
I think this error is due to an uptade of ctExtract
which does not give names such as "DRIFT" anymore but now directly give "pop_DIRFT", etc... I think the error might be resolved easily by modfying the script accordingly:
for (matname in c("pop_DRIFT", "pop_DIFFUSIONcov", "pop_asymDIFFUSION"))
Then deleting the first conditional part that is not usefull anymore.
Did I guessed rigth?
Hi Charles,
After updating, I think there is an issue with ctKalmain().
I think the error is here:
subjects <- idmap[which(idmap[, 1] %in% subjects), 2]
because it returns an empty vector.
Not 100% sure that is the cause, but am unable to run some code from the previous version.
Thank you!
In sgd.R
line 130 you have a browser call if(any(is.na(newpars))) browser()
. I can imagine this is helpful when debugging, or possibly when running a single model at a time to investigate what parameter is being sampled incorrectly. But this is problematic when running simulations because it stops the simulation run entirely when the browser call is activated. It is probably better to replace this with a stop()
call and informative error message. Alternatively you could make debugging
with browser an option which you can feed to ctStanFit (and then stanoptimis), e.g. if(any(is.na(newpars))){ if(isTRUE(debugging) browser() else stop()}
This is a minor issue, but the i386 (32-bit) builds fail on Launchpad for Ubuntu. The amd64 (64-bit) build fine, which is very rare. Here is the error:
make[1]: Entering directory '/<>/src'
"/usr/lib/R/bin/Rscript" -e "source(file.path('..', 'tools', 'make_cc.R')); make_cc(commandArgs(TRUE))" stan_files/ctsm.stan
Error in file(con, "r") : invalid 'description' argument
Calls: make_cc -> cat -> readLines -> file
Execution halted
Makevars:18: recipe for target 'stan_files/ctsm.cc' failed
make[1]: *** [stan_files/ctsm.cc] Error 1
make[1]: Leaving directory '/<>/src'
make[1]: Entering directory '/<>/src'
make[1]: Leaving directory '/<>/src'
ERROR: compilation failed for package ‘ctsem’
Full buildlog can be found here:
https://launchpadlibrarian.net/436747358/buildlog_ubuntu-bionic-i386.ctsem_3.0.0-1cran1ppabionic0_BUILDING.txt.gz
If you call
source("https://raw.githubusercontent.com/stan-dev/rstan/develop/StanHeaders/install-github.R")
install_StanHeaders(math_branch = "StanHeaders_2.21", library_branch = "StanHeaders_2.21")
under r-devel to install the next StanHeaders and then try to install ctsem, I get
installing to /home/ben/stan-dev/rstan/StanHeaders/revdep/checks/ctsem/new/ctsem.Rcheck/00LOCK-ctsem/00new/ctsem/libs
** R
** data
*** moving datasets to lazyload DB
*** caught segfault ***
address 0x3cb4e2, cause 'memory not mapped'
which I believe is due to ctstantestfit.rda
containing a stanfit
object that was compiled with StanHeaders 2.19.x . Although the R structure of a stanfit
object is not changing, the C++ representation of it is, which gets auto-loaded through the Rcpp Module mechanism.
The way in which we have avoided having such .rda objects in rstanarm is to have a .R file that comes early alphabetically whose example creates a fit object quickly:
https://github.com/stan-dev/rstanarm/blob/master/R/doc-example_model.R#L35
and then .R files that come later in the alphabet can have examples that first test whether it is there
https://github.com/stan-dev/rstanarm/blob/master/R/loo-prediction.R#L36
and, if not, first call the previous example. This way, when you run R CMD check runs the examples you get 10 seconds of CPU time to create the example and then the object persists for subsequent examples.
Another way of doing it would be to generate static CSV files with the posterior draws by specifying the sample_file
argument to sampling
and then dynamically create the stanfit object by calling rstan::read_stan_csv
. That way the Rcpp Module thing should be avoided, although some Stan functions like get_num_upars
might not work.
Let me know if neither of those seem acceptable, but getting a new StanHeaders onto CRAN now that 2.23 has been released and R 4.0 is about to be released is a big priority. Packages like ctsem can benefit a lot from the post-2.19 mechanism of compiling the base class into rstan (less RAM, and you should be able to bring back 32 bit Windows) as well as things like reduce_sum
.
This line
https://github.com/cdriveraus/ctsem/blob/master/R/ctStanFit.R#L1049
causes R CMD check --as-cran
to fail because it forks as many times as there are cores on the machine. It should say cores = min(chains, parallel::detectCores())
.
More generally, we have a bunch of recommendations for R packages that use Stan at
https://cran.r-project.org/web/packages/rstantools/vignettes/developer-guidelines.html
In particular, it would be much better if you converted the writemodel
function into a .stan file or .stan files with branching logic that were compiled when the package is built on CRAN.
Hi Charlie,
Noticed an issue when using ctStanSubjectPars(..., pointest = FALSE) to extract posterior draws of subject-specific parameters. I've fit the model in a seperate session, and receive the error
Error in stan_unconstrainsamples(object$stanfit$stanfit) : stanfit object must be reinitialized but no data is provided
I've tracked the issue down. ctStanSubjectPars()
calls ctExtract()
(line 36 summary.ctStanFit.R
)
tfp <- ctExtract(fit,subjectMatrices = TRUE,cores=cores,nsamples=nsamples)
ctExtract()
then calls stan_unconstrainsamples()
(line 32 extract.ctStanFit.R
)
samps <- t(stan_unconstrainsamples(object$stanfit$stanfit))
The problem is that stan_unconstrainsamples() should also specify a standata
argument. I could get the function call to work properly by changing the above line to
samps <- t(stan_unconstrainsamples(object$stanfit$stanfit, standata = object$standata))
I think that should resolve the issue, but I'm not totally clear on what the different uses are for stan_constrainsamples
and stan_unconstrainsamples
In cFit
it looks like you are hardcoding
idcol='id'
obsTpoints=max(unlist(lapply(unique(dat[,idcol]),function(x)
length(dat[dat[,idcol]==x, idcol]) )))
But the user specifies that in the model function so I think you can just make it
idcol <- ctmodelobj$id
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.