Learn R Programming

lgpr

R-package for interpretable nonparametric modeling of longitudinal data using additive Gaussian processes. Contains functionality for inferring covariate effects and assessing covariate relevances. Various models can be specified using a convenient formula syntax.

[!NOTE] Using this package is computationally viable if your data set has maybe less than 300 observations. But the much more scalable lgpr2 package has been released! It is much faster but unfortunately doesn't have all the special modeling features included in this package.

Getting started

See overview, tutorials, vignettes and documentation at https://jtimonen.github.io/lgpr-usage/index.html.

Requirements

  • The package should work on all major operating systems.
  • R 3.4 or later is required, R 4.2 or later is recommended

Installing from CRAN

  • The latest released version that is available from CRAN can be installed simply via
install.packages("lgpr")

Installing from CRAN is probably the easiest option since they might have binaries for your system (so no need to build the package from source yourself).

Installing from source

  • The latest released version (which might not be in CRAN yet) can be installed via
install.packages('devtools') # if you don't have devtools already
devtools::install_github('jtimonen/lgpr', build_vignettes = TRUE)
  • The latest development version can be installed via
devtools::install_github('jtimonen/lgpr', ref = "develop")

Github installations are source installations (they require a C++ compiler).

  • If you have trouble installing the dependency rstan, see these instructions
  • Installing from source requires that you have your toolchain setup properly.

See the instructions for:

Using R < 4.2

If you are using R version 4.1 or earlier, you can get an error

cc1plus.exe: out of memory allocating 65536 bytes
make: *** [C:/PROGRA~1/R/R-40~1.2/etc/i386/Makeconf:227: stanExports_lgp_latent.o] Error 1

because both 64-bit and 32-bit versions of the package are getting installed. To disable this and resolve error, ugrade to latest R or install the version that has Biarch: false by

devtools::install_github('jtimonen/lgpr', ref = "no-biarch")

Real data and reproducing the experiments

For code to reproduce the experiments of our manuscript see https://github.com/jtimonen/lgpr-usage. Preprocessed longitudinal proteomics data is also provided there. See also the built-in read_proteomics_data() function.

Copy Link

Version

Install

install.packages('lgpr')

Monthly Downloads

220

Version

1.2.5

License

GPL (>= 3)

Issues

Pull Requests

Stars

Forks

Maintainer

Juho Timonen

Last Published

October 30th, 2025

Functions in lgpr (1.2.5)

lgpfit-class

An S4 class to represent the output of the lgp function
fit_summary

Print a fit summary.
lgpexpr-class

An S4 class to represent an lgp expression
create_scaling

Create a standardizing transform
lgp

Main function of the 'lgpr' package
lgpscaling-class

An S4 class to represent variable scaling
lgprhs-class

An S4 class to represent the right-hand side of an lgp formula
get_pred

Extract model predictions and function posteriors
lgpterm-class

An S4 class to represent one formula term
kernel

Compute a kernel matrix (covariance matrix)
lgpsim-class

An S4 class to represent a data set simulated using the additive GP formalism
lgpformula-class

An S4 class to represent an lgp formula
prior_pred

Prior (predictive) sampling
prior_to_num

Convert given prior to numeric format
plot_data

Vizualizing longitudinal data
plot_pred

Visualizing model predictions or inferred covariate effects
plot_inputwarp

Visualize input warping function with several steepness parameter values
plot_api_c

Plot a generated/fit model component
operations

Operations on formula terms and expressions
lgpmodel-class

An S4 class to represent an additive GP model
lgpr-package

The 'lgpr' package.
plot_invgamma

Plot the inverse gamma-distribution pdf
plot_draws

Visualize the distribution of parameter draws
plot_sim

Visualize an lgpsim object (simulated data)
show

Printing formula object info using the show generic
get_draws

Extract parameter draws from lgpfit or stanfit
sim.create_f

Simulate latent function components for longitudinal data analysis
select

Select relevant components
sample_model

Fitting a model
read_proteomics_data

Function for reading the built-in proteomics data
priors

Prior definitions
model_summary

Print a model summary.
new_x

Create test input points for prediction
plot_api_g

Plot longitudinal data and/or model fit so that each subject/group has their own panel
relevances

Assess component relevances
plot_components

Visualize all model components
pred

Posterior predictions and function posteriors
sim.create_x

Create an input data frame X for simulated data
sim.create_y

Simulate noisy observations
ppc

Graphical posterior predictive checks
s4_generics

S4 generics for lgpfit, lgpmodel, and other objects
var_mask

Variance masking function
warp_input

Input warping function
validate

Validate S4 class objects
testdata_002

Medium-size artificial test data, used mostly for tutorials
testdata_001

A very small artificial test data, used mostly for unit tests
split

Split data into training and test sets
simulate_data

Generate an artificial longitudinal data set
sim.kernels

Compute all kernel matrices when simulating data
create_model

Create a model
Prediction-class

An S4 class to represent prior or posterior draws from an additive function distribution.
KernelComputer-class

An S4 class to represent input for kernel matrix computations
add_factor

Easily add a categorical covariate to a data frame
as_character

Character representations of different formula objects
GaussianPrediction-class

An S4 class to represent analytically computed predictive distributions (conditional on hyperparameters) of an additive GP model
add_factor_crossing

Add a crossing of two factors to a data frame
apply_scaling

Apply variable scaling
add_dis_age

Easily add the disease-related age variable to a data frame
adjusted_c_hat

Set the GP mean vector, taking TMM or other normalization into account
create_model.prior

Parse given prior
create_model.likelihood

Parse the response variable and its likelihood model
example_fit

Quick way to create an example lgpfit, useful for debugging
draw_pred

Draw pseudo-observations from posterior or prior predictive distribution
create_plot_df

Helper function for plots
dinvgamma_stanlike

Density and quantile functions of the inverse gamma distribution
create_model.options

Parse the given modeling options
create_model.formula

Create a model formula
create_model.covs_and_comps

Parse the covariates and model components from given data and formula