# New lgpr package and preprint: Longitudinal models using additive GPs

**URL:** <https://discourse.mc-stan.org/t/new-lgpr-package-and-preprint-longitudinal-models-using-additive-gps/12246>\
**Category:** Publicity\
**Created:** [December 10, 2019, 2:30pm UTC](https://discourse.mc-stan.org/t/new-lgpr-package-and-preprint-longitudinal-models-using-additive-gps/12246 "2019-12-10T14:30:01Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![avehtari](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/avehtari/32/5935_2.png) [@avehtari](https://discourse.mc-stan.org/u/avehtari)\
**Post date:** [December 10, 2019, 2:30pm UTC](https://discourse.mc-stan.org/t/new-lgpr-package-and-preprint-longitudinal-models-using-additive-gps/12246/1 "2019-12-10T14:30:01Z")

</div>

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 [https://jtimonen.github.io/lgpr-usage/index.html](https://jtimonen.github.io/lgpr-usage/index.html)

Preprint at [https://arxiv.org/abs/1912.03549](https://arxiv.org/abs/1912.03549)

![ELau9O6W4AEQeHB](https://canada1.discourse-cdn.com/flex030/uploads/mc_stan/original/2X/9/955070ccc48d3abe595c286f2379916ba65a36da.jpeg)

---

<div class="post-metadata">

**Author:** ![bgoodri](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bgoodri/32/4451_2.png) [@bgoodri](https://discourse.mc-stan.org/u/bgoodri)\
**Post date:** [December 10, 2019, 4:44pm UTC](https://discourse.mc-stan.org/t/new-lgpr-package-and-preprint-longitudinal-models-using-additive-gps/12246/2 "2019-12-10T16:44:47Z")

</div>

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

> <https://github.com/stan-dev/rstanarm/blob/master/tests/testthat/test_stan_functions.R#L60>

---

<div class="post-metadata">

**Author:** ![jtimonen](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/jtimonen/32/9034_2.png) [@jtimonen](https://discourse.mc-stan.org/u/jtimonen)\
**Post date:** [December 10, 2019, 7:29pm UTC](https://discourse.mc-stan.org/t/new-lgpr-package-and-preprint-longitudinal-models-using-additive-gps/12246/3 "2019-12-10T19:29:02Z")

</div>

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.

-Juho

---

<div class="post-metadata">

**Author:** ![bgoodri](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bgoodri/32/4451_2.png) [@bgoodri](https://discourse.mc-stan.org/u/bgoodri)\
**Post date:** [December 10, 2019, 7:33pm UTC](https://discourse.mc-stan.org/t/new-lgpr-package-and-preprint-longitudinal-models-using-additive-gps/12246/4 "2019-12-10T19:33:08Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jtimonen](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/jtimonen/32/9034_2.png) [@jtimonen](https://discourse.mc-stan.org/u/jtimonen)\
**Post date:** [December 16, 2019, 11:24am UTC](https://discourse.mc-stan.org/t/new-lgpr-package-and-preprint-longitudinal-models-using-additive-gps/12246/5 "2019-12-16T11:24:28Z")

</div>

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?

> <https://github.com/jtimonen/lgpr/issues/1>
>
> I am using R 3.6.1 and Rtools 3.5 (latest version, reinstalled it today) but cannot compile, seems to be some kind...

---

<div class="post-metadata">

**Author:** ![ssalimi](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/ssalimi/32/7119_2.png) [@ssalimi](https://discourse.mc-stan.org/u/ssalimi)\
**Post date:** [March 6, 2020, 10:30pm UTC](https://discourse.mc-stan.org/t/new-lgpr-package-and-preprint-longitudinal-models-using-additive-gps/12246/6 "2020-03-06T22:30:56Z")

</div>

> [@avehtari](#):
>
> > [@avehtari](#):
> >
> > 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.

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

> [@jtimonen](#):
>
> 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.

`````no-highlight
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)

fit_hearing1<-brm(
  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)
`````

---

<div class="post-metadata">

**Author:** ![ssalimi](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/ssalimi/32/7119_2.png) [@ssalimi](https://discourse.mc-stan.org/u/ssalimi)\
**Post date:** [March 6, 2020, 10:36pm UTC](https://discourse.mc-stan.org/t/new-lgpr-package-and-preprint-longitudinal-models-using-additive-gps/12246/7 "2020-03-06T22:36:30Z")

</div>

> [@jtimonen](#):
>
> 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?
> 
> [github.com/jtimonen/lgpr](https://github.com/jtimonen/lgpr/issues/1)

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

---

<div class="post-metadata">

**Author:** ![jtimonen](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/jtimonen/32/9034_2.png) [@jtimonen](https://discourse.mc-stan.org/u/jtimonen)\
**Post date:** [March 6, 2020, 11:38pm UTC](https://discourse.mc-stan.org/t/new-lgpr-package-and-preprint-longitudinal-models-using-additive-gps/12246/8 "2020-03-06T23:38:11Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jtimonen](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/jtimonen/32/9034_2.png) [@jtimonen](https://discourse.mc-stan.org/u/jtimonen)\
**Post date:** [March 6, 2020, 11:41pm UTC](https://discourse.mc-stan.org/t/new-lgpr-package-and-preprint-longitudinal-models-using-additive-gps/12246/9 "2020-03-06T23:41:09Z")

</div>

I never had any problems on Windows myself. Have you configured your toolchain using these instructions [https://github.com/stan-dev/rstan/wiki/Installing-RStan-from-source-on-Windows#configuration](https://github.com/stan-dev/rstan/wiki/Installing-RStan-from-source-on-Windows#configuration) ? Can you post your `sessionInfo()`?

---

<div class="post-metadata">

**Author:** ![ssalimi](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/ssalimi/32/7119_2.png) [@ssalimi](https://discourse.mc-stan.org/u/ssalimi)\
**Post date:** [March 6, 2020, 11:45pm UTC](https://discourse.mc-stan.org/t/new-lgpr-package-and-preprint-longitudinal-models-using-additive-gps/12246/10 "2020-03-06T23:45:47Z")

</div>

> [@jtimonen](#):
>
> 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.

```no-highlight
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

locale:
[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 

```

---

<div class="post-metadata">

**Author:** ![ssalimi](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/ssalimi/32/7119_2.png) [@ssalimi](https://discourse.mc-stan.org/u/ssalimi)\
**Post date:** [March 6, 2020, 11:52pm UTC](https://discourse.mc-stan.org/t/new-lgpr-package-and-preprint-longitudinal-models-using-additive-gps/12246/11 "2020-03-06T23:52:58Z")

</div>

> [@jtimonen](#):
>
> I never had any problems on Windows myself. Have you configured your toolchain using these instructions [Home · stan-dev/rstan Wiki · GitHub](https://github.com/stan-dev/rstan/wiki/Installing-RStan-from-source-on-Windows#configuration)

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!

---

<div class="post-metadata">

**Author:** ![ssalimi](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/ssalimi/32/7119_2.png) [@ssalimi](https://discourse.mc-stan.org/u/ssalimi)\
**Post date:** [March 7, 2020, 12:13am UTC](https://discourse.mc-stan.org/t/new-lgpr-package-and-preprint-longitudinal-models-using-additive-gps/12246/12 "2020-03-07T00:13:10Z")

</div>

> [@avehtari](#):
>
> lgpr package built on top of RStan at [Longitudinal Gaussian Process Regression • lgpr](https://jtimonen.github.io/lgpr-usage/index.html)
> 
> Preprint at [[1912.03549] lgpr: An interpretable nonparametric method for inferring covariate effects from longitudinal data](https://arxiv.org/abs/1912.03549)

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

---

<div class="post-metadata">

**Author:** ![jtimonen](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/jtimonen/32/9034_2.png) [@jtimonen](https://discourse.mc-stan.org/u/jtimonen)\
**Post date:** [March 8, 2020, 3:19am UTC](https://discourse.mc-stan.org/t/new-lgpr-package-and-preprint-longitudinal-models-using-additive-gps/12246/13 "2020-03-08T03:19:24Z")

</div>

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:

[https://jtimonen.github.io/lgpr-usage/ordinal.html](https://jtimonen.github.io/lgpr-usage/ordinal.html)

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.

---

<div class="post-metadata">

**Author:** ![ssalimi](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/ssalimi/32/7119_2.png) [@ssalimi](https://discourse.mc-stan.org/u/ssalimi)\
**Post date:** [March 8, 2020, 3:26am UTC](https://discourse.mc-stan.org/t/new-lgpr-package-and-preprint-longitudinal-models-using-additive-gps/12246/14 "2020-03-08T03:26:13Z")

</div>

> [@jtimonen](#):
>
> 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:
> 
> [https://jtimonen.github.io/lgpr-usage/ordinal.html](https://jtimonen.github.io/lgpr-usage/ordinal.html)
> 
> 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.

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.
