New lgpr package and preprint: Longitudinal models using additive GPs

Bayesian longitudinal models using additive GPs including uncertainty in disease effect times and heterogeneous effects by @jtimonen, Henrik Mannerström, I and Harri Lähdesmäki.

lgpr package built on top of RStan at

Preprint at



A nice example of a R package created with the new version of rstantools. I would have liked to see unit tests of the Stan functions with rstan::expose_stan_functions. We do it in rstanarm at


Thanks for pointing out the tests of rstanarm @bgoodri. At some point I actually tried to include some stan functions into parts of the postprocessing functionality using rstan::expose_stan_functions, so that I could avoid code duplication (same function coded both in r and stan). However, I couldn’t get that to work without R CMD check warnings/notes, if I remember correctly. But I could try adding some unit tests following the rstanarm example.


1 Like

I have a branch for rstantools that somewhat facilitates having the user-defined Stan functions be C++ functions that are exported into the package’s namespace by the usual Rcpp mechanism. Except the usual Rcpp mechanism does not quite work so it requires some manual editing.

1 Like

Do you know what is causing this installation issue on Windows? I think the package has the default Makevars created by rstantools, so is the problem in the user’s personal toolchain?

1 Like

Do you think I can adapt his for longitudinal data for an ordinal response?

This is the model and I uploaded a simulated data. I want to estimate the effect of sev_h on bod for each individual over time(age). Similar to your paper, not every one experience the disease effect. I am not sure what family is suitable her. I was using cumulative. Thanks
phear<-get_prior( bodn~ sev_h+sex+age+sex*age+sev_h*age+sev_h*id,,family=???(),
  data =test_lgpr)

  formula = bodn~ sev_h+sex+age+sex*age+sev_h*age+sev_h*id,family=???(),
  data =test_lgpr,prior=phear, chains=5,cores=future::availableCores())

  ````[test_lgpr.csv|attachment](upload://jXQHtXMhAX03aeOcv8HizWSTjZj.csv) (3.0 KB)

I also have this problem on windows. Could you solve yours, if so, could you kindly guide how? Thanks

It would probably need some modifications. At least the thresholds would need to be added as additional parameters. But I don’t know what kind of likelihood to use for ordinal response. If you can explain the model that you want exactly, then I can possibly implement it.

1 Like

I never had any problems on Windows myself. Have you configured your toolchain using these instructions ? Can you post your sessionInfo()?

R version 3.6.2 (2019-12-12)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] parallel  stats4    stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] rstan_2.19.3         ggplot2_3.2.1        StanHeaders_2.21.0-1 S4Vectors_0.24.3    
[5] BiocGenerics_0.32.0 

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.3         pillar_1.4.3       compiler_3.6.2     remotes_2.1.1      prettyunits_1.1.1 
 [6] tools_3.6.2        testthat_2.3.1     pkgload_1.0.2      digest_0.6.25      pkgbuild_1.0.6    
[11] memoise_1.1.0      lifecycle_0.1.0    tibble_2.1.3       gtable_0.3.0       pkgconfig_2.0.3   
[16] rlang_0.4.4        cli_2.0.2          rstudioapi_0.11    curl_4.3           yaml_2.2.1        
[21] loo_2.2.0          gridExtra_2.3      withr_2.1.2        dplyr_0.8.4        fs_1.3.1          
[26] desc_1.2.0         devtools_2.2.2     rprojroot_1.3-2    grid_3.6.2         tidyselect_1.0.0  
[31] glue_1.3.1         inline_0.3.15      R6_2.4.1           processx_3.4.2     fansi_0.4.1       
[36] sessioninfo_1.1.1  purrr_0.3.3        callr_3.4.2        magrittr_1.5       usethis_1.5.1     
[41] backports_1.1.5    ellipsis_0.3.0     matrixStats_0.55.0 scales_1.1.0       ps_1.3.2          
[46] assertthat_0.2.1   colorspace_1.4-1   lazyeval_0.2.2     munsell_0.5.0      crayon_1.3.4 

I did follow the instruction. This is not lgpr package, I had the same issue with brms. I uninstalled Rtools, and when ran the program asked me to install the required packages and I clicked “yes”. But, every time it keeps asking that even after installing Rtool3.5. I have not been able to resolve this on windows, so far!

@avehtari, @jtimonen Do you think if i can apply the disease effect on an ordinal response in a longitudinal data?

I created a branch where I implemented the ordinal observation model using ordered_probit_lpmf. It is a quick initial version and I am not sure if is correct and at least needs some way of determining the noise proportion before it can be merged to master. Here is an example notebook how to use it with the current version:

And if this is correct, then yes you could use also the disease effect modeling for ordinal response. I can help better if you describe your data and the model that you want to have.

1 Like

Awsome! Thanks a lot. I use it and let you know . I tried to download lgpr but still because of Rtools have issues on my computer. I try to get it downloaded on virtual machine on Monday and will let you know the results. I want to be able to know in which individuals the disease levels does not affect the response (outcome). If I can distinguish this, it would be great.
I let you know. Thanks again.